Skip to content

feat(parser): resolve TypeScript path aliases in IMPORTS_FROM edges#53

Closed
JF10R wants to merge 3 commits intotirth8205:mainfrom
JF10R:feat/tsconfig-alias-resolution
Closed

feat(parser): resolve TypeScript path aliases in IMPORTS_FROM edges#53
JF10R wants to merge 3 commits intotirth8205:mainfrom
JF10R:feat/tsconfig-alias-resolution

Conversation

@JF10R
Copy link

@JF10R JF10R commented Mar 22, 2026

Summary

  • Add TsconfigResolver class that discovers and parses tsconfig.json files (with JSONC comment support and recursive extends resolution)
  • Resolve TypeScript path aliases (e.g., @/*src/*) declared in compilerOptions.paths to absolute file paths
  • IMPORTS_FROM edge targets are now resolved when the target file exists on disk, enabling importers_of() queries to work with alias imports

Before: importers_of('src/hooks/useApiData.ts') returned 0 results despite 28 files importing it via @/hooks/useApiData
After: Returns all 28 importers correctly

Changes

  • New file: code_review_graph/tsconfig_resolver.pyTsconfigResolver class with tsconfig discovery, JSONC parsing, extends chain resolution, path alias matching, and filesystem probing
  • Modified: code_review_graph/parser.py — integrated resolver into _do_resolve_module() for non-relative imports and _extract_from_tree() for IMPORTS_FROM edge resolution
  • New tests: tests/test_tsconfig_resolver.py (7 unit tests) + 2 integration tests in test_parser.py
  • New fixtures: tsconfig.json, src/lib/utils.ts, alias_importer.ts

Design decisions

  • Resolution only replaces raw import strings when the target file exists on disk — npm packages and unresolvable aliases remain as-is
  • tsconfig is cached per directory (all files in the same project share one entry)
  • Supports extends chains with cycle detection; skips npm-scoped extends (e.g., @tsconfig/recommended)

Test plan

  • All 37 parser + resolver tests pass (pytest tests/test_parser.py tests/test_tsconfig_resolver.py -v)
  • Full test suite: 196 passed, 26 pre-existing Windows-only SQLite teardown errors
  • Validated on a real-world TypeScript project (357 files): importers_of() returns correct results for alias-imported files

🤖 Generated with Claude Code

JF10R added 2 commits March 22, 2026 11:08
…M edges

Resolve TypeScript path aliases (e.g., @/ -> src/) by reading
tsconfig.json compilerOptions.paths and baseUrl. Supports JSONC
comments, recursive extends chains, and caches per repo root.

IMPORTS_FROM edge targets are now resolved to absolute file paths
when the target file exists on disk, enabling importers_of() queries
to work with alias imports.

New files:
- tsconfig_resolver.py: TsconfigResolver class
- test_tsconfig_resolver.py: 7 unit tests
- fixtures for alias resolution testing
- _resolve_extends: garde positive au lieu du double-négatif
- _match_pattern: early return + variable end explicite
- tests: convertis en style pytest (cohérent avec le repo), test cache amélioré
Copilot AI review requested due to automatic review settings March 22, 2026 15:20
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds TypeScript tsconfig.json path-alias awareness to the graph parser so IMPORTS_FROM edges can resolve alias imports (e.g., @/…) to real on-disk files, enabling accurate importers_of() queries in TS/TSX/Vue projects.

Changes:

  • Introduces TsconfigResolver to discover/parse tsconfig.json (JSONC + extends) and resolve compilerOptions.paths aliases to existing files.
  • Integrates alias resolution into CodeParser module resolution and IMPORTS_FROM edge extraction.
  • Adds unit/integration tests and fixtures to validate alias resolution and no-tsconfig behavior.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
code_review_graph/tsconfig_resolver.py New resolver for tsconfig discovery, parsing, extends resolution, and alias-to-file probing.
code_review_graph/parser.py Uses resolver during module resolution and updates IMPORTS_FROM edges to prefer resolved file paths.
tests/test_tsconfig_resolver.py Unit tests for JSONC stripping, alias resolution, and caching behavior.
tests/test_parser.py Integration tests ensuring alias imports resolve and missing tsconfig doesn’t break parsing.
tests/fixtures/tsconfig.json Fixture tsconfig defining baseUrl and paths aliases used by tests.
tests/fixtures/src/lib/utils.ts Fixture target file for alias resolution.
tests/fixtures/alias_importer.ts Fixture importer using @/… alias.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Replace regex-based JSONC comment stripping with a state-machine that
  skips comment markers inside quoted strings (fixes URL corruption)
- Memoize all intermediate directories visited during tsconfig lookup
  to avoid O(depth) repeated walks
- Sort path alias patterns by non-wildcard prefix length so more
  specific aliases win regardless of JSON insertion order
- Fix _probe_path: append extension instead of replacing existing suffix
- Align _resolve_extends docstring: "Shallow-merges" (dict.update)
- tests/test_parser.py: split `import tempfile, os`, use
  TemporaryDirectory for isolation, fix E501 long assert lines
- tests/test_tsconfig_resolver.py: replace hard-coded /tmp path with
  tempfile.TemporaryDirectory

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@JF10R
Copy link
Author

JF10R commented Mar 22, 2026

All 9 review comments addressed in 9093057:

tsconfig_resolver.py:

  • JSONC comment stripping rewritten as state machine (no longer corrupts URLs in strings)
  • _load_tsconfig_for_file() now caches all visited directories during walk-up
  • Docstring corrected: "deep-merges" to "shallow-merges" to match dict.update() behavior
  • Path alias patterns sorted by specificity (longest non-wildcard prefix first)
  • _probe_path() appends extensions when base already has a suffix instead of replacing

Tests:

  • Split import tempfile, os (Ruff E401)
  • Long assert line extracted into separate error_msg variable
  • Both test files use TemporaryDirectory for isolation instead of hardcoded paths

tirth8205 added a commit that referenced this pull request Mar 26, 2026
Adds TsconfigResolver module that resolves TypeScript path aliases
(e.g., @/ -> src/) from tsconfig.json compilerOptions.paths. Also
resolves import targets to absolute file paths in IMPORTS_FROM edges.

Co-Authored-By: JF10R <noreply@github.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
tirth8205 added a commit that referenced this pull request Mar 26, 2026
…nfigurable embeddings, MiniMax, Perl)

* feat: integrate PR #43 — R language support

Adds R language parsing with function extraction (both <- and = assignment),
S4/R5 class detection via setClass/setRefClass, library/require/source
imports, namespace-qualified calls (dplyr::filter), and testthat test detection.

Co-Authored-By: michael-denyer <noreply@github.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: integrate PR #54 — Vitest/Jest test detection

Adds describe/it/test block parsing for JS/TS test files, producing
synthetic Test nodes with description labels. Supports modifier suffixes
(describe.only, it.skip, test.each) and nested describe/it containment.

Co-Authored-By: JF10R <noreply@github.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: integrate PR #53 — tsconfig path alias resolution

Adds TsconfigResolver module that resolves TypeScript path aliases
(e.g., @/ -> src/) from tsconfig.json compilerOptions.paths. Also
resolves import targets to absolute file paths in IMPORTS_FROM edges.

Co-Authored-By: JF10R <noreply@github.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: integrate PR #58 — .mjs/.astro support

Adds .mjs extension mapping to JavaScript and .astro extension mapping
to TypeScript for import path resolution.

Co-Authored-By: zoneghost7 <noreply@github.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: integrate PR #55 — configurable embedding model

Adds CRG_EMBEDDING_MODEL env var and model parameter to embedding
functions, allowing users to specify any sentence-transformers compatible
model. Changing the model re-embeds all nodes automatically.

Co-Authored-By: eugenepro2 <noreply@github.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: integrate PR #45 — MiniMax embedding provider

Adds MiniMaxEmbeddingProvider using the embo-01 model (1536 dimensions)
with support for distinct task types (db/query), batching, and retry logic.

Co-Authored-By: octo-patch <noreply@github.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: integrate PR #62 — Perl support

Adds Perl language parsing with package detection, subroutine extraction,
use/require imports, and function call tracking. Includes test fixture
and comprehensive test class.

Co-Authored-By: potatogim <noreply@github.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: michael-denyer <noreply@github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@tirth8205
Copy link
Owner

Integrated into main via PR #68. Thank you for the contribution! 🎉

@tirth8205 tirth8205 closed this Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants