@@ -253,6 +253,7 @@ function installPackages (specs, prefix, opts) {
253
253
module . exports . _execCommand = execCommand
254
254
function execCommand ( _existing , argv ) {
255
255
return findNodeScript ( _existing , argv ) . then ( existing => {
256
+ const argvCmdOpts = argv . cmdOpts || [ ]
256
257
if ( existing && ! argv . alwaysSpawn && ! argv . nodeArg && ! argv . shell && existing !== process . argv [ 1 ] ) {
257
258
const Module = require ( 'module' )
258
259
// let it take over the process. This means we can skip node startup!
@@ -263,31 +264,35 @@ function execCommand (_existing, argv) {
263
264
process . argv = [
264
265
process . argv [ 0 ] , // Current node binary
265
266
existing // node script path. `runMain()` will set this as the new main
266
- ] . concat ( argv . cmdOpts ) // options for the cmd itself
267
+ ] . concat ( argvCmdOpts ) // options for the cmd itself
267
268
Module . runMain ( ) // ✨MAGIC✨. Sorry-not-sorry
268
269
} else if ( ! existing && argv . nodeArg && argv . nodeArg . length ) {
269
270
throw new Error ( Y ( ) `ERROR: --node-arg/-n can only be used on packages with node scripts.` )
270
271
} else {
271
272
let cmd = existing
272
- let opts = argv
273
- if ( existing && argv . nodeArg && argv . nodeArg . length ) {
273
+ let cmdOpts = argvCmdOpts
274
+ if ( existing ) {
275
+ cmd = process . argv [ 0 ]
276
+ if ( process . platform === 'win32' ) {
277
+ cmd = child . escapeArg ( cmd , true )
278
+ }
274
279
// If we know we're running a run script and we got a --node-arg,
275
280
// we need to fudge things a bit to get them working right.
276
- let nargs = argv . nodeArg
277
- if ( typeof nargs === 'string' ) {
278
- nargs = [ nargs ]
281
+ cmdOpts = argv . nodeArg
282
+ if ( cmdOpts ) {
283
+ cmdOpts = Array . isArray ( cmdOpts ) ? cmdOpts : [ cmdOpts ]
284
+ } else {
285
+ cmdOpts = [ ]
279
286
}
280
287
// It's valid for a single arg to be a string of multiple
281
288
// space-separated node args.
282
289
// Example: `$ npx -n '--inspect --harmony --debug' ...`
283
- nargs = nargs . reduce ( ( acc , arg ) => {
290
+ cmdOpts = cmdOpts . reduce ( ( acc , arg ) => {
284
291
return acc . concat ( arg . split ( / \s + / ) )
285
292
} , [ ] )
286
- cmd = child . escapeArg ( process . argv [ 0 ] , true )
287
- opts = Object . assign ( { } , argv , {
288
- cmdOpts : nargs . concat ( [ existing ] , argv . cmdOpts || [ ] )
289
- } )
293
+ cmdOpts = cmdOpts . concat ( existing , argvCmdOpts )
290
294
}
295
+ const opts = Object . assign ( { } , argv , { cmdOpts } )
291
296
return child . runCommand ( cmd , opts ) . catch ( err => {
292
297
if ( err . isOperational && err . exitCode ) {
293
298
// At this point, we want to treat errors from the child as if
0 commit comments