Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2019-11-10 11:59:16 +0300
committerAnna Henningsen <anna@addaleax.net>2019-11-19 15:43:59 +0300
commitefce655c0f1671d0e86b5c89092ac93db983ef94 (patch)
tree26af173e687a6c8ee0f26d2857742ffce01729f2 /lib/internal/main
parent0f78dcc86d9af8f742f76505c5a104c6dff17ca9 (diff)
module: reduce circular dependency of internal/modules/cjs/loader
Previously `internal/bootstrap/pre_execution.js` requires `internal/modules/cjs/loader.js` which in turn requires `internal/bootstrap/pre_execution.js`. This patch moves the entry point execution logic out of `pre_execution.js` and puts it into `internal/modules/run_main.js`. It also tests that `Module.runMain` can be monkey-patched before further deprecation/refactoring can be done. Also added an internal assertion `hasLoadedAnyUserCJSModule` for documentation purposes. PR-URL: https://github.com/nodejs/node/pull/30349 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'lib/internal/main')
-rw-r--r--lib/internal/main/run_main_module.js10
-rw-r--r--lib/internal/main/worker_thread.js8
2 files changed, 12 insertions, 6 deletions
diff --git a/lib/internal/main/run_main_module.js b/lib/internal/main/run_main_module.js
index eae9042041a..ca5d1122c59 100644
--- a/lib/internal/main/run_main_module.js
+++ b/lib/internal/main/run_main_module.js
@@ -6,10 +6,12 @@ const {
prepareMainThreadExecution(true);
-const CJSModule = require('internal/modules/cjs/loader').Module;
-
markBootstrapComplete();
// Note: this loads the module through the ESM loader if the module is
-// determined to be an ES module
-CJSModule.runMain(process.argv[1]);
+// determined to be an ES module. This hangs from the CJS module loader
+// because we currently allow monkey-patching of the module loaders
+// in the preloaded scripts through require('module').
+// runMain here might be monkey-patched by users in --require.
+// XXX: the monkey-patchability here should probably be deprecated.
+require('internal/modules/cjs/loader').Module.runMain(process.argv[1]);
diff --git a/lib/internal/main/worker_thread.js b/lib/internal/main/worker_thread.js
index 7cf8ffb8b40..13d7e8de0ec 100644
--- a/lib/internal/main/worker_thread.js
+++ b/lib/internal/main/worker_thread.js
@@ -108,6 +108,9 @@ port.on('message', (message) => {
initializeDeprecations();
initializeCJSLoader();
initializeESMLoader();
+
+ const CJSLoader = require('internal/modules/cjs/loader');
+ assert(!CJSLoader.hasLoadedAnyUserCJSModule);
loadPreloadModules();
initializeFrozenIntrinsics();
publicWorker.parentPort = publicPort;
@@ -141,8 +144,9 @@ port.on('message', (message) => {
evalScript('[worker eval]', filename);
} else {
// script filename
- const CJSModule = require('internal/modules/cjs/loader').Module;
- CJSModule.runMain(process.argv[1] = filename);
+ // runMain here might be monkey-patched by users in --require.
+ // XXX: the monkey-patchability here should probably be deprecated.
+ CJSLoader.Module.runMain(process.argv[1] = filename);
}
} else if (message.type === STDIO_PAYLOAD) {
const { stream, chunk, encoding } = message;