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: nodejs/node#45849
Backport-PR-URL: nodejs/node#46425
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
  • Loading branch information
sercher committed Apr 24, 2024
1 parent 3406df6 commit 4076635
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions graal-nodejs/lib/internal/modules/run_main.js
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 Down Expand Up @@ -41,6 +41,7 @@ function shouldUseESMLoader(mainPath) {
getOptionValue('--experimental-specifier-resolution');
if (esModuleSpecifierResolution === 'node')
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 @@ -83,6 +84,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
2 changes: 1 addition & 1 deletion graal-nodejs/test/fixtures/errors/force_colors.snapshot
Expand Up @@ -8,7 +8,7 @@ Error: Should include grayed stack trace
 at Module._extensions..js (node:internal*modules*cjs*loader:1310:10)
 at Module.load (node:internal*modules*cjs*loader:1119:32)
 at Module._load (node:internal*modules*cjs*loader:960:12)
 at Function.executeUserEntryPoint [as runMain] (node:internal*modules*run_main:86:12)
 at Function.executeUserEntryPoint [as runMain] (node:internal*modules*run_main:88:12)
 at node:internal*main*run_main_module:23:47

Node.js *

0 comments on commit 4076635

Please sign in to comment.