Skip to content

Commit f54118c

Browse files
JakobJingleheimeraduh95
authored andcommitted
doc: correct customization hook types & clarify descriptions
PR-URL: #56454 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 47fad8c commit f54118c

File tree

2 files changed

+37
-11
lines changed

2 files changed

+37
-11
lines changed

doc/api/module.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,13 +1039,14 @@ changes:
10391039
* `nextResolve` {Function} The subsequent `resolve` hook in the chain, or the
10401040
Node.js default `resolve` hook after the last user-supplied `resolve` hook
10411041
* `specifier` {string}
1042-
* `context` {Object}
1042+
* `context` {Object|undefined} When omitted, the defaults are provided. When provided, defaults
1043+
are merged in with preference to the provided properties.
10431044
* Returns: {Object|Promise} The asynchronous version takes either an object containing the
10441045
following properties, or a `Promise` that will resolve to such an object. The
10451046
synchronous version only accepts an object returned synchronously.
1046-
* `format` {string|null|undefined} A hint to the load hook (it might be
1047-
ignored)
1048-
`'builtin' | 'commonjs' | 'json' | 'module' | 'wasm'`
1047+
* `format` {string|null|undefined} A hint to the `load` hook (it might be ignored). It can be a
1048+
module format (such as `'commonjs'` or `'module'`) or an arbitrary value like `'css'` or
1049+
`'yaml'`.
10491050
* `importAttributes` {Object|undefined} The import attributes to use when
10501051
caching the module (optional; if excluded the input will be used)
10511052
* `shortCircuit` {undefined|boolean} A signal that this hook intends to
@@ -1148,12 +1149,14 @@ changes:
11481149
* `context` {Object}
11491150
* `conditions` {string\[]} Export conditions of the relevant `package.json`
11501151
* `format` {string|null|undefined} The format optionally supplied by the
1151-
`resolve` hook chain
1152+
`resolve` hook chain. This can be any string value as an input; input values do not need to
1153+
conform to the list of acceptable return values described below.
11521154
* `importAttributes` {Object}
11531155
* `nextLoad` {Function} The subsequent `load` hook in the chain, or the
11541156
Node.js default `load` hook after the last user-supplied `load` hook
11551157
* `url` {string}
1156-
* `context` {Object}
1158+
* `context` {Object|undefined} When omitted, defaults are provided. When provided, defaults are
1159+
merged in with preference to the provided properties.
11571160
* Returns: {Object|Promise} The asynchronous version takes either an object containing the
11581161
following properties, or a `Promise` that will resolve to such an object. The
11591162
synchronous version only accepts an object returned synchronously.

lib/internal/modules/customization_hooks.js

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,40 @@ let debug = require('internal/util/debuglog').debuglog('module_hooks', (fn) => {
2525
debug = fn;
2626
});
2727

28-
/** @typedef {import('internal/modules/cjs/loader.js').Module} Module */
2928
/**
30-
* @typedef {(specifier: string, context: ModuleResolveContext, nextResolve: ResolveHook)
31-
* => ModuleResolveResult} ResolveHook
32-
* @typedef {(url: string, context: ModuleLoadContext, nextLoad: LoadHook)
33-
* => ModuleLoadResult} LoadHook
29+
* @typedef {import('internal/modules/cjs/loader.js').Module} Module
30+
*/
31+
/**
32+
* @typedef {(
33+
* specifier: string,
34+
* context: Partial<ModuleResolveContext>,
35+
* ) => ModuleResolveResult
36+
* } NextResolve
37+
* @typedef {(
38+
* specifier: string,
39+
* context: ModuleResolveContext,
40+
* nextResolve: NextResolve,
41+
* ) => ModuleResolveResult
42+
* } ResolveHook
43+
* @typedef {(
44+
* url: string,
45+
* context: Partial<ModuleLoadContext>,
46+
* ) => ModuleLoadResult
47+
* } NextLoad
48+
* @typedef {(
49+
* url: string,
50+
* context: ModuleLoadContext,
51+
* nextLoad: NextLoad,
52+
* ) => ModuleLoadResult
53+
* } LoadHook
3454
*/
3555

3656
// Use arrays for better insertion and iteration performance, we don't care
3757
// about deletion performance as much.
58+
59+
/** @type {ResolveHook[]} */
3860
const resolveHooks = [];
61+
/** @type {LoadHook[]} */
3962
const loadHooks = [];
4063
const hookId = Symbol('kModuleHooksIdKey');
4164
let nextHookId = 0;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy