Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created July 22, 2019 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacs/5ab2523ec09488dcb11b86968050b9f3 to your computer and use it in GitHub Desktop.
Save isaacs/5ab2523ec09488dcb11b86968050b9f3 to your computer and use it in GitHub Desktop.
diff --git a/index.js b/index.js
index b2a25ee..b34ae25 100644
--- a/index.js
+++ b/index.js
@@ -21,19 +21,14 @@ const resolveFrom = require('resolve-from')
const DEFAULT_NODE_GYP_PATH = resolveFrom(__dirname, 'node-gyp/bin/node-gyp')
const hookStatCache = new Map()
-let PATH = 'PATH'
+let PATH = isWindows ? 'Path' : 'PATH'
// windows calls its path 'Path' usually, but this is not guaranteed.
-if (isWindows) {
- PATH = 'Path'
- if (!process.env[PATH]) {
- Object.keys(process.env).forEach(function (e) {
- if (e.match(/^PATH$/i)) {
- PATH = e
- }
- })
- }
-}
+// merge them all together in the order they appear in the object.
+const mergePath = env =>
+ Object.keys(env).filter(p => /^path$/i.test(p) && env[p])
+ .map(p => env[p])
+ .join(';')
exports._pathEnvName = PATH
@@ -127,7 +122,8 @@ function lifecycle_ (pkg, stage, wd, opts, env, cb) {
pathArr.push(path.dirname(process.execPath))
}
- if (env[PATH]) pathArr.push(env[PATH])
+ const envPath = mergePath(env)
+ if (envPath) pathArr.push(envPath)
env[PATH] = pathArr.join(isWindows ? ';' : ':')
var packageLifecycle = pkg.scripts && pkg.scripts.hasOwnProperty(stage)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment