@@ -174,7 +174,7 @@ changes:
174174
175175Module resolution and loading can be customized by registering a file which
176176exports 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
178178using the ` -- import ` flag:
179179
180180` ` ` bash
@@ -203,7 +203,7 @@ node --import some-package/register ./my-app.js
203203` ` `
204204
205205Where ` 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 `
207207example.
208208
209209Using ` -- import ` ensures that the hooks are registered before any application
@@ -235,14 +235,14 @@ import('./my-app.js');
235235In this example, we are registering the ` http- to- https` hooks, but they will
236236only be available for subsequently imported modules—in this case, ` my- app .js `
237237and 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
242242static 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
246246modules that it references via either ` import` or ` require` .
247247
248248Finally, 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
262262import { register } from ' node:module' ;
263263
264- register (new URL ( ' ./first.mjs' , import .meta.url) );
264+ register (' ./first.mjs' , import .meta.url);
265265register (' ./second.mjs' , import .meta.url);
266266await import (' ./my-app.mjs' );
267267` ` `
@@ -272,7 +272,7 @@ const { register } = require('node:module');
272272const { pathToFileURL } = require (' node:url' );
273273
274274const parentURL = pathToFileURL (__filename );
275- register (new URL ( ' ./first.mjs' , parentURL) );
275+ register (' ./first.mjs' , parentURL);
276276register (' ./second.mjs' , parentURL);
277277import (' ./my-app.mjs' );
278278` ` `
@@ -296,8 +296,8 @@ like ports.
296296import { register } from ' node:module' ;
297297import { 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.
301301const { port1 , port2 } = new MessageChannel ();
302302
303303port1 .on (' message' , (msg ) => {
@@ -317,7 +317,7 @@ const { pathToFileURL } = require('node:url');
317317const { 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.
321321const { port1 , port2 } = new MessageChannel ();
322322
323323port1 .on (' message' , (msg ) => {
@@ -396,7 +396,7 @@ either:
396396Module 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
401401export 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:
602602The value of ` source` is ignored for type ` ' builtin' ` because currently it is
603603not 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