diff --git a/lib/common/reset-search-paths.js b/lib/common/reset-search-paths.js index c53364a2a14f..bdd2125d5b4c 100644 --- a/lib/common/reset-search-paths.js +++ b/lib/common/reset-search-paths.js @@ -6,27 +6,26 @@ Module.globalPaths.length = 0 // Clear current and parent(init.js)'s search paths. module.paths = [] - module.parent.paths = [] // Prevent Node from adding paths outside this app to search paths. Module._nodeModulePaths = function (from) { - var dir, i, part, parts, paths, skipOutsidePaths, splitRe, tip from = path.resolve(from) // If "from" is outside the app then we do nothing. - skipOutsidePaths = from.startsWith(process.resourcesPath) + const skipOutsidePaths = from.startsWith(process.resourcesPath) // Following logic is copied from module.js. - splitRe = process.platform === 'win32' ? /[\/\\]/ : /\// - paths = [] - parts = from.split(splitRe) - for (tip = i = parts.length - 1; i >= 0; tip = i += -1) { - part = parts[tip] + const splitRe = process.platform === 'win32' ? /[\/\\]/ : /\// + const paths = [] + const parts = from.split(splitRe) + + for (let tip = i = parts.length - 1; i >= 0; tip = i += -1) { + const part = parts[tip] if (part === 'node_modules') { continue } - dir = parts.slice(0, tip + 1).join(path.sep) + const dir = parts.slice(0, tip + 1).join(path.sep) if (skipOutsidePaths && !dir.startsWith(process.resourcesPath)) { break }