From f4121de4bdfaefb8a98f3249afa8f1021dc9db54 Mon Sep 17 00:00:00 2001 From: Lucas Azzola Date: Sun, 22 Oct 2017 14:03:18 +1000 Subject: [PATCH] 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`. Refs: https://github.com/nodejs/node/pull/15445 --- doc/api/esm.md | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/doc/api/esm.md b/doc/api/esm.md index bc25c88b9a82e9..5e0018c0724b6d 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -129,10 +129,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: @@ -206,3 +214,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