From bac4d51169b5b8167e90b60bd8107324de459186 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 23 Jun 2016 15:56:29 -0700 Subject: [PATCH] Reuse root path variable --- lib/common/reset-search-paths.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/common/reset-search-paths.js b/lib/common/reset-search-paths.js index 5cec77b606aa..924cb388d4d9 100644 --- a/lib/common/reset-search-paths.js +++ b/lib/common/reset-search-paths.js @@ -9,21 +9,19 @@ module.paths = [] module.parent.paths = [] // Prevent Node from adding paths outside this app to search paths. +const resourcesPathWithTrailingSlash = process.resourcesPath + path.sep const originalNodeModulePaths = Module._nodeModulePaths Module._nodeModulePaths = function (from) { const paths = originalNodeModulePaths(from) - - // If "from" is outside the app then we do nothing. - const rootPath = process.resourcesPath + path.sep const fromPath = path.resolve(from) + path.sep - const skipOutsidePaths = fromPath.startsWith(rootPath) - if (skipOutsidePaths) { + // If "from" is outside the app then we do nothing. + if (fromPath.startsWith(resourcesPathWithTrailingSlash)) { return paths.filter(function (candidate) { - return candidate.startsWith(rootPath) + return candidate.startsWith(resourcesPathWithTrailingSlash) }) + } else { + return paths } - - return paths } // Patch Module._resolveFilename to always require the Electron API when