@@ -86,14 +86,15 @@ const {
8686const isWindows = process . platform === 'win32' ;
8787
8888let requireDepth = 0 ;
89- let statCache = new Map ( ) ;
89+ let statCache = null ;
9090function stat ( filename ) {
9191 filename = path . toNamespacedPath ( filename ) ;
92- if ( statCache === null ) statCache = new Map ( ) ;
93- let result = statCache . get ( filename ) ;
94- if ( result !== undefined ) return result ;
95- result = internalModuleStat ( filename ) ;
96- statCache . set ( filename , result ) ;
92+ if ( statCache !== null ) {
93+ const result = statCache . get ( filename ) ;
94+ if ( result !== undefined ) return result ;
95+ }
96+ const result = internalModuleStat ( filename ) ;
97+ if ( statCache !== null ) statCache . set ( filename , result ) ;
9798 return result ;
9899}
99100
@@ -196,7 +197,7 @@ Module._debug = deprecate(debug, 'Module._debug is deprecated.', 'DEP0077');
196197// -> a.<ext>
197198// -> a/index.<ext>
198199
199- // check if the directory is a package.json dir
200+ // Check if the directory is a package.json dir.
200201const packageMainCache = Object . create ( null ) ;
201202
202203function readPackage ( requestPath ) {
@@ -830,6 +831,7 @@ Module.prototype._compile = function(content, filename) {
830831 const exports = this . exports ;
831832 const thisValue = exports ;
832833 const module = this ;
834+ if ( requireDepth === 0 ) statCache = new Map ( ) ;
833835 if ( inspectorWrapper ) {
834836 result = inspectorWrapper ( compiledWrapper , thisValue , exports ,
835837 require , module , filename , dirname ) ;
0 commit comments