@@ -68,31 +68,30 @@ function run(options) {
68
68
var args = runCmd ? utils . stringify ( executable , cmd . args ) : ':' ;
69
69
var spawnArgs = [ sh , [ shFlag , args ] ] ;
70
70
71
- if ( utils . version . major === 0 && utils . version . minor < 8 ) {
72
- // use the old spawn args :-\
73
- } else {
74
- spawnArgs . push ( {
75
- env : utils . merge ( options . execOptions . env , process . env ) ,
76
- stdio : stdio ,
77
- } ) ;
78
- }
71
+ spawnArgs . push ( {
72
+ env : utils . merge ( options . execOptions . env , process . env ) ,
73
+ stdio : stdio ,
74
+ } ) ;
79
75
80
76
const firstArg = cmd . args [ 0 ] || '' ;
81
77
78
+ // hasStdio allows us to correctly handle stdin piping
79
+ // see: https://git.io/vNtX3
80
+ const hasStdio = utils . satisfies ( '>= 6.4.0 || < 5' ) ;
81
+
82
82
if (
83
- // this is a hack to avoid forking if there's a node argument being passed
84
- // it's a short term fix, and I'm not 100% sure that `fork` is the right way
85
- firstArg . indexOf ( '-' ) === - 1 &&
86
- firstArg !== 'inspect' &&
87
- executable === 'node' &&
88
- utils . version . major > 4
83
+ firstArg . indexOf ( '-' ) === - 1 && // don't fork if there's a node arg
84
+ firstArg !== 'inspect' && // don't fork it's `inspect` debugger
85
+ executable === 'node' && // only fork if node
86
+ utils . version . major > 4 // only fork if node version > 4
89
87
) {
90
88
var forkArgs = cmd . args . slice ( 1 ) ;
91
89
var env = utils . merge ( options . execOptions . env , process . env ) ;
92
90
stdio . push ( 'ipc' ) ;
93
91
child = fork ( options . execOptions . script , forkArgs , {
94
92
env : env ,
95
93
stdio : stdio ,
94
+ silent : ! hasStdio ,
96
95
} ) ;
97
96
utils . log . detail ( 'forking' ) ;
98
97
debug ( forkArgs ) ;
@@ -216,9 +215,7 @@ function run(options) {
216
215
// if the stdin piping is on, we need to unpipe, but also close stdin on
217
216
// the child, otherwise linux can throw EPIPE or ECONNRESET errors.
218
217
if ( options . stdin ) {
219
- if ( process . stdin . unpipe ) { // node > 0.8
220
- process . stdin . unpipe ( child . stdin ) ;
221
- }
218
+ process . stdin . unpipe ( child . stdin ) ;
222
219
}
223
220
224
221
if ( utils . isWindows ) {
@@ -234,12 +231,8 @@ function run(options) {
234
231
// this seems to fix the 0.11.x issue with the "rs" restart command,
235
232
// though I'm unsure why. it seems like more data is streamed in to
236
233
// stdin after we close.
237
- if ( child && options . stdin && oldPid === child . pid ) {
238
- // this is stupid and horrible, but node 0.12 on windows blows up
239
- // with this line, so we'll skip it entirely.
240
- if ( ! utils . isWindows ) {
241
- child . stdin . end ( ) ;
242
- }
234
+ if ( child && options . stdin && child . stdin && oldPid === child . pid ) {
235
+ child . stdin . end ( ) ;
243
236
}
244
237
callback ( ) ;
245
238
} ) ;
@@ -263,8 +256,12 @@ function run(options) {
263
256
264
257
// swallow the stdin error if it happens
265
258
// ref: https://github.com/remy/nodemon/issues/1195
266
- child . stdin . on ( 'error' , ( ) => { } ) ;
267
- process . stdin . pipe ( child . stdin ) ;
259
+ if ( hasStdio ) {
260
+ child . stdin . on ( 'error' , ( ) => { } ) ;
261
+ process . stdin . pipe ( child . stdin ) ;
262
+ } else {
263
+ child . stdout . pipe ( process . stdout ) ;
264
+ }
268
265
269
266
bus . once ( 'exit' , function ( ) {
270
267
if ( child && process . stdin . unpipe ) { // node > 0.8
0 commit comments