doc: correct customization hook types & clarify descriptions

PR-URL: https://github.com/nodejs/node/pull/56454
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
Jacob Smith 2025-01-14 15:24:41 +01:00 committed by GitHub
parent 5770972dc6
commit fc11189cbd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 37 additions and 11 deletions

View file

@ -25,17 +25,40 @@ let debug = require('internal/util/debuglog').debuglog('module_hooks', (fn) => {
debug = fn;
});
/** @typedef {import('internal/modules/cjs/loader.js').Module} Module */
/**
* @typedef {(specifier: string, context: ModuleResolveContext, nextResolve: ResolveHook)
* => ModuleResolveResult} ResolveHook
* @typedef {(url: string, context: ModuleLoadContext, nextLoad: LoadHook)
* => ModuleLoadResult} LoadHook
* @typedef {import('internal/modules/cjs/loader.js').Module} Module
*/
/**
* @typedef {(
* specifier: string,
* context: Partial<ModuleResolveContext>,
* ) => ModuleResolveResult
* } NextResolve
* @typedef {(
* specifier: string,
* context: ModuleResolveContext,
* nextResolve: NextResolve,
* ) => ModuleResolveResult
* } ResolveHook
* @typedef {(
* url: string,
* context: Partial<ModuleLoadContext>,
* ) => ModuleLoadResult
* } NextLoad
* @typedef {(
* url: string,
* context: ModuleLoadContext,
* nextLoad: NextLoad,
* ) => ModuleLoadResult
* } LoadHook
*/
// Use arrays for better insertion and iteration performance, we don't care
// about deletion performance as much.
/** @type {ResolveHook[]} */
const resolveHooks = [];
/** @type {LoadHook[]} */
const loadHooks = [];
const hookId = Symbol('kModuleHooksIdKey');
let nextHookId = 0;