Skip to content

modules: fix sync hook short-circuit in require() in imported CJS#62920

Open
joyeecheung wants to merge 1 commit intonodejs:mainfrom
joyeecheung:fix-hooks
Open

modules: fix sync hook short-circuit in require() in imported CJS#62920
joyeecheung wants to merge 1 commit intonodejs:mainfrom
joyeecheung:fix-hooks

Conversation

@joyeecheung
Copy link
Copy Markdown
Member

  • For imported CJS, if it's not customized by asynchronous hooks, make sure it won't use the quirky re-invented require in all cases.
  • When the imported CJS module is customized by synchronous hooks, in the synthetic module evalutation step, avoid calling the respective default step again.
  • Make the branching of loadCJSModuleWithModuleLoad() and loadCJSModuleWithSpecialRequire() more explicit, and fold the tentative fs read in the 'commonjs' translator into the share createCJSModuleWrap() helper instead of checking it twice in the same path.

Refs: #55808 (comment)

@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders

@nodejs-github-bot nodejs-github-bot added esm Issues and PRs related to the ECMAScript Modules implementation. module Issues and PRs related to the module subsystem. needs-ci PRs that need a full CI run. labels Apr 23, 2026
- For imported CJS, if it's not customized by asynchronous hooks,
  make sure it won't use the quirky re-invented require in all
  cases.
- When the imported CJS module is customized by synchronous hooks,
  in the synthetic module evalutation step, avoid calling the
  respective default step again.
- Make the branching of loadCJSModuleWithModuleLoad() and
  loadCJSModuleWithSpecialRequire() more explicit, and fold
  the tentative fs read in the 'commonjs' translator into the
  share createCJSModuleWrap() helper instead of checking it
  twice in the same path.
@joyeecheung
Copy link
Copy Markdown
Member Author

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.62%. Comparing base (acb1bd7) to head (7630a01).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #62920      +/-   ##
==========================================
- Coverage   91.43%   89.62%   -1.82%     
==========================================
  Files         356      706     +350     
  Lines      150580   219321   +68741     
  Branches    23602    42016   +18414     
==========================================
+ Hits       137686   196568   +58882     
- Misses      12625    14660    +2035     
- Partials      269     8093    +7824     
Files with missing lines Coverage Δ
lib/internal/modules/cjs/loader.js 98.16% <100.00%> (+18.55%) ⬆️
lib/internal/modules/esm/load.js 91.40% <ø> (+7.70%) ⬆️
lib/internal/modules/esm/loader.js 99.71% <100.00%> (+38.39%) ⬆️
lib/internal/modules/esm/translators.js 97.47% <100.00%> (+5.96%) ⬆️

... and 472 files with indirect coverage changes

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

esm Issues and PRs related to the ECMAScript Modules implementation. module Issues and PRs related to the module subsystem. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants