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-09-29 12:19:09 +0300
committerDanielle Adams <adamzdanielle@gmail.com>2022-10-02 13:09:37 +0300
commit2f5f41c315c0dea7afcc827d2a33869a23dc666a (patch)
tree9d3eb5486192e1ec20441d7c26f8c96a72851d39 /src
parent2e7a17d73551dea4974e7067037b1f135215698e (diff)
cli: add `--watch`
PR-URL: https://github.com/nodejs/node/pull/44366 Backport-PR-URL: https://github.com/nodejs/node/pull/44815 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 cbe4b734b1c..e38531800e7 100644
--- a/src/env-inl.h
+++ b/src/env-inl.h
@@ -655,7 +655,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 38ecd530148..c722ae31235 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -497,6 +497,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 bd4ad2f6408..d08184f3da5 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 b20cfae1419..2f114242978 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;