runtime-node
runtime-node copied to clipboard
Implement new hook system
This PR introduces a new hooking system. Instead of checking if a package is installed and patching it directly, we now wrap the require function and patch modules on their first import.
Advantages
- Only patch modules that are used
- Allows modifying default exports (required for Fastify, Undici, Koa)
- Should improve support for bundlers
- Do not wrap a method multiple times if different interceptor types are used
- Support patching multiple versions of one package, if it's installed directly and indirectly with a different version as a sub dependency
Tasks
- [x] Wrap require calls
- [x] Support patching internal modules and main exports of packages
- [x] Support js file export wrapping
- [x] Add support for wrapping new instances
- [x] Wrap globals using new hook system
- [x] Wrap process.getBuiltinModule
- [x] Migrate all sources and sinks to new api
Codecov Report
Attention: Patch coverage is 97.01601% with 41 lines in your changes missing coverage. Please review.
:loudspeaker: Thoughts on this report? Let us know!