Skip to content

Commit ada3473

Browse files
committed
module: remove async module customization hooks
Remove `module.register()` (DEP0205), the `--experimental-loader` and `--loader` flags, and the machinery that supported them: the loader hooks worker thread, the hooks proxy, the async module customization hook chains for resolving and loading, the internal worker class used to run the loader thread, and the asynchronous module job linking. Module customization is now provided only by `module.registerHooks()`, which runs synchronously on the thread that loads the modules. As the loader thread no longer exists, the ES module loader always loads and links modules synchronously, so the code that handled promises and the re-invented `require()` for imported CommonJS customized by the async module customization hooks is removed too. `import()` still defers evaluation of the module to a later microtask, as before. `worker_threads.isInternalThread` is kept for compatibility and is now always `false`; removing it is left for a future semver-major change. The `ERR_ASYNC_LOADER_REQUEST_NEVER_SETTLED` and `ERR_LOADER_CHAIN_INCOMPLETE` error codes are no longer used and are documented as removed. Tests that exist only to exercise the async module customization hooks are removed. Assisted-by: Claude Signed-off-by: Geoffrey Booth <webadmin@geoffreybooth.com>
1 parent d699704 commit ada3473

258 files changed

Lines changed: 258 additions & 7878 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎doc/api/cli.md‎

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,33 +1509,6 @@ added:
15091509
15101510
Enable experimental support for inspector network resources.
15111511

1512-
### `--experimental-loader=module`
1513-
1514-
<!-- YAML
1515-
added: v8.8.0
1516-
changes:
1517-
- version:
1518-
- v23.6.1
1519-
- v22.13.1
1520-
- v20.18.2
1521-
pr-url: https://github.com/nodejs-private/node-private/pull/629
1522-
description: Using this feature with the permission model enabled requires
1523-
passing `--allow-worker`.
1524-
- version: v12.11.1
1525-
pr-url: https://github.com/nodejs/node/pull/29752
1526-
description: This flag was renamed from `--loader` to
1527-
`--experimental-loader`.
1528-
-->
1529-
1530-
> This flag is discouraged and may be removed in a future version of Node.js.
1531-
> Please use
1532-
> [`--import` with `register()`][preloading asynchronous module customization hooks] instead.
1533-
1534-
Specify the `module` containing exported [asynchronous module customization hooks][].
1535-
`module` may be any string accepted as an [`import` specifier][].
1536-
1537-
This feature requires `--allow-worker` if used with the [Permission Model][].
1538-
15391512
### `--experimental-network-inspection`
15401513

15411514
<!-- YAML
@@ -4306,7 +4279,6 @@ one is included in the list below.
43064279
* `--experimental-import-meta-resolve`
43074280
* `--experimental-import-text`
43084281
* `--experimental-json-modules`
4309-
* `--experimental-loader`
43104282
* `--experimental-modules`
43114283
* `--experimental-package-map`
43124284
* `--experimental-print-required-tla`
@@ -4990,7 +4962,6 @@ node --stack-trace-limit=12 -p -e "Error.stackTraceLimit" # prints 12
49904962
[`dns.setDefaultResultOrder()`]: dns.md#dnssetdefaultresultorderorder
49914963
[`dnsPromises.lookup()`]: dns.md#dnspromiseslookuphostname-options
49924964
[`import.meta.url`]: esm.md#importmetaurl
4993-
[`import` specifier]: esm.md#import-specifiers
49944965
[`inspector.open()`]: inspector.md#inspectoropenport-host-wait
49954966
[`net.getDefaultAutoSelectFamilyAttemptTimeout()`]: net.md#netgetdefaultautoselectfamilyattempttimeout
49964967
[`node:ffi`]: ffi.md
@@ -5007,7 +4978,6 @@ node --stack-trace-limit=12 -p -e "Error.stackTraceLimit" # prints 12
50074978
[`v8.startupSnapshot.setDeserializeMainFunction()`]: v8.md#v8startupsnapshotsetdeserializemainfunctioncallback-data
50084979
[`v8.startupSnapshot` API]: v8.md#startup-snapshot-api
50094980
[`vfs.mount()`]: vfs.md#vfsmount
5010-
[asynchronous module customization hooks]: module.md#asynchronous-customization-hooks
50114981
[benchmark runner]: bench.md#command-line-runner
50124982
[captured by the built-in snapshot of Node.js]: https://github.com/nodejs/node/blob/b19525a33cc84033af4addd0f80acd4dc33ce0cf/test/parallel/test-bootstrap-modules.js#L24
50134983
[collecting code coverage from tests]: test.md#collecting-code-coverage
@@ -5025,7 +4995,6 @@ node --stack-trace-limit=12 -p -e "Error.stackTraceLimit" # prints 12
50254995
[jitless]: https://v8.dev/blog/jitless
50264996
[libuv threadpool documentation]: https://docs.libuv.org/en/latest/threadpool.html
50274997
[module compile cache]: module.md#module-compile-cache
5028-
[preloading asynchronous module customization hooks]: module.md#registration-of-asynchronous-customization-hooks
50294998
[randomizing tests execution order]: test.md#randomizing-tests-execution-order
50304999
[remote code execution]: https://www.owasp.org/index.php/Code_Injection
50315000
[running tests from the command line]: test.md#running-tests-from-the-command-line

‎doc/api/deprecations.md‎

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4615,6 +4615,9 @@ no longer supported.
46154615
46164616
<!-- YAML
46174617
changes:
4618+
- version: REPLACEME
4619+
pr-url: https://github.com/nodejs/node/pull/67090
4620+
description: End-of-Life.
46184621
- version: v26.0.0
46194622
pr-url: https://github.com/nodejs/node/pull/62401
46204623
description: Runtime deprecation.
@@ -4625,18 +4628,14 @@ changes:
46254628
description: Documentation-only deprecation.
46264629
-->
46274630
4628-
Type: Runtime
4631+
Type: End-of-Life
46294632
4630-
[`module.register()`][] is deprecated. Use [`module.registerHooks()`][]
4631-
instead.
4633+
The `module.register()` API and the `--experimental-loader` and `--loader`
4634+
flags have been removed. Use [`module.registerHooks()`][] instead.
46324635
4633-
The `module.register()` API provides off-thread async hooks for customizing ES modules;
4634-
the `module.registerHooks()` API provides similar hooks that are synchronous, in-thread, and
4635-
work for all types of modules.
4636-
Supporting async hooks has proven to be complex, involving worker threads orchestration, and there are issues
4637-
that have proven unresolvable. See [caveats of asynchronous customization hooks][]. Please migrate to
4638-
`module.registerHooks()` as soon as possible as `module.register()` will be
4639-
removed in a future version of Node.js.
4636+
The `module.register()` API provided off-thread async module customization
4637+
hooks for customizing ES modules; the `module.registerHooks()` API provides
4638+
similar hooks that are synchronous and work for all types of modules.
46404639
46414640
### DEP0206: Calling `digest()` on an already-finalized `Hmac` instance
46424641
@@ -4935,7 +4934,6 @@ Type: Documentation-only
49354934
[`message.trailersDistinct`]: http.md#messagetrailersdistinct
49364935
[`message.trailers`]: http.md#messagetrailers
49374936
[`module.createRequire()`]: module.md#modulecreaterequirefilename
4938-
[`module.register()`]: module.md#moduleregisterspecifier-parenturl-options
49394937
[`module.registerHooks()`]: module.md#moduleregisterhooksoptions
49404938
[`os.networkInterfaces()`]: os.md#osnetworkinterfaces
49414939
[`os.tmpdir()`]: os.md#ostmpdir
@@ -4991,7 +4989,6 @@ Type: Documentation-only
49914989
[`zlib.bytesWritten`]: zlib.md#zlibbyteswritten
49924990
[alloc]: buffer.md#static-method-bufferallocsize-fill-encoding
49934991
[alloc_unsafe_size]: buffer.md#static-method-bufferallocunsafesize-alignment
4994-
[caveats of asynchronous customization hooks]: module.md#caveats-of-asynchronous-customization-hooks
49954992
[from_arraybuffer]: buffer.md#static-method-bufferfromarraybuffer-byteoffset-length
49964993
[from_string_encoding]: buffer.md#static-method-bufferfromstring-encoding
49974994
[legacy URL API]: url.md#legacy-url-api

‎doc/api/errors.md‎

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -733,13 +733,6 @@ by the `node:assert` module.
733733
An attempt was made to register something that is not a function as an
734734
`AsyncHooks` callback.
735735

736-
<a id="ERR_ASYNC_LOADER_REQUEST_NEVER_SETTLED"></a>
737-
738-
### `ERR_ASYNC_LOADER_REQUEST_NEVER_SETTLED`
739-
740-
An operation related to module loading is customized by an asynchronous loader
741-
hook that never settled the promise before the loader thread exits.
742-
743736
<a id="ERR_ASYNC_RESOURCE_DOMAIN_REMOVED"></a>
744737

745738
### `ERR_ASYNC_RESOURCE_DOMAIN_REMOVED`
@@ -2354,19 +2347,6 @@ for more information.
23542347

23552348
IP is blocked by `net.BlockList`.
23562349

2357-
<a id="ERR_LOADER_CHAIN_INCOMPLETE"></a>
2358-
2359-
### `ERR_LOADER_CHAIN_INCOMPLETE`
2360-
2361-
<!-- YAML
2362-
added:
2363-
- v18.6.0
2364-
- v16.17.0
2365-
-->
2366-
2367-
An ESM loader hook returned without calling `next()` and without explicitly
2368-
signaling a short circuit.
2369-
23702350
<a id="ERR_LOAD_SQLITE_EXTENSION"></a>
23712351

23722352
### `ERR_LOAD_SQLITE_EXTENSION`
@@ -3915,6 +3895,17 @@ attempting a [`require()`][] operation or when loading the program entry point.
39153895
> Stability: 0 - Deprecated. These error codes are either inconsistent, or have
39163896
> been removed.
39173897
3898+
<a id="ERR_ASYNC_LOADER_REQUEST_NEVER_SETTLED"></a>
3899+
3900+
### `ERR_ASYNC_LOADER_REQUEST_NEVER_SETTLED`
3901+
3902+
<!-- YAML
3903+
removed: REPLACEME
3904+
-->
3905+
3906+
An operation related to module loading is customized by an asynchronous loader
3907+
hook that never settled the promise before the loader thread exits.
3908+
39183909
<a id="ERR_CANNOT_TRANSFER_OBJECT"></a>
39193910

39203911
### `ERR_CANNOT_TRANSFER_OBJECT`
@@ -4153,6 +4144,20 @@ changes:
41534144

41544145
An invalid transfer object was passed to `postMessage()`.
41554146

4147+
<a id="ERR_LOADER_CHAIN_INCOMPLETE"></a>
4148+
4149+
### `ERR_LOADER_CHAIN_INCOMPLETE`
4150+
4151+
<!-- YAML
4152+
added:
4153+
- v18.6.0
4154+
- v16.17.0
4155+
removed: REPLACEME
4156+
-->
4157+
4158+
An ESM loader hook returned without calling `next()` and without explicitly
4159+
signaling a short circuit.
4160+
41564161
<a id="ERR_MANIFEST_ASSERT_INTEGRITY"></a>
41574162

41584163
### `ERR_MANIFEST_ASSERT_INTEGRITY`

‎doc/api/esm.md‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,7 @@ ES modules are resolved and cached as URLs. This means that special characters
199199
must be [percent-encoded][], such as `#` with `%23` and `?` with `%3F`.
200200

201201
`file:`, `node:`, and `data:` URL schemes are supported. A specifier like
202-
`'https://example.com/app.js'` is not supported natively in Node.js unless using
203-
a [custom HTTPS loader][].
202+
`'https://example.com/app.js'` is not supported natively in Node.js.
204203

205204
#### `file:` URLs
206205

@@ -493,8 +492,6 @@ resolutions are subject to the permitted exports resolutions within the package.
493492
494493
* This can result in synchronous file-system operations, which
495494
can impact performance similarly to `require.resolve`.
496-
* This feature is not available within custom loaders (it would
497-
create a deadlock).
498495
499496
**Non-standard API**:
500497
@@ -1316,8 +1313,8 @@ _isImports_, _conditions_)
13161313
### Customizing ESM specifier resolution algorithm
13171314
13181315
[Module customization hooks][] provide a mechanism for customizing the ESM
1319-
specifier resolution algorithm. An example that provides CommonJS-style
1320-
resolution for ESM specifiers is [commonjs-extension-resolution-loader][].
1316+
specifier resolution algorithm, for example to provide CommonJS-style
1317+
resolution for ESM specifiers.
13211318
13221319
<!-- Note: The merve link should be kept in-sync with the deps version -->
13231320
@@ -1360,8 +1357,6 @@ resolution for ESM specifiers is [commonjs-extension-resolution-loader][].
13601357
[`process.dlopen`]: process.md#processdlopenmodule-filename-flags
13611358
[`require(esm)`]: modules.md#loading-ecmascript-modules-using-require
13621359
[`url.fileURLToPath()`]: url.md#urlfileurltopathurl-options
1363-
[commonjs-extension-resolution-loader]: https://github.com/nodejs/loaders-test/tree/main/commonjs-extension-resolution-loader
1364-
[custom https loader]: module.md#import-from-https
13651360
[import.meta.resolve]: #importmetaresolvespecifier
13661361
[merve]: https://github.com/anonrig/merve/tree/v1.0.0
13671362
[percent-encoded]: url.md#percent-encoding-in-urls

0 commit comments

Comments
 (0)