Skip to content

feat(resolve): tsconfig path aliases + index-file resolution for TS imports#67

Merged
smochan merged 1 commit into
mainfrom
feat/ts-path-aliases
Jun 10, 2026
Merged

feat(resolve): tsconfig path aliases + index-file resolution for TS imports#67
smochan merged 1 commit into
mainfrom
feat/ts-path-aliases

Conversation

@smochan

@smochan smochan commented Jun 10, 2026

Copy link
Copy Markdown
Owner

Summary

Track B1 of the three-track build (tracing correctness). Fixes the README's deferred 'TypeScript R2 patterns — path aliases':

  • New codegraph/resolve/tsconfig_paths.py: tolerant tsconfig/jsconfig loader (strips comments + trailing commas, stdlib only); rewrite_alias maps @/lib/dbsrc.lib.db via compilerOptions.paths wildcards + baseUrl.
  • _build_import_bindings rewrites the module portion of TS import targets before normalization, so the binding table already holds real qualnames.
  • Heuristic 5b in _resolve_target: index-file fallback (./modelsmodels/index.ts), unambiguous-match-only (reviewer tightened the same-module variant to require uniqueness).
  • All parameters optional/None-default — non-TS repos and existing callers unaffected.

Implemented by a Sonnet subagent against a Fable spec; reviewed + uniqueness fix by the orchestrating session.

Test plan

  • 14 new tests (alias resolve, jsconfig, comment/trailing-comma tolerance, index re-export, no-tsconfig regression)
  • Full suite 720 passed; ruff + mypy --strict clean

🤖 Generated with Claude Code

…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).
@github-actions

Copy link
Copy Markdown

codegraph PR review

Diff vs main · severity ≤ high

codegraph review (target: main)

Diff: +49 / -0 / ~2 nodes, +183 / -17 edges

Findings (2)

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

@smochan smochan merged commit d7166ce into main Jun 10, 2026
5 checks passed
@smochan smochan deleted the feat/ts-path-aliases branch June 10, 2026 14:14
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 10, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant