Skip to content

Commit d97a950

Browse files
committed
Renames into readFile / statFile
1 parent bdc8aff commit d97a950

File tree

3 files changed

+25
-27
lines changed

3 files changed

+25
-27
lines changed

doc/design/overview.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
# Loaders Design
22

3-
There are currently [three loader hooks](https://github.com/nodejs/node/tree/master/doc/api/esm.html#esm_hooks):
3+
There are currently the following [loader hooks](https://github.com/nodejs/node/tree/master/doc/api/esm.html#esm_hooks):
44

55
1. `resolve`: Takes a specifier (the string after `from` in an `import` statement) and converts it into an URL to be loaded.
66

7-
1. `loadManifest`: Takes the resolved URL and returns the `package.json` from the location (or `null` if it doesn't exist).
8-
97
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):
108
* `commonjs`
119
* `module`
1210
* `builtin` (a Node internal module, like `fs`)
1311
* `json` (with `--experimental-json-modules`)
1412
* `wasm` (with `--experimental-wasm-modules`)
1513

16-
* `globalPreload`: Defines a string of JavaScript to be injected into the application global scope.
14+
1. `statFile`: Takes the resolved URL and returns its [`fs.Stats` record](https://nodejs.org/api/fs.html#class-fsstats) (or `null` if it doesn't exist).
15+
16+
1. `readFile`: Takes the resolved URL and returns its binary content (or `null` if it doesn't exist).
17+
18+
1. `globalPreload`: Defines a string of JavaScript to be injected into the application global scope.
1719

1820
## Chaining
1921

doc/design/proposal-chaining-iterative.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ const babelOutputToFormat = new Map([
283283
```
284284
</details>
285285
286-
## Chaining `loadManifest` hooks
286+
## Chaining `readFile` hooks
287287
288288
Say you had a chain of three loaders:
289289
@@ -302,26 +302,24 @@ node \
302302
303303
These would be called in the following sequence:
304304
305-
(`zip` OR `defaultLoadManifest`) → `tgz``warc`
305+
(`zip` OR `defaultReadFile`) → `tgz``warc`
306306
307-
1. `defaultLoadManifest` / `zip` needs to be first to know whether the manifest exists on the actual filesystem, which is fed to the subsequent loader
307+
1. `defaultReadFile` / `zip` needs to be first to know whether the manifest exists on the actual filesystem, which is fed to the subsequent loader
308308
1. `tgz` receives the raw source from the previous loader and, if necessary, checks for the manifest existence via its own rules
309309
1. `warc` does the same thing
310310
311311
LoadManifest hooks would have the following signature:
312312
313313
```ts
314-
export async function loadManifest(
315-
manifestUrl: string, // A URL that may or may not point to an existing
316-
// location
314+
export async function readFile(
315+
url: string, // A URL that point to a location; whether the file
316+
// exists or not isn't guaranteed
317317
interimResult: { // result from the previous hook
318-
manifest: string | ArrayBuffer | TypedArray | null, // The content of the
319-
// manifest, or `null` if it doesn't exist.
318+
data: string | ArrayBuffer | TypedArray | null, // The content of the
319+
// file, or `null` if it doesn't exist.
320320
},
321321
context: {
322322
conditions = string[], // Export conditions of the relevant package.json
323-
parentUrl = null, // The module importing this one, or null if
324-
// this is the Node entry point
325323
},
326324
defaultLoadManifest: function, // Node's default load hook
327325
): {
@@ -330,7 +328,7 @@ export async function loadManifest(
330328
interimIgnored?: true, // interimResult was intentionally ignored
331329
shortCircuit?: true, // `resolve` chain should be terminated
332330
},
333-
manifest: string | ArrayBuffer | TypedArray | null, // The content of the
334-
// manifest, or `null` if it doesn't exist.
331+
data: string | ArrayBuffer | TypedArray | null, // The content of the
332+
// file, or `null` if it doesn't exist.
335333
} {
336334
```

doc/design/proposal-chaining-middleware.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ export async function load(
264264
```
265265
</details>
266266
267-
## Chaining `loadManifest` hooks
267+
## Chaining `readFile` hooks
268268
269269
Say you had a chain of three loaders:
270270
@@ -286,20 +286,18 @@ These would be called in the following sequence: `zip` calls `tgz`, which calls
286286
Load hooks would have the following signature:
287287
288288
```ts
289-
export async function loadManifest(
290-
manifestUrl: string, // A URL that may or may not point to an existing
291-
// location
289+
export async function readFile(
290+
url: string, // A URL that point to a location; whether the file
291+
// exists or not isn't guaranteed
292292
context: {
293293
conditions = string[], // Export conditions of the relevant `package.json`
294-
parentUrl = null, // The module importing this one, or null if
295-
// this is the Node entry point
296294
},
297-
next: function, // The subsequent `loadManifest` hook in the chain,
298-
// or Node’s default `loadManifest` hook after the
299-
// last user-supplied `loadManifest` hook
295+
next: function, // The subsequent `readFile` hook in the chain,
296+
// or Node’s default `readFile` hook after the
297+
// last user-supplied `readFile` hook
300298
): {
301-
manifest: string | ArrayBuffer | TypedArray | null, // The content of the
302-
// manifest, or `null` if it doesn't exist.
299+
data: string | ArrayBuffer | TypedArray | null, // The content of the
300+
// file, or `null` if it doesn't exist.
303301
shortCircuit?: true, // A signal that this hook intends to terminate
304302
// the chain of `load` hooks
305303
} {

0 commit comments

Comments
 (0)