Skip to content

Commit 1704f24

Browse files
GeoffreyBoothUlisesGascon
authored andcommittedSep 10, 2023
doc: add signature for module.register
PR-URL: #49251 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed
 

‎doc/api/esm.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1715,14 +1715,14 @@ for ESM specifiers is [commonjs-extension-resolution-loader][].
17151715
[`import`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
17161716
[`initialize`]: #initialize
17171717
[`module.createRequire()`]: module.md#modulecreaterequirefilename
1718-
[`module.register()`]: module.md#moduleregister
1718+
[`module.register()`]: module.md#moduleregisterspecifier-parenturl-options
17191719
[`module.syncBuiltinESMExports()`]: module.md#modulesyncbuiltinesmexports
17201720
[`package.json`]: packages.md#nodejs-packagejson-field-definitions
17211721
[`port.postMessage`]: worker_threads.md#portpostmessagevalue-transferlist
17221722
[`port.ref()`]: https://nodejs.org/dist/latest-v17.x/docs/api/worker_threads.html#portref
17231723
[`port.unref()`]: https://nodejs.org/dist/latest-v17.x/docs/api/worker_threads.html#portunref
17241724
[`process.dlopen`]: process.md#processdlopenmodule-filename-flags
1725-
[`register`]: module.md#moduleregister
1725+
[`register`]: module.md#moduleregisterspecifier-parenturl-options
17261726
[`string`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
17271727
[`util.TextDecoder`]: util.md#class-utiltextdecoder
17281728
[cjs-module-lexer]: https://github.com/nodejs/cjs-module-lexer/tree/1.2.2

‎doc/api/module.md

+19-4
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,29 @@ isBuiltin('fs'); // true
8080
isBuiltin('wss'); // false
8181
```
8282
83-
### `module.register()`
83+
### `module.register(specifier[, parentURL][, options])`
8484
8585
<!-- YAML
8686
added: v20.6.0
8787
-->
8888
89-
In addition to using the `--experimental-loader` option in the CLI,
90-
loaders can be registered programmatically using the
91-
`module.register()` method.
89+
> Stability: 1.1 - Active development
90+
91+
* `specifier` {string} Customization hooks to be registered; this should be the
92+
same string that would be passed to `import()`, except that if it is relative,
93+
it is resolved relative to `parentURL`.
94+
* `parentURL` {string} If you want to resolve `specifier` relative to a base
95+
URL, such as `import.meta.url`, you can pass that URL here. **Default:**
96+
`'data:'`
97+
* `options` {Object}
98+
* `data` {any} Any arbitrary, cloneable JavaScript value to pass into the
99+
[`initialize`][] hook.
100+
* `transferList` {Object\[]} [transferrable objects][] to be passed into the
101+
`initialize` hook.
102+
* Returns: {any} returns whatever was returned by the `initialize` hook.
103+
104+
Register a module that exports hooks that customize Node.js module resolution
105+
and loading behavior.
92106
93107
```mjs
94108
import { register } from 'node:module';
@@ -390,3 +404,4 @@ returned object contains the following keys:
390404
[`module`]: modules.md#the-module-object
391405
[module wrapper]: modules.md#the-module-wrapper
392406
[source map include directives]: https://sourcemaps.info/spec.html#h.lmz475t4mvbx
407+
[transferrable objects]: worker_threads.md#portpostmessagevalue-transferlist

0 commit comments

Comments
 (0)
Please sign in to comment.