@@ -605,23 +605,6 @@ function spawn(file, args, options) {
605
605
const killSignal = sanitizeKillSignal ( options . killSignal ) ;
606
606
const child = new ChildProcess ( ) ;
607
607
608
- if ( options . signal ) {
609
- const signal = options . signal ;
610
- if ( signal . aborted ) {
611
- onAbortListener ( ) ;
612
- } else {
613
- signal . addEventListener ( 'abort' , onAbortListener , { once : true } ) ;
614
- child . once ( 'exit' ,
615
- ( ) => signal . removeEventListener ( 'abort' , onAbortListener ) ) ;
616
- }
617
-
618
- function onAbortListener ( ) {
619
- process . nextTick ( ( ) => {
620
- abortChildProcess ( child , killSignal ) ;
621
- } ) ;
622
- }
623
- }
624
-
625
608
debug ( 'spawn' , options ) ;
626
609
child . spawn ( options ) ;
627
610
@@ -645,6 +628,21 @@ function spawn(file, args, options) {
645
628
} ) ;
646
629
}
647
630
631
+ if ( options . signal ) {
632
+ const signal = options . signal ;
633
+ if ( signal . aborted ) {
634
+ process . nextTick ( onAbortListener ) ;
635
+ } else {
636
+ signal . addEventListener ( 'abort' , onAbortListener , { once : true } ) ;
637
+ child . once ( 'exit' ,
638
+ ( ) => signal . removeEventListener ( 'abort' , onAbortListener ) ) ;
639
+ }
640
+
641
+ function onAbortListener ( ) {
642
+ abortChildProcess ( child , killSignal ) ;
643
+ }
644
+ }
645
+
648
646
return child ;
649
647
}
650
648
@@ -778,37 +776,6 @@ function sanitizeKillSignal(killSignal) {
778
776
}
779
777
}
780
778
781
- // This level of indirection is here because the other child_process methods
782
- // call spawn internally but should use different cancellation logic.
783
- function spawnWithSignal ( file , args , options ) {
784
- // Remove signal from options to spawn
785
- // to avoid double emitting of AbortError
786
- const opts = options && typeof options === 'object' && ( 'signal' in options ) ?
787
- { ...options , signal : undefined } :
788
- options ;
789
-
790
- if ( options ?. signal ) {
791
- // Validate signal, if present
792
- validateAbortSignal ( options . signal , 'options.signal' ) ;
793
- }
794
- const child = spawn ( file , args , opts ) ;
795
-
796
- if ( options ?. signal ) {
797
- const killSignal = sanitizeKillSignal ( options . killSignal ) ;
798
-
799
- function kill ( ) {
800
- abortChildProcess ( child , killSignal ) ;
801
- }
802
- if ( options . signal . aborted ) {
803
- process . nextTick ( kill ) ;
804
- } else {
805
- options . signal . addEventListener ( 'abort' , kill , { once : true } ) ;
806
- const remove = ( ) => options . signal . removeEventListener ( 'abort' , kill ) ;
807
- child . once ( 'exit' , remove ) ;
808
- }
809
- }
810
- return child ;
811
- }
812
779
module . exports = {
813
780
_forkChild,
814
781
ChildProcess,
@@ -817,6 +784,6 @@ module.exports = {
817
784
execFileSync,
818
785
execSync,
819
786
fork,
820
- spawn : spawnWithSignal ,
787
+ spawn,
821
788
spawnSync
822
789
} ;
0 commit comments