@@ -86,14 +86,15 @@ const {
86
86
const isWindows = process . platform === 'win32' ;
87
87
88
88
let requireDepth = 0 ;
89
- let statCache = new Map ( ) ;
89
+ let statCache = null ;
90
90
function stat ( filename ) {
91
91
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 ) ;
97
98
return result ;
98
99
}
99
100
@@ -196,7 +197,7 @@ Module._debug = deprecate(debug, 'Module._debug is deprecated.', 'DEP0077');
196
197
// -> a.<ext>
197
198
// -> a/index.<ext>
198
199
199
- // check if the directory is a package.json dir
200
+ // Check if the directory is a package.json dir.
200
201
const packageMainCache = Object . create ( null ) ;
201
202
202
203
function readPackage ( requestPath ) {
@@ -830,6 +831,7 @@ Module.prototype._compile = function(content, filename) {
830
831
const exports = this . exports ;
831
832
const thisValue = exports ;
832
833
const module = this ;
834
+ if ( requireDepth === 0 ) statCache = new Map ( ) ;
833
835
if ( inspectorWrapper ) {
834
836
result = inspectorWrapper ( compiledWrapper , thisValue , exports ,
835
837
require , module , filename , dirname ) ;
0 commit comments