Skip to content

Commit 386f328

Browse files
authored
fix(npx): always save true when installing to npx cache (#8154)
Override config `save` to always be `true` when installing to the npx cache. fixes: #8151
1 parent 2f5392a commit 386f328

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

workspaces/libnpmexec/lib/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ const exec = async (opts) => {
292292
}
293293
await npxArb.reify({
294294
...flatOptions,
295+
save: true,
295296
add,
296297
})
297298
}

workspaces/libnpmexec/test/registry.js

+31
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const { resolve } = require('node:path')
22
const t = require('tap')
33
const { setup, createPkg, merge } = require('./fixtures/setup.js')
44
const crypto = require('node:crypto')
5+
const { existsSync } = require('node:fs')
56

67
t.test('run from registry - no local packages', async t => {
78
const { fixtures, package } = createPkg({ versions: ['2.0.0'] })
@@ -297,3 +298,33 @@ t.test('npx tree triggers manifest fetch when local version does satisfy range u
297298
value: 'packages-2.0.1',
298299
})
299300
})
301+
302+
t.test('override save to true when installing to npx cache', async t => {
303+
const { fixtures, package } = createPkg({ versions: ['2.0.0'] })
304+
305+
const hash = crypto.createHash('sha512')
306+
.update('@npmcli/create-index')
307+
.digest('hex')
308+
.slice(0, 16)
309+
310+
const { exec, path, registry, readOutput } = setup(t, {
311+
testdir: merge(fixtures, {
312+
global: {},
313+
}),
314+
})
315+
316+
await package({ registry, path })
317+
318+
await exec({
319+
args: ['@npmcli/create-index'],
320+
globalPath: resolve(path, 'global'),
321+
save: false,
322+
})
323+
324+
const packageJsonPath = resolve(path, 'npxCache', hash, 'package.json')
325+
t.ok(existsSync(packageJsonPath), 'package.json should exist at npmCache')
326+
327+
t.match(await readOutput('@npmcli-create-index'), {
328+
value: 'packages-2.0.0',
329+
})
330+
})

0 commit comments

Comments
 (0)