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

Function loadBuiltinWithHooks

lib/internal/modules/cjs/loader.js:1284–1303  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

1282 * of the builtin module. Otherwise, return the loadResult for the caller to continue loading.
1283 */
1284function 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.

Callers 1

loader.jsFile · 0.85

Calls 5

loadWithHooksFunction · 0.85
getCjsConditionsArrayFunction · 0.85
getDefaultLoadFunction · 0.85
loadBuiltinModuleFunction · 0.85
debugFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…