nodejs / nodejs/require-in-the-middle
Allow sync function to be modified at runtime
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 186
- Forks
- 34
- PR merge metrics
- No merged PRs in 30d
Description
While developing a solution for a similar problem to that described in #35, I identified that there are two small changes which could be made to this module that facilitate the use of alternate resolvers such as the one used in webpack.
This basically comes down to exposing the list of hooks as a global and storing the resolve.sync function reference as a class member.
The example webhook plugin provided in #35 (with some modernization for webpack 5) works OK if require-in-the-middle is part of the webpack bundle. However, when instrumentation is set up prior to the execution of the bundle (e.g. when using opentelemetry's lambda layer or really any other case where the node option --require is used), it does not because the require-in-the-middle hooks have already been initialized. Where this becomes especially problematic is when the module being hooked is part of the webpack bundle.
Providing a global list of registered hooks and a way to override the sync function addresses this situation and, when not in use, should not impact other uses of this library.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the module's hook initialization and every reference to the resolve.sync function, using the issue context and related issue #35. Done means registered hooks are accessible globally and the sync resolver can be overridden at runtime without changing behavior for existing uses.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- backend, tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100