GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — watch: strip underscore aliases of watch flags by trivikr · Pull Request #66365 · nodejs/node

watch: strip underscore aliases of watch flags #66365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
nodejs-github-bot merged 2 commits into nodejs:main from trivikr:watch-underscore-aliases
Oct 6, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

watch: strip underscore aliases of watch flags #66365

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
2 commits
Select commit Hold shift + click to select a range
5c84adc
watch: strip underscore aliases of watch flags
trivikr Sep 28, 2026
0594e97
fixup! watch: strip underscore aliases of watch flags
trivikr Sep 28, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

35 changes: 26 additions & 9 deletions 35 lib/internal/main/watch_mode.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const {
ArrayPrototypePushApply,
ArrayPrototypeSlice,
StringPrototypeIncludes,
StringPrototypeIndexOf,
StringPrototypeReplaceAll,
StringPrototypeSlice,
StringPrototypeStartsWith,
} = primordials;

Expand Down Expand Up @@ -42,9 +44,23 @@ const kPreserveOutput = getOptionValue('--watch-preserve-output');
const kCommand = ArrayPrototypeSlice(process.argv, 1);
const kCommandStr = inspect(ArrayPrototypeJoin(kCommand, ' '));

// The C++ option parser treats `_` and `-` as equivalent in option names
// (e.g. --watch_path is --watch-path), so normalize before matching.
function normalizeOptionName(arg) {
if (!StringPrototypeStartsWith(arg, '--')) {
return arg;
}
const equalsIndex = StringPrototypeIndexOf(arg, '=');
if (equalsIndex === -1) {
return StringPrototypeReplaceAll(arg, '_', '-');
}
return StringPrototypeReplaceAll(StringPrototypeSlice(arg, 0, equalsIndex), '_', '-') +
StringPrototypeSlice(arg, equalsIndex);
}

const argsWithoutWatchOptions = [];
for (let i = 0; i < process.execArgv.length; i++) {
const arg = process.execArgv[i];
const arg = normalizeOptionName(process.execArgv[i]);
if (StringPrototypeStartsWith(arg, '--watch=')) {
continue;
}
Expand Down Expand Up @@ -75,7 +91,7 @@ for (let i = 0; i < process.execArgv.length; i++) {
if (arg === '--experimental-default-config-file') {
continue;
}
ArrayPrototypePush(argsWithoutWatchOptions, arg);
ArrayPrototypePush(argsWithoutWatchOptions, process.execArgv[i]);
}

ArrayPrototypePushApply(argsWithoutWatchOptions, kCommand);
Expand All @@ -89,15 +105,16 @@ if (kNodeOptions != null) {
const parts = parseNodeOptionsEnvVar(kNodeOptions);
for (let i = 0; i < parts.length; i++) {
const part = parts[i];
if (part === '--watch' ||
part === '--watch-preserve-output' ||
StringPrototypeStartsWith(part, '--watch=') ||
StringPrototypeStartsWith(part, '--watch-preserve-output=') ||
StringPrototypeStartsWith(part, '--watch-path=') ||
StringPrototypeStartsWith(part, '--watch-kill-signal=')) {
const name = normalizeOptionName(part);
if (name === '--watch' ||
name === '--watch-preserve-output' ||
StringPrototypeStartsWith(name, '--watch=') ||
StringPrototypeStartsWith(name, '--watch-preserve-output=') ||
StringPrototypeStartsWith(name, '--watch-path=') ||
StringPrototypeStartsWith(name, '--watch-kill-signal=')) {
continue;
}
if (part === '--watch-path' || part === '--watch-kill-signal') {
if (name === '--watch-path' || name === '--watch-kill-signal') {
// Skip the flag and its separate value argument
i++;
continue;
Expand Down
54 changes: 54 additions & 0 deletions 54 test/sequential/test-watch-mode.mjs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,60 @@ process.on('message', (message) => {
}
});

it('should strip underscore aliases of watch flags from NODE_OPTIONS', async () => {
// Avoid recursively watching the repository's source and test trees.
const cwd = tmpdir.resolve('node-options-underscore');
mkdirSync(path.join(cwd, 'src'), { recursive: true });
mkdirSync(path.join(cwd, 'test'));
const file = createTmpFile('console.log(process.env.NODE_OPTIONS);');
const nodeOptions = [
'--watch_path=./src',
'--watch_path', './test',
'--watch_preserve_output',
'--watch_preserve_output=true',
'--watch_kill_signal=SIGKILL',
'--watch_kill_signal', 'SIGINT',
'--max_old_space_size=4096',
'--no-warnings',
].join(' ');
const { done, restart } = runInBackground({
args: ['--watch', file],
options: {
cwd,
env: { ...process.env, NODE_OPTIONS: nodeOptions },
},
});

try {
const { stdout, stderr } = await restart();

assert.strictEqual(stderr, '');
const nodeOptionsLine = stdout.find((line) => line.includes('--max_old_space_size'));
assert.ok(nodeOptionsLine);
assert.strictEqual(nodeOptionsLine, '--max_old_space_size=4096 --no-warnings');
} finally {
await done();
}
});

it('should strip --watch_path from execArgv in child process', async () => {
const dir = tmpdir.resolve('exec-argv-underscore');
mkdirSync(dir, { recursive: true });
const file = createTmpFile('console.log(JSON.stringify(process.execArgv));');
const { done, restart } = runInBackground({
args: [`--watch_path=${dir}`, file],
});

try {
const { stdout, stderr } = await restart();

assert.strictEqual(stderr, '');
assert.ok(stdout.includes('["--no-warnings"]'));
} finally {
await done();
}
});

it('should not strip --watch when it appears inside a quoted NODE_OPTIONS value', {
// Honoring --require from NODE_OPTIONS is required for this test.
skip: !!process.config.variables.node_without_node_options,
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.