fix(js): resolve calls through CommonJS require bindings
Merged
CO
18d ago+158+158+012345678901234567890123456789-7-7-0123456789
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, soindex.jswas never tried.- Default imports. They never followed
module.exports = X,exports = module.exports = Xormodule.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 = implandmodule.exports = { a, b: c }also bind names the export index couldn't see before.
Measured (wasm, main vs fix)
| repo | edges | notes |
|---|---|---|
| express | −1087 +727 | 707 express() → createApplication; supertest/node:assert no longer edge to the local variable; compileETag/compileTrust/setCharset no longer → normalizeType |
| eslint | −750 +827 | new RuleTester() / new SourceCode() reach the class, not another test's variable |
| mocha | −83 +90 | run(...) reaches the helpers' runMochaJSON, not another spec file's run |
| koa | −65 +65 | 65 response() calls were going to request |
| body-parser | −4 +24 | bodyParser() → index.js |
| zod, trpc, hono, typeorm, axios | unchanged |
Test plan
-
__tests__/commonjs-require-calls.test.ts(fails on main, passes here) - Full suite: 387 files / 5682 tests passed
🤖 Generated with Claude Code