From 5ec4fd391d625d2cc4cbc95cb3433cf532aa796f Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Sat, 19 Aug 2023 17:04:01 -0700 Subject: [PATCH] module: add docs signature for `register` --- doc/api/module.md | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/doc/api/module.md b/doc/api/module.md index 04b4d00c04b372..5bbbd43a7a2572 100644 --- a/doc/api/module.md +++ b/doc/api/module.md @@ -80,15 +80,27 @@ isBuiltin('fs'); // true isBuiltin('wss'); // false ``` -### `module.register()` +### `module.register(specifier[, parentURL[, options]])` -In addition to using the `--experimental-loader` option in the CLI, -loaders can be registered programmatically using the -`module.register()` method. +* `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'; @@ -390,3 +402,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