Skip to content

Commit f6c6673

Browse files
joyeecheungtargos
authored andcommitted
lib: lazy-load deps in modules/run_main.js
So that the file can be snapshotted PR-URL: #45849 Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
1 parent e529ea4 commit f6c6673

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/internal/modules/run_main.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ const {
44
ObjectCreate,
55
StringPrototypeEndsWith,
66
} = primordials;
7-
const CJSLoader = require('internal/modules/cjs/loader');
8-
const { Module, toRealPath, readPackageScope } = CJSLoader;
7+
98
const { getOptionValue } = require('internal/options');
109
const path = require('path');
1110

1211
function resolveMainPath(main) {
1312
// Note extension resolution for the main entry point can be deprecated in a
1413
// future major.
1514
// Module._findPath is monkey-patchable here.
15+
const { Module, toRealPath } = require('internal/modules/cjs/loader');
1616
let mainPath = Module._findPath(path.resolve(main), null, true);
1717
if (!mainPath)
1818
return;
@@ -37,6 +37,7 @@ function shouldUseESMLoader(mainPath) {
3737
const userImports = getOptionValue('--import');
3838
if (userLoaders.length > 0 || userImports.length > 0)
3939
return true;
40+
const { readPackageScope } = require('internal/modules/cjs/loader');
4041
// Determine the module format of the main
4142
if (mainPath && StringPrototypeEndsWith(mainPath, '.mjs'))
4243
return true;
@@ -79,6 +80,7 @@ function executeUserEntryPoint(main = process.argv[1]) {
7980
runMainESM(resolvedMain || main);
8081
} else {
8182
// Module._load is the monkey-patchable CJS module loader.
83+
const { Module } = require('internal/modules/cjs/loader');
8284
Module._load(main, null, true);
8385
}
8486
}

0 commit comments

Comments
 (0)