UNPKG

nstdlib-nightly

Version:

Node.js standard library converted to runtime-agnostic ES modules.

30 lines (24 loc) 1.43 kB
// Source: https://github.com/nodejs/node/blob/65eff1eb/lib/internal/main/run_main_module.js import * as __hoisted_internal_modules_cjs_loader__ from "nstdlib/lib/internal/modules/cjs/loader"; import { prepareMainThreadExecution, markBootstrapComplete, } from "nstdlib/lib/internal/process/pre_execution"; import { getOptionValue } from "nstdlib/lib/internal/options"; import * as __hoisted_internal_modules_run_main__ from "nstdlib/lib/internal/modules/run_main"; const mainEntry = prepareMainThreadExecution(true); markBootstrapComplete(); // Necessary to reset RegExp statics before user code runs. RegExp.prototype.exec.call(/^/, ""); if (getOptionValue("--experimental-default-type") === "module") { __hoisted_internal_modules_run_main__.executeUserEntryPoint(mainEntry); } else { /** * To support legacy monkey-patching of `Module.runMain`, we call `runMain` here to have the CommonJS loader begin * the execution of the main entry point, even if the ESM loader immediately takes over because the main entry is an * ES module or one of the other opt-in conditions (such as the use of `--import`) are met. Users can monkey-patch * before the main entry point is loaded by doing so via scripts loaded through `--require`. This monkey-patchability * is undesirable and is removed in `--experimental-default-type=module` mode. */ __hoisted_internal_modules_cjs_loader__.Module.runMain(mainEntry); }