aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2019-03-26 16:28:53 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2019-04-03 14:19:59 +0200
commit8a6dcd040f35b023f0cc0208c4bc553fcc7e6a4d (patch)
treea215f2585681499ebae520d287675215cbc2763e /lib
parent1087805eebcebfb17537455816eb155ea9c46672 (diff)
downloadandroid-node-v8-8a6dcd040f35b023f0cc0208c4bc553fcc7e6a4d.tar.gz
android-node-v8-8a6dcd040f35b023f0cc0208c4bc553fcc7e6a4d.tar.bz2
android-node-v8-8a6dcd040f35b023f0cc0208c4bc553fcc7e6a4d.zip
module: fix repl require calling the same file again
This makes sure multiple require calls will not fail in case a file was created after the first attempt. PR-URL: https://github.com/nodejs/node/pull/26928 Fixes: https://github.com/nodejs/node/issues/26926 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Jan Krems <jan.krems@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/modules/cjs/loader.js16
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js
index 2f06d35546..e03cece3ad 100644
--- a/lib/internal/modules/cjs/loader.js
+++ b/lib/internal/modules/cjs/loader.js
@@ -78,14 +78,15 @@ const {
const isWindows = process.platform === 'win32';
let requireDepth = 0;
-let statCache = new Map();
+let statCache = null;
function stat(filename) {
filename = path.toNamespacedPath(filename);
- if (statCache === null) statCache = new Map();
- let result = statCache.get(filename);
- if (result !== undefined) return result;
- result = internalModuleStat(filename);
- statCache.set(filename, result);
+ if (statCache !== null) {
+ const result = statCache.get(filename);
+ if (result !== undefined) return result;
+ }
+ const result = internalModuleStat(filename);
+ if (statCache !== null) statCache.set(filename, result);
return result;
}
@@ -188,7 +189,7 @@ Module._debug = deprecate(debug, 'Module._debug is deprecated.', 'DEP0077');
// -> a.<ext>
// -> a/index.<ext>
-// check if the directory is a package.json dir
+// Check if the directory is a package.json dir.
const packageMainCache = Object.create(null);
function readPackage(requestPath) {
@@ -794,6 +795,7 @@ Module.prototype._compile = function(content, filename) {
const exports = this.exports;
const thisValue = exports;
const module = this;
+ if (requireDepth === 0) statCache = new Map();
if (inspectorWrapper) {
result = inspectorWrapper(compiledWrapper, thisValue, exports,
require, module, filename, dirname);