Skip to content

fix: use synchronous module hooks - #459

Open
evertheylen wants to merge 1 commit into
nodejs:mainfrom
evertheylen:fix-register-hooks
Open

fix: use synchronous module hooks#459
evertheylen wants to merge 1 commit into
nodejs:mainfrom
evertheylen:fix-register-hooks

Conversation

@evertheylen

@evertheylen evertheylen commented Sep 10, 2026

Copy link
Copy Markdown

Note: this PR was made with AI. It solves a deprecation warning I'm getting on Node 26:

DEP0205: DeprecationWarning: module.register() is deprecated. Use module.registerHooks() instead

This switches Amaro's preload registration to Node's synchronous customization hooks where available, avoiding the warning. I did read through the code myself too, and tested a similar patch in my own repo.

Summary

  • register strip and transform with module.registerHooks() on Node 22.15+
  • retain module.register() as a compatibility fallback for Node 22.0–22.14
  • expose synchronous variants of both load hooks while preserving the asynchronous hooks for the fallback
  • emit loader files as .mjs and keep the shared error helper CommonJS, avoiding module-type warnings
  • update the programmatic bootstrap example to import amaro/strip directly

Testing

  • NODE_OPTIONS='' npm run ci
  • NODE_OPTIONS='' npm run typecheck
  • NODE_OPTIONS='' npm run clean && NODE_OPTIONS='' npm run build && NODE_OPTIONS='' npm test (60 tests)
  • loader suite on Node 22 latest and Node 24 latest (16 tests each)
  • fallback loader suite on Node 22.14 with --experimental-strip-types (16 tests)
  • strip and transform preloads on Node 26 with --throw-deprecation
  • packed-package test loading TypeScript from node_modules through both --import=amaro/strip and a bootstrap import

Signed-off-by: Evert Heylen <evertheylen@gmail.com>
@marco-ippolito

Copy link
Copy Markdown
Member

Can you please rebase, thanks!

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.

2 participants