Skip to content

Commit c060e60

Browse files
committedApr 25, 2024
fix: return command and argv from load
1 parent 180b919 commit c060e60

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed
 

‎lib/cli/entry.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,12 @@ module.exports = async (process, validateEngines) => {
3939
// Now actually fire up npm and run the command.
4040
// This is how to use npm programmatically:
4141
try {
42-
const { exec } = await npm.load()
42+
const { exec, command, args } = await npm.load()
4343

4444
if (!exec) {
4545
return exitHandler()
4646
}
4747

48-
const command = npm.argv.shift()
49-
const args = npm.argv
50-
5148
if (!command) {
5249
output.standard(npm.usage)
5350
process.exitCode = 1

‎lib/npm.js

+2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ class Npm {
9797
const { exec = true } = await this.#load().then(r => r ?? {})
9898
return {
9999
exec,
100+
command: this.argv.shift(),
101+
args: this.argv,
100102
}
101103
})
102104
}

‎test/fixtures/mock-npm.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,11 @@ const setupMockNpm = async (t, {
241241
init,
242242
load,
243243
mocks: withDirs(mocks),
244-
npm: { argv, excludeNpmCwd: true, ...withDirs(npmOpts) },
244+
npm: {
245+
argv: command ? [command, ...argv] : argv,
246+
excludeNpmCwd: true,
247+
...withDirs(npmOpts),
248+
},
245249
})
246250

247251
if (config.omit?.includes('prod')) {

0 commit comments

Comments
 (0)