diff --git a/src/node.cc b/src/node.cc index 90ed0e39d96bfa..9906a917d2ea9a 100644 --- a/src/node.cc +++ b/src/node.cc @@ -347,7 +347,7 @@ MaybeLocal StartExecution(Environment* env, StartExecutionCallback cb) { return StartExecution(env, "internal/main/test_runner"); } - if (env->options()->watch_mode && !first_argv.empty()) { + if (env->options()->watch_mode) { return StartExecution(env, "internal/main/watch_mode"); } diff --git a/src/node_options-inl.h b/src/node_options-inl.h index 7facb22afc3c9b..988814c876ee4e 100644 --- a/src/node_options-inl.h +++ b/src/node_options-inl.h @@ -466,7 +466,7 @@ void OptionsParser::Parse( UNREACHABLE(); } } - options->CheckOptions(errors); + options->CheckOptions(errors, orig_args); } } // namespace options_parser diff --git a/src/node_options.cc b/src/node_options.cc index 98f7d5b6e52a0d..ff1fb266a60f17 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -34,7 +34,8 @@ Mutex cli_options_mutex; std::shared_ptr cli_options{new PerProcessOptions()}; } // namespace per_process -void DebugOptions::CheckOptions(std::vector* errors) { +void DebugOptions::CheckOptions(std::vector* errors, + std::vector* argv) { #if !NODE_USE_V8_PLATFORM && !HAVE_INSPECTOR if (inspector_enabled) { errors->push_back("Inspector is not available when Node is compiled " @@ -64,7 +65,8 @@ void DebugOptions::CheckOptions(std::vector* errors) { } } -void PerProcessOptions::CheckOptions(std::vector* errors) { +void PerProcessOptions::CheckOptions(std::vector* errors, + std::vector* argv) { #if HAVE_OPENSSL if (use_openssl_ca && use_bundled_ca) { errors->push_back("either --use-openssl-ca or --use-bundled-ca can be " @@ -91,14 +93,16 @@ void PerProcessOptions::CheckOptions(std::vector* errors) { use_largepages != "silent") { errors->push_back("invalid value for --use-largepages"); } - per_isolate->CheckOptions(errors); + per_isolate->CheckOptions(errors, argv); } -void PerIsolateOptions::CheckOptions(std::vector* errors) { - per_env->CheckOptions(errors); +void PerIsolateOptions::CheckOptions(std::vector* errors, + std::vector* argv) { + per_env->CheckOptions(errors, argv); } -void EnvironmentOptions::CheckOptions(std::vector* errors) { +void EnvironmentOptions::CheckOptions(std::vector* errors, + std::vector* argv) { if (has_policy_integrity_string && experimental_policy.empty()) { errors->push_back("--policy-integrity requires " "--experimental-policy be enabled"); @@ -169,15 +173,13 @@ void EnvironmentOptions::CheckOptions(std::vector* errors) { if (watch_mode) { if (syntax_check_only) { errors->push_back("either --watch or --check can be used, not both"); - } - - if (has_eval_string) { + } else if (has_eval_string) { errors->push_back("either --watch or --eval can be used, not both"); - } - - if (force_repl) { + } else if (force_repl) { errors->push_back("either --watch or --interactive " "can be used, not both"); + } else if (argv->size() < 1 || (*argv)[1].empty()) { + errors->push_back("--watch requires specifying a file"); } #ifndef ALLOW_ATTACHING_DEBUGGER_IN_WATCH_MODE @@ -222,7 +224,7 @@ void EnvironmentOptions::CheckOptions(std::vector* errors) { heap_prof_dir = diagnostic_dir; } - debug_options_.CheckOptions(errors); + debug_options_.CheckOptions(errors, argv); #endif // HAVE_INSPECTOR } diff --git a/src/node_options.h b/src/node_options.h index 915d2a4bdcfab8..6c8073dead6de4 100644 --- a/src/node_options.h +++ b/src/node_options.h @@ -50,7 +50,8 @@ class HostPort { class Options { public: - virtual void CheckOptions(std::vector* errors) {} + virtual void CheckOptions(std::vector* errors, + std::vector* argv) {} virtual ~Options() = default; }; @@ -99,7 +100,8 @@ class DebugOptions : public Options { return break_first_line || break_node_first_line; } - void CheckOptions(std::vector* errors) override; + void CheckOptions(std::vector* errors, + std::vector* argv) override; }; class EnvironmentOptions : public Options { @@ -202,7 +204,8 @@ class EnvironmentOptions : public Options { inline DebugOptions* get_debug_options() { return &debug_options_; } inline const DebugOptions& debug_options() const { return debug_options_; } - void CheckOptions(std::vector* errors) override; + void CheckOptions(std::vector* errors, + std::vector* argv) override; private: DebugOptions debug_options_; @@ -217,7 +220,8 @@ class PerIsolateOptions : public Options { bool experimental_shadow_realm = false; std::string report_signal = "SIGUSR2"; inline EnvironmentOptions* get_per_env_options(); - void CheckOptions(std::vector* errors) override; + void CheckOptions(std::vector* errors, + std::vector* argv) override; }; class PerProcessOptions : public Options { @@ -290,7 +294,8 @@ class PerProcessOptions : public Options { std::vector cmdline; inline PerIsolateOptions* get_per_isolate_options(); - void CheckOptions(std::vector* errors) override; + void CheckOptions(std::vector* errors, + std::vector* argv) override; }; // The actual options parser, as opposed to the structs containing them: