Skip to content

Commit b9a966c

Browse files
authored
fix(exec): ignore packageLockOnly flag (#4843)
1 parent 62af3a1 commit b9a966c

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

lib/commands/exec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ class Exec extends BaseCommand {
7373

7474
return libexec({
7575
...flatOptions,
76+
// we explicitly set packageLockOnly to false because if it's true
77+
// when we try to install a missing package, we won't actually install it
78+
packageLockOnly: false,
7679
args,
7780
call,
7881
localBin,

test/lib/commands/exec.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,64 @@ t.test('npm exec foo, not present locally or in central loc', async t => {
385385
])
386386
})
387387

388+
t.test('npm exec foo, packageLockOnly set to true', async t => {
389+
const path = t.testdir()
390+
const installDir = resolve('npx-cache-dir/f7fbba6e0636f890')
391+
npm.localPrefix = path
392+
npm.config.set('package-lock-only', true)
393+
t.teardown(() => {
394+
npm.config.set('package-lock-only', false)
395+
})
396+
397+
ARB_ACTUAL_TREE[path] = {
398+
inventory: {
399+
query () {
400+
return new Set()
401+
},
402+
},
403+
}
404+
ARB_ACTUAL_TREE[installDir] = {
405+
inventory: {
406+
query () {
407+
return new Set()
408+
},
409+
},
410+
}
411+
MANIFESTS.foo = {
412+
name: 'foo',
413+
version: '1.2.3',
414+
bin: {
415+
foo: 'foo',
416+
},
417+
_from: 'foo@',
418+
}
419+
await exec.exec(['foo', 'one arg', 'two arg'])
420+
t.strictSame(MKDIRPS, [installDir], 'need to make install dir')
421+
t.match(ARB_CTOR, [{
422+
path,
423+
packageLockOnly: false,
424+
}])
425+
t.match(ARB_REIFY, [{
426+
add: ['foo@'],
427+
legacyPeerDeps: false,
428+
packageLockOnly: false,
429+
}], 'need to install foo@')
430+
t.equal(PROGRESS_ENABLED, true, 'progress re-enabled')
431+
const PATH = `${resolve(installDir, 'node_modules', '.bin')}${delimiter}${process.env.PATH}`
432+
t.match(RUN_SCRIPTS, [
433+
{
434+
pkg: { scripts: { npx: 'foo' } },
435+
args: ['one arg', 'two arg'],
436+
banner: false,
437+
path: process.cwd(),
438+
stdioString: true,
439+
event: 'npx',
440+
env: { PATH },
441+
stdio: 'inherit',
442+
},
443+
])
444+
})
445+
388446
t.test('npm exec foo, not present locally but in central loc', async t => {
389447
const path = t.testdir()
390448
const installDir = resolve('npx-cache-dir/f7fbba6e0636f890')

0 commit comments

Comments
 (0)