feat(resolve): tsconfig path aliases + index-file resolution for TS imports#67
Merged
Conversation
…mports
- Add codegraph/resolve/tsconfig_paths.py: tolerant loader for tsconfig.json
and jsconfig.json (strips // comments, /* */ blocks, trailing commas before
json.loads — no new dependency). Exposes TsPathMapping, load_ts_path_mapping,
and rewrite_alias for @/* and exact-match patterns.
- Thread TsPathMapping through _build_import_bindings so alias targets like
"@/lib/db" are rewritten to dotted qualnames (e.g. "src.lib.db") before the
existing normalization step. re-attaches imported_name suffix after rewrite so
full qualnames (src.lib.db.db) are preserved in bindings.
- Add index-file fallback in _resolve_target (heuristic 5b): when a module
qualname has no direct match, retry "<target>.index" before the expensive
suffix scan — covers "import { User } from './models'" -> models/index.ts.
- Update GraphBuilder.build() to pass repo_root to resolve_unresolved_edges
(new optional parameter; fully backward compatible).
- 14 new tests (test_resolve_ts_paths.py): unit tests for loader and
rewrite_alias; integration tests for tsconfig.json with comments/trailing
commas, jsconfig.json, index-file resolution, and no-tsconfig regression.
Zero regressions (717 pass / 3 skip).
codegraph PR reviewDiff vs main · severity ≤
|
| severity | rule | kind | qualname | file:line | score | message |
|---|---|---|---|---|---|---|
| med | modified-signature | graph | codegraph.resolve.calls._build_import_bindings |
codegraph/resolve/calls.py:375 | 20 | Modified node signature change |
| med | modified-signature | graph | codegraph.resolve.calls.resolve_unresolved_edges |
codegraph/resolve/calls.py:454 | 20 | Modified node signature change |
Triggered by codegraph CI · last run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Track B1 of the three-track build (tracing correctness). Fixes the README's deferred 'TypeScript R2 patterns — path aliases':
codegraph/resolve/tsconfig_paths.py: tolerant tsconfig/jsconfig loader (strips comments + trailing commas, stdlib only);rewrite_aliasmaps@/lib/db→src.lib.dbviacompilerOptions.pathswildcards +baseUrl._build_import_bindingsrewrites the module portion of TS import targets before normalization, so the binding table already holds real qualnames._resolve_target: index-file fallback (./models→models/index.ts), unambiguous-match-only (reviewer tightened the same-module variant to require uniqueness).Implemented by a Sonnet subagent against a Fable spec; reviewed + uniqueness fix by the orchestrating session.
Test plan
🤖 Generated with Claude Code