File tree 2 files changed +15
-2
lines changed
2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -93,7 +93,12 @@ const npm = module.exports = new class extends EventEmitter {
93
93
}
94
94
95
95
process . emit ( 'time' , `command:${ cmd } ` )
96
- this . command = cmd
96
+ // since 'test', 'start', 'stop', etc. commands re-enter this function
97
+ // to call the run-script command, we need to only set it one time.
98
+ if ( ! this . command ) {
99
+ process . env . npm_command = cmd
100
+ this . command = cmd
101
+ }
97
102
98
103
// Options are prefixed by a hyphen-minus (-, \u2d).
99
104
// Other dash-type chars look similar but are invalid.
@@ -142,7 +147,6 @@ const npm = module.exports = new class extends EventEmitter {
142
147
}
143
148
if ( ! er && ! this [ _flatOptions ] ) {
144
149
this [ _flatOptions ] = require ( './utils/flat-options.js' ) ( this )
145
- process . env . npm_command = this . command
146
150
}
147
151
process . emit ( 'timeEnd' , 'npm:load' )
148
152
this . emit ( 'load' , er )
Original file line number Diff line number Diff line change @@ -4,7 +4,16 @@ const fs = require('fs')
4
4
5
5
// delete this so that we don't have configs from the fact that it
6
6
// is being run by 'npm test'
7
+ const event = process . env . npm_lifecycle_event
7
8
for ( const env of Object . keys ( process . env ) . filter ( e => / ^ n p m _ / . test ( e ) ) ) {
9
+ if ( env === 'npm_command' ) {
10
+ // should only be running this in the 'test' or 'run-script' command!
11
+ // if the lifecycle event is 'test', then it'll be 'test', otherwise
12
+ // it should always be run-script. Of course, it'll be missing if this
13
+ // test is just run directly, which is also acceptable.
14
+ const cmd = event === 'test' ? 'test' : 'run-script'
15
+ t . match ( process . env [ env ] , cmd )
16
+ }
8
17
delete process . env [ env ]
9
18
}
10
19
You can’t perform that action at this time.
0 commit comments