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

Merged
JO
7mo ago
+265-89
  • 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: https://github.com/nodejs/node/issues/55808#issuecomment-4230585317
Fixes: https://github.com/nodejs/node/issues/63060