Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: add signature for module.register #49251

Merged
merged 1 commit into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: REPLACEME
-->

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