Skip to content

Commit 903b695

Browse files
wraithgarlukekarrys
authored andcommitted
fix(npx): properly look for local bins when there are more than one
1 parent 221ed4f commit 903b695

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

workspaces/libnpmexec/lib/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ const exec = async (opts) => {
110110
return run()
111111
}
112112

113-
const needPackageCommandSwap = (args.length > 0) && (packages.length === 0)
113+
let needPackageCommandSwap = (args.length > 0) && (packages.length === 0)
114114
// If they asked for a command w/o specifying a package, see if there is a
115115
// bin that directly matches that name:
116116
// - in the local package itself
@@ -126,9 +126,11 @@ const exec = async (opts) => {
126126
if (localManifest?.bin?.[args[0]]) {
127127
// we have to install the local package into the npx cache so that its
128128
// bin links get set up
129+
flatOptions.installLinks = false
130+
// args[0] will exist when the package is installed
129131
packages.push(path)
130132
yes = true
131-
flatOptions.installLinks = false
133+
needPackageCommandSwap = false
132134
} else {
133135
const dir = dirname(dirname(localBin))
134136
const localBinPath = await localFileExists(dir, args[0], '/')

workspaces/libnpmexec/test/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ t.test('bin in local pkg', async t => {
2828
const pkg = {
2929
name: '@npmcli/local-pkg-bin-test',
3030
bin: {
31+
b: 'echo this is something else',
3132
a: 'local-bin-test.js',
3233
},
3334
}

0 commit comments

Comments
 (0)