Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,13 @@ static ExitCode InitializeNodeWithArgsInternal(
exit_code =
ProcessGlobalArgsInternal(argv, exec_argv, errors, kDisallowedInEnvvar);
if (exit_code != ExitCode::kNoFailure) return exit_code;

auto env_opts = per_process::cli_options->per_isolate->per_env;
if (env_opts->watch_mode && !env_opts->test_runner &&
env_opts->watch_mode_paths.empty() && argv->size() < 2) {
errors->push_back("--watch requires specifying a file");
return ExitCode::kInvalidCommandLineArgument;
}
}

// Set the process.title immediately after processing argv if --title is set.
Expand Down
2 changes: 0 additions & 2 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,6 @@ void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors,
} else if (test_runner_force_exit) {
errors->push_back("either --watch or --test-force-exit "
"can be used, not both");
} else if (!test_runner && watch_mode_paths.empty() && argv->size() < 1) {
errors->push_back("--watch requires specifying a file");
}

#ifndef ALLOW_ATTACHING_DEBUGGER_IN_WATCH_MODE
Expand Down
9 changes: 9 additions & 0 deletions test/sequential/test-watch-mode-watch-flags.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ async function runNode({
tmpdir.refresh();

describe('watch mode - watch flags', { concurrency: !process.env.TEST_PARALLEL, timeout: 60_000 }, () => {
it('should require a file to watch', async () => {
const { code, signal, stderr, stdout } = await common.spawnPromisified(execPath, ['--watch']);

assert.strictEqual(code, 9);
assert.strictEqual(signal, null);
assert.match(stderr, /--watch requires specifying a file/);
assert.strictEqual(stdout, '');
});

it('when multiple `--watch` flags are provided should run as if only one was', async () => {
const projectDir = tmpdir.resolve('project-multi-flag');
mkdirSync(projectDir);
Expand Down