@@ -16,7 +16,6 @@ import { makeLog } from './log'
16
16
const version = require ( '../package.json' ) . version
17
17
const tsNodeVersion = require ( 'ts-node' ) . VERSION
18
18
const tsVersion = require ( 'typescript' ) . version
19
- const signals : NodeJS . Signals [ ] = [ 'SIGINT' , 'SIGTERM' ]
20
19
21
20
export const runDev = (
22
21
script : string ,
@@ -119,7 +118,6 @@ export const runDev = (
119
118
child = fork ( cmd [ 0 ] , cmd . slice ( 1 ) , {
120
119
cwd : process . cwd ( ) ,
121
120
env : process . env ,
122
- detached : true ,
123
121
} )
124
122
125
123
starting = false
@@ -169,15 +167,11 @@ export const runDev = (
169
167
compiler . compile ( message )
170
168
} )
171
169
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
181
175
} )
182
176
183
177
if ( cfg . respawn ) {
@@ -209,14 +203,14 @@ export const runDev = (
209
203
} )
210
204
compiler . writeReadyFile ( )
211
205
}
212
- const killChild = ( signal : NodeJS . Signals ) => {
206
+ const killChild = ( ) => {
213
207
if ( ! child ) return
214
- log . debug ( ` Sending ${ signal } to child pid` , child . pid )
208
+ log . debug ( ' Sending SIGTERM kill to child pid' , child . pid )
215
209
if ( opts [ 'tree-kill' ] ) {
216
210
log . debug ( 'Using tree-kill' )
217
211
kill ( child . pid )
218
212
} else {
219
- child . kill ( signal )
213
+ child . kill ( 'SIGTERM' )
220
214
}
221
215
}
222
216
function stop ( willTerminate ?: boolean ) {
@@ -229,8 +223,8 @@ export const runDev = (
229
223
log . debug ( 'Disconnecting from child' )
230
224
child . disconnect ( )
231
225
if ( ! willTerminate ) {
226
+ killChild ( )
232
227
}
233
- killChild ( 'SIGTERM' )
234
228
}
235
229
}
236
230
@@ -267,17 +261,11 @@ export const runDev = (
267
261
}
268
262
}
269
263
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 )
281
269
} )
282
270
283
271
const compiler = makeCompiler ( opts , {
0 commit comments