Skip to content

Commit

Permalink
fix(exec): ignore packageLock and packageLockOnly flags
Browse files Browse the repository at this point in the history
  • Loading branch information
nlf committed May 3, 2022
1 parent 21b823e commit 2f2916b
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/commands/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ class Exec extends BaseCommand {

return libexec({
...flatOptions,
// we explicitly set packageLock and packageLockOnly to false because
// they don't make any sense in this context and if we have to reify
// a missing package they could break things
packageLock: false,
packageLockOnly: false,
args,
call,
localBin,
Expand Down
60 changes: 60 additions & 0 deletions test/lib/commands/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,66 @@ t.test('npm exec foo, not present locally or in central loc', async t => {
])
})

t.test('npm exec foo, packageLockOnly set to true', async t => {
const path = t.testdir()
const installDir = resolve('npx-cache-dir/f7fbba6e0636f890')
npm.localPrefix = path
npm.config.set('package-lock-only', true)
t.teardown(() => {
npm.config.set('package-lock-only', false)
})

ARB_ACTUAL_TREE[path] = {
inventory: {
query () {
return new Set()
},
},
}
ARB_ACTUAL_TREE[installDir] = {
inventory: {
query () {
return new Set()
},
},
}
MANIFESTS.foo = {
name: 'foo',
version: '1.2.3',
bin: {
foo: 'foo',
},
_from: 'foo@',
}
await exec.exec(['foo', 'one arg', 'two arg'])
t.strictSame(MKDIRPS, [installDir], 'need to make install dir')
t.match(ARB_CTOR, [{
path,
packageLock: false,
packageLockOnly: false,
}])
t.match(ARB_REIFY, [{
add: ['foo@'],
legacyPeerDeps: false,
packageLock: false,
packageLockOnly: false,
}], 'need to install foo@')
t.equal(PROGRESS_ENABLED, true, 'progress re-enabled')
const PATH = `${resolve(installDir, 'node_modules', '.bin')}${delimiter}${process.env.PATH}`
t.match(RUN_SCRIPTS, [
{
pkg: { scripts: { npx: 'foo' } },
args: ['one arg', 'two arg'],
banner: false,
path: process.cwd(),
stdioString: true,
event: 'npx',
env: { PATH },
stdio: 'inherit',
},
])
})

t.test('npm exec foo, not present locally but in central loc', async t => {
const path = t.testdir()
const installDir = resolve('npx-cache-dir/f7fbba6e0636f890')
Expand Down

0 comments on commit 2f2916b

Please sign in to comment.