MCPcopy Index your code
hub / github.com/nodejs/node / loadCJSModuleWithModuleLoad

Function loadCJSModuleWithModuleLoad

lib/internal/modules/esm/translators.js:354–384  ·  view source on GitHub ↗

* Loads a CommonJS module through Module._load to accommodate monkey-patchers. * If the module was resolved by synchronous hooks (i.e. not by the default resolver), * passes the pre-resolved information and source to Module._load to avoid * re-resolving and re-loading. * @param {import('internal

(module, source, url, filename, isMain, translateContext)

Source from the content-addressed store, hash-verified

352 * @param {import('./loader').TranslateContext} translateContext Context for the translator
353 */
354function loadCJSModuleWithModuleLoad(module, source, url, filename, isMain, translateContext) {
355 assert(module === CJSModule._cache[filename]);
356 debug(`loadCJSModuleWithModuleLoad ${url}`);
357 let exports;
358 if (translateContext.isResolvedBySyncHooks) {
359 exports = wrapModuleLoad(filename, undefined, isMain, {
360 __proto__: null,
361 resolved: {
362 __proto__: null,
363 filename,
364 format: translateContext.format,
365 url,
366 },
367 shouldSkipModuleHooks: true,
368 source,
369 });
370 } else {
371 // If it gets here in the translators, the hooks must have already been invoked
372 // in the loader. Skip them in the synthetic module evaluation step.
373 exports = wrapModuleLoad(filename, undefined, isMain, kShouldSkipModuleHooks);
374 }
375
376 // Patched Module._load implementations may return exports without updating the
377 // ESM-created cache entry. Mirror the returned value into the translator-owned
378 // module so the synthetic module namespace observes the loaded exports.
379 if (!module.loaded) {
380 module.exports = exports;
381 module.loaded = true;
382 }
383 module[kModuleExport] = exports;
384}
385
386// Handle CommonJS modules referenced by `import` statements or expressions,
387// or as the initial entry point when the ESM loader handles a CommonJS entry.

Callers 1

createCJSModuleWrapFunction · 0.85

Calls 3

wrapModuleLoadFunction · 0.85
assertFunction · 0.50
debugFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…