Skip to content

Commit dd2e421

Browse files
Merge pull request #36 from nodejs/reorg-design-docs
2 parents 2fc1aa0 + f9e7ad0 commit dd2e421

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This team is spun off from the [Modules team](https://github.com/nodejs/modules)
1414

1515
- [Use cases](./doc/use-cases.md)
1616

17-
- [Design](./doc/design.md)
17+
- [Design](./doc/design/overview.md)
1818

1919
- [Project board](https://github.com/nodejs/node/projects/17)
2020

doc/design/overview.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Loaders Design
2+
3+
There are currently [three loader hooks](https://github.com/nodejs/node/tree/master/doc/api/esm.html#esm_hooks):
4+
5+
1. `resolve`: Takes a specifier (the string after `from` in an `import` statement) and converts it into an URL to be loaded.
6+
7+
1. `load`: Takes the resolved URL and returns runnable code (JavaScript, Wasm, etc.) as well as the name of one of Node’s ESM loader’s [“translators”](https://github.com/nodejs/node/blob/master/lib/internal/modules/esm/translators.js):
8+
* `commonjs`
9+
* `module`
10+
* `builtin` (a Node internal module, like `fs`)
11+
* `json` (with `--experimental-json-modules`)
12+
* `wasm` (with `--experimental-wasm-modules`)
13+
14+
* `globalPreload`: Defines a string of JavaScript to be injected into the application global scope.
15+
16+
## Chaining
17+
18+
Custom loaders are intended to chain to support various concerns beyond the scope of core, such as build tooling, mocking, transpilation, etc.
19+
20+
### Proposals
21+
22+
* [Recursive chaining](./proposal-chaining-recursive.md)
23+
24+
## History
25+
26+
### Hook consolidation
27+
28+
The initial experimental implementation consisted of 5 hooks:
29+
30+
* `resolve`
31+
* `getFormat`
32+
* `getSource`
33+
* `transformSource`
34+
* `getGlobalPreloadCode`
35+
36+
These were consolidated (in [nodejs/node#37468](https://github.com/nodejs/node/pull/37468)) to avoid counter-intuitive and paradoxical behaviour when used in multiple custom loaders.

doc/design.md renamed to doc/design/proposal-chaining-recursive.md

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
# Loaders Design
2-
3-
## Hooks
4-
5-
There are currently [three loader hooks](https://nodejs.org/api/esm.html#esm_hooks):
6-
7-
- `resolve`: Take a specifier (the string after `from` in an `import` statement) and convert it into an URL to be loaded.
8-
9-
- `load`: Take the resolved URL and return runnable code (JavaScript, Wasm, etc.) as well as the name of one of Node’s ESM loader’s [“translators”](https://github.com/nodejs/node/blob/master/lib/internal/modules/esm/translators.js): `commonjs`, `module`, `builtin` (a Node internal module like `fs`), `json` (with `--experimental-json-modules`) or `wasm` (with `--experimental-wasm-modules`).
10-
11-
- `globalPreload`: Define a string of JavaScript to be injected into the application global scope.
1+
# Chaining Hooks “Recursive” Design
122

133
## Chaining `resolve` hooks
144

0 commit comments

Comments
 (0)