You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Phantom self-cycles: same-basename cross-extension re-exports (X.ts → ./X.mjs) collapse to one node #1814
Version observed: graphify (PyPI graphifyy) 0.9.12
Summary
When a source file re-exports from a same-basename sibling with a different extension — e.g. foo.ts doing export { … } from "./foo.mjs" — graphify records a false self-loop (foo.ts → foo.ts) and reports it as a 1-file import cycle. The extension is stripped during edge resolution, so the re-export target ./foo.mjs is matched back to the foo.ts node instead of a distinct foo.mjs node.
Repro
mkdir demo && cd demo
# foo.mjs — hand-written plain-ESM runtime
printf 'export const N = 1;\n' > foo.mjs
# foo.ts — typed wrapper that re-exports the runtime
printf 'export { N } from "./foo.mjs";\n' > foo.ts
graphify update .
Two nodes (foo.ts, foo.mjs) with one directed edge foo.ts —re_exports→ foo.mjs. No cycle.
Actual
One node whose id is the extension-stripped basename, with a self-edge:
--> foo.ts [re_exports]
<-- foo.ts [re_exports]
and foo.ts is listed under Import Cycles in GRAPH_REPORT.md. In the graph JSON the edge is relation: "re_exports" with source == target and a node id like …foo_ts_…foo (the .ts node id concatenated with the extension-stripped target).
Root cause (best guess)
Node identity for an import/re-export target is keyed by path with the extension stripped, so foo.ts and foo.mjs resolve to the same node id. The manifest does index .mjs/.d.mts as separate files — it's specifically the edge/import resolver's basename matching that collapses them.
Why the obvious workaround doesn't fit
This pattern is a legitimate, common one: a hand-written .mjs plain-ESM runtime (so it's importable by Node/CI without a TS build step) plus a thin typed .ts wrapper (export … from "./X.mjs") and a hand-written .d.mts. So:
Excluding dist/ / build/ does nothing — the files aren't build output.
Excluding **/*.d.mts doesn't remove the loop (the loop is .ts → .mjs).
Excluding **/*.mjs would delete real runtime source.
Suggested fix
Key nodes by full path including extension so foo.ts and foo.mjs are distinct nodes (then foo.ts → foo.mjs is a correct 2-node edge and the phantom cycle disappears). Equivalently: when a re-export specifier carries an explicit extension that resolves to a different physical file, don't strip it back to the same-basename sibling.
Impact
Over-reports import cycles for any codebase using the ESM-runtime + typed-wrapper convention (7 phantom cycles surfaced in a single app), which can mislead a cycle-cleanup pass into "fixing" non-problems.
I'd love to contribute to Graphify and work on this. If there's anything specific you'd like done differently from the current discussion, let me know. I'll put together a PR.
Activity
Rishet11 commentedon Jul 12, 2026
I'd love to contribute to Graphify and work on this. If there's anything specific you'd like done differently from the current discussion, let me know. I'll put together a PR.
fix(resolution): repoint cross-extension re-exports without leaking a…
docs: cut 0.9.19, document install --strict, fix Graphify-Labs#1814 c…
fix(extract): resolve calls edges through an aliased Python import (#…
Squashed commit of the following:
fix(extract): canonicalize out-of-root import/include edge targets (#…
fix(resolution): repoint cross-extension re-exports without leaking a…
docs: cut 0.9.19, document install --strict, fix Graphify-Labs#1814 c…
fix(extract): resolve calls edges through an aliased Python import (G…
fix(extract): canonicalize out-of-root import/include edge targets (G…
fix(godot): land edges into a same-stem scene/script pair on the righ…