Skip to content

Commit

Permalink
fix: return command and argv from load
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Apr 25, 2024
1 parent 180b919 commit c060e60
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 1 addition & 4 deletions lib/cli/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ class Npm {
const { exec = true } = await this.#load().then(r => r ?? {})
return {
exec,
command: this.argv.shift(),
args: this.argv,
}
})
}
Expand Down
6 changes: 5 additions & 1 deletion test/fixtures/mock-npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down

0 comments on commit c060e60

Please sign in to comment.