Skip to content

Commit

Permalink
doc: document resolve hook formats
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
azz authored and MylesBorins committed Dec 12, 2017
1 parent cb33487 commit 821951e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,18 @@ argument to the resolver for easy compatibility workflows.

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

For example a dummy loader to load JavaScript restricted to browser resolution
| `format` | Description |
| --- | --- |
| `"esm"` | Load a standard JavaScript module |
| `"cjs"` | Load a node-style CommonJS module |
| `"builtin"` | Load a node builtin CommonJS module |
| `"json"` | Load a JSON file |
| `"addon"` | Load a [C++ Addon][addons] |
| `"dynamic"` | Use a [dynamic instantiate hook][] |

For example, a dummy loader to load JavaScript restricted to browser resolution
rules with only JS file extension and Node builtin modules support could
be written:

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

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

0 comments on commit 821951e

Please sign in to comment.