Skip to content

Commit

Permalink
fix: use binPaths
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wraithgar committed Aug 2, 2022
1 parent bf1b3cf commit 0a8ee24
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
12 changes: 6 additions & 6 deletions workspaces/libnpmexec/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const noTTY = require('./no-tty.js')
const runScript = require('./run-script.js')
const isWindows = require('./is-windows.js')

const { delimiter, dirname, resolve } = require('path')
const { dirname, resolve } = require('path')

const pathArr = process.env.PATH.split(delimiter)
const binPaths = []

// when checking the local tree we look up manifests, cache those results by
// spec.raw so we don't have to fetch again when we check npxCache
Expand Down Expand Up @@ -96,7 +96,7 @@ const exec = async (opts) => {
locationMsg,
output,
path,
pathArr,
binPaths,
runPath,
scriptShell,
})
Expand All @@ -113,10 +113,10 @@ const exec = async (opts) => {
const dir = dirname(dirname(localBin))
const localBinPath = await localFileExists(dir, args[0], '/')
if (localBinPath) {
// @npmcli/run-script adds local bin to $PATH itself
binPaths.push(localBinPath)
return await run()
} else if (await fileExists(`${globalBin}/${args[0]}`)) {
pathArr.unshift(globalBin)
binPaths.push(globalBin)
return await run()
}

Expand Down Expand Up @@ -213,7 +213,7 @@ const exec = async (opts) => {
add,
})
}
pathArr.unshift(resolve(installDir, 'node_modules/.bin'))
binPaths.push(resolve(installDir, 'node_modules/.bin'))
}

return await run()
Expand Down
8 changes: 2 additions & 6 deletions workspaces/libnpmexec/lib/run-script.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const { delimiter } = require('path')

const chalk = require('chalk')
const ciDetect = require('@npmcli/ci-detect')
const runScript = require('@npmcli/run-script')
Expand All @@ -22,7 +20,7 @@ const run = async ({
locationMsg,
output = () => {},
path,
pathArr,
binPaths,
runPath,
scriptShell,
}) => {
Expand Down Expand Up @@ -71,11 +69,9 @@ const run = async ({
// we always run in cwd, not --prefix
path: runPath,
stdioString: true,
binPaths,
event: 'npx',
args,
env: {
PATH: pathArr.join(delimiter),
},
stdio: 'inherit',
})
} finally {
Expand Down
1 change: 0 additions & 1 deletion workspaces/libnpmexec/test/run-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const baseOpts = {
call: '',
color: false,
path: '',
pathArr: [''],
runPath: '',
shell: process.platform === 'win32'
? process.env.ComSpec || 'cmd'
Expand Down

0 comments on commit 0a8ee24

Please sign in to comment.