@@ -16,7 +16,6 @@ import { makeLog } from './log'
1616const version = require ( '../package.json' ) . version
1717const tsNodeVersion = require ( 'ts-node' ) . VERSION
1818const tsVersion = require ( 'typescript' ) . version
19- const signals : NodeJS . Signals [ ] = [ 'SIGINT' , 'SIGTERM' ]
2019
2120export const runDev = (
2221 script : string ,
@@ -119,7 +118,6 @@ export const runDev = (
119118 child = fork ( cmd [ 0 ] , cmd . slice ( 1 ) , {
120119 cwd : process . cwd ( ) ,
121120 env : process . env ,
122- detached : true ,
123121 } )
124122
125123 starting = false
@@ -169,15 +167,11 @@ export const runDev = (
169167 compiler . compile ( message )
170168 } )
171169
172- child . on ( 'close' , ( code : number , signal : string ) => {
173- log . debug ( 'Child closed with code %s' , code )
174- if ( signal ) {
175- log . debug ( `Exiting process with signal ${ signal } ` )
176- process . kill ( process . pid , signal )
177- } else {
178- log . debug ( `Exiting process with code ${ code } ` )
179- process . exit ( code )
180- }
170+ child . on ( 'exit' , function ( code ) {
171+ log . debug ( 'Child exited with code %s' , code )
172+ if ( ! child ) return
173+ if ( ! child . respawn ) process . exit ( code || 0 )
174+ child = undefined
181175 } )
182176
183177 if ( cfg . respawn ) {
@@ -209,14 +203,14 @@ export const runDev = (
209203 } )
210204 compiler . writeReadyFile ( )
211205 }
212- const killChild = ( signal : NodeJS . Signals ) => {
206+ const killChild = ( ) => {
213207 if ( ! child ) return
214- log . debug ( ` Sending ${ signal } to child pid` , child . pid )
208+ log . debug ( ' Sending SIGTERM kill to child pid' , child . pid )
215209 if ( opts [ 'tree-kill' ] ) {
216210 log . debug ( 'Using tree-kill' )
217211 kill ( child . pid )
218212 } else {
219- child . kill ( signal )
213+ child . kill ( 'SIGTERM' )
220214 }
221215 }
222216 function stop ( willTerminate ?: boolean ) {
@@ -229,8 +223,8 @@ export const runDev = (
229223 log . debug ( 'Disconnecting from child' )
230224 child . disconnect ( )
231225 if ( ! willTerminate ) {
226+ killChild ( )
232227 }
233- killChild ( 'SIGTERM' )
234228 }
235229 }
236230
@@ -267,17 +261,11 @@ export const runDev = (
267261 }
268262 }
269263
270- signals . forEach ( ( signal : NodeJS . Signals ) =>
271- process . on ( signal , ( ) => {
272- log . debug ( `Process got ${ signal } , killing child` )
273- killChild ( signal )
274- } )
275- )
276-
277- process . on ( 'exit' , ( ) => {
278- if ( child ) {
279- child . kill ( )
280- }
264+ // Relay SIGTERM
265+ process . on ( 'SIGTERM' , function ( ) {
266+ log . debug ( 'Process got SIGTERM' )
267+ killChild ( )
268+ process . exit ( 0 )
281269 } )
282270
283271 const compiler = makeCompiler ( opts , {
0 commit comments