node/test/module-hooks
Joyee Cheung 3e31baeda6
esm: use sync loading/resolving on non-loader-hook thread
ESM resolution and loading is now always synchronous from a
non-loader-hook thread. If no asynchrnous loader hooks are
registered, the resolution/loading is entirely synchronous.
If asynchronous loader hooks are registered, these would be
synchronous on the non-loader-hook thread, and asynchronous
on the loader hook thread.

This avoids several races caused by async/sync loading sharing
the same cache. In particular, asynchronous loader hooks
now works with `require(esm)` - previously it tends to break
due to races.

In addition, when an asynchronous loader hook
returns a promise that never settles, the main thread no longer
silently exits with exit code 13, leaving the code below
any module loading calls silently ignored without being executed.
Instead, it now throws ERR_ASYNC_LOADER_REQUEST_NEVER_SETTLED
which can be caught and handled by the main thread. If the module
request comes from `import()`, the never-settling promise is
now relayed to the result returned by `import()`.

Drive-by: when annotating the error about importing undetectable
named exports from CommonJS, it now no longer reload the source
code of the CommonJS module, and instead reuses format information
cached when the module was loaded for linking.

PR-URL: https://github.com/nodejs/node/pull/60380
Fixes: https://github.com/nodejs/node/issues/59666
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
2025-10-31 20:45:10 +00:00
..
module-hooks.status
test-module-hooks-builtin-require.js module: convert schema-only core module on convertCJSFilenameToURL 2025-06-25 16:49:56 +00:00
test-module-hooks-custom-conditions-cjs.js module: fix conditions override in synchronous resolve hooks 2025-07-26 09:13:11 +00:00
test-module-hooks-custom-conditions-special-values.js module: fix conditions override in synchronous resolve hooks 2025-07-26 09:13:11 +00:00
test-module-hooks-custom-conditions.mjs module: fix conditions override in synchronous resolve hooks 2025-07-26 09:13:11 +00:00
test-module-hooks-import-wasm.mjs tools: add lint rule to ensure assertions are reached 2025-10-07 12:40:05 +00:00
test-module-hooks-load-async-and-sync.js module: handle null source from async loader hooks in sync hooks 2025-10-14 16:28:22 +00:00
test-module-hooks-load-buffers.js tools: add lint rule to ensure assertions are reached 2025-10-07 12:40:05 +00:00
test-module-hooks-load-builtin-import.mjs
test-module-hooks-load-builtin-require.js module: convert schema-only core module on convertCJSFilenameToURL 2025-06-25 16:49:56 +00:00
test-module-hooks-load-chained.js tools: add lint rule to ensure assertions are reached 2025-10-07 12:40:05 +00:00
test-module-hooks-load-context-merged-esm.mjs module: allow omitting context in synchronous next hooks 2025-02-18 15:28:59 +00:00
test-module-hooks-load-context-merged.js module: allow omitting context in synchronous next hooks 2025-02-18 15:28:59 +00:00
test-module-hooks-load-context-optional-esm.mjs module: allow omitting context in synchronous next hooks 2025-02-18 15:28:59 +00:00
test-module-hooks-load-context-optional.js module: allow omitting context in synchronous next hooks 2025-02-18 15:28:59 +00:00
test-module-hooks-load-detection.js tools: add lint rule to ensure assertions are reached 2025-10-07 12:40:05 +00:00
test-module-hooks-load-esm-mock.js tools,test: enforce best practices to detect never settling promises 2025-07-16 10:57:22 +02:00
test-module-hooks-load-esm.js tools,test: enforce best practices to detect never settling promises 2025-07-16 10:57:22 +02:00
test-module-hooks-load-invalid.js
test-module-hooks-load-mock.js
test-module-hooks-load-short-circuit-required-middle.js
test-module-hooks-load-short-circuit-required-start.js
test-module-hooks-load-short-circuit.js
test-module-hooks-load-url-change-import.mjs tools: add lint rule to ensure assertions are reached 2025-10-07 12:40:05 +00:00
test-module-hooks-load-url-change-require.js tools: add lint rule to ensure assertions are reached 2025-10-07 12:40:05 +00:00
test-module-hooks-preload.js
test-module-hooks-require-esm.js esm: use sync loading/resolving on non-loader-hook thread 2025-10-31 20:45:10 +00:00
test-module-hooks-require-wasm.js tools: add lint rule to ensure assertions are reached 2025-10-07 12:40:05 +00:00
test-module-hooks-resolve-builtin-builtin-import.mjs
test-module-hooks-resolve-builtin-builtin-require.js tools: add lint rule to ensure assertions are reached 2025-10-07 12:40:05 +00:00
test-module-hooks-resolve-builtin-on-disk-import.mjs
test-module-hooks-resolve-builtin-on-disk-require.js tools: add lint rule to ensure assertions are reached 2025-10-07 12:40:05 +00:00
test-module-hooks-resolve-context-merged-esm.mjs module: allow omitting context in synchronous next hooks 2025-02-18 15:28:59 +00:00
test-module-hooks-resolve-context-merged.js module: allow omitting context in synchronous next hooks 2025-02-18 15:28:59 +00:00
test-module-hooks-resolve-context-optional-esm.mjs module: allow omitting context in synchronous next hooks 2025-02-18 15:28:59 +00:00
test-module-hooks-resolve-context-optional.js module: allow omitting context in synchronous next hooks 2025-02-18 15:28:59 +00:00
test-module-hooks-resolve-invalid.js
test-module-hooks-resolve-load-import-inline-typescript-override.mjs
test-module-hooks-resolve-load-import-inline-typescript.mjs
test-module-hooks-resolve-load-require-inline-typescript-override.js
test-module-hooks-resolve-load-require-inline-typescript.js
test-module-hooks-resolve-short-circuit-required-middle.js
test-module-hooks-resolve-short-circuit-required-start.js
test-module-hooks-resolve-short-circuit.js
testcfg.py