Skip to content

Commit 19f1497

Browse files
wraithgarnlf
authored andcommitted
fix: use binPaths
This will allow for a locally installed package to differ from the one requested on the command line, the one requested will now actually run.
1 parent ea44995 commit 19f1497

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

workspaces/libnpmexec/lib/index.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ const noTTY = require('./no-tty.js')
1919
const runScript = require('./run-script.js')
2020
const isWindows = require('./is-windows.js')
2121

22-
const { delimiter, dirname, resolve } = require('path')
22+
const { dirname, resolve } = require('path')
2323

24-
const pathArr = process.env.PATH.split(delimiter)
24+
const binPaths = []
2525

2626
// when checking the local tree we look up manifests, cache those results by
2727
// spec.raw so we don't have to fetch again when we check npxCache
@@ -96,7 +96,7 @@ const exec = async (opts) => {
9696
locationMsg,
9797
output,
9898
path,
99-
pathArr,
99+
binPaths,
100100
runPath,
101101
scriptShell,
102102
})
@@ -113,10 +113,10 @@ const exec = async (opts) => {
113113
const dir = dirname(dirname(localBin))
114114
const localBinPath = await localFileExists(dir, args[0], '/')
115115
if (localBinPath) {
116-
// @npmcli/run-script adds local bin to $PATH itself
116+
binPaths.push(localBinPath)
117117
return await run()
118118
} else if (await fileExists(`${globalBin}/${args[0]}`)) {
119-
pathArr.unshift(globalBin)
119+
binPaths.push(globalBin)
120120
return await run()
121121
}
122122

@@ -213,7 +213,7 @@ const exec = async (opts) => {
213213
add,
214214
})
215215
}
216-
pathArr.unshift(resolve(installDir, 'node_modules/.bin'))
216+
binPaths.push(resolve(installDir, 'node_modules/.bin'))
217217
}
218218

219219
return await run()

workspaces/libnpmexec/lib/run-script.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const { delimiter } = require('path')
2-
31
const chalk = require('chalk')
42
const ciDetect = require('@npmcli/ci-detect')
53
const runScript = require('@npmcli/run-script')
@@ -22,7 +20,7 @@ const run = async ({
2220
locationMsg,
2321
output = () => {},
2422
path,
25-
pathArr,
23+
binPaths,
2624
runPath,
2725
scriptShell,
2826
}) => {
@@ -71,11 +69,9 @@ const run = async ({
7169
// we always run in cwd, not --prefix
7270
path: runPath,
7371
stdioString: true,
72+
binPaths,
7473
event: 'npx',
7574
args,
76-
env: {
77-
PATH: pathArr.join(delimiter),
78-
},
7975
stdio: 'inherit',
8076
})
8177
} finally {

workspaces/libnpmexec/test/run-script.js

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const baseOpts = {
55
call: '',
66
color: false,
77
path: '',
8-
pathArr: [''],
98
runPath: '',
109
shell: process.platform === 'win32'
1110
? process.env.ComSpec || 'cmd'

0 commit comments

Comments
 (0)