Open
Description
In a CommonJS project, two common require forms produce no graph edges, so fn-impact, deps and impact under-report without saying so.
- A call through a module binding gets no call edge.
const m = require('./x'); m.fn()andrequire('./x').fn()are not counted as callers offn. Only the destructured form,const { fn } = require('./x'), is. - A directory require does not resolve to its
index.js.require('./tools')adds no import edge totools/index.js, so that file shows no importers.
On a real codebase this showed up as fn-impact finding 4 of a function's 19 callers.
Environment
- @optave/codegraph 3.17.0 (npm global), native engine
- Windows 11, Node.js 26.12.1
Reproduce
Six files:
// lib/embeddings.js
'use strict';
function search(q) { return [q]; }
module.exports = { search };
// lib/a.js: destructured (found)
'use strict';
const { search } = require('./embeddings');
function viaDestructure(q) { return search(q); }
module.exports = { viaDestructure };
// lib/b.js: through the module binding (missed)
'use strict';
const embeddings = require('./embeddings');
function viaBinding(q) { return embeddings.search(q); }
module.exports = { viaBinding };
// lib/c.js: inline require (missed)
'use strict';
function viaInline(q) { return require('./embeddings').search(q); }
module.exports = { viaInline };
// lib/tools/index.js
'use strict';
module.exports = { list() { return []; } };
// lib/d.js: directory require (missed)
'use strict';
const tools = require('./tools');
function useTools() { return tools.list(); }
module.exports = { useTools };Then:
codegraph build .
codegraph fn-impact search
codegraph deps lib/tools/index.js
Actual
Function impact: C search -- lib/a.js:2
-- Level 1 (1 functions):
^ f viaDestructure lib/a.js:3
Function impact: f search -- lib/embeddings.js:2
-- Level 1 (1 functions):
^ # lib/embeddings.js lib/embeddings.js:0
# lib/tools/index.js
-> Imports (0):
<- Imported by (0):
Expected
fn-impact searchlistsviaDestructure,viaBindingandviaInlineas callers ofsearchinlib/embeddings.js.deps lib/tools/index.jslistslib/d.jsunder "Imported by", resolvingrequire('./tools')the way Node does (./tools.js, then./tools/index.js).
Notes
- Nothing in the output marks these results as partial, so a refactor that trusts
fn-impactcan miss most of a function's callers. - I found no option in
.codegraphrc.jsonthat covers either case. The 3.15.0 and 3.17.0 notes on CommonJS mention destructured bindings only.
Metadata
Metadata
Assignees
Labels
No labels
Activity