diff --git a/workspaces/libnpmexec/lib/index.js b/workspaces/libnpmexec/lib/index.js index 4d7c126654689..2e2679877ea82 100644 --- a/workspaces/libnpmexec/lib/index.js +++ b/workspaces/libnpmexec/lib/index.js @@ -264,6 +264,7 @@ const exec = async (opts) => { const npxArb = new Arborist({ ...flatOptions, path: installDir, + global: false, }) const lockPath = join(installDir, 'concurrency.lock') const npxTree = await withLock(lockPath, () => npxArb.loadActual()) diff --git a/workspaces/libnpmexec/test/registry.js b/workspaces/libnpmexec/test/registry.js index adbf4116107b4..d1c2489b6f3d8 100644 --- a/workspaces/libnpmexec/test/registry.js +++ b/workspaces/libnpmexec/test/registry.js @@ -328,3 +328,34 @@ t.test('override save to true when installing to npx cache', async t => { value: 'packages-2.0.0', }) }) + +t.test('ignore inherited global config when installing to npx cache', async t => { + const { fixtures, package } = createPkg({ versions: ['2.0.0'] }) + + const hash = crypto.createHash('sha512') + .update('@npmcli/create-index') + .digest('hex') + .slice(0, 16) + + const { exec, path, registry, readOutput } = setup(t, { + testdir: merge(fixtures, { + global: {}, + }), + }) + + await package({ registry, path }) + + await exec({ + args: ['@npmcli/create-index'], + globalPath: resolve(path, 'global'), + global: true, + }) + + const binPath = resolve(path, 'npxCache', hash, 'node_modules', '.bin') + t.ok(existsSync(binPath), 'bins should be linked at npxCache') + t.notOk(existsSync(resolve(path, 'npxCache', 'bin')), 'bins should not be linked globally') + + t.match(await readOutput('@npmcli-create-index'), { + value: 'packages-2.0.0', + }) +})