Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit aea0d64

Browse files
committedSep 10, 2023
cjs/loader.js
1 parent e658b36 commit aea0d64

File tree

1 file changed

+242
-46
lines changed

1 file changed

+242
-46
lines changed
 

‎lib/internal/modules/cjs/loader.js

+242-46
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ let requireDepth = 0;
155155
let isPreloading = false;
156156
let statCache = null;
157157

158+
/**
159+
* Our internal implementation of `require`.
160+
* @param {Module} module Parent module of what is being required
161+
* @param {string} id Specifier of the child module being imported
162+
*/
158163
function internalRequire(module, id) {
159164
validateString(id, 'id');
160165
if (id === '') {
@@ -169,6 +174,10 @@ function internalRequire(module, id) {
169174
}
170175
}
171176

177+
/**
178+
* Get a path's properties, using an in-memory cache to minimize lookups.
179+
* @param {string} filename Absolute path to the file
180+
*/
172181
function stat(filename) {
173182
filename = path.toNamespacedPath(filename);
174183
if (statCache !== null) {
@@ -195,24 +204,45 @@ ObjectDefineProperty(Module, '_stat', {
195204
configurable: true,
196205
});
197206

207+
/**
208+
* Update the parent's children array with the child module.
209+
* @param {Module} parent Module requiring the children
210+
* @param {Module} child Module being required
211+
* @param {boolean} scan Add the child to the parent's children if not already present
212+
*/
198213
function updateChildren(parent, child, scan) {
199214
const children = parent?.children;
200215
if (children && !(scan && ArrayPrototypeIncludes(children, child))) { ArrayPrototypePush(children, child); }
201216
}
202217

218+
/**
219+
* Tell the watch mode that a module was required.
220+
* @param {string} filename Absolute path of the module
221+
*/
203222
function reportModuleToWatchMode(filename) {
204223
if (shouldReportRequiredModules() && process.send) {
205224
process.send({ 'watch:require': [filename] });
206225
}
207226
}
208227

228+
/**
229+
* Tell the watch mode that a module was not found.
230+
* @param {string} basePath The absolute path that errored
231+
* @param {string[]} extensions The extensions that were tried
232+
*/
209233
function reportModuleNotFoundToWatchMode(basePath, extensions) {
210234
if (shouldReportRequiredModules() && process.send) {
211235
process.send({ 'watch:require': ArrayPrototypeMap(extensions, (ext) => path.resolve(`${basePath}${ext}`)) });
212236
}
213237
}
214238

239+
/** @type {Map<Module, Module>} */
215240
const moduleParentCache = new SafeWeakMap();
241+
/**
242+
* Create a new module instance.
243+
* @param {string} id
244+
* @param {Module} parent
245+
*/
216246
function Module(id = '', parent) {
217247
this.id = id;
218248
this.path = path.dirname(id);
@@ -235,16 +265,24 @@ function Module(id = '', parent) {
235265
this[require_private_symbol] = internalRequire;
236266
}
237267

268+
/** @type {Record<string, Module>} */
238269
Module._cache = { __proto__: null };
270+
/** @type {Record<string, string>} */
239271
Module._pathCache = { __proto__: null };
272+
/** @type {Record<string, (module: Module, filename: string) => void>} */
240273
Module._extensions = { __proto__: null };
274+
/** @type {string[]} */
241275
let modulePaths = [];
276+
/** @type {string[]} */
242277
Module.globalPaths = [];
243278

244279
let patched = false;
245280

246-
// eslint-disable-next-line func-style
247-
let wrap = function(script) {
281+
/**
282+
* Add the CommonJS wrapper around a module's source code.
283+
* @param {string} script Module source code
284+
*/
285+
let wrap = function(script) { // eslint-disable-line func-style
248286
return Module.wrapper[0] + script + Module.wrapper[1];
249287
};
250288

@@ -295,10 +333,17 @@ const isPreloadingDesc = { get() { return isPreloading; } };
295333
ObjectDefineProperty(Module.prototype, 'isPreloading', isPreloadingDesc);
296334
ObjectDefineProperty(BuiltinModule.prototype, 'isPreloading', isPreloadingDesc);
297335

336+
/**
337+
* Get the parent of the current module from our cache.
338+
*/
298339
function getModuleParent() {
299340
return moduleParentCache.get(this);
300341
}
301342

343+
/**
344+
* Set the parent of the current module in our cache.
345+
* @param {Module} value
346+
*/
302347
function setModuleParent(value) {
303348
moduleParentCache.set(this, value);
304349
}
@@ -325,7 +370,10 @@ ObjectDefineProperty(Module.prototype, 'parent', {
325370
Module._debug = pendingDeprecate(debug, 'Module._debug is deprecated.', 'DEP0077');
326371
Module.isBuiltin = BuiltinModule.isBuiltin;
327372

328-
// This function is called during pre-execution, before any user code is run.
373+
/**
374+
* Prepare to run CommonJS code.
375+
* This function is called during pre-execution, before any user code is run.
376+
*/
329377
function initializeCJS() {
330378
// This need to be done at runtime in case --expose-internals is set.
331379
const builtinModules = BuiltinModule.getCanBeRequiredByUsersWithoutSchemeList();
@@ -373,6 +421,11 @@ ObjectDefineProperty(Module, '_readPackage', {
373421
configurable: true,
374422
});
375423

424+
/**
425+
* Get the nearest parent package.json file from a given path.
426+
* Return the package.json data and the path to the package.json file, or false.
427+
* @param {string} checkPath The path to start searching from.
428+
*/
376429
function readPackageScope(checkPath) {
377430
const rootSeparatorIndex = StringPrototypeIndexOf(checkPath, sep);
378431
let separatorIndex;
@@ -397,6 +450,13 @@ function readPackageScope(checkPath) {
397450
return false;
398451
}
399452

453+
/**
454+
* Try to load a specifier as a package.
455+
* @param {string} requestPath The path to what we are trying to load
456+
* @param {string[]} exts File extensions to try appending in order to resolve the file
457+
* @param {boolean} isMain Whether the file is the main entry point of the app
458+
* @param {string} originalPath The specifier passed to `require`
459+
*/
400460
function tryPackage(requestPath, exts, isMain, originalPath) {
401461
const pkg = _readPackage(requestPath).main;
402462

@@ -434,15 +494,20 @@ function tryPackage(requestPath, exts, isMain, originalPath) {
434494
return actual;
435495
}
436496

437-
// In order to minimize unnecessary lstat() calls,
438-
// this cache is a list of known-real paths.
439-
// Set to an empty Map to reset.
497+
/**
498+
* Cache for storing resolved real paths of modules.
499+
* In order to minimize unnecessary lstat() calls, this cache is a list of known-real paths.
500+
* Set to an empty Map to reset.
501+
* @type {Map<string, string>}
502+
*/
440503
const realpathCache = new SafeMap();
441504

442-
// Check if the file exists and is not a directory
443-
// if using --preserve-symlinks and isMain is false,
444-
// keep symlinks intact, otherwise resolve to the
445-
// absolute realpath.
505+
/**
506+
* Check if the file exists and is not a directory if using `--preserve-symlinks` and `isMain` is false, keep symlinks
507+
* intact, otherwise resolve to the absolute realpath.
508+
* @param {string} requestPath The path to the file to load.
509+
* @param {boolean} isMain Whether the file is the main module.
510+
*/
446511
function tryFile(requestPath, isMain) {
447512
const rc = _stat(requestPath);
448513
if (rc !== 0) { return; }
@@ -452,16 +517,26 @@ function tryFile(requestPath, isMain) {
452517
return toRealPath(requestPath);
453518
}
454519

520+
521+
/**
522+
* Resolves the path of a given `require` specifier, following symlinks.
523+
* @param {string} requestPath The `require` specifier
524+
*/
455525
function toRealPath(requestPath) {
456526
return fs.realpathSync(requestPath, {
457527
[internalFS.realpathCacheKey]: realpathCache,
458528
});
459529
}
460530

461-
// Given a path, check if the file exists with any of the set extensions
462-
function tryExtensions(p, exts, isMain) {
531+
/**
532+
* Given a path, check if the file exists with any of the set extensions.
533+
* @param {string} basePath The path and filename without extension
534+
* @param {string[]} exts The extensions to try
535+
* @param {boolean} isMain Whether the module is the main module
536+
*/
537+
function tryExtensions(basePath, exts, isMain) {
463538
for (let i = 0; i < exts.length; i++) {
464-
const filename = tryFile(p + exts[i], isMain);
539+
const filename = tryFile(basePath + exts[i], isMain);
465540

466541
if (filename) {
467542
return filename;
@@ -470,8 +545,10 @@ function tryExtensions(p, exts, isMain) {
470545
return false;
471546
}
472547

473-
// Find the longest (possibly multi-dot) extension registered in
474-
// Module._extensions
548+
/**
549+
* Find the longest (possibly multi-dot) extension registered in `Module._extensions`.
550+
* @param {string} filename The filename to find the longest registered extension for.
551+
*/
475552
function findLongestRegisteredExtension(filename) {
476553
const name = path.basename(filename);
477554
let currentExtension;
@@ -486,6 +563,10 @@ function findLongestRegisteredExtension(filename) {
486563
return '.js';
487564
}
488565

566+
/**
567+
* Tries to get the absolute file path of the parent module.
568+
* @param {Module} parent The parent module object.
569+
*/
489570
function trySelfParentPath(parent) {
490571
if (!parent) { return false; }
491572

@@ -500,6 +581,11 @@ function trySelfParentPath(parent) {
500581
}
501582
}
502583

584+
/**
585+
* Attempt to resolve a module request using the parent module package metadata.
586+
* @param {string} parentPath The path of the parent module
587+
* @param {string} request The module request to resolve
588+
*/
503589
function trySelf(parentPath, request) {
504590
if (!parentPath) { return false; }
505591

@@ -528,10 +614,18 @@ function trySelf(parentPath, request) {
528614
}
529615
}
530616

531-
// This only applies to requests of a specific form:
532-
// 1. name/.*
533-
// 2. @scope/name/.*
617+
/**
618+
* This only applies to requests of a specific form:
619+
* 1. `name/.*`
620+
* 2. `@scope/name/.*`
621+
*/
534622
const EXPORTS_PATTERN = /^((?:@[^/\\%]+\/)?[^./\\%][^/\\%]*)(\/.*)?$/;
623+
624+
/**
625+
* Resolves the exports for a given module path and request.
626+
* @param {string} nmPath The path to the module.
627+
* @param {string} request The request for the module.
628+
*/
535629
function resolveExports(nmPath, request) {
536630
// The implementation's behavior is meant to mirror resolution in ESM.
537631
const { 1: name, 2: expansion = '' } =
@@ -553,9 +647,10 @@ function resolveExports(nmPath, request) {
553647
}
554648

555649
/**
556-
* @param {string} request a relative or absolute file path
557-
* @param {Array<string>} paths file system directories to search as file paths
558-
* @param {boolean} isMain if the request is the main app entry point
650+
* Get the absolute path to a module.
651+
* @param {string} request Relative or absolute file path
652+
* @param {Array<string>} paths Folders to search as file paths
653+
* @param {boolean} isMain Whether the request is the main app entry point
559654
* @returns {string | false}
560655
*/
561656
Module._findPath = function(request, paths, isMain) {
@@ -673,11 +768,14 @@ Module._findPath = function(request, paths, isMain) {
673768
return false;
674769
};
675770

676-
// 'node_modules' character codes reversed
771+
/** `node_modules` character codes reversed */
677772
const nmChars = [ 115, 101, 108, 117, 100, 111, 109, 95, 101, 100, 111, 110 ];
678773
const nmLen = nmChars.length;
679774
if (isWindows) {
680-
// 'from' is the __dirname of the module.
775+
/**
776+
* Get the paths to the `node_modules` folder for a given path.
777+
* @param {string} from `__dirname` of the module
778+
*/
681779
Module._nodeModulePaths = function(from) {
682780
// Guarantee that 'from' is absolute.
683781
from = path.resolve(from);
@@ -692,6 +790,7 @@ if (isWindows) {
692790
CHAR_BACKWARD_SLASH &&
693791
StringPrototypeCharCodeAt(from, from.length - 2) === CHAR_COLON) { return [from + 'node_modules']; }
694792

793+
/** @type {string[]} */
695794
const paths = [];
696795
for (let i = from.length - 1, p = 0, last = from.length; i >= 0; --i) {
697796
const code = StringPrototypeCharCodeAt(from, i);
@@ -723,7 +822,10 @@ if (isWindows) {
723822
return paths;
724823
};
725824
} else { // posix
726-
// 'from' is the __dirname of the module.
825+
/**
826+
* Get the paths to the `node_modules` folder for a given path.
827+
* @param {string} from `__dirname` of the module
828+
*/
727829
Module._nodeModulePaths = function(from) {
728830
// Guarantee that 'from' is absolute.
729831
from = path.resolve(from);
@@ -734,6 +836,7 @@ if (isWindows) {
734836
// note: this approach *only* works when the path is guaranteed
735837
// to be absolute. Doing a fully-edge-case-correct path.split
736838
// that works on both Windows and Posix is non-trivial.
839+
/** @type {string[]} */
737840
const paths = [];
738841
for (let i = from.length - 1, p = 0, last = from.length; i >= 0; --i) {
739842
const code = StringPrototypeCharCodeAt(from, i);
@@ -762,6 +865,11 @@ if (isWindows) {
762865
};
763866
}
764867

868+
/**
869+
* Get the paths for module resolution.
870+
* @param {string} request
871+
* @param {Module} parent
872+
*/
765873
Module._resolveLookupPaths = function(request, parent) {
766874
if (BuiltinModule.normalizeRequirableId(request)) {
767875
debug('looking for %j in []', request);
@@ -775,6 +883,7 @@ Module._resolveLookupPaths = function(request, parent) {
775883
StringPrototypeCharAt(request, 1) !== '/' &&
776884
(!isWindows || StringPrototypeCharAt(request, 1) !== '\\'))) {
777885

886+
/** @type {string[]} */
778887
let paths;
779888
if (parent?.paths?.length) {
780889
paths = ArrayPrototypeSlice(modulePaths);
@@ -804,6 +913,10 @@ Module._resolveLookupPaths = function(request, parent) {
804913
return parentDir;
805914
};
806915

916+
/**
917+
* Emits a warning when a non-existent property of module exports is accessed inside a circular dependency.
918+
* @param {string} prop The name of the non-existent property.
919+
*/
807920
function emitCircularRequireWarning(prop) {
808921
process.emitWarning(
809922
`Accessing non-existent property '${String(prop)}' of module exports ` +
@@ -834,6 +947,12 @@ const CircularRequirePrototypeWarningProxy = new Proxy({}, {
834947
},
835948
});
836949

950+
/**
951+
* Returns the exports object for a module that has a circular `require`.
952+
* If the exports object is a plain object, it is wrapped in a proxy that warns
953+
* about circular dependencies.
954+
* @param {Module} module The module instance
955+
*/
837956
function getExportsForCircularRequire(module) {
838957
if (module.exports &&
839958
!isProxy(module.exports) &&
@@ -851,13 +970,17 @@ function getExportsForCircularRequire(module) {
851970
return module.exports;
852971
}
853972

854-
// Check the cache for the requested file.
855-
// 1. If a module already exists in the cache: return its exports object.
856-
// 2. If the module is native: call
857-
// `BuiltinModule.prototype.compileForPublicLoader()` and return the exports.
858-
// 3. Otherwise, create a new module for the file and save it to the cache.
859-
// Then have it load the file contents before returning its exports
860-
// object.
973+
/**
974+
* Load a module from cache if it exists, otherwise create a new module instance.
975+
* 1. If a module already exists in the cache: return its exports object.
976+
* 2. If the module is native: call
977+
* `BuiltinModule.prototype.compileForPublicLoader()` and return the exports.
978+
* 3. Otherwise, create a new module for the file and save it to the cache.
979+
* Then have it load the file contents before returning its exports object.
980+
* @param {string} request Specifier of module to load via `require`
981+
* @param {string} parent Absolute path of the module importing the child
982+
* @param {boolean} isMain Whether the module is the main entry point
983+
*/
861984
Module._load = function(request, parent, isMain) {
862985
let relResolveCacheIdentifier;
863986
if (parent) {
@@ -953,6 +1076,15 @@ Module._load = function(request, parent, isMain) {
9531076
return module.exports;
9541077
};
9551078

1079+
/**
1080+
* Given a `require` string and its context, get its absolute file path.
1081+
* @param {string} request The specifier to resolve
1082+
* @param {Module} parent The module containing the `require` call
1083+
* @param {boolean} isMain Whether the module is the main entry point
1084+
* @param {ResolveFilenameOptions} options Options object
1085+
* @typedef {object} ResolveFilenameOptions
1086+
* @property {string[]} paths Paths to search for modules in
1087+
*/
9561088
Module._resolveFilename = function(request, parent, isMain, options) {
9571089
if (BuiltinModule.normalizeRequirableId(request)) {
9581090
return request;
@@ -1041,6 +1173,14 @@ Module._resolveFilename = function(request, parent, isMain, options) {
10411173
throw err;
10421174
};
10431175

1176+
/**
1177+
* Finishes resolving an ES module specifier into an absolute file path.
1178+
* @param {string} resolved The resolved module specifier
1179+
* @param {string} parentPath The path of the parent module
1180+
* @param {string} pkgPath The path of the package.json file
1181+
* @throws {ERR_INVALID_MODULE_SPECIFIER} If the resolved module specifier contains encoded `/` or `\\` characters
1182+
* @throws {Error} If the module cannot be found
1183+
*/
10441184
function finalizeEsmResolution(resolved, parentPath, pkgPath) {
10451185
const { encodedSepRegEx } = require('internal/modules/esm/resolve');
10461186
if (RegExpPrototypeExec(encodedSepRegEx, resolved) !== null) {
@@ -1055,6 +1195,11 @@ function finalizeEsmResolution(resolved, parentPath, pkgPath) {
10551195
throw err;
10561196
}
10571197

1198+
/**
1199+
* Creates an error object for when a requested ES module cannot be found.
1200+
* @param {string} request The name of the requested module
1201+
* @param {string} [path] The path to the requested module
1202+
*/
10581203
function createEsmNotFoundErr(request, path) {
10591204
// eslint-disable-next-line no-restricted-syntax
10601205
const err = new Error(`Cannot find module '${request}'`);
@@ -1064,7 +1209,10 @@ function createEsmNotFoundErr(request, path) {
10641209
return err;
10651210
}
10661211

1067-
// Given a file name, pass it to the proper extension handler.
1212+
/**
1213+
* Given a file name, pass it to the proper extension handler.
1214+
* @param {string} filename The `require` specifier
1215+
*/
10681216
Module.prototype.load = function(filename) {
10691217
debug('load %j for module %j', filename, this.id);
10701218

@@ -1090,9 +1238,12 @@ Module.prototype.load = function(filename) {
10901238
!cascadedLoader.cjsCache.has(this)) { cascadedLoader.cjsCache.set(this, exports); }
10911239
};
10921240

1093-
// Loads a module at the given file path. Returns that module's
1094-
// `exports` property.
1095-
// Note: when using the experimental policy mechanism this function is overridden
1241+
/**
1242+
* Loads a module at the given file path. Returns that module's `exports` property.
1243+
* Note: when using the experimental policy mechanism this function is overridden.
1244+
* @param {string} id
1245+
* @throws {ERR_INVALID_ARG_TYPE} When `id` is not a string
1246+
*/
10961247
Module.prototype.require = function(id) {
10971248
validateString(id, 'id');
10981249
if (id === '') {
@@ -1107,11 +1258,23 @@ Module.prototype.require = function(id) {
11071258
}
11081259
};
11091260

1110-
// Resolved path to process.argv[1] will be lazily placed here
1111-
// (needed for setting breakpoint when called with --inspect-brk)
1261+
/**
1262+
* Resolved path to `process.argv[1]` will be lazily placed here
1263+
* (needed for setting breakpoint when called with `--inspect-brk`).
1264+
* @type {string | undefined}
1265+
*/
11121266
let resolvedArgv;
11131267
let hasPausedEntry = false;
1268+
/** @type {import('vm').Script} */
11141269
let Script;
1270+
1271+
/**
1272+
* Wraps the given content in a script and runs it in a new context.
1273+
* @param {string} filename The name of the file being loaded
1274+
* @param {string} content The content of the file being loaded
1275+
* @param {Module} cjsModuleInstance The CommonJS loader instance
1276+
* @param {object} codeCache The SEA code cache
1277+
*/
11151278
function wrapSafe(filename, content, cjsModuleInstance, codeCache) {
11161279
if (patched) {
11171280
const wrapper = Module.wrap(content);
@@ -1177,10 +1340,12 @@ function wrapSafe(filename, content, cjsModuleInstance, codeCache) {
11771340
}
11781341
}
11791342

1180-
// Run the file contents in the correct scope or sandbox. Expose
1181-
// the correct helper variables (require, module, exports) to
1182-
// the file.
1183-
// Returns exception, if any.
1343+
/**
1344+
* Run the file contents in the correct scope or sandbox. Expose the correct helper variables (`require`, `module`,
1345+
* `exports`) to the file. Returns exception, if any.
1346+
* @param {string} content The source code of the module
1347+
* @param {string} filename The file path of the module
1348+
*/
11841349
Module.prototype._compile = function(content, filename) {
11851350
let moduleURL;
11861351
let redirects;
@@ -1235,7 +1400,11 @@ Module.prototype._compile = function(content, filename) {
12351400
return result;
12361401
};
12371402

1238-
// Native extension for .js
1403+
/**
1404+
* Native handler for `.js` files.
1405+
* @param {Module} module The module to compile
1406+
* @param {string} filename The file path of the module
1407+
*/
12391408
Module._extensions['.js'] = function(module, filename) {
12401409
// If already analyzed the source, then it will be cached.
12411410
const cached = cjsParseCache.get(module);
@@ -1284,8 +1453,11 @@ Module._extensions['.js'] = function(module, filename) {
12841453
module._compile(content, filename);
12851454
};
12861455

1287-
1288-
// Native extension for .json
1456+
/**
1457+
* Native handler for `.json` files.
1458+
* @param {Module} module The module to compile
1459+
* @param {string} filename The file path of the module
1460+
*/
12891461
Module._extensions['.json'] = function(module, filename) {
12901462
const content = fs.readFileSync(filename, 'utf8');
12911463

@@ -1303,8 +1475,11 @@ Module._extensions['.json'] = function(module, filename) {
13031475
}
13041476
};
13051477

1306-
1307-
// Native extension for .node
1478+
/**
1479+
* Native handler for `.node` files.
1480+
* @param {Module} module The module to compile
1481+
* @param {string} filename The file path of the module
1482+
*/
13081483
Module._extensions['.node'] = function(module, filename) {
13091484
const manifest = policy()?.manifest;
13101485
if (manifest) {
@@ -1316,6 +1491,10 @@ Module._extensions['.node'] = function(module, filename) {
13161491
return process.dlopen(module, path.toNamespacedPath(filename));
13171492
};
13181493

1494+
/**
1495+
* Creates a `require` function that can be used to load modules from the specified path.
1496+
* @param {string} filename The path to the module
1497+
*/
13191498
function createRequireFromPath(filename) {
13201499
// Allow a directory to be passed as the filename
13211500
const trailingSlash =
@@ -1336,6 +1515,12 @@ function createRequireFromPath(filename) {
13361515
const createRequireError = 'must be a file URL object, file URL string, or ' +
13371516
'absolute path string';
13381517

1518+
/**
1519+
* Creates a new `require` function that can be used to load modules.
1520+
* @param {string | URL} filename The path or URL to the module context for this `require`
1521+
* @throws {ERR_INVALID_ARG_VALUE} If `filename` is not a string or URL, or if it is a relative path that cannot be
1522+
* resolved to an absolute path.
1523+
*/
13391524
function createRequire(filename) {
13401525
let filepath;
13411526

@@ -1357,6 +1542,9 @@ function createRequire(filename) {
13571542

13581543
Module.createRequire = createRequire;
13591544

1545+
/**
1546+
* Define the paths to use for resolving a module.
1547+
*/
13601548
Module._initPaths = function() {
13611549
const homeDir = isWindows ? process.env.USERPROFILE : safeGetenv('HOME');
13621550
const nodePath = isWindows ? process.env.NODE_PATH : safeGetenv('NODE_PATH');
@@ -1387,6 +1575,10 @@ Module._initPaths = function() {
13871575
Module.globalPaths = ArrayPrototypeSlice(modulePaths);
13881576
};
13891577

1578+
/**
1579+
* Handle modules loaded via `--require`.
1580+
* @param {string[]} requests The values of `--require`
1581+
*/
13901582
Module._preloadModules = function(requests) {
13911583
if (!ArrayIsArray(requests)) { return; }
13921584

@@ -1408,6 +1600,10 @@ Module._preloadModules = function(requests) {
14081600
isPreloading = false;
14091601
};
14101602

1603+
/**
1604+
* If the user has overridden an export from a builtin module, this function can ensure that the override is used in
1605+
* both CommonJS and ES module contexts.
1606+
*/
14111607
Module.syncBuiltinESMExports = function syncBuiltinESMExports() {
14121608
for (const mod of BuiltinModule.map.values()) {
14131609
if (BuiltinModule.canBeRequiredWithoutScheme(mod.id)) {

0 commit comments

Comments
 (0)
Please sign in to comment.