fix(js): resolve calls through CommonJS require bindings

Merged
CO
18d ago
+158-7

Summary

Four gaps left CommonJS calls on the local alias variable, or on the wrong function:

  • require('../') up to the project root. It produced an empty relative path, so index.js was never tried.
  • Default imports. They never followed module.exports = X, exports = module.exports = X or module.exports = require('./lib/x').
  • Declarator lists. In var a = require('x'), b = require('y'), only the first declarator was a binding. b() (a package call) stayed on the local variable.
  • require('./utils').member. It was read as the module's default export, so every such alias in express resolved to utils' first exported function (normalizeType). It's now the named member. exports.name = function impl(…), module.exports.name = impl and module.exports = { a, b: c } also bind names the export index couldn't see before.

Measured (wasm, main vs fix)

repoedgesnotes
express−1087 +727707 express() → createApplication; supertest/node:assert no longer edge to the local variable; compileETag/compileTrust/setCharset no longer → normalizeType
eslint−750 +827new RuleTester() / new SourceCode() reach the class, not another test's variable
mocha−83 +90run(...) reaches the helpers' runMochaJSON, not another spec file's run
koa−65 +6565 response() calls were going to request
body-parser−4 +24bodyParser() → index.js
zod, trpc, hono, typeorm, axiosunchanged

Test plan

  • __tests__/commonjs-require-calls.test.ts (fails on main, passes here)
  • Full suite: 387 files / 5682 tests passed

🤖 Generated with Claude Code