@@ -33,7 +33,7 @@ module.exports = function (script, scriptArgs, nodeArgs, opts) {
33
33
if ( cfg . dedupe ) process . env . NODE_DEV_PRELOAD = __dirname + '/dedupe' ;
34
34
35
35
var watcher = filewatcher ( { forcePolling : opts . poll } ) ;
36
-
36
+ var starting = false
37
37
watcher . on ( 'change' , function ( file ) {
38
38
if ( file === compiler . tsConfigPath ) {
39
39
notify ( 'Reinitializing TS compilation' ) ;
@@ -42,8 +42,10 @@ module.exports = function (script, scriptArgs, nodeArgs, opts) {
42
42
/* eslint-disable no-octal-escape */
43
43
if ( cfg . clear ) process . stdout . write ( '\033[2J\033[H' ) ;
44
44
notify ( 'Restarting' , file + ' has been modified' ) ;
45
- compiler . compileChanged ( file )
46
- //watcher.removeAll();
45
+ compiler . compileChanged ( file )
46
+ if ( starting ) return
47
+ watcher . removeAll ( ) ;
48
+ starting = true
47
49
if ( child ) {
48
50
// Child is still running, restart upon exit
49
51
child . on ( 'exit' , start ) ;
@@ -72,7 +74,7 @@ module.exports = function (script, scriptArgs, nodeArgs, opts) {
72
74
cwd : process . cwd ( ) ,
73
75
env : process . env
74
76
} ) ;
75
-
77
+ starting = false
76
78
var compileReqWatcher = filewatcher ( { forcePolling : opts . poll } ) ;
77
79
var currentCompilePath
78
80
fs . writeFileSync ( compiler . getCompileReqFilePath ( ) , '' ) ;
@@ -98,12 +100,13 @@ module.exports = function (script, scriptArgs, nodeArgs, opts) {
98
100
} )
99
101
} )
100
102
child . on ( 'message' , function ( message ) {
101
- if ( currentCompilePath == message . compiledPath ) return
103
+ if ( ! message . compiledPath || currentCompilePath = == message . compiledPath ) return
102
104
currentCompilePath = message . compiledPath
103
105
compiler . compile ( message )
104
106
} ) ;
105
107
106
108
child . on ( 'exit' , function ( code ) {
109
+ if ( ! child ) return
107
110
if ( ! child . respawn ) process . exit ( code ) ;
108
111
child = undefined ;
109
112
} ) ;
@@ -135,14 +138,15 @@ module.exports = function (script, scriptArgs, nodeArgs, opts) {
135
138
}
136
139
137
140
function stop ( willTerminate ) {
138
- // if (!child || child.stopping) {
139
- // //console.log('stop no child')
140
- // return
141
- // };
141
+ if ( ! child || child . stopping ) {
142
+ return
143
+ } ;
142
144
child . stopping = true
143
145
child . respawn = true ;
144
- child . disconnect ( ) ;
145
- if ( ! willTerminate ) child . kill ( 'SIGTERM' ) ;
146
+ if ( child . connected === undefined || child . connected === true ) {
147
+ child . disconnect ( ) ;
148
+ if ( ! willTerminate ) child . kill ( 'SIGTERM' ) ;
149
+ }
146
150
}
147
151
148
152
// Relay SIGTERM
0 commit comments