Skip to content

Commit 0b92919

Browse files
committed
src: rewrite task runner in c++
1 parent 9790ddf commit 0b92919

11 files changed

+321
-154
lines changed

lib/internal/main/run.js

-74
This file was deleted.

lib/internal/shell.js

-37
This file was deleted.

node.gyp

+2
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
'src/node_stat_watcher.cc',
137137
'src/node_symbols.cc',
138138
'src/node_task_queue.cc',
139+
'src/node_task_runner.cc',
139140
'src/node_trace_events.cc',
140141
'src/node_types.cc',
141142
'src/node_url.cc',
@@ -397,6 +398,7 @@
397398
'test/cctest/test_base_object_ptr.cc',
398399
'test/cctest/test_cppgc.cc',
399400
'test/cctest/test_node_postmortem_metadata.cc',
401+
'test/cctest/test_node_task_runner.cc',
400402
'test/cctest/test_environment.cc',
401403
'test/cctest/test_linked_binding.cc',
402404
'test/cctest/test_node_api.cc',

src/node.cc

+16-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "node.h"
2323
#include "node_dotenv.h"
24+
#include "node_task_runner.h"
2425

2526
// ========== local headers ==========
2627

@@ -409,10 +410,6 @@ MaybeLocal<Value> StartExecution(Environment* env, StartExecutionCallback cb) {
409410
return StartExecution(env, "internal/main/watch_mode");
410411
}
411412

412-
if (!env->options()->run.empty()) {
413-
return StartExecution(env, "internal/main/run");
414-
}
415-
416413
if (!first_argv.empty() && first_argv != "-") {
417414
return StartExecution(env, "internal/main/run_main_module");
418415
}
@@ -1059,6 +1056,21 @@ InitializeOncePerProcessInternal(const std::vector<std::string>& args,
10591056
}
10601057
}
10611058

1059+
if (!per_process::cli_options->run.empty()) {
1060+
// Check if "--no-warnings" is passed to suppress the warning.
1061+
if (std::find(args.begin(), args.end(), "--no-warnings") == args.end()) {
1062+
fprintf(stderr,
1063+
"ExperimentalWarning: Task runner is an experimental feature and "
1064+
"might change at any time\n\n");
1065+
}
1066+
1067+
auto positional_args = task_runner::GetPositionalArgs(args);
1068+
result->early_return_ = true;
1069+
task_runner::RunTask(
1070+
&result, per_process::cli_options->run, positional_args);
1071+
return result;
1072+
}
1073+
10621074
if (!(flags & ProcessInitializationFlags::kNoPrintHelpOrVersionOutput)) {
10631075
if (per_process::cli_options->print_version) {
10641076
printf("%s\n", NODE_VERSION);

src/node_options.cc

+5-4
Original file line numberDiff line numberDiff line change
@@ -574,10 +574,7 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
574574
"process V8 profiler output generated using --prof",
575575
&EnvironmentOptions::prof_process);
576576
// Options after --prof-process are passed through to the prof processor.
577-
AddAlias("--prof-process", { "--prof-process", "--" });
578-
AddOption("--run",
579-
"Run a script specified in package.json",
580-
&EnvironmentOptions::run);
577+
AddAlias("--prof-process", {"--prof-process", "--"});
581578
#if HAVE_INSPECTOR
582579
AddOption("--cpu-prof",
583580
"Start the V8 CPU profiler on start up, and write the CPU profile "
@@ -1081,6 +1078,10 @@ PerProcessOptionsParser::PerProcessOptionsParser(
10811078
"Generate a blob that can be embedded into the single executable "
10821079
"application",
10831080
&PerProcessOptions::experimental_sea_config);
1081+
1082+
AddOption("--run",
1083+
"Run a script specified in package.json",
1084+
&PerProcessOptions::run);
10841085
}
10851086

10861087
inline std::string RemoveBrackets(const std::string& host) {

src/node_options.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ class EnvironmentOptions : public Options {
162162
bool heap_prof = false;
163163
#endif // HAVE_INSPECTOR
164164
std::string redirect_warnings;
165-
std::string run;
166165
std::string diagnostic_dir;
167166
std::string env_file;
168167
bool has_env_file_string = false;
@@ -282,6 +281,7 @@ class PerProcessOptions : public Options {
282281
bool print_v8_help = false;
283282
bool print_version = false;
284283
std::string experimental_sea_config;
284+
std::string run;
285285

286286
#ifdef NODE_HAVE_I18N_SUPPORT
287287
std::string icu_data_dir;

0 commit comments

Comments
 (0)