From c704d3337f4c6124f38e05d1f88d2883f7c3f4cb Mon Sep 17 00:00:00 2001 From: Efe Karasakal Date: Wed, 11 Feb 2026 20:58:01 +0100 Subject: [PATCH 1/2] watch: get flags from execArgv --- lib/internal/main/watch_mode.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/internal/main/watch_mode.js b/lib/internal/main/watch_mode.js index 225436661f5e56..06c2c8602da444 100644 --- a/lib/internal/main/watch_mode.js +++ b/lib/internal/main/watch_mode.js @@ -18,7 +18,7 @@ const { triggerUncaughtException, exitCodes: { kNoFailure }, } = internalBinding('errors'); -const { getOptionValue, getOptionsAsFlagsFromBinding } = require('internal/options'); +const { getOptionValue } = require('internal/options'); const { FilesWatcher } = require('internal/watch_mode/files_watcher'); const { green, blue, red, white, clear } = require('internal/util/colors'); const { convertToValidSignal } = require('internal/util'); @@ -44,14 +44,13 @@ const kCommand = ArrayPrototypeSlice(process.argv, 1); const kCommandStr = inspect(ArrayPrototypeJoin(kCommand, ' ')); const argsWithoutWatchOptions = []; -const argsFromBinding = getOptionsAsFlagsFromBinding(); -for (let i = 0; i < argsFromBinding.length; i++) { - const arg = argsFromBinding[i]; +for (let i = 0; i < process.execArgv.length; i++) { + const arg = process.execArgv[i]; if (StringPrototypeStartsWith(arg, '--watch=')) { continue; } if (arg === '--watch') { - const nextArg = argsFromBinding[i + 1]; + const nextArg = process.execArgv[i + 1]; if (nextArg && nextArg[0] !== '-') { // If `--watch` doesn't include `=` and the next // argument is not a flag then it is interpreted as From 062f3a59e10b9874f21d945765083a043649c510 Mon Sep 17 00:00:00 2001 From: Efe Karasakal Date: Wed, 11 Feb 2026 21:12:26 +0100 Subject: [PATCH 2/2] watch: add test for checking cli flag order --- test/sequential/test-watch-mode.mjs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/sequential/test-watch-mode.mjs b/test/sequential/test-watch-mode.mjs index 4fb0f0acb377c3..a5cac129ad1c21 100644 --- a/test/sequential/test-watch-mode.mjs +++ b/test/sequential/test-watch-mode.mjs @@ -893,4 +893,33 @@ process.on('message', (message) => { await done(); } }); + + it('should respect the order for --env-file and --env-file-if-exists', async () => { + const envKey = `TEST_ENV_${Date.now()}`; + const jsFile = createTmpFile(`console.log('ENV: ' + process.env.${envKey});`); + + const envFile = createTmpFile(`${envKey}=base`, '.env'); + const envFileIfExists = createTmpFile(`${envKey}=override`, '.env'); + + const { done, restart } = runInBackground({ + args: [ + '--watch', + `--env-file=${envFile}`, + `--env-file-if-exists=${envFileIfExists}`, + jsFile, + ], + }); + + try { + const { stdout, stderr } = await restart(); + + assert.strictEqual(stderr, ''); + assert.deepStrictEqual(stdout, [ + 'ENV: override', + `Completed running ${inspect(jsFile)}. Waiting for file changes before restarting...`, + ]); + } finally { + await done(); + } + }); });