From c060e60a7ce767f6fdb32782c0d373e717df7856 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Wed, 24 Apr 2024 16:15:51 -0700 Subject: [PATCH] fix: return command and argv from load --- lib/cli/entry.js | 5 +---- lib/npm.js | 2 ++ test/fixtures/mock-npm.js | 6 +++++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/cli/entry.js b/lib/cli/entry.js index fc196b8e234fc..5d676c3f0a8a1 100644 --- a/lib/cli/entry.js +++ b/lib/cli/entry.js @@ -39,15 +39,12 @@ module.exports = async (process, validateEngines) => { // Now actually fire up npm and run the command. // This is how to use npm programmatically: try { - const { exec } = await npm.load() + const { exec, command, args } = await npm.load() if (!exec) { return exitHandler() } - const command = npm.argv.shift() - const args = npm.argv - if (!command) { output.standard(npm.usage) process.exitCode = 1 diff --git a/lib/npm.js b/lib/npm.js index 54bb4f9a47b0a..eb715fa803508 100644 --- a/lib/npm.js +++ b/lib/npm.js @@ -97,6 +97,8 @@ class Npm { const { exec = true } = await this.#load().then(r => r ?? {}) return { exec, + command: this.argv.shift(), + args: this.argv, } }) } diff --git a/test/fixtures/mock-npm.js b/test/fixtures/mock-npm.js index 6fd94b8f0e038..d8a4834a9abff 100644 --- a/test/fixtures/mock-npm.js +++ b/test/fixtures/mock-npm.js @@ -241,7 +241,11 @@ const setupMockNpm = async (t, { init, load, mocks: withDirs(mocks), - npm: { argv, excludeNpmCwd: true, ...withDirs(npmOpts) }, + npm: { + argv: command ? [command, ...argv] : argv, + excludeNpmCwd: true, + ...withDirs(npmOpts), + }, }) if (config.omit?.includes('prod')) {