diff --git a/tools/files.js b/tools/files.js index 2e7a5cda58..c168255901 100644 --- a/tools/files.js +++ b/tools/files.js @@ -194,6 +194,10 @@ files.getDevBundle = function () { return files.pathJoin(files.getCurrentToolsDir(), 'dev_bundle'); }; +files.getCurrentNodeBinDir = function () { + return files.pathJoin(files.getDevBundle(), "bin"); +} + // Return the top-level directory for this meteor install or checkout files.getCurrentToolsDir = function () { var dirname = files.convertToStandardPath(__dirname); @@ -1173,6 +1177,17 @@ files.getHomeDir = function () { } }; +files.currentEnvWithPathsAdded = function (...paths) { + const env = {...process.env}; + + const convertedPaths = paths.map(path => files.convertToOSPath(path)); + let pathDecomposed = (env.PATH || "").split(files.pathOsDelimiter); + pathDecomposed.unshift(...convertedPaths); + + env.PATH = pathDecomposed.join(files.pathOsDelimiter); + return env; +} + // add .bat extension to link file if not present var ensureBatExtension = function (p) { if (p.indexOf(".bat") !== p.length - 4) { diff --git a/tools/isobuild/meteor-npm.js b/tools/isobuild/meteor-npm.js index a515765d6b..db4704b2a4 100644 --- a/tools/isobuild/meteor-npm.js +++ b/tools/isobuild/meteor-npm.js @@ -338,17 +338,13 @@ var currentNodeCompatibilityVersion = function () { }; var runNpmCommand = function (args, cwd) { + const nodeBinDir = files.getCurrentNodeBinDir(); var npmPath; - var nodeBinDir; if (os.platform() === "win32") { - npmPath = files.convertToOSPath( - files.pathJoin(files.getDevBundle(), "bin", "npm.cmd")); - nodeBinDir = files.convertToOSPath( - files.pathJoin(files.getDevBundle(), "bin")); + npmPath = files.pathJoin(nodeBinDir, "npm.cmd"); } else { - npmPath = files.pathJoin(files.getDevBundle(), "bin", "npm"); - nodeBinDir = files.pathJoin(files.getDevBundle(), "bin"); + npmPath = files.pathJoin(nodeBinDir, "npm"); } if (meteorNpm._printNpmCalls) // only used by test-bundler.js @@ -358,7 +354,6 @@ var runNpmCommand = function (args, cwd) { if (cwd) cwd = files.convertToOSPath(cwd); - var env = process.env; // It looks like some npm commands (such as build commands, specifically on // Windows) rely on having a global node binary present. // Sometimes users have a global node installed, so it is not @@ -367,9 +362,8 @@ var runNpmCommand = function (args, cwd) { // containing the node binary we are running in right now as the highest // priority. // This hack is confusing as npm is supposed to do it already. - var pathDecomposed = (env.PATH || "").split(files.pathOsDelimiter); - pathDecomposed.unshift(nodeBinDir); - env.PATH = pathDecomposed.join(files.pathOsDelimiter); + const env = files.currentEnvWithPathsAdded(nodeBinDir); + var opts = { cwd: cwd, env: env, maxBuffer: 10 * 1024 * 1024 }; var future = new Future; @@ -648,4 +642,3 @@ var logUpdateDependencies = function (packageName, npmDependencies) { }; exports.runNpmCommand = runNpmCommand; -