1'use strict';
2
3const { RegExpPrototypeExec } = primordials;
4
5const {
6  prepareMainThreadExecution,
7  markBootstrapComplete,
8} = require('internal/process/pre_execution');
9const { getOptionValue } = require('internal/options');
10
11const mainEntry = prepareMainThreadExecution(true);
12
13markBootstrapComplete();
14
15// Necessary to reset RegExp statics before user code runs.
16RegExpPrototypeExec(/^/, '');
17
18if (getOptionValue('--experimental-default-type') === 'module') {
19  require('internal/modules/run_main').executeUserEntryPoint(mainEntry);
20} else {
21  /**
22   * To support legacy monkey-patching of `Module.runMain`, we call `runMain` here to have the CommonJS loader begin
23   * the execution of the main entry point, even if the ESM loader immediately takes over because the main entry is an
24   * ES module or one of the other opt-in conditions (such as the use of `--import`) are met. Users can monkey-patch
25   * before the main entry point is loaded by doing so via scripts loaded through `--require`. This monkey-patchability
26   * is undesirable and is removed in `--experimental-default-type=module` mode.
27   */
28  require('internal/modules/cjs/loader').Module.runMain(mainEntry);
29}
30