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

Function createCJSNoSourceModuleWrap

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

* Creates a ModuleWrap object for a CommonJS module without source texts. * @param {string} url - The URL of the module. * @param {string|undefined} parentURL - URL of the parent module, if any. * @returns {ModuleWrap} The ModuleWrap object for the CommonJS module.

(url, parentURL)

Source from the content-addressed store, hash-verified

282 * @returns {ModuleWrap} The ModuleWrap object for the CommonJS module.
283 */
284function createCJSNoSourceModuleWrap(url, parentURL) {
285 debug(`Translating CJSModule without source ${url}`);
286 const isMain = (parentURL === undefined);
287
288 const filename = urlToFilename(url);
289
290 const module = cjsEmplaceModuleCacheEntry(filename);
291 cjsCache.set(url, module);
292
293 if (isMain) {
294 setOwnProperty(process, 'mainModule', module);
295 }
296
297 // Addon export names are not known until the addon is loaded.
298 const exportNames = ['default', 'module.exports'];
299 return new ModuleWrap(url, undefined, exportNames, function evaluationCallback() {
300 debug(`Loading CJSModule ${url}`);
301
302 if (!module.loaded) {
303 // If it gets here in the translators, the hooks must have already been invoked
304 // in the loader. Skip them in the synthetic module evaluation step.
305 wrapModuleLoad(filename, null, isMain, kShouldSkipModuleHooks);
306 }
307
308 /** @type {import('./loader').ModuleExports} */
309 let exports;
310 if (module[kModuleExport] !== undefined) {
311 exports = module[kModuleExport];
312 module[kModuleExport] = undefined;
313 } else {
314 ({ exports } = module);
315 }
316
317 this.setExport('default', exports);
318 this.setExport('module.exports', exports);
319 }, module);
320}
321
322translators.set('commonjs-sync', function requireCommonJS(url, translateContext, parentURL) {
323 return createCJSModuleWrap(url, translateContext, parentURL);

Callers 1

translators.jsFile · 0.85

Calls 7

urlToFilenameFunction · 0.85
setOwnPropertyFunction · 0.85
wrapModuleLoadFunction · 0.85
setExportMethod · 0.80
debugFunction · 0.50
setMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…