Skip to content

CommonJS: calls through a module binding and directory requires produce no graph edges #2694

Open

Description

@DarkBaneX

In a CommonJS project, two common require forms produce no graph edges, so fn-impact, deps and impact under-report without saying so.

  1. A call through a module binding gets no call edge. const m = require('./x'); m.fn() and require('./x').fn() are not counted as callers of fn. Only the destructured form, const { fn } = require('./x'), is.
  2. A directory require does not resolve to its index.js. require('./tools') adds no import edge to tools/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 search lists viaDestructure, viaBinding and viaInline as callers of search in lib/embeddings.js.
  • deps lib/tools/index.js lists lib/d.js under "Imported by", resolving require('./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-impact can miss most of a function's callers.
  • I found no option in .codegraphrc.json that covers either case. The 3.15.0 and 3.17.0 notes on CommonJS mention destructured bindings only.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions