Skip to content

Commit

Permalink
src: rewrite task runner in c++
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Apr 20, 2024
1 parent 9790ddf commit 558c595
Show file tree
Hide file tree
Showing 11 changed files with 320 additions and 154 deletions.
74 changes: 0 additions & 74 deletions lib/internal/main/run.js

This file was deleted.

37 changes: 0 additions & 37 deletions lib/internal/shell.js

This file was deleted.

2 changes: 2 additions & 0 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
'src/node_stat_watcher.cc',
'src/node_symbols.cc',
'src/node_task_queue.cc',
'src/node_task_runner.cc',
'src/node_trace_events.cc',
'src/node_types.cc',
'src/node_url.cc',
Expand Down Expand Up @@ -397,6 +398,7 @@
'test/cctest/test_base_object_ptr.cc',
'test/cctest/test_cppgc.cc',
'test/cctest/test_node_postmortem_metadata.cc',
'test/cctest/test_node_task_runner.cc',
'test/cctest/test_environment.cc',
'test/cctest/test_linked_binding.cc',
'test/cctest/test_node_api.cc',
Expand Down
20 changes: 16 additions & 4 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "node.h"
#include "node_dotenv.h"
#include "node_task_runner.h"

// ========== local headers ==========

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

if (!env->options()->run.empty()) {
return StartExecution(env, "internal/main/run");
}

if (!first_argv.empty() && first_argv != "-") {
return StartExecution(env, "internal/main/run_main_module");
}
Expand Down Expand Up @@ -1059,6 +1056,21 @@ InitializeOncePerProcessInternal(const std::vector<std::string>& args,
}
}

if (!per_process::cli_options->run.empty()) {
// Check if "--no-warnings" is passed to suppress the warning.
if (std::find(args.begin(), args.end(), "--no-warnings") == args.end()) {
fprintf(stderr,
"ExperimentalWarning: Task runner is an experimental feature and "
"might change at any time\n\n");
}

auto positional_args = task_runner::GetPositionalArgs(args);
result->early_return_ = true;
task_runner::RunTask(
&result, per_process::cli_options->run, positional_args);
return result;
}

if (!(flags & ProcessInitializationFlags::kNoPrintHelpOrVersionOutput)) {
if (per_process::cli_options->print_version) {
printf("%s\n", NODE_VERSION);
Expand Down
9 changes: 5 additions & 4 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -574,10 +574,7 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
"process V8 profiler output generated using --prof",
&EnvironmentOptions::prof_process);
// Options after --prof-process are passed through to the prof processor.
AddAlias("--prof-process", { "--prof-process", "--" });
AddOption("--run",
"Run a script specified in package.json",
&EnvironmentOptions::run);
AddAlias("--prof-process", {"--prof-process", "--"});
#if HAVE_INSPECTOR
AddOption("--cpu-prof",
"Start the V8 CPU profiler on start up, and write the CPU profile "
Expand Down Expand Up @@ -1081,6 +1078,10 @@ PerProcessOptionsParser::PerProcessOptionsParser(
"Generate a blob that can be embedded into the single executable "
"application",
&PerProcessOptions::experimental_sea_config);

AddOption("--run",
"Run a script specified in package.json",
&PerProcessOptions::run);
}

inline std::string RemoveBrackets(const std::string& host) {
Expand Down
2 changes: 1 addition & 1 deletion src/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ class EnvironmentOptions : public Options {
bool heap_prof = false;
#endif // HAVE_INSPECTOR
std::string redirect_warnings;
std::string run;
std::string diagnostic_dir;
std::string env_file;
bool has_env_file_string = false;
Expand Down Expand Up @@ -282,6 +281,7 @@ class PerProcessOptions : public Options {
bool print_v8_help = false;
bool print_version = false;
std::string experimental_sea_config;
std::string run;

#ifdef NODE_HAVE_I18N_SUPPORT
std::string icu_data_dir;
Expand Down
Loading

0 comments on commit 558c595

Please sign in to comment.