* Load a specified builtin module, invoking load hooks if necessary. * @param {string} id The module ID (without the node: prefix) * @param {string} url The module URL (with the node: prefix) * @param {string} format Format from resolution. * @returns {{builtinExports: any, resultFromHook: undef
(id, url, format)
| 1282 | * of the builtin module. Otherwise, return the loadResult for the caller to continue loading. |
| 1283 | */ |
| 1284 | function loadBuiltinWithHooks(id, url, format) { |
| 1285 | let resultFromHook; |
| 1286 | if (loadHooks.length) { |
| 1287 | url ??= `node:${id}`; |
| 1288 | debug('loadBuiltinWithHooks ', loadHooks.length, id, url, format); |
| 1289 | // TODO(joyeecheung): do we really want to invoke the load hook for the builtins? |
| 1290 | resultFromHook = loadWithHooks(url, format || 'builtin', /* importAttributes */ undefined, |
| 1291 | getCjsConditionsArray(), getDefaultLoad(url, id), validateLoadStrict); |
| 1292 | if (resultFromHook.format && resultFromHook.format !== 'builtin') { |
| 1293 | debug('loadBuiltinWithHooks overriding module', id, url, resultFromHook); |
| 1294 | // Format has been overridden, return result for the caller to continue loading. |
| 1295 | return { builtinExports: undefined, resultFromHook }; |
| 1296 | } |
| 1297 | } |
| 1298 | |
| 1299 | // No hooks or the hooks have not overridden the format. Load it as a builtin module and return the |
| 1300 | // exports. |
| 1301 | const mod = loadBuiltinModule(id); |
| 1302 | return { builtinExports: mod.exports, resultFromHook: undefined }; |
| 1303 | } |
| 1304 | |
| 1305 | /** |
| 1306 | * Load a module from cache if it exists, otherwise create a new module instance. |
no test coverage detected
searching dependent graphs…