nodejs / nodejs/require-in-the-middle

Allow sync function to be modified at runtime

Open
#80 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.