GeezerVison is showing github.com — src: rewrite task runner in c++ · nodejs/node@fb24c44
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/main/run.js -74Lines changed: 0 additions & 74 deletions Collapse file Copy file name to clipboardExpand all lines: lib/internal/shell.js -37Lines changed: 0 additions & 37 deletions Collapse file Copy file name to clipboardExpand all lines: node.gyp +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 136 | 136 | 'src/node_stat_watcher.cc', | 137 | 137 | 'src/node_symbols.cc', | 138 | 138 | 'src/node_task_queue.cc', | | 139 | + 'src/node_task_runner.cc', | 139 | 140 | 'src/node_trace_events.cc', | 140 | 141 | 'src/node_types.cc', | 141 | 142 | 'src/node_url.cc', | | 397 | 398 | 'test/cctest/test_base_object_ptr.cc', | 398 | 399 | 'test/cctest/test_cppgc.cc', | 399 | 400 | 'test/cctest/test_node_postmortem_metadata.cc', | | 401 | + 'test/cctest/test_node_task_runner.cc', | 400 | 402 | 'test/cctest/test_environment.cc', | 401 | 403 | 'test/cctest/test_linked_binding.cc', | 402 | 404 | 'test/cctest/test_node_api.cc', | |
Collapse file Copy file name to clipboardExpand all lines: src/node.cc +21-8Lines changed: 21 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 21 | 21 |
| 22 | 22 | #include "node.h" | 23 | 23 | #include "node_dotenv.h" | | 24 | +#include "node_task_runner.h" | 24 | 25 |
| 25 | 26 | // ========== local headers ========== | 26 | 27 |
| @@ -409,10 +410,6 @@ MaybeLocal<Value> StartExecution(Environment* env, StartExecutionCallback cb) { | 409 | 410 | return StartExecution(env, "internal/main/watch_mode"); | 410 | 411 | } | 411 | 412 |
| 412 | | - if (!env->options()->run.empty()) { | 413 | | - return StartExecution(env, "internal/main/run"); | 414 | | - } | 415 | | - | 416 | 413 | if (!first_argv.empty() && first_argv != "-") { | 417 | 414 | return StartExecution(env, "internal/main/run_main_module"); | 418 | 415 | } | @@ -1025,11 +1022,11 @@ int InitializeNodeWithArgs(std::vector<std::string>* argv, | 1025 | 1022 | InitializeNodeWithArgsInternal(argv, exec_argv, errors, flags)); | 1026 | 1023 | } | 1027 | 1024 |
| 1028 | | -static std::unique_ptr<InitializationResultImpl> | | 1025 | +static std::shared_ptr<InitializationResultImpl> | 1029 | 1026 | InitializeOncePerProcessInternal(const std::vector<std::string>& args, | 1030 | 1027 | ProcessInitializationFlags::Flags flags = | 1031 | 1028 | ProcessInitializationFlags::kNoFlags) { | 1032 | | - auto result = std::make_unique<InitializationResultImpl>(); | | 1029 | + auto result = std::make_shared<InitializationResultImpl>(); | 1033 | 1030 | result->args_ = args; | 1034 | 1031 |
| 1035 | 1032 | if (!(flags & ProcessInitializationFlags::kNoParseGlobalDebugVariables)) { | @@ -1059,6 +1056,22 @@ InitializeOncePerProcessInternal(const std::vector<std::string>& args, | 1059 | 1056 | } | 1060 | 1057 | } | 1061 | 1058 |
| | 1059 | + if (!per_process::cli_options->run.empty()) { | | 1060 | + // TODO(@anonrig): Handle NODE_NO_WARNINGS, NODE_REDIRECT_WARNINGS, | | 1061 | + // --disable-warning and --redirect-warnings. | | 1062 | + if (per_process::cli_options->per_isolate->per_env->warnings) { | | 1063 | + fprintf(stderr, | | 1064 | + "ExperimentalWarning: Task runner is an experimental feature and " | | 1065 | + "might change at any time\n\n"); | | 1066 | + } | | 1067 | + | | 1068 | + auto positional_args = task_runner::GetPositionalArgs(args); | | 1069 | + result->early_return_ = true; | | 1070 | + task_runner::RunTask( | | 1071 | + result, per_process::cli_options->run, positional_args); | | 1072 | + return result; | | 1073 | + } | | 1074 | + | 1062 | 1075 | if (!(flags & ProcessInitializationFlags::kNoPrintHelpOrVersionOutput)) { | 1063 | 1076 | if (per_process::cli_options->print_version) { | 1064 | 1077 | printf("%s\n", NODE_VERSION); | @@ -1218,7 +1231,7 @@ InitializeOncePerProcessInternal(const std::vector<std::string>& args, | 1218 | 1231 | return result; | 1219 | 1232 | } | 1220 | 1233 |
| 1221 | | -std::unique_ptr<InitializationResult> InitializeOncePerProcess( | | 1234 | +std::shared_ptr<InitializationResult> InitializeOncePerProcess( | 1222 | 1235 | const std::vector<std::string>& args, | 1223 | 1236 | ProcessInitializationFlags::Flags flags) { | 1224 | 1237 | return InitializeOncePerProcessInternal(args, flags); | @@ -1424,7 +1437,7 @@ static ExitCode StartInternal(int argc, char** argv) { | 1424 | 1437 | // Hack around with the argv pointer. Used for process.title = "blah". | 1425 | 1438 | argv = uv_setup_args(argc, argv); | 1426 | 1439 |
| 1427 | | - std::unique_ptr<InitializationResultImpl> result = | | 1440 | + std::shared_ptr<InitializationResultImpl> result = | 1428 | 1441 | InitializeOncePerProcessInternal( | 1429 | 1442 | std::vector<std::string>(argv, argv + argc)); | 1430 | 1443 | for (const std::string& error : result->errors()) { | |
Collapse file Copy file name to clipboardExpand all lines: src/node.h +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -349,7 +349,7 @@ NODE_DEPRECATED("Use InitializeOncePerProcess() instead", | 349 | 349 | // including the arguments split into argv/exec_argv, a list of potential | 350 | 350 | // errors encountered during initialization, and a potential suggested | 351 | 351 | // exit code. | 352 | | -NODE_EXTERN std::unique_ptr<InitializationResult> InitializeOncePerProcess( | | 352 | +NODE_EXTERN std::shared_ptr<InitializationResult> InitializeOncePerProcess( | 353 | 353 | const std::vector<std::string>& args, | 354 | 354 | ProcessInitializationFlags::Flags flags = | 355 | 355 | ProcessInitializationFlags::kNoFlags); | @@ -358,7 +358,7 @@ NODE_EXTERN std::unique_ptr<InitializationResult> InitializeOncePerProcess( | 358 | 358 | NODE_EXTERN void TearDownOncePerProcess(); | 359 | 359 | // Convenience overload for specifying multiple flags without having | 360 | 360 | // to worry about casts. | 361 | | -inline std::unique_ptr<InitializationResult> InitializeOncePerProcess( | | 361 | +inline std::shared_ptr<InitializationResult> InitializeOncePerProcess( | 362 | 362 | const std::vector<std::string>& args, | 363 | 363 | std::initializer_list<ProcessInitializationFlags::Flags> list) { | 364 | 364 | uint64_t flags_accum = ProcessInitializationFlags::kNoFlags; | |
Collapse file Copy file name to clipboardExpand all lines: src/node_modules.cc -24Lines changed: 0 additions & 24 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -367,28 +367,6 @@ void BindingData::GetNearestParentPackageJSONType( | 367 | 367 | args.GetReturnValue().Set(Array::New(realm->isolate(), values, 3)); | 368 | 368 | } | 369 | 369 |
| 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 | | - | 392 | 370 | void BindingData::GetPackageScopeConfig( | 393 | 371 | const FunctionCallbackInfo<Value>& args) { | 394 | 372 | CHECK_GE(args.Length(), 1); | @@ -469,7 +447,6 @@ void BindingData::CreatePerIsolateProperties(IsolateData* isolate_data, | 469 | 447 | "getNearestParentPackageJSON", | 470 | 448 | GetNearestParentPackageJSON); | 471 | 449 | SetMethod(isolate, target, "getPackageScopeConfig", GetPackageScopeConfig); | 472 | | - SetMethod(isolate, target, "getPackageJSONScripts", GetPackageJSONScripts); | 473 | 450 | } | 474 | 451 |
| 475 | 452 | void BindingData::CreatePerContextProperties(Local<Object> target, | @@ -486,7 +463,6 @@ void BindingData::RegisterExternalReferences( | 486 | 463 | registry->Register(GetNearestParentPackageJSONType); | 487 | 464 | registry->Register(GetNearestParentPackageJSON); | 488 | 465 | registry->Register(GetPackageScopeConfig); | 489 | | - registry->Register(GetPackageJSONScripts); | 490 | 466 | } | 491 | 467 |
| 492 | 468 | } // namespace modules | |
Collapse file Copy file name to clipboardExpand all lines: src/node_options.cc +5-4Lines changed: 5 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -578,10 +578,7 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { | 578 | 578 | "process V8 profiler output generated using --prof", | 579 | 579 | &EnvironmentOptions::prof_process); | 580 | 580 | // Options after --prof-process are passed through to the prof processor. | 581 | | - AddAlias("--prof-process", { "--prof-process", "--" }); | 582 | | - AddOption("--run", | 583 | | - "Run a script specified in package.json", | 584 | | - &EnvironmentOptions::run); | | 581 | + AddAlias("--prof-process", {"--prof-process", "--"}); | 585 | 582 | #if HAVE_INSPECTOR | 586 | 583 | AddOption("--cpu-prof", | 587 | 584 | "Start the V8 CPU profiler on start up, and write the CPU profile " | @@ -1085,6 +1082,10 @@ PerProcessOptionsParser::PerProcessOptionsParser( | 1085 | 1082 | "Generate a blob that can be embedded into the single executable " | 1086 | 1083 | "application", | 1087 | 1084 | &PerProcessOptions::experimental_sea_config); | | 1085 | + | | 1086 | + AddOption("--run", | | 1087 | + "Run a script specified in package.json", | | 1088 | + &PerProcessOptions::run); | 1088 | 1089 | } | 1089 | 1090 |
| 1090 | 1091 | inline std::string RemoveBrackets(const std::string& host) { | |
Collapse file Copy file name to clipboardExpand all lines: src/node_options.h +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -162,7 +162,6 @@ class EnvironmentOptions : public Options { | 162 | 162 | bool heap_prof = false; | 163 | 163 | #endif // HAVE_INSPECTOR | 164 | 164 | std::string redirect_warnings; | 165 | | - std::string run; | 166 | 165 | std::string diagnostic_dir; | 167 | 166 | std::string env_file; | 168 | 167 | bool has_env_file_string = false; | @@ -282,6 +281,7 @@ class PerProcessOptions : public Options { | 282 | 281 | bool print_v8_help = false; | 283 | 282 | bool print_version = false; | 284 | 283 | std::string experimental_sea_config; | | 284 | + std::string run; | 285 | 285 |
| 286 | 286 | #ifdef NODE_HAVE_I18N_SUPPORT | 287 | 287 | std::string icu_data_dir; | |
|