Skip to content

Commit 52368de

Browse files
committed
repl: reject --watch without script
Signed-off-by: iclectic <tansonestost@yahoo.com>
1 parent 4d27d80 commit 52368de

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

‎src/node.cc‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,13 @@ static ExitCode InitializeNodeWithArgsInternal(
993993
exit_code =
994994
ProcessGlobalArgsInternal(argv, exec_argv, errors, kDisallowedInEnvvar);
995995
if (exit_code != ExitCode::kNoFailure) return exit_code;
996+
997+
auto env_opts = per_process::cli_options->per_isolate->per_env;
998+
if (env_opts->watch_mode && !env_opts->test_runner &&
999+
env_opts->watch_mode_paths.empty() && argv->size() < 2) {
1000+
errors->push_back("--watch requires specifying a file");
1001+
return ExitCode::kInvalidCommandLineArgument;
1002+
}
9961003
}
9971004

9981005
// Set the process.title immediately after processing argv if --title is set.

‎src/node_options.cc‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,6 @@ void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors,
266266
} else if (test_runner_force_exit) {
267267
errors->push_back("either --watch or --test-force-exit "
268268
"can be used, not both");
269-
} else if (!test_runner && watch_mode_paths.empty() && argv->size() < 1) {
270-
errors->push_back("--watch requires specifying a file");
271269
}
272270

273271
#ifndef ALLOW_ATTACHING_DEBUGGER_IN_WATCH_MODE

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ async function runNode({
5151
tmpdir.refresh();
5252

5353
describe('watch mode - watch flags', { concurrency: !process.env.TEST_PARALLEL, timeout: 60_000 }, () => {
54+
it('should require a file to watch', async () => {
55+
const { code, signal, stderr, stdout } = await common.spawnPromisified(execPath, ['--watch']);
56+
57+
assert.strictEqual(code, 9);
58+
assert.strictEqual(signal, null);
59+
assert.match(stderr, /--watch requires specifying a file/);
60+
assert.strictEqual(stdout, '');
61+
});
62+
5463
it('when multiple `--watch` flags are provided should run as if only one was', async () => {
5564
const projectDir = tmpdir.resolve('project-multi-flag');
5665
mkdirSync(projectDir);

0 commit comments

Comments
 (0)