Skip to content

Commit 9c935dd

Browse files
committed
Always set npm.command to canonical command name
This ensures that we get a npm_command env set to, eg 'run-script' instead of the shorthand 'run'.
1 parent 2b3d1f9 commit 9c935dd

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

lib/npm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const proxyCmds = new Proxy({}, {
2525
// old way of doing things, until we can make breaking changes to the
2626
// npm.commands[x] api
2727
target[actual] = new Proxy(
28-
(args, cb) => npm[_runCmd](cmd, impl, args, cb),
28+
(args, cb) => npm[_runCmd](actual, impl, args, cb),
2929
{
3030
get: (target, attr, receiver) => {
3131
return Reflect.get(impl, attr, receiver)

test/lib/npm.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ for (const env of Object.keys(process.env).filter(e => /^npm_/.test(e))) {
1515
'should match "npm test" or "npm run test"'
1616
)
1717
} else
18-
t.match(process.env[env], /^(run)|(run-script)|(exec)$/)
18+
t.match(process.env[env], /^(run-script|exec)$/)
1919
}
2020
delete process.env[env]
2121
}
@@ -411,10 +411,15 @@ t.test('npm.load', t => {
411411
npm.localPrefix = dir
412412

413413
await new Promise((res, rej) => {
414-
npm.commands['run-script']([], er => {
414+
// verify that calling the command with a short name still sets
415+
// the npm.command property to the full canonical name of the cmd.
416+
npm.command = null
417+
npm.commands.run([], er => {
415418
if (er)
416419
rej(er)
417420

421+
t.equal(npm.command, 'run-script', 'npm.command set to canonical name')
422+
418423
t.match(
419424
consoleLogs,
420425
[

0 commit comments

Comments
 (0)