Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMoshe Atlow <moshe@atlow.co.il>2022-08-23 20:50:21 +0300
committerMoshe Atlow <moshe@atlow.co.il>2022-09-05 12:25:09 +0300
commitbeb0520af74ed20c3d48a1b4f6ca8a89664976c6 (patch)
treea1d36990721522ceae29a485b672e29abd9cfad5 /src
parent50a413183e92c690e1d9c594d59603cc8e717d62 (diff)
cli: add `--watch`
PR-URL: https://github.com/nodejs/node/pull/44366 Fixes: https://github.com/nodejs/node/issues/40429 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/env-inl.h3
-rw-r--r--src/inspector_agent.cc3
-rw-r--r--src/node.cc4
-rw-r--r--src/node_options.cc37
-rw-r--r--src/node_options.h5
5 files changed, 50 insertions, 2 deletions
diff --git a/src/env-inl.h b/src/env-inl.h
index 28fb3fda0db..569737ea211 100644
--- a/src/env-inl.h
+++ b/src/env-inl.h
@@ -648,7 +648,8 @@ inline bool Environment::owns_inspector() const {
}
inline bool Environment::should_create_inspector() const {
- return (flags_ & EnvironmentFlags::kNoCreateInspector) == 0;
+ return (flags_ & EnvironmentFlags::kNoCreateInspector) == 0 &&
+ !options_->test_runner && !options_->watch_mode;
}
inline bool Environment::tracks_unmanaged_fds() const {
diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc
index 34bb11e7d71..9ee779fb597 100644
--- a/src/inspector_agent.cc
+++ b/src/inspector_agent.cc
@@ -676,6 +676,9 @@ bool Agent::Start(const std::string& path,
const DebugOptions& options,
std::shared_ptr<ExclusiveAccess<HostPort>> host_port,
bool is_main) {
+ if (!options.allow_attaching_debugger) {
+ return false;
+ }
path_ = path;
debug_options_ = options;
CHECK_NOT_NULL(host_port);
diff --git a/src/node.cc b/src/node.cc
index 9f6a4a6a6ab..494c95046a0 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -340,6 +340,10 @@ MaybeLocal<Value> StartExecution(Environment* env, StartExecutionCallback cb) {
return StartExecution(env, "internal/main/test_runner");
}
+ if (env->options()->watch_mode && !first_argv.empty()) {
+ return StartExecution(env, "internal/main/watch_mode");
+ }
+
if (!first_argv.empty() && first_argv != "-") {
return StartExecution(env, "internal/main/run_main_module");
}
diff --git a/src/node_options.cc b/src/node_options.cc
index b9ffafb7cac..3ab9ab6e6da 100644
--- a/src/node_options.cc
+++ b/src/node_options.cc
@@ -156,9 +156,36 @@ void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors) {
errors->push_back("either --test or --interactive can be used, not both");
}
+ if (watch_mode) {
+ // TODO(MoLow): Support (incremental?) watch mode within test runner
+ errors->push_back("either --test or --watch can be used, not both");
+ }
+
if (debug_options_.inspector_enabled) {
errors->push_back("the inspector cannot be used with --test");
}
+#ifndef ALLOW_ATTACHING_DEBUGGER_IN_TEST_RUNNER
+ debug_options_.allow_attaching_debugger = false;
+#endif
+ }
+
+ if (watch_mode) {
+ if (syntax_check_only) {
+ errors->push_back("either --watch or --check can be used, not both");
+ }
+
+ if (has_eval_string) {
+ errors->push_back("either --watch or --eval can be used, not both");
+ }
+
+ if (force_repl) {
+ errors->push_back("either --watch or --interactive "
+ "can be used, not both");
+ }
+
+#ifndef ALLOW_ATTACHING_DEBUGGER_IN_WATCH_MODE
+ debug_options_.allow_attaching_debugger = false;
+#endif
}
#if HAVE_INSPECTOR
@@ -586,7 +613,15 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
"", /* undocumented, only for debugging */
&EnvironmentOptions::verify_base_objects,
kAllowedInEnvironment);
-
+ AddOption("--watch",
+ "run in watch mode",
+ &EnvironmentOptions::watch_mode,
+ kAllowedInEnvironment);
+ AddOption("--watch-path",
+ "path to watch",
+ &EnvironmentOptions::watch_mode_paths,
+ kAllowedInEnvironment);
+ Implies("--watch-path", "--watch");
AddOption("--check",
"syntax check script without executing",
&EnvironmentOptions::syntax_check_only);
diff --git a/src/node_options.h b/src/node_options.h
index ca43192d85a..004bcae837c 100644
--- a/src/node_options.h
+++ b/src/node_options.h
@@ -71,6 +71,7 @@ class DebugOptions : public Options {
DebugOptions(DebugOptions&&) = default;
DebugOptions& operator=(DebugOptions&&) = default;
+ bool allow_attaching_debugger = true;
// --inspect
bool inspector_enabled = false;
// --debug
@@ -172,6 +173,10 @@ class EnvironmentOptions : public Options {
false;
#endif // DEBUG
+ bool watch_mode = false;
+ bool watch_mode_report_to_parent = false;
+ std::vector<std::string> watch_mode_paths;
+
bool syntax_check_only = false;
bool has_eval_string = false;
bool experimental_wasi = false;