Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 30e3818

Browse filesBrowse files
efekrskladuh95
authored andcommitted
watch: get flags from execArgv
PR-URL: #61779 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
1 parent a433759 commit 30e3818
Copy full SHA for 30e3818

2 files changed

+33-5Lines changed: 33 additions & 5 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/main/watch_mode.js‎

Copy file name to clipboardExpand all lines: lib/internal/main/watch_mode.js
+4-5Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const {
1818
triggerUncaughtException,
1919
exitCodes: { kNoFailure },
2020
} = internalBinding('errors');
21-
const { getOptionValue, getOptionsAsFlagsFromBinding } = require('internal/options');
21+
const { getOptionValue } = require('internal/options');
2222
const { FilesWatcher } = require('internal/watch_mode/files_watcher');
2323
const { green, blue, red, white, clear } = require('internal/util/colors');
2424
const { convertToValidSignal } = require('internal/util');
@@ -44,14 +44,13 @@ const kCommand = ArrayPrototypeSlice(process.argv, 1);
4444
const kCommandStr = inspect(ArrayPrototypeJoin(kCommand, ' '));
4545

4646
const argsWithoutWatchOptions = [];
47-
const argsFromBinding = getOptionsAsFlagsFromBinding();
48-
for (let i = 0; i < argsFromBinding.length; i++) {
49-
const arg = argsFromBinding[i];
47+
for (let i = 0; i < process.execArgv.length; i++) {
48+
const arg = process.execArgv[i];
5049
if (StringPrototypeStartsWith(arg, '--watch=')) {
5150
continue;
5251
}
5352
if (arg === '--watch') {
54-
const nextArg = argsFromBinding[i + 1];
53+
const nextArg = process.execArgv[i + 1];
5554
if (nextArg && nextArg[0] !== '-') {
5655
// If `--watch` doesn't include `=` and the next
5756
// argument is not a flag then it is interpreted as
Collapse file

‎test/sequential/test-watch-mode.mjs‎

Copy file name to clipboardExpand all lines: test/sequential/test-watch-mode.mjs
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,4 +893,33 @@ process.on('message', (message) => {
893893
await done();
894894
}
895895
});
896+
897+
it('should respect the order for --env-file and --env-file-if-exists', async () => {
898+
const envKey = `TEST_ENV_${Date.now()}`;
899+
const jsFile = createTmpFile(`console.log('ENV: ' + process.env.${envKey});`);
900+
901+
const envFile = createTmpFile(`${envKey}=base`, '.env');
902+
const envFileIfExists = createTmpFile(`${envKey}=override`, '.env');
903+
904+
const { done, restart } = runInBackground({
905+
args: [
906+
'--watch',
907+
`--env-file=${envFile}`,
908+
`--env-file-if-exists=${envFileIfExists}`,
909+
jsFile,
910+
],
911+
});
912+
913+
try {
914+
const { stdout, stderr } = await restart();
915+
916+
assert.strictEqual(stderr, '');
917+
assert.deepStrictEqual(stdout, [
918+
'ENV: override',
919+
`Completed running ${inspect(jsFile)}. Waiting for file changes before restarting...`,
920+
]);
921+
} finally {
922+
await done();
923+
}
924+
});
896925
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.