Skip to content

Commit 4937898

Browse files
Apply suggestions from code review
Co-authored-by: Jacob Smith <[email protected]>
1 parent 4ca4d28 commit 4937898

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

doc/api/cli.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ directory. That path is then resolved by [CommonJS][] module loader. If no
2929
corresponding file is found, an error is thrown.
3030

3131
If a file is found, its path will be passed to the
32-
[ECMAScript module loader][Modules loaders] under any of the following
32+
[ES module loader][Modules loaders] under any of the following
3333
conditions:
3434

3535
* The program was started with a command-line flag that forces the entry
@@ -44,7 +44,7 @@ Otherwise, the file is loaded using the CommonJS module loader. See
4444

4545
### ECMAScript modules loader entry point caveat
4646

47-
When loading [ECMAScript module loader][Modules loaders] loads the program entry
47+
When loading, the [ECMAScript module loader][Modules loaders] loads the program entry
4848
point, the `node` command will accept as input only files with `.js`, `.mjs`, or
4949
`.cjs` extensions; and with `.wasm` extensions when
5050
[`--experimental-wasm-modules`][] is enabled.

doc/api/module.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ changes:
174174
175175
Module resolution and loading can be customized by registering a file which
176176
exports a set of hooks. This can be done using the [`register`][] method
177-
imported from `node:module`, which you can run before your application code by
177+
from `node:module`, which you can run before your application code by
178178
using the `--import` flag:
179179
180180
```bash
@@ -203,7 +203,7 @@ node --import some-package/register ./my-app.js
203203
```
204204
205205
Where `some-package` has an [`"exports"`][] field defining the `/register`
206-
export to map to a file that calls `register()`, like this `register-hooks.js`
206+
export to map to a file that calls `register()`, like the following `register-hooks.js`
207207
example.
208208
209209
Using `--import` ensures that the hooks are registered before any application
@@ -235,14 +235,14 @@ import('./my-app.js');
235235
In this example, we are registering the `http-to-https` hooks, but they will
236236
only be available for subsequently imported modules—in this case, `my-app.js`
237237
and anything it references via `import` or `require`. If the
238-
`import('./my-app.js')` had instead been a static `import './my-app.js'`, _the
239-
app would already have been loaded_ before the `http-to-https` hooks were
240-
registered. This is part of the design of ES modules, where static imports are
241-
evaluated from the leaves of the tree first back to the trunk. There can be
238+
`import('./my-app.js')` had instead been a static `import './my-app.js'`, the
239+
app would have _already_ been loaded **before** the `http-to-https` hooks were
240+
registered. This due to the ES modules specification, where static imports are
241+
evaluated from the leaves of the tree first, then back to the trunk. There can be
242242
static imports _within_ `my-app.js`, which will not be evaluated until
243243
`my-app.js` is when it's dynamically imported.
244244
245-
The `my-app.js` file can also be CommonJS. Customization hooks will run for any
245+
`my-app.js` can also be CommonJS. Customization hooks will run for any
246246
modules that it references via either `import` or `require`.
247247
248248
Finally, if all you want to do is register hooks before your app runs and you
@@ -261,7 +261,7 @@ It's possible to call `register` more than once:
261261
// entrypoint.mjs
262262
import { register } from 'node:module';
263263

264-
register(new URL('./first.mjs', import.meta.url));
264+
register('./first.mjs', import.meta.url);
265265
register('./second.mjs', import.meta.url);
266266
await import('./my-app.mjs');
267267
```
@@ -272,7 +272,7 @@ const { register } = require('node:module');
272272
const { pathToFileURL } = require('node:url');
273273

274274
const parentURL = pathToFileURL(__filename);
275-
register(new URL('./first.mjs', parentURL));
275+
register('./first.mjs', parentURL);
276276
register('./second.mjs', parentURL);
277277
import('./my-app.mjs');
278278
```
@@ -296,8 +296,8 @@ like ports.
296296
import { register } from 'node:module';
297297
import { MessageChannel } from 'node:worker_threads';
298298

299-
// This example showcases how a message channel can be used to
300-
// communicate to the hooks, by sending `port2` to the hooks.
299+
// This example demonstrates how a message channel can be used to
300+
// communicate with the hooks, by sending `port2` to the hooks.
301301
const { port1, port2 } = new MessageChannel();
302302

303303
port1.on('message', (msg) => {
@@ -317,7 +317,7 @@ const { pathToFileURL } = require('node:url');
317317
const { MessageChannel } = require('node:worker_threads');
318318

319319
// This example showcases how a message channel can be used to
320-
// communicate to the hooks, by sending `port2` to the hooks.
320+
// communicate with the hooks, by sending `port2` to the hooks.
321321
const { port1, port2 } = new MessageChannel();
322322

323323
port1.on('message', (msg) => {
@@ -396,7 +396,7 @@ either:
396396
Module customization code:
397397
398398
```mjs
399-
// In the below example this file is referenced as `/path-to-my-hooks.js`.
399+
// path-to-my-hooks.js
400400

401401
export async function initialize({ number, port }) {
402402
port.postMessage(`increment: ${number + 1}`);
@@ -602,7 +602,7 @@ The final value of `format` must be one of the following:
602602
The value of `source` is ignored for type `'builtin'` because currently it is
603603
not possible to replace the value of a Node.js builtin (core) module.
604604
605-
The value of `source` can be omitted for type `'commonjs'`:
605+
Omitting vs providing a `source` for `'commonjs'` has very different effects:
606606
607607
* When a `source` is provided, all `require` calls from this module will be
608608
processed by the ESM loader with registered `resolve` and `load` hooks; all

0 commit comments

Comments
 (0)