Skip to content

Commit 06f7a29

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

File tree

12 files changed

+324
-181
lines changed

12 files changed

+324
-181
lines changed

lib/internal/main/run.js

Lines changed: 0 additions & 74 deletions
This file was deleted.

lib/internal/shell.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

node.gyp

Lines changed: 2 additions & 0 deletions
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

Lines changed: 16 additions & 4 deletions
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_modules.cc

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -367,28 +367,6 @@ void BindingData::GetNearestParentPackageJSONType(
367367
args.GetReturnValue().Set(Array::New(realm->isolate(), values, 3));
368368
}
369369

370-
void BindingData::GetPackageJSONScripts(
371-
const FunctionCallbackInfo<Value>& args) {
372-
Realm* realm = Realm::GetCurrent(args);
373-
std::string_view path = "package.json";
374-
375-
THROW_IF_INSUFFICIENT_PERMISSIONS(
376-
realm->env(), permission::PermissionScope::kFileSystemRead, path);
377-
378-
auto package_json = GetPackageJSON(realm, path);
379-
if (package_json == nullptr) {
380-
printf("Can't read package.json\n");
381-
return;
382-
} else if (!package_json->scripts.has_value()) {
383-
printf("Can't read package.json \"scripts\" object\n");
384-
return;
385-
}
386-
387-
args.GetReturnValue().Set(
388-
ToV8Value(realm->context(), package_json->scripts.value())
389-
.ToLocalChecked());
390-
}
391-
392370
void BindingData::GetPackageScopeConfig(
393371
const FunctionCallbackInfo<Value>& args) {
394372
CHECK_GE(args.Length(), 1);
@@ -469,7 +447,6 @@ void BindingData::CreatePerIsolateProperties(IsolateData* isolate_data,
469447
"getNearestParentPackageJSON",
470448
GetNearestParentPackageJSON);
471449
SetMethod(isolate, target, "getPackageScopeConfig", GetPackageScopeConfig);
472-
SetMethod(isolate, target, "getPackageJSONScripts", GetPackageJSONScripts);
473450
}
474451

475452
void BindingData::CreatePerContextProperties(Local<Object> target,
@@ -486,7 +463,6 @@ void BindingData::RegisterExternalReferences(
486463
registry->Register(GetNearestParentPackageJSONType);
487464
registry->Register(GetNearestParentPackageJSON);
488465
registry->Register(GetPackageScopeConfig);
489-
registry->Register(GetPackageJSONScripts);
490466
}
491467

492468
} // namespace modules

src/node_options.cc

Lines changed: 5 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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)