* 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)
| 282 | * @returns {ModuleWrap} The ModuleWrap object for the CommonJS module. |
| 283 | */ |
| 284 | function 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 | |
| 322 | translators.set('commonjs-sync', function requireCommonJS(url, translateContext, parentURL) { |
| 323 | return createCJSModuleWrap(url, translateContext, parentURL); |
no test coverage detected
searching dependent graphs…