@@ -5,6 +5,7 @@ import { join } from 'path'
55import v8flags = require ( 'v8flags' )
66
77const argv = process . argv . slice ( 2 )
8+ const signals : NodeJS . Signals [ ] = [ 'SIGINT' , 'SIGTERM' , 'SIGWINCH' ]
89
910v8flags ( function ( err , v8flags ) {
1011 if ( err ) {
@@ -53,16 +54,30 @@ v8flags(function (err, v8flags) {
5354 const proc = spawn (
5455 process . execPath ,
5556 nodeArgs . concat ( join ( __dirname , '_bin.js' ) , scriptArgs ) ,
56- { stdio : 'inherit' }
57+ {
58+ // We need to run in detached mode so to avoid
59+ // automatic propagation of signals to the child process.
60+ // This is necessary because by default, keyboard interrupts
61+ // are propagated to the process tree, but `kill` is not.
62+ //
63+ // See: https://nodejs.org/api/child_process.html#child_process_options_detached
64+ detached : true ,
65+ stdio : 'inherit'
66+ }
5767 )
5868
59- proc . on ( 'exit' , function ( code : number , signal : string ) {
60- process . on ( 'exit' , function ( ) {
61- if ( signal ) {
62- process . kill ( process . pid , signal )
63- } else {
64- process . exit ( code )
65- }
66- } )
69+ // Ignore signals, and instead forward them to the child process.
70+ signals . forEach ( signal => process . on ( signal , ( ) => proc . kill ( signal ) ) )
71+
72+ // On spawned close, exit this process with the same code.
73+ proc . on ( 'close' , ( code : number , signal : string ) => {
74+ if ( signal ) {
75+ process . kill ( process . pid , signal )
76+ } else {
77+ process . exit ( code )
78+ }
6779 } )
80+
81+ // If this process exits, kill the child first.
82+ process . on ( 'exit' , ( ) => proc . kill ( ) )
6883} )
0 commit comments