Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions workspaces/libnpmexec/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,19 @@ const exec = async (opts) => {
args[0] = getBinFromManifest(commandManifest)

if (needInstall.length > 0 && globalPath) {
// See if the package is installed globally, and run the translated bin
// See if the package is installed globally. If it is, run the translated bin
const globalArb = new Arborist({ ...flatOptions, path: globalPath, global: true })
const globalTree = await globalArb.loadActual()
const { manifest: globalManifest } =
await missingFromTree({ spec, tree: globalTree, flatOptions, shallow: true })
if (!globalManifest && await fileExists(`${globalBin}/${args[0]}`)) {
binPaths.push(globalBin)
return await run()
const globalTree = await globalArb.loadActual().catch(() => {
log.verbose(`Could not read global path ${globalPath}, ignoring`)
return null
})
if (globalTree) {
const { manifest: globalManifest } =
await missingFromTree({ spec, tree: globalTree, flatOptions, shallow: true })
if (!globalManifest && await fileExists(`${globalBin}/${args[0]}`)) {
binPaths.push(globalBin)
return await run()
}
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions workspaces/libnpmexec/test/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,22 @@ t.test('packages with different versions in the global tree', async t => {
created: 'global/node_modules/@npmcli/A/bin-file.js',
})
})

t.test('run from registry - non existant global path', async t => {
const { fixtures, package } = createPkg({ versions: ['2.0.0'] })

const { exec, path, registry, readOutput } = setup(t, {
testdir: fixtures,
})

await package({ registry, path })

await exec({
args: ['@npmcli/create-index'],
globalPath: resolve(path, 'non-existant'),
})

t.match(await readOutput('@npmcli-create-index'), {
value: 'packages-2.0.0',
})
})