Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(exec): ignore packageLockOnly flag #4843

Merged
merged 1 commit into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/commands/exec.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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