Repository navigation
feat: detect circular import dependencies at file level - #961
Conversation
- Add find_import_cycles() to analyze.py - Collapses symbol nodes to parent files, builds directed file graph - Uses nx.simple_cycles() bounded by max_cycle_length (default 5) - Deduplicates rotations, returns shortest cycles first - Considers both imports_from and re_exports edges Tested on a 976-file Next.js codebase: found 4 cycles including a known utils↔barrel circular dependency and a 4-file API cycle.
|
Thanks for the contribution — circular import cycle detection is a genuinely useful feature and the algorithm choice ( Blocking issues1.
|
- use source_file-only endpoint resolution (no label fallback) - support Graph/DiGraph orientation via edge source_file - return structured cycle records and include self-loops - integrate Import Cycles section into GRAPH_REPORT.md - expand cycle tests for real-schema IDs, undirected input, missing source_file nodes, and non-import relations
|
Addressed all blockers and smaller issues:
Tests (9 total):
All tests use Validated on a production repo (~976 TS/TSX files):
|
|
Re-reviewed the updated diff — all three blocking issues are resolved correctly. Verified:
One minor nit (non-blocking): the Merging now — great turnaround, thanks! |
…s#961) * feat: detect circular import dependencies at file level - Add find_import_cycles() to analyze.py - Collapses symbol nodes to parent files, builds directed file graph - Uses nx.simple_cycles() bounded by max_cycle_length (default 5) - Deduplicates rotations, returns shortest cycles first - Considers both imports_from and re_exports edges Tested on a 976-file Next.js codebase: found 4 cycles including a known utils↔barrel circular dependency and a 4-file API cycle. * fix: resolve import-cycle merge blockers - use source_file-only endpoint resolution (no label fallback) - support Graph/DiGraph orientation via edge source_file - return structured cycle records and include self-loops - integrate Import Cycles section into GRAPH_REPORT.md - expand cycle tests for real-schema IDs, undirected input, missing source_file nodes, and non-import relations
Summary
Adds file-level circular import cycle detection on top of v8.
This surfaces dependency loops that are hard to spot in symbol-level graphs and helps identify refactor blockers for tree-shaking and modularization.
Why
Import cycles in JS/TS and mixed-language projects can:
A built-in cycle detector makes these risks visible and actionable in graph analysis.
What changed
Related
Test Plan
Run targeted cycle tests:
uv run --with pytest pytest tests/test_analyze.py -k "cycle"
Result:
7 passed
Optional broader analyze test run:
uv run --with pytest pytest tests/test_analyze.py -q --tb=short