Repository navigation
Description
Summary
graphify 0.8.35 reports a 2-file cycle for our apps/web/lib/i18n/ module even though the TypeScript imports are acyclic.
- 2-file cycle: apps/web/lib/i18n/index.ts -> apps/web/lib/i18n/locale-routes.ts -> apps/web/lib/i18n/index.ts
What the code actually does
apps/web/lib/i18n/index.ts:
export { LOCALE_COOKIE, LOCALES, DEFAULT_LOCALE, isLocale } from './locale';
export type { Locale } from './locale';
import type { Locale } from './locale';
export {
LOCALE_URL_PREFIXES,
LOCALE_PREFIXED_ROUTE_SEGMENTS,
matchLocalePrefix,
localePath,
} from './locale-routes';apps/web/lib/i18n/locale-routes.ts:
// Locale-URL routing primitives. Kept in a SEPARATE module from `index.ts`
// (which imports the en/zh/es bundles) so the Edge `proxy.ts` middleware can
// import the matcher without pulling every translation string into the Edge
// bundle. Imports the `Locale` type from the tiny ./locale module rather than
// from ./index so the dependency graph stays acyclic (graphify 2026-06-07).
// Re-exported from `index.ts` for non-Edge callers.
import type { Locale } from './locale';The only index.ts mentions inside locale-routes.ts are inside // comments (backtick-quoted within the prose). There is no actual import ... from './index' statement.
Hypothesis
The TS extractor appears to count backtick-quoted module references inside line comments as import edges. Possibly the regex strips comment delimiters before matching import / from patterns, or matches on any backtick-quoted module-shaped string.
Repro
graphify 0.8.35
node 22
TypeScript 5.x project
Take any TS module B that has zero imports from a sibling module A but mentions A in a doc comment like // from \./A``. graphify reports a cycle.
Expected
graphify should parse TypeScript ESM imports only from import ... from "..." / import("...") / export ... from "..." statements, ignoring identifiers inside // and /* */ comments and inside string/template literals.
Workaround we used
Removed the backtick-quoted './index' mention from a code comment — that suppressed the false positive locally. The fix didn't survive code review (the comment was useful for human readers explaining what was moved where).
Why this matters
Cycles are one of the headline findings in GRAPH_REPORT.md and trigger refactor PRs. A false positive directs engineering time at a non-existent problem and erodes trust in the report.
Happy to test a fix on a representative repo if useful. Thanks for the great tool.
Activity
Vincentas commentedon Jun 8, 2026
Follow-up investigation
Cloned
safishamsi/graphifyto dig in. The reported edge has these attributes in ourgraphify-out/graph.json:{ "relation": "imports_from", "context": "import", "confidence": "EXTRACTED", "source_file": "apps/web/lib/i18n/locale-routes.ts", "source_location": "L6", "weight": 1.0, "confidence_score": 1.0, "source": "i18n_locale_routes", "target": "i18n_index" }But tree-sitter-typescript on the SAME file reports only one import_statement, at row=6 (so L7 1-indexed), pointing to
'./locale':So:
//comment)._resolve_js_import_target('./locale', ...)correctly returns('apps_web_lib_i18n_locale_ts', .../locale.ts).graph.jsoncarries a phantom edge from L6 toi18n_index.Repro is reliable:
rm -rf graphify-out/cache && graphify update .produces the same phantom edge.I'm not able to identify the exact codepath that emits this edge — it doesn't come from
_import_js(which would produce L7, targeti18n_locale_ts), nor from_resolve_js_import_targetdirectly, nor fromsymbol_resolution.py(that path is bash-source only).Possible angles for the maintainer:
i18n_indexbased onapps/web/lib/i18n/index.tsre-exporting fromapps/web/lib/i18n/locale-routes.ts(forward edge), with a downstream pass adding the inverseimports_fromedge — but the edge is markedEXTRACTEDnotINFERRED, which argues against this.from \index.ts`` literally inside the comment.rm -rf graphify-out/cache(the cache filestat-index.jsonhad no entry for locale-routes.ts).Happy to send a draft patch if you can point at the codepath. Otherwise the cleanest fix I can see from outside is a post-pass in
analyze.find_import_cyclesthat re-validates the source_location line against tree-sitter before counting it toward a cycle, but that feels like papering over the symptom.Reproducer repo on request.
ayushcodes10 commentedon Sep 16, 2026
Already fixed on current
v8(or never reproduced against the AST-based TS extractor — see caveat below).Reproduced the repro shape: a
locale-routes.tsfile whose only mention ofindex.tsis inside a//comment, alongside a realimport type { Locale } from './locale'. Extracting all three files and inspecting theimportsedges:Only one
importsedge exists, fromlocale-routes.tstolocale.ts. There is no edge fromlocale-routes.tsback toindex.ts, so the edge set stays a DAG — no 2-file cycle betweenindex.tsandlocale-routes.tscan be reported from this edge set.Caveat: this confirms the import-edge extraction itself is correct for the exact shape in this issue (current TS extraction walks
import_statementAST nodes, which are structurally separate from comment nodes, so a comment mentioning a filename can't produce a phantom edge by construction). I didn't separately trace the standalone cycle-report routine, and I don't know which historical change (if any) fixed this versus it never applying to the AST-based extractor. If you still have a repo where this reproduces, a concrete GRAPH_REPORT.md excerpt showing the false cycle would help re-open with a solid repro.