Skip to content

Commit 821951e

Browse files
azzMylesBorins
authored andcommitted
doc: document resolve hook formats
Add `"dynamic"` to the list of supported `format`s returned by a custom resolve hook. Add a table describing the meaning of each `format`. PR-URL: #16375 Refs: #15445 Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent cb33487 commit 821951e

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

doc/api/esm.md

+13-3
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,18 @@ argument to the resolver for easy compatibility workflows.
128128

129129
In addition to returning the resolved file URL value, the resolve hook also
130130
returns a `format` property specifying the module format of the resolved
131-
module. This can be one of `"esm"`, `"cjs"`, `"json"`, `"builtin"` or
132-
`"addon"`.
131+
module. This can be one of the following:
133132

134-
For example a dummy loader to load JavaScript restricted to browser resolution
133+
| `format` | Description |
134+
| --- | --- |
135+
| `"esm"` | Load a standard JavaScript module |
136+
| `"cjs"` | Load a node-style CommonJS module |
137+
| `"builtin"` | Load a node builtin CommonJS module |
138+
| `"json"` | Load a JSON file |
139+
| `"addon"` | Load a [C++ Addon][addons] |
140+
| `"dynamic"` | Use a [dynamic instantiate hook][] |
141+
142+
For example, a dummy loader to load JavaScript restricted to browser resolution
135143
rules with only JS file extension and Node builtin modules support could
136144
be written:
137145

@@ -205,3 +213,5 @@ then be called at the exact point of module evalutation order for that module
205213
in the import tree.
206214

207215
[Node.js EP for ES Modules]: https://github.com/nodejs/node-eps/blob/master/002-es-modules.md
216+
[addons]: addons.html
217+
[dynamic instantiate hook]: #esm_dynamic_instantiate_hook

0 commit comments

Comments
 (0)