@@ -16,7 +16,7 @@ var restart = null;
1616var psTree = require ( 'pstree.remy' ) ;
1717var path = require ( 'path' ) ;
1818var signals = require ( './signals' ) ;
19- const osRelease = parseInt ( require ( 'os' ) . release ( ) . split ( "." ) [ 0 ] , 10 ) ;
19+ const osRelease = parseInt ( require ( 'os' ) . release ( ) . split ( '.' ) [ 0 ] , 10 ) ;
2020
2121function run ( options ) {
2222 var cmd = config . command . raw ;
@@ -67,7 +67,7 @@ function run(options) {
6767 PATH : binPath + ':' + process . env . PATH ,
6868 } ) ,
6969 stdio : stdio ,
70- }
70+ } ;
7171
7272 var executable = cmd . executable ;
7373
@@ -76,12 +76,15 @@ function run(options) {
7676 // but *only* apply to the first command, and none of the arguments.
7777 // ref #1251 and #1236
7878 if ( executable . indexOf ( '/' ) !== - 1 ) {
79- executable = executable . split ( ' ' ) . map ( ( e , i ) => {
80- if ( i === 0 ) {
81- return path . normalize ( e ) ;
82- }
83- return e ;
84- } ) . join ( ' ' ) ;
79+ executable = executable
80+ . split ( ' ' )
81+ . map ( ( e , i ) => {
82+ if ( i === 0 ) {
83+ return path . normalize ( e ) ;
84+ }
85+ return e ;
86+ } )
87+ . join ( ' ' ) ;
8588 }
8689 // taken from npm's cli: https://git.io/vNFD4
8790 sh = process . env . comspec || 'cmd' ;
@@ -111,7 +114,7 @@ function run(options) {
111114 ! ( firstArg . indexOf ( '-' ) === 0 ) && // don't fork if there's a node exec arg
112115 firstArg !== 'inspect' && // don't fork it's `inspect` debugger
113116 executable === 'node' && // only fork if node
114- utils . version . major > 4 // only fork if node version > 4
117+ utils . version . major > 4 ; // only fork if node version > 4
115118
116119 if ( shouldFork ) {
117120 // this assumes the first argument is the script and slices it out, since
@@ -125,7 +128,7 @@ function run(options) {
125128 silent : ! hasStdio ,
126129 } ) ;
127130 utils . log . detail ( 'forking' ) ;
128- debug ( 'fork' , sh , shFlag , args )
131+ debug ( 'fork' , sh , shFlag , args ) ;
129132 } else {
130133 utils . log . detail ( 'spawning' ) ;
131134 child = spawn . apply ( null , spawnArgs ) ;
@@ -181,8 +184,9 @@ function run(options) {
181184 }
182185
183186 if ( code === 127 ) {
184- utils . log . error ( 'failed to start process, "' + cmd . executable +
185- '" exec not found' ) ;
187+ utils . log . error (
188+ 'failed to start process, "' + cmd . executable + '" exec not found'
189+ ) ;
186190 bus . emit ( 'error' , code ) ;
187191 process . exit ( ) ;
188192 }
@@ -227,7 +231,8 @@ function run(options) {
227231 return restart ( ) ;
228232 }
229233
230- if ( code === 0 ) { // clean exit - wait until file change to restart
234+ if ( code === 0 ) {
235+ // clean exit - wait until file change to restart
231236 if ( runCmd ) {
232237 utils . log . status ( 'clean exit - waiting for changes before restart' ) ;
233238 }
@@ -241,8 +246,9 @@ function run(options) {
241246 process . exit ( 1 ) ;
242247 }
243248 } else {
244- utils . log . fail ( 'app crashed - waiting for file changes before' +
245- ' starting...' ) ;
249+ utils . log . fail (
250+ 'app crashed - waiting for file changes before' + ' starting...'
251+ ) ;
246252 child = null ;
247253 }
248254 }
@@ -267,21 +273,25 @@ function run(options) {
267273 // swallow the stdin error if it happens
268274 // ref: https://github.com/remy/nodemon/issues/1195
269275 if ( hasStdio ) {
270- child . stdin . on ( 'error' , ( ) => { } ) ;
276+ child . stdin . on ( 'error' , ( ) => { } ) ;
271277 process . stdin . pipe ( child . stdin ) ;
272278 } else {
273279 if ( child . stdout ) {
274280 child . stdout . pipe ( process . stdout ) ;
275281 } else {
276- utils . log . error ( 'running an unsupported version of node ' +
277- process . version ) ;
278- utils . log . error ( 'nodemon may not work as expected - ' +
279- 'please consider upgrading to LTS' ) ;
282+ utils . log . error (
283+ 'running an unsupported version of node ' + process . version
284+ ) ;
285+ utils . log . error (
286+ 'nodemon may not work as expected - ' +
287+ 'please consider upgrading to LTS'
288+ ) ;
280289 }
281290 }
282291
283292 bus . once ( 'exit' , function ( ) {
284- if ( child && process . stdin . unpipe ) { // node > 0.8
293+ if ( child && process . stdin . unpipe ) {
294+ // node > 0.8
285295 process . stdin . unpipe ( child . stdin ) ;
286296 }
287297 } ) ;
@@ -300,14 +310,16 @@ function waitForSubProcesses(pid, callback) {
300310 return callback ( ) ;
301311 }
302312
303- utils . log . status ( `still waiting for ${ pids . length } sub-process${
304- pids . length > 2 ? 'es' : '' } to finish...`) ;
313+ utils . log . status (
314+ `still waiting for ${ pids . length } sub-process${
315+ pids . length > 2 ? 'es' : ''
316+ } to finish...`
317+ ) ;
305318 setTimeout ( ( ) => waitForSubProcesses ( pid , callback ) , 1000 ) ;
306319 } ) ;
307320}
308321
309322function kill ( child , signal , callback ) {
310-
311323 if ( ! callback ) {
312324 callback = noop ;
313325 }
@@ -317,15 +329,14 @@ function kill(child, signal, callback) {
317329 try {
318330 exec ( 'taskkill /pid ' + child . pid + ' /T /F' ) ;
319331 } catch ( e ) {
320- utils . log . error ( " Could not shutdown sub process cleanly" ) ;
332+ utils . log . error ( ' Could not shutdown sub process cleanly' ) ;
321333 }
322- }
334+ } ;
323335
324336 // We are handling a 'SIGKILL' POSIX signal under Windows the
325337 // same way it is handled on a UNIX system: We are performing
326338 // a hard shutdown without waiting for the process to clean-up.
327339 if ( signal === 'SIGKILL' || osRelease < 10 ) {
328-
329340 debug ( 'terminating process group by force: %s' , child . pid ) ;
330341
331342 // We are using the taskkill utility to terminate the whole
@@ -337,43 +348,43 @@ function kill(child, signal, callback) {
337348 return ;
338349 }
339350
340- // We are using the Windows Management Instrumentation Command-line
341- // (wmic.exe) to resolve the sub-child process identifier, because the
342- // 'child' process in this context is actually a cmd.exe wrapper.
343- // We want to send the termination signal directly to the node process.
344- // The '2> nul' silences the no process found error message.
345- const resultBuffer = execSync (
346- `wmic process where (ParentProcessId=${ child . pid } ) get ProcessId 2> nul`
347- ) ;
348- const result = resultBuffer . toString ( ) . match ( / ^ [ 0 - 9 ] + / m) ;
351+ try {
352+ // We are using the Windows Management Instrumentation Command-line
353+ // (wmic.exe) to resolve the sub-child process identifier, because the
354+ // 'child' process in this context is actually a cmd.exe wrapper.
355+ // We want to send the termination signal directly to the node process.
356+ // The '2> nul' silences the no process found error message.
357+ const resultBuffer = execSync (
358+ `wmic process where (ParentProcessId=${ child . pid } ) get ProcessId 2> nul`
359+ ) ;
360+ const result = resultBuffer . toString ( ) . match ( / ^ [ 0 - 9 ] + / m) ;
349361
350- // If there is no sub-child process we fall back to the child process.
351- const processId = Array . isArray ( result ) ? result [ 0 ] : child . pid ;
362+ // If there is no sub-child process we fall back to the child process.
363+ const processId = Array . isArray ( result ) ? result [ 0 ] : child . pid ;
352364
353- debug ( 'sending kill signal SIGINT to process: %s' , processId ) ;
365+ debug ( 'sending kill signal SIGINT to process: %s' , processId ) ;
354366
355- // We are using the standalone 'windows-kill' executable to send the
356- // standard POSIX signal 'SIGINT' to the node process. This fixes #1720.
357- const windowsKill = path . normalize (
358- `${ __dirname } /../../bin/windows-kill.exe`
359- ) ;
367+ // We are using the standalone 'windows-kill' executable to send the
368+ // standard POSIX signal 'SIGINT' to the node process. This fixes #1720.
369+ const windowsKill = path . normalize (
370+ `${ __dirname } /../../bin/windows-kill.exe`
371+ ) ;
372+
373+ // We have to detach the 'windows-kill' execution completely from this
374+ // process group to avoid terminating the nodemon process itself.
375+ // See: https://github.com/alirdn/windows-kill#how-it-works--limitations
376+ //
377+ // Therefore we are using 'start' to create a new cmd.exe context.
378+ // The '/min' option hides the new terminal window and the '/wait'
379+ // option lets the process wait for the command to finish.
360380
361- // We have to detach the 'windows-kill' execution completely from this
362- // process group to avoid terminating the nodemon process itself.
363- // See: https://github.com/alirdn/windows-kill#how-it-works--limitations
364- //
365- // Therefore we are using 'start' to create a new cmd.exe context.
366- // The '/min' option hides the new terminal window and the '/wait'
367- // option lets the process wait for the command to finish.
368- try {
369381 execSync (
370382 `start "windows-kill" /min /wait "${ windowsKill } " -SIGINT ${ processId } `
371383 ) ;
372384 } catch ( e ) {
373385 taskKill ( ) ;
374386 }
375387 callback ( ) ;
376-
377388 } else {
378389 // we use psTree to kill the full subtree of nodemon, because when
379390 // spawning processes like `coffee` under the `--debug` flag, it'll spawn
@@ -395,15 +406,13 @@ function kill(child, signal, callback) {
395406
396407 child . kill ( signal ) ;
397408
398- pids . sort ( ) . forEach ( pid => exec ( `kill -${ sig } ${ pid } ` , noop ) ) ;
409+ pids . sort ( ) . forEach ( ( pid ) => exec ( `kill -${ sig } ${ pid } ` , noop ) ) ;
399410
400411 waitForSubProcesses ( child . pid , ( ) => {
401412 // finally kill the main user process
402413 exec ( `kill -${ sig } ${ child . pid } ` , callback ) ;
403414 } ) ;
404-
405415 } ) ;
406-
407416 }
408417}
409418
@@ -510,7 +519,9 @@ bus.on('restart', function () {
510519// remove the child file on exit
511520process . on ( 'exit' , function ( ) {
512521 utils . log . detail ( 'exiting' ) ;
513- if ( child ) { child . kill ( ) ; }
522+ if ( child ) {
523+ child . kill ( ) ;
524+ }
514525} ) ;
515526
516527// because windows borks when listening for the SIG* events
@@ -520,10 +531,11 @@ if (!utils.isWindows) {
520531 process . once ( 'SIGINT' , ( ) => bus . emit ( 'quit' , 130 ) ) ;
521532 process . once ( 'SIGTERM' , ( ) => {
522533 bus . emit ( 'quit' , 143 ) ;
523- if ( child ) { child . kill ( 'SIGTERM' ) ; }
534+ if ( child ) {
535+ child . kill ( 'SIGTERM' ) ;
536+ }
524537 } ) ;
525- } )
538+ } ) ;
526539}
527540
528-
529541module . exports = run ;
0 commit comments