From f6c6673ec4bdd6d00f89ba8585587bb2f12ced3d Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 13 Dec 2022 22:35:42 +0100 Subject: [PATCH] lib: lazy-load deps in modules/run_main.js So that the file can be snapshotted PR-URL: https://github.com/nodejs/node/pull/45849 Reviewed-By: Geoffrey Booth Reviewed-By: Chengzhong Wu --- lib/internal/modules/run_main.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/internal/modules/run_main.js b/lib/internal/modules/run_main.js index 738c945bc21c21..c948eaf4ae4437 100644 --- a/lib/internal/modules/run_main.js +++ b/lib/internal/modules/run_main.js @@ -4,8 +4,7 @@ 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'); @@ -13,6 +12,7 @@ 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; @@ -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; @@ -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); } }