runtime-node icon indicating copy to clipboard operation
runtime-node copied to clipboard

Implement new hook system

Open timokoessler opened this issue 1 year ago • 1 comments

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

timokoessler avatar Aug 08 '24 15:08 timokoessler