@@ -460,16 +460,14 @@ function normalizeSpawnArguments(file, args, options) {
460
460
}
461
461
462
462
// Validate windowsVerbatimArguments, if present.
463
- if ( options . windowsVerbatimArguments != null &&
464
- typeof options . windowsVerbatimArguments !== 'boolean' ) {
463
+ let { windowsVerbatimArguments } = options ;
464
+ if ( windowsVerbatimArguments != null &&
465
+ typeof windowsVerbatimArguments !== 'boolean' ) {
465
466
throw new ERR_INVALID_ARG_TYPE ( 'options.windowsVerbatimArguments' ,
466
467
'boolean' ,
467
- options . windowsVerbatimArguments ) ;
468
+ windowsVerbatimArguments ) ;
468
469
}
469
470
470
- // Make a shallow copy so we don't clobber the user's options object.
471
- options = { ...options } ;
472
-
473
471
if ( options . shell ) {
474
472
const command = [ file ] . concat ( args ) . join ( ' ' ) ;
475
473
// Set the shell, switches, and commands.
@@ -481,7 +479,7 @@ function normalizeSpawnArguments(file, args, options) {
481
479
// '/d /s /c' is used only for cmd.exe.
482
480
if ( / ^ (?: .* \\ ) ? c m d (?: \. e x e ) ? $ / i. test ( file ) ) {
483
481
args = [ '/d' , '/s' , '/c' , `"${ command } "` ] ;
484
- options . windowsVerbatimArguments = true ;
482
+ windowsVerbatimArguments = true ;
485
483
} else {
486
484
args = [ '-c' , command ] ;
487
485
}
@@ -521,58 +519,42 @@ function normalizeSpawnArguments(file, args, options) {
521
519
}
522
520
523
521
return {
524
- file : file ,
525
- args : args ,
526
- options : options ,
527
- envPairs : envPairs
522
+ // Make a shallow copy so we don't clobber the user's options object.
523
+ ...options ,
524
+ args,
525
+ detached : ! ! options . detached ,
526
+ envPairs,
527
+ file,
528
+ windowsHide : ! ! options . windowsHide ,
529
+ windowsVerbatimArguments : ! ! windowsVerbatimArguments
528
530
} ;
529
531
}
530
532
531
533
532
534
var spawn = exports . spawn = function spawn ( file , args , options ) {
533
- const opts = normalizeSpawnArguments ( file , args , options ) ;
534
535
const child = new ChildProcess ( ) ;
535
536
536
- options = opts . options ;
537
- debug ( 'spawn' , opts . args , options ) ;
538
-
539
- child . spawn ( {
540
- file : opts . file ,
541
- args : opts . args ,
542
- cwd : options . cwd ,
543
- windowsHide : ! ! options . windowsHide ,
544
- windowsVerbatimArguments : ! ! options . windowsVerbatimArguments ,
545
- detached : ! ! options . detached ,
546
- envPairs : opts . envPairs ,
547
- stdio : options . stdio ,
548
- uid : options . uid ,
549
- gid : options . gid
550
- } ) ;
537
+ options = normalizeSpawnArguments ( file , args , options ) ;
538
+ debug ( 'spawn' , options ) ;
539
+ child . spawn ( options ) ;
551
540
552
541
return child ;
553
542
} ;
554
543
555
544
function spawnSync ( file , args , options ) {
556
- const opts = normalizeSpawnArguments ( file , args , options ) ;
557
-
558
- const defaults = {
545
+ options = {
559
546
maxBuffer : MAX_BUFFER ,
560
- ...opts . options
547
+ ...normalizeSpawnArguments ( file , args , options )
561
548
} ;
562
- options = opts . options = defaults ;
563
549
564
- debug ( 'spawnSync' , opts . args , options ) ;
550
+ debug ( 'spawnSync' , options ) ;
565
551
566
552
// Validate the timeout, if present.
567
553
validateTimeout ( options . timeout ) ;
568
554
569
555
// Validate maxBuffer, if present.
570
556
validateMaxBuffer ( options . maxBuffer ) ;
571
557
572
- options . file = opts . file ;
573
- options . args = opts . args ;
574
- options . envPairs = opts . envPairs ;
575
-
576
558
// Validate and translate the kill signal, if present.
577
559
options . killSignal = sanitizeKillSignal ( options . killSignal ) ;
578
560
@@ -603,7 +585,7 @@ function spawnSync(file, args, options) {
603
585
}
604
586
}
605
587
606
- return child_process . spawnSync ( opts ) ;
588
+ return child_process . spawnSync ( options ) ;
607
589
}
608
590
exports . spawnSync = spawnSync ;
609
591
@@ -628,15 +610,15 @@ function checkExecSyncError(ret, args, cmd) {
628
610
629
611
630
612
function execFileSync ( command , args , options ) {
631
- const opts = normalizeSpawnArguments ( command , args , options ) ;
632
- const inheritStderr = ! opts . options . stdio ;
613
+ options = normalizeSpawnArguments ( command , args , options ) ;
633
614
634
- const ret = spawnSync ( opts . file , opts . args . slice ( 1 ) , opts . options ) ;
615
+ const inheritStderr = ! options . stdio ;
616
+ const ret = spawnSync ( options . file , options . args . slice ( 1 ) , options ) ;
635
617
636
618
if ( inheritStderr && ret . stderr )
637
619
process . stderr . write ( ret . stderr ) ;
638
620
639
- const err = checkExecSyncError ( ret , opts . args , undefined ) ;
621
+ const err = checkExecSyncError ( ret , options . args , undefined ) ;
640
622
641
623
if ( err )
642
624
throw err ;
0 commit comments