From b9a966cf33cfa9b1e5f16c16219f63633bbe19d6 Mon Sep 17 00:00:00 2001 From: nlf Date: Tue, 3 May 2022 13:53:10 -0700 Subject: [PATCH] fix(exec): ignore packageLockOnly flag (#4843) --- lib/commands/exec.js | 3 ++ test/lib/commands/exec.js | 58 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/lib/commands/exec.js b/lib/commands/exec.js index f764cea528adb..d9a686cc9a3be 100644 --- a/lib/commands/exec.js +++ b/lib/commands/exec.js @@ -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, diff --git a/test/lib/commands/exec.js b/test/lib/commands/exec.js index d6e598d568d5b..1117885b91731 100644 --- a/test/lib/commands/exec.js +++ b/test/lib/commands/exec.js @@ -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')