diff --git a/lib/internal/main/watch_mode.js b/lib/internal/main/watch_mode.js index d70908e6e3cd9b..4a2482f854d74c 100644 --- a/lib/internal/main/watch_mode.js +++ b/lib/internal/main/watch_mode.js @@ -6,6 +6,7 @@ const { ArrayPrototypePush, ArrayPrototypePushApply, ArrayPrototypeSlice, + StringPrototypeSplit, StringPrototypeStartsWith, } = primordials; @@ -22,10 +23,11 @@ const { FilesWatcher } = require('internal/watch_mode/files_watcher'); const { green, blue, red, white, clear } = require('internal/util/colors'); const { spawn } = require('child_process'); -const { inspect } = require('util'); +const { inspect, parseEnv } = require('util'); const { setTimeout, clearTimeout } = require('timers'); const { resolve } = require('path'); const { once } = require('events'); +const { readFileSync } = require('fs'); prepareMainThreadExecution(false, false); markBootstrapComplete(); @@ -64,11 +66,23 @@ let exited; function start() { exited = false; + + let kEnv = {}; + for (const arg of process.execArgv) { + if (StringPrototypeStartsWith(arg, '--env-file')) { + const envFile = resolve(StringPrototypeSplit(arg, '=')[1]); + watcher.filterFile(envFile, null); + const envContent = parseEnv(readFileSync(envFile, 'utf8')); + kEnv = { ...kEnv, ...envContent }; + } + } + const stdio = kShouldFilterModules ? ['inherit', 'inherit', 'inherit', 'ipc'] : 'inherit'; child = spawn(process.execPath, argsWithoutWatchOptions, { stdio, env: { ...process.env, + ...kEnv, WATCH_REPORT_DEPENDENCIES: '1', }, });