Skip to content

Commit

Permalink
lib: lazy-load deps in modules/run_main.js
Browse files Browse the repository at this point in the history
So that the file can be snapshotted

PR-URL: #45849
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
  • Loading branch information
joyeecheung authored and targos committed Jan 1, 2023
1 parent e529ea4 commit f6c6673
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/internal/modules/run_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ const {
ObjectCreate,
StringPrototypeEndsWith,
} = primordials;
const CJSLoader = require('internal/modules/cjs/loader');
const { Module, toRealPath, readPackageScope } = CJSLoader;

const { getOptionValue } = require('internal/options');
const path = require('path');

function resolveMainPath(main) {
// Note extension resolution for the main entry point can be deprecated in a
// future major.
// Module._findPath is monkey-patchable here.
const { Module, toRealPath } = require('internal/modules/cjs/loader');
let mainPath = Module._findPath(path.resolve(main), null, true);
if (!mainPath)
return;
Expand All @@ -37,6 +37,7 @@ function shouldUseESMLoader(mainPath) {
const userImports = getOptionValue('--import');
if (userLoaders.length > 0 || userImports.length > 0)
return true;
const { readPackageScope } = require('internal/modules/cjs/loader');
// Determine the module format of the main
if (mainPath && StringPrototypeEndsWith(mainPath, '.mjs'))
return true;
Expand Down Expand Up @@ -79,6 +80,7 @@ function executeUserEntryPoint(main = process.argv[1]) {
runMainESM(resolvedMain || main);
} else {
// Module._load is the monkey-patchable CJS module loader.
const { Module } = require('internal/modules/cjs/loader');
Module._load(main, null, true);
}
}
Expand Down

0 comments on commit f6c6673

Please sign in to comment.