Skip to content

Commit 2f2916b

Browse files
committed
fix(exec): ignore packageLock and packageLockOnly flags
1 parent 21b823e commit 2f2916b

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

lib/commands/exec.js

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

7474
return libexec({
7575
...flatOptions,
76+
// we explicitly set packageLock and packageLockOnly to false because
77+
// they don't make any sense in this context and if we have to reify
78+
// a missing package they could break things
79+
packageLock: false,
80+
packageLockOnly: false,
7681
args,
7782
call,
7883
localBin,

test/lib/commands/exec.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,66 @@ 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+
packageLock: false,
424+
packageLockOnly: false,
425+
}])
426+
t.match(ARB_REIFY, [{
427+
add: ['foo@'],
428+
legacyPeerDeps: false,
429+
packageLock: false,
430+
packageLockOnly: false,
431+
}], 'need to install foo@')
432+
t.equal(PROGRESS_ENABLED, true, 'progress re-enabled')
433+
const PATH = `${resolve(installDir, 'node_modules', '.bin')}${delimiter}${process.env.PATH}`
434+
t.match(RUN_SCRIPTS, [
435+
{
436+
pkg: { scripts: { npx: 'foo' } },
437+
args: ['one arg', 'two arg'],
438+
banner: false,
439+
path: process.cwd(),
440+
stdioString: true,
441+
event: 'npx',
442+
env: { PATH },
443+
stdio: 'inherit',
444+
},
445+
])
446+
})
447+
388448
t.test('npm exec foo, not present locally but in central loc', async t => {
389449
const path = t.testdir()
390450
const installDir = resolve('npx-cache-dir/f7fbba6e0636f890')

0 commit comments

Comments
 (0)