Skip to content

Commit

Permalink
doc: add signature for module.register
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
GeoffreyBooth authored and UlisesGascon committed Sep 10, 2023
1 parent f2552a4 commit 1704f24
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
4 changes: 2 additions & 2 deletions doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -1715,14 +1715,14 @@ for ESM specifiers is [commonjs-extension-resolution-loader][].
[`import`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
[`initialize`]: #initialize
[`module.createRequire()`]: module.md#modulecreaterequirefilename
[`module.register()`]: module.md#moduleregister
[`module.register()`]: module.md#moduleregisterspecifier-parenturl-options
[`module.syncBuiltinESMExports()`]: module.md#modulesyncbuiltinesmexports
[`package.json`]: packages.md#nodejs-packagejson-field-definitions
[`port.postMessage`]: worker_threads.md#portpostmessagevalue-transferlist
[`port.ref()`]: https://nodejs.org/dist/latest-v17.x/docs/api/worker_threads.html#portref
[`port.unref()`]: https://nodejs.org/dist/latest-v17.x/docs/api/worker_threads.html#portunref
[`process.dlopen`]: process.md#processdlopenmodule-filename-flags
[`register`]: module.md#moduleregister
[`register`]: module.md#moduleregisterspecifier-parenturl-options
[`string`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
[`util.TextDecoder`]: util.md#class-utiltextdecoder
[cjs-module-lexer]: https://github.com/nodejs/cjs-module-lexer/tree/1.2.2
Expand Down
23 changes: 19 additions & 4 deletions doc/api/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,29 @@ isBuiltin('fs'); // true
isBuiltin('wss'); // false
```
### `module.register()`
### `module.register(specifier[, parentURL][, options])`
<!-- YAML
added: v20.6.0
-->
In addition to using the `--experimental-loader` option in the CLI,
loaders can be registered programmatically using the
`module.register()` method.
> Stability: 1.1 - Active development
* `specifier` {string} Customization hooks to be registered; this should be the
same string that would be passed to `import()`, except that if it is relative,
it is resolved relative to `parentURL`.
* `parentURL` {string} If you want to resolve `specifier` relative to a base
URL, such as `import.meta.url`, you can pass that URL here. **Default:**
`'data:'`
* `options` {Object}
* `data` {any} Any arbitrary, cloneable JavaScript value to pass into the
[`initialize`][] hook.
* `transferList` {Object\[]} [transferrable objects][] to be passed into the
`initialize` hook.
* Returns: {any} returns whatever was returned by the `initialize` hook.
Register a module that exports hooks that customize Node.js module resolution
and loading behavior.
```mjs
import { register } from 'node:module';
Expand Down Expand Up @@ -390,3 +404,4 @@ returned object contains the following keys:
[`module`]: modules.md#the-module-object
[module wrapper]: modules.md#the-module-wrapper
[source map include directives]: https://sourcemaps.info/spec.html#h.lmz475t4mvbx
[transferrable objects]: worker_threads.md#portpostmessagevalue-transferlist

0 comments on commit 1704f24

Please sign in to comment.