@@ -24,6 +24,7 @@ const { green, blue, red, white, clear } = require('internal/util/colors');
2424const { convertToValidSignal } = require ( 'internal/util' ) ;
2525
2626const { spawn } = require ( 'child_process' ) ;
27+ const { existsSync } = require ( 'fs' ) ;
2728const { inspect } = require ( 'util' ) ;
2829const { setTimeout, clearTimeout } = require ( 'timers' ) ;
2930const { resolve } = require ( 'path' ) ;
@@ -34,10 +35,8 @@ markBootstrapComplete();
3435
3536const kKillSignal = convertToValidSignal ( getOptionValue ( '--watch-kill-signal' ) ) ;
3637const kShouldFilterModules = getOptionValue ( '--watch-path' ) . length === 0 ;
37- const kEnvFiles = [
38- ...getOptionValue ( '--env-file' ) ,
39- ...getOptionValue ( '--env-file-if-exists' ) ,
40- ] ;
38+ const kEnvFiles = getOptionValue ( '--env-file' ) ;
39+ const kOptionalEnvFiles = getOptionValue ( '--env-file-if-exists' ) ;
4140const kWatchedPaths = ArrayPrototypeMap ( getOptionValue ( '--watch-path' ) , ( path ) => resolve ( path ) ) ;
4241const kPreserveOutput = getOptionValue ( '--watch-preserve-output' ) ;
4342const kCommand = ArrayPrototypeSlice ( process . argv , 1 ) ;
@@ -105,6 +104,14 @@ function start() {
105104 if ( kEnvFiles . length > 0 ) {
106105 ArrayPrototypeForEach ( kEnvFiles , ( file ) => watcher . filterFile ( resolve ( file ) ) ) ;
107106 }
107+ if ( kOptionalEnvFiles . length > 0 ) {
108+ ArrayPrototypeForEach ( kOptionalEnvFiles , ( file ) => {
109+ const resolvedPath = resolve ( file ) ;
110+ if ( existsSync ( resolvedPath ) ) {
111+ watcher . filterFile ( resolvedPath ) ;
112+ }
113+ } ) ;
114+ }
108115 child . once ( 'exit' , ( code ) => {
109116 exited = true ;
110117 const waitingForChanges = 'Waiting for file changes before restarting...' ;
0 commit comments