Skip to content

feat(node)!: replace async module.register with sync module.registerHooks#28

Merged
twada merged 12 commits into
mainfrom
sync-register-hooks
Jun 25, 2026
Merged

feat(node)!: replace async module.register with sync module.registerHooks#28
twada merged 12 commits into
mainfrom
sync-register-hooks

Conversation

@twada

@twada twada commented Jun 21, 2026

Copy link
Copy Markdown
Owner

Summary

  • Replace module.register() (async, off-thread) with module.registerHooks() (sync, in-thread) in @power-assert/node, following its deprecation as DEP0205
  • Add synchronous transpile functions to @power-assert/transpiler
  • Bump minimum Node.js version to >=22.15.0

Motivation

The async/off-thread hook model of module.register() had fundamental architectural issues that the Node.js team deemed unresolvable: deadlocks, lost console.log() output, inability to cover createRequire(), and inter-thread communication overhead. It was runtime-deprecated in v26.0.0 and is slated for removal in v27.

Changes

@power-assert/transpiler

  • Add transpileSync(), transpileWithInlineSourceMapSync(), transpileWithSeparatedSourceMapSync(), and findIncomingSourceMapSync() to support synchronous hooks

@power-assert/node

  • Rewrite hooks.mts from async functions to sync typed function expressions (ResolveHookSync / LoadHookSync)
  • Rewrite register.mts to use module.registerHooks() with direct function references instead of indirect specifier-based module.register()
  • Bump engines.node to >=22.15.0

Docs

  • Add ADR-007 documenting the design rationale and migration context

Breaking Changes

  • Async hooks via module.register() are replaced with sync hooks via module.registerHooks()
  • Requires Node.js >=22.15.0

twada added 12 commits June 20, 2026 07:54
this decision is subject to change
…ooks

Merge sync.mts implementation into hooks.mts and update register.mts
to use module.registerHooks() directly. Remove the separate ./sync
export as the main entry point is now sync-only.

BREAKING CHANGE: async hooks via module.register() are replaced with
sync hooks via module.registerHooks(). Requires Node.js >= 22.18.0.
module.registerHooks() was backported to Node.js 22.15.0 LTS,
so 22.18.0 was unnecessarily restrictive. Also fix the version
range for --experimental-strip-types in the README.
…ming convention

Rename SyncNextResolveFn/SyncNextLoadFn to NextResolveFnSync/NextLoadFnSync
to align with the Node.js suffix convention (ResolveHookSync, LoadHookSync).
@twada
twada merged commit ccb645e into main Jun 25, 2026
2 checks passed
@twada
twada deleted the sync-register-hooks branch June 25, 2026 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant