James M Snell
dff7a160fe
lib: put node:bench behind an --experimental-bench flag
...
Signed-off-by: James M Snell <jasnell@gmail.com >
Assisted-by: Opencode
PR-URL: https://github.com/nodejs/node/pull/65920
Reviewed-By: Jordan Harband <ljharb@gmail.com >
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com >
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br >
Reviewed-By: Xuguang Mei <meixuguang@gmail.com >
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com >
Reviewed-By: Filip Skokan <panva.ip@gmail.com >
2026-09-12 08:29:12 +00:00
James M Snell
bc96423ce4
lib: implement bench/reporters
...
Signed-off-by: James M Snell <jasnell@gmail.com >
Assisted-by: Opencode
PR-URL: https://github.com/nodejs/node/pull/65606
Reviewed-By: Filip Skokan <panva.ip@gmail.com >
Reviewed-By: Robert Nagy <ronagy@icloud.com >
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br >
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day >
2026-09-03 15:37:21 +00:00
James M Snell
4d2f7a6f4c
lib: implement node:bench
...
Signed-off-by: James M Snell <jasnell@gmail.com >
Assisted-by: Opencode
PR-URL: https://github.com/nodejs/node/pull/65606
Reviewed-By: Filip Skokan <panva.ip@gmail.com >
Reviewed-By: Robert Nagy <ronagy@icloud.com >
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br >
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day >
2026-09-03 15:37:21 +00:00
Remco Haszing
2c4ea73ae9
module: implement Symbol.dispose in ModuleHooks
...
This change implements the `Symbol.dispose` key in the
`ModuleHooks` class as an alias for deregister. This makes
`registerHooks` work with the `using` keyword.
Fixes: https://github.com/nodejs/node/issues/63846
Signed-off-by: Remco Haszing <remcohaszing@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/63928
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk >
Reviewed-By: Jacob Smith <jacob@frende.me >
2026-07-26 00:59:39 +00:00
Joyee Cheung
4f44c6f5fe
module: fix sync hook short-circuit in require() in imported CJS
...
- For imported CJS, if it's not customized by asynchronous hooks,
make sure it won't use the quirky re-invented require in all
cases.
- When the imported CJS module is customized by synchronous hooks,
in the synthetic module evalutation step, avoid calling the
respective default step again.
- Make the branching of loadCJSModuleWithModuleLoad() and
loadCJSModuleWithSpecialRequire() more explicit, and fold
the tentative fs read in the 'commonjs' translator into the
share createCJSModuleWrap() helper instead of checking it
twice in the same path.
Signed-off-by: Joyee Cheung <joyeec9h3@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/62920
Fixes: https://github.com/nodejs/node/issues/63060
Reviewed-By: Paolo Insogna <paolo@cowtech.it >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day >
2026-05-07 14:44:56 +00:00
Geoffrey Booth
0dfdec9542
module: runtime-deprecate module.register()
...
PR-URL: https://github.com/nodejs/node/pull/62401
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com >
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day >
Reviewed-By: Filip Skokan <panva.ip@gmail.com >
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: Jacob Smith <jacob@frende.me >
2026-04-01 15:37:26 +02:00
Joyee Cheung
dd400b9f12
module: run require.resolve through module.registerHooks()
...
Previously, require.resolve() called Module._resolveFilename() directly,
bypassing any resolve hooks registered via module.registerHooks(). This
patch fixes that.
PR-URL: https://github.com/nodejs/node/pull/62028
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com >
2026-03-02 18:28:25 +00:00
Marco Ippolito
89f4b6cddb
module: remove --experimental-transform-types
...
PR-URL: https://github.com/nodejs/node/pull/61803
Refs: https://github.com/nodejs/typescript/issues/51
Reviewed-By: Paolo Insogna <paolo@cowtech.it >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Jordan Harband <ljharb@gmail.com >
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com >
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com >
2026-02-27 16:32:43 +00:00
Joyee Cheung
f4646a7f4b
module: do not invoke resolve hooks twice for imported cjs
...
Previously the resolve hook can be invoked twice from the
synthetic module evaluation step of imported CJS in the extra
module._load() call that's invoked on the resolved full path.
Add an option to avoid it, since the resolution and loading
has already been done before.
PR-URL: https://github.com/nodejs/node/pull/61529
Fixes: https://github.com/nodejs/node/issues/57125
Refs: https://github.com/nodejs/node/issues/55808
Refs: https://github.com/nodejs/node/issues/56241
Reviewed-By: Jacob Smith <jacob@frende.me >
2026-02-02 23:04:23 +00:00
Joyee Cheung
3da4dce296
test: split test-esm-loader-hooks
...
Previously whenever one of the test case fails in the CI, it
barely logged anything useful in the CI and it was difficult to
nail down the specific failing case with a local reproduction,
especially when the test fixutre is inline JavaScript. This patch:
- Puts all the inline JavaScript in on-disk fixtures so that
they can be re-run easily.
- Split the tests into individual files so that it's easier to nail
down the failure
- Use spawnSyncAndAssert which logs useful information when the child
process does not behave as expected.
- Rename the tests as module-hooks/test-async-loader-hooks-* because
they belong to the module hooks test suite and are not esm-specific.
PR-URL: https://github.com/nodejs/node/pull/61374
Refs: https://github.com/nodejs/reliability/blob/main/reports/2026-01-13.md
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
2026-01-16 14:30:12 +00:00
Antoine du Hamel
0457bfee2c
test: forbid use of named imports for fixtures
...
PR-URL: https://github.com/nodejs/node/pull/61228
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk >
2026-01-01 23:48:26 +00:00
Joyee Cheung
28f468a615
module: fix sync resolve hooks for require with node: prefixes
...
Previously, when require()-ing builtins with the node: prefix,
the sync resolve hooks were not properly invoked, and load hooks
could not override the builtin's format. This fixes the
handling and enables redirecting prefixed built-ins to on-disk
files and overriding them with other module types via hooks.
PR-URL: https://github.com/nodejs/node/pull/61088
Fixes: https://github.com/nodejs/node/issues/60005
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com >
2025-12-22 14:35:45 +00:00
Joyee Cheung
4f24aff94a
module: preserve URL in the parent created by createRequire()
...
Previously, createRequire() does not preserve the URL it gets
passed in the mock parent module created, which can be
observable if it's used together with module.registerHooks().
This patch adds preservation of the URL if createRequire()
is invoked with one.
PR-URL: https://github.com/nodejs/node/pull/60974
Fixes: https://github.com/nodejs/node/issues/60973
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com >
2025-12-13 07:36:20 +00:00
Antoine du Hamel
14f02fc2f7
lib,src,test: fix tests without SQLite
...
PR-URL: https://github.com/nodejs/node/pull/60906
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2025-12-11 23:04:24 +01:00
Antoine du Hamel
f1f6f3df84
test: ensure assertions are reached on more tests
...
PR-URL: https://github.com/nodejs/node/pull/60641
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
2025-11-11 09:56:18 +00:00
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
Joyee Cheung
170848bc18
module: handle null source from async loader hooks in sync hooks
...
This relaxes the validation in sync hooks so that it accepts
the quirky nullish source returned by the default step of the
async loader when the module being loaded is CommonJS.
When there are no customization hooks registered, a saner
synchronous default load step is used to use a property
instead of a reset nullish source to signify that the module
should go through the CJS monkey patching routes and reduce
excessive reloading from disk.
PR-URL: https://github.com/nodejs/node/pull/59929
Fixes: https://github.com/nodejs/node/issues/59384
Fixes: https://github.com/nodejs/node/issues/57327
Refs: https://github.com/nodejs/node/issues/59666
Refs: https://github.com/dygabo/load_module_test
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com >
Reviewed-By: Jacob Smith <jacob@frende.me >
2025-10-14 16:28:22 +00:00
Antoine du Hamel
ec26b1c01a
tools: add lint rule to ensure assertions are reached
...
PR-URL: https://github.com/nodejs/node/pull/60125
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com >
2025-10-07 12:40:05 +00:00
Joyee Cheung
6ea421a3d3
module: fix conditions override in synchronous resolve hooks
...
1. Make sure that the conditions are converted into arrays when
being passed into user hooks.
2. Pass the conditions from user hooks into the ESM resolution
so that it takes effect.
PR-URL: https://github.com/nodejs/node/pull/59011
Fixes: https://github.com/nodejs/node/issues/59003
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com >
Reviewed-By: Jacob Smith <jacob@frende.me >
2025-07-26 09:13:11 +00:00
Guy Bedford
0df15188d7
esm: unflag --experimental-wasm-modules
...
PR-URL: https://github.com/nodejs/node/pull/57038
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com >
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
2025-07-22 13:24:06 -07:00
Antoine du Hamel
48fff6baf8
tools,test: enforce best practices to detect never settling promises
...
PR-URL: https://github.com/nodejs/node/pull/58992
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
2025-07-16 10:57:22 +02:00
Alex Yang and Joyee Cheung
a705e240b1
module: convert schema-only core module on convertCJSFilenameToURL
...
Co-authored-by: Joyee Cheung <joyeec9h3@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/58612
Fixes: https://github.com/nodejs/node/issues/58607
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
2025-06-25 16:49:56 +00:00
Joyee Cheung
ea2004a2ac
module: allow omitting context in synchronous next hooks
...
This aligns the behavior of synchronous hooks with asynchronous
hooks by allowing omission of the context parameter in the
invocation of next hooks. The contexts are merged along the
chain.
PR-URL: https://github.com/nodejs/node/pull/57056
Fixes: https://github.com/nodejs/node/issues/57030
Reviewed-By: Jacob Smith <jacob@frende.me >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2025-02-18 15:28:59 +00:00
Vitalii Akimov
9ec7bed7b9
module: fixing url change in load sync hook chain
...
Fixes: https://github.com/nodejs/node/issues/56376
PR-URL: https://github.com/nodejs/node/pull/56402
Reviewed-By: Jacob Smith <jacob@frende.me >
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2025-01-22 10:25:00 -08:00
Marco Ippolito
ba5992831b
module: unflag --experimental-strip-types
...
PR-URL: https://github.com/nodejs/node/pull/56350
Fixes: https://github.com/nodejs/typescript/issues/17
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com >
Reviewed-By: Paolo Insogna <paolo@cowtech.it >
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com >
2024-12-26 18:46:06 +00:00
Joyee Cheung
e85964610c
module: implement module.registerHooks()
...
PR-URL: https://github.com/nodejs/node/pull/55698
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: Guy Bedford <guybedford@gmail.com >
2024-12-09 23:27:08 +00:00