Skip to content

Commit

Permalink
fix(exec): ignore packageLockOnly flag
Browse files Browse the repository at this point in the history
  • Loading branch information
nlf committed May 3, 2022
1 parent 21b823e commit 8ebaea8
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/commands/exec.js
Expand Up @@ -73,6 +73,9 @@ class Exec extends BaseCommand {

return libexec({
...flatOptions,
// we explicitly set packageLockOnly to false because if it's true
// when we try to install a missing package, we won't actually install it
packageLockOnly: false,
args,
call,
localBin,
Expand Down
58 changes: 58 additions & 0 deletions test/lib/commands/exec.js
Expand Up @@ -385,6 +385,64 @@ 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,
packageLockOnly: false,
}])
t.match(ARB_REIFY, [{
add: ['foo@'],
legacyPeerDeps: 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 8ebaea8

Please sign in to comment.