diff options
author | nlf <quitlahok@gmail.com> | 2022-05-03 23:53:10 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-03 23:53:10 +0300 |
commit | b9a966cf33cfa9b1e5f16c16219f63633bbe19d6 (patch) | |
tree | 99f5dc1090bcf688e4601f1ecbb697b4ec48a85d | |
parent | 62af3a1dc003cf23c563d18437be81f61e65cb49 (diff) |
fix(exec): ignore packageLockOnly flag (#4843)
-rw-r--r-- | lib/commands/exec.js | 3 | ||||
-rw-r--r-- | test/lib/commands/exec.js | 58 |
2 files changed, 61 insertions, 0 deletions
diff --git a/lib/commands/exec.js b/lib/commands/exec.js index f764cea52..d9a686cc9 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 d6e598d56..1117885b9 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') |