aboutsummaryrefslogtreecommitdiff
path: root/sandbox/testAppNevena/Front/node_modules/@npmcli/run-script/lib/set-path.js
diff options
context:
space:
mode:
authorDanijel Andjelkovic <adanijel99@gmail.com>2022-03-01 20:21:29 +0000
committerDanijel Andjelkovic <adanijel99@gmail.com>2022-03-01 20:21:29 +0000
commit61cb1570a3410c85a4489b97c172e3a50715f36c (patch)
tree8fe4a5b77ea54bba80abc817ce2c9ef0e79e7e66 /sandbox/testAppNevena/Front/node_modules/@npmcli/run-script/lib/set-path.js
parent21a53d349788c99d2007cba91a923db982353b31 (diff)
parenta9ee9e0a500a4a15bd0b5dcaf041f827228ed309 (diff)
Merge branch 'researchML' into 'dev'
Research ml See merge request igrannonica/neuronstellar!6
Diffstat (limited to 'sandbox/testAppNevena/Front/node_modules/@npmcli/run-script/lib/set-path.js')
-rw-r--r--sandbox/testAppNevena/Front/node_modules/@npmcli/run-script/lib/set-path.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/sandbox/testAppNevena/Front/node_modules/@npmcli/run-script/lib/set-path.js b/sandbox/testAppNevena/Front/node_modules/@npmcli/run-script/lib/set-path.js
new file mode 100644
index 00000000..d7bd2c28
--- /dev/null
+++ b/sandbox/testAppNevena/Front/node_modules/@npmcli/run-script/lib/set-path.js
@@ -0,0 +1,44 @@
+const {resolve, dirname} = require('path')
+const isWindows = require('./is-windows.js')
+// the path here is relative, even though it does not need to be
+// in order to make the posix tests pass in windows
+const nodeGypPath = resolve(__dirname, '../lib/node-gyp-bin')
+
+// Windows typically calls its PATH environ 'Path', but this is not
+// guaranteed, nor is it guaranteed to be the only one. Merge them
+// all together in the order they appear in the object.
+const setPATH = (projectPath, env) => {
+ // not require('path').delimiter, because we fake this for testing
+ const delimiter = isWindows ? ';' : ':'
+ const PATH = Object.keys(env).filter(p => /^path$/i.test(p) && env[p])
+ .map(p => env[p].split(delimiter))
+ .reduce((set, p) => set.concat(p.filter(p => !set.includes(p))), [])
+ .join(delimiter)
+
+ const pathArr = []
+ // unshift the ./node_modules/.bin from every folder
+ // walk up until dirname() does nothing, at the root
+ // XXX should we specify a cwd that we don't go above?
+ let p = projectPath
+ let pp
+ do {
+ pathArr.push(resolve(p, 'node_modules', '.bin'))
+ pp = p
+ p = dirname(p)
+ } while (p !== pp)
+ pathArr.push(nodeGypPath, PATH)
+
+ const pathVal = pathArr.join(delimiter)
+
+ // XXX include the node-gyp-bin path somehow? Probably better for
+ // npm or arborist or whoever to just provide that by putting it in
+ // the PATH environ, since that's preserved anyway.
+ for (const key of Object.keys(env)) {
+ if (/^path$/i.test(key))
+ env[key] = pathVal
+ }
+
+ return env
+}
+
+module.exports = setPATH