Skip to content

fix(tsconfig): resolve non-relative imports against baseUrl - #1098

Open
Balghisa12 wants to merge 1 commit into
tirth8205:stagingfrom
Balghisa12:fix/tsconfig-baseurl-resolution
Open

Balghisa12 wants to merge 1 commit into
tirth8205:stagingfrom
Balghisa12:fix/tsconfig-baseurl-resolution

Conversation

@Balghisa12

Copy link
Copy Markdown

Pull Request

Linked issue

No existing issue. Found while evaluating the graph on a NestJS monorepo. Related to #1030 (workspace packages), which is a separate gap.

What & why

TsconfigResolver.resolve_alias returned None whenever compilerOptions.paths was empty, so a tsconfig that sets only baseUrl resolved no non-relative import. tsc resolves such specifiers against baseUrl, both without paths and when no paths pattern matches. The resolver now does the same, after trying paths. docs/FEATURES.md already lists paths/baseUrl resolution, so no docs change.

On a NestJS service of 1,181 TypeScript files that imports src/... with "baseUrl": "./" and no paths:

  • unresolved src/... import edges: 1,849 → 44 (the 44 point at generated clients absent from the checkout);
  • the import edges are identical to declaring "paths": { "src/*": ["src/*"] }, which takes importers_of for one service from 14 to 35 of its 35 importers and the real callers callers_of finds for its method from 4 to all 6.

How it was tested

uv run pytest tests/test_tsconfig_resolver.py -q   # on staging: 2 failed (the two baseUrl cases); with the fix: 15 passed
uv run pytest tests/ --tb=short -q                 # 4272 passed, 850 skipped, 2 xfailed, 2 xpassed
uv run --extra dev ruff check code_review_graph/   # All checks passed
uv run --extra dev mypy code_review_graph/ --ignore-missing-imports --no-strict-optional  # no issues in 77 files
uvx bandit -q -r code_review_graph/tsconfig_resolver.py -c pyproject.toml                # clean

tsc 5.8.3 with --traceResolution on two fixtures, baseUrl alone and baseUrl with a non-matching paths entry, resolves src/lib/util through baseUrl in both.

Checklist

  • Tests added for new functionality
  • All tests pass: uv run pytest tests/ --tb=short -q
  • Linting passes: uv run ruff check code_review_graph/
  • Type checking passes: uv run mypy code_review_graph/ --ignore-missing-imports --no-strict-optional
  • Lines are at most 100 characters
  • Docs updated where behavior changed (README, docs/, docstrings)

🤖 Generated with Claude Code

resolve_alias returned None whenever compilerOptions.paths was empty, so a
tsconfig that sets only baseUrl resolved no non-relative import. tsc resolves
such specifiers against baseUrl, both without paths and when no paths pattern
matches; the resolver now does the same, after trying paths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant