Repository navigation
fix(tsconfig): resolve non-relative imports against baseUrl - #1098
1 commit merged into
Conversation
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>
|
Thank you for this PR. I ran the tsconfig tests and compared the results with tsc 5.9.3. The baseUrl-only case works well now. Before I can merge it, please fix these:
Note: PR #1111 changes the same function. After one is merged, the other will need an update. After you push the fix, I will test it again. |
There was a problem hiding this comment.
🟡 Changes recommended
The baseUrl fallback mishandles empty values and inherited configurations and incorrectly retries matched paths whose targets are missing, leaving valid imports unresolved or creating incorrect import edges.
3 open issues
What changed in this PR
This PR adds baseUrl fallback resolution for TypeScript and JavaScript imports, helping the graph link non-relative imports to files rather than retain bare specifiers. Workspace-package resolution from #1030 remains separate.
Changes:
- Probe imports against
baseUrlafter attemptingpathsresolution. - Add tests for baseUrl-only configurations, unmatched aliases, and unresolved imports.
- Document the fix and observed graph improvements in the changelog.
| File | Description |
|---|---|
| tests/test_tsconfig_resolver.py | Adds four baseUrl resolution regression tests. |
| code_review_graph/tsconfig_resolver.py | Implements the baseUrl fallback and updates its documentation. |
| CHANGELOG.md | Records the resolution fix and its impact. |
Review effort: Balanced
| if resolved: | ||
| return resolved | ||
|
|
||
| # Like tsc, resolve a specifier no paths entry resolved against baseUrl. |
| return resolved | ||
|
|
||
| # Like tsc, resolve a specifier no paths entry resolved against baseUrl. | ||
| if base_url: |
|
|
||
| # Like tsc, resolve a specifier no paths entry resolved against baseUrl. | ||
| if base_url: | ||
| found = _probe_path((base_dir / import_str).resolve()) |
0160eb0
… and in bounds (review of tirth8205#1098) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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_aliasreturnedNonewhenevercompilerOptions.pathswas empty, so a tsconfig that sets onlybaseUrlresolved no non-relative import.tscresolves such specifiers againstbaseUrl, both withoutpathsand when nopathspattern matches. The resolver now does the same, after tryingpaths.docs/FEATURES.mdalready listspaths/baseUrlresolution, so no docs change.On a NestJS service of 1,181 TypeScript files that imports
src/...with"baseUrl": "./"and nopaths:src/...import edges: 1,849 → 44 (the 44 point at generated clients absent from the checkout);"paths": { "src/*": ["src/*"] }, which takesimporters_offor one service from 14 to 35 of its 35 importers and the real callerscallers_offinds for its method from 4 to all 6.How it was tested
tsc5.8.3 with--traceResolutionon two fixtures,baseUrlalone andbaseUrlwith a non-matchingpathsentry, resolvessrc/lib/utilthroughbaseUrlin both.Checklist
uv run pytest tests/ --tb=short -quv run ruff check code_review_graph/uv run mypy code_review_graph/ --ignore-missing-imports --no-strict-optionaldocs/, docstrings)🤖 Generated with Claude Code