node icon indicating copy to clipboard operation
node copied to clipboard

module: preserve URL in the parent created by createRequire()

Open joyeecheung opened this issue 2 weeks ago • 7 comments

Previously, createRequire() does not preserve the URL it gets passed in the mock parent module created, which can be observable if it's used together with module.registerHooks(). This patch adds preservation of the URL if createRequire() is invoked with one.

Fixes: https://github.com/nodejs/node/issues/60973

joyeecheung avatar Dec 06 '25 05:12 joyeecheung

Review requested:

  • [ ] @nodejs/loaders

nodejs-github-bot avatar Dec 06 '25 05:12 nodejs-github-bot

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 88.51%. Comparing base (644fb88) to head (a66fbbd). :warning: Report is 70 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #60974      +/-   ##
==========================================
- Coverage   88.51%   88.51%   -0.01%     
==========================================
  Files         703      703              
  Lines      208394   208438      +44     
  Branches    40193    40206      +13     
==========================================
+ Hits       184470   184505      +35     
- Misses      15934    15940       +6     
- Partials     7990     7993       +3     
Files with missing lines Coverage Δ
lib/internal/modules/cjs/loader.js 98.02% <100.00%> (+<0.01%) :arrow_up:

... and 51 files with indirect coverage changes

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Dec 06 '25 06:12 codecov[bot]

Thank you for your quick fix! I was wondering if this PR can be backported to v22 or v24?

sxzz avatar Dec 06 '25 06:12 sxzz

It should be back portable after staying in 25 for a few weeks (per LTS policy), the code touched is not the in usual volatile parts of the module loader but in the implementation of createRequire() which is fairly stable so there should be little conflicts.

joyeecheung avatar Dec 06 '25 11:12 joyeecheung

CI: https://ci.nodejs.org/job/node-test-pull-request/70416/

nodejs-github-bot avatar Dec 08 '25 10:12 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/70429/

nodejs-github-bot avatar Dec 08 '25 14:12 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/70432/

nodejs-github-bot avatar Dec 08 '25 16:12 nodejs-github-bot

Commit Queue failed
- Loading data for nodejs/node/pull/60974
✔  Done loading data for nodejs/node/pull/60974
----------------------------------- PR info ------------------------------------
Title      module: preserve URL in the parent created by createRequire() (#60974)
Author     Joyee Cheung <[email protected]> (@joyeecheung)
Branch     joyeecheung:fix-create-require-url -> nodejs:main
Labels     module, needs-ci, review wanted
Commits    1
 - module: preserve URL in the parent created by createRequire()
Committers 1
 - Joyee Cheung <[email protected]>
PR-URL: https://github.com/nodejs/node/pull/60974
Fixes: https://github.com/nodejs/node/issues/60973
Reviewed-By: Benjamin Gruenbaum <[email protected]>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/60974
Fixes: https://github.com/nodejs/node/issues/60973
Reviewed-By: Benjamin Gruenbaum <[email protected]>
--------------------------------------------------------------------------------
   ℹ  This PR was created on Sat, 06 Dec 2025 05:36:14 GMT
   ✔  Approvals: 1
   ✔  - Benjamin Gruenbaum (@benjamingr) (TSC): https://github.com/nodejs/node/pull/60974#pullrequestreview-3548026675
   ✘  This PR needs to wait 12 more hours to land (or 0 hours if there is one more approval)
   ✔  Last GitHub CI successful
   ℹ  Last Full PR CI on 2025-12-08T16:06:54Z: https://ci.nodejs.org/job/node-test-pull-request/70432/
- Querying data for job/node-test-pull-request/70432/
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu
https://github.com/nodejs/node/actions/runs/20174007589

nodejs-github-bot avatar Dec 12 '25 17:12 nodejs-github-bot

Landed in 4f24aff94ad9160bceaf9dcc9cf5235a65f01029

nodejs-github-bot avatar Dec 13 '25 07:12 nodejs-github-bot