fix: check tsconfig matching before using resolver
This PR fixes an issue where the resolver was using a cached resolver before determining which tsconfig file actually includes the current file when multiple tsconfig files are specified for the same directory path.
Problem:
When multiple tsconfig files (e.g., tsconfig.node.json and tsconfig.web.json) exist in the same directory with different include patterns, the cached resolver was used before matching which tsconfig includes the current file. This caused incorrect tsconfig settings to be applied.
Solution: Reorder the resolver cache check to occur after tsconfig matching. This ensures the correct tsconfig configuration is identified before attempting to use a cached resolver.
Changes:
- Modified
src/index.tsto move resolver cache check from lines 101-107 to after tsconfig matching (now at lines 133-139) - Added e2e test case
multipleTsconfigsWithReferences:- Backend files (
backend/**/*) correctly usetsconfig.node.jsonwith@backend/*paths - Frontend files (
frontend/**/*) correctly usetsconfig.web.jsonwith@frontend/*paths - Both configurations properly resolve shared utilities via
@shared/*paths
- Backend files (
- Updated test snapshots
[!IMPORTANT] Fix resolver cache check order in
src/index.tsto ensure correct tsconfig is identified before using cached resolver, with new e2e test added.
- Behavior:
- Reorder resolver cache check in
resolve()insrc/index.tsto occur after tsconfig matching, ensuring correct tsconfig is identified before using cached resolver.- Tests:
- Add e2e test
multipleTsconfigsWithReferencesto verify correct tsconfig usage for backend and frontend files.- Backend files use
tsconfig.node.jsonand frontend files usetsconfig.web.json, both resolving shared utilities via@shared/*paths.- Misc:
- Update test snapshots to reflect new test case.
This description was created by
for 6697e04dcebea6aa36cb90eb35e5c80d08a1f1a5. You can customize this summary. It will automatically update as commits are pushed.
Summary by CodeRabbit
-
Performance Improvements
- Deferred resolver cache checks to improve lookup efficiency during configuration resolution.
-
Bug Fixes
- Fixed resolver selection when multiple TypeScript configurations are present so the correct resolver is used.
-
Tests
- Added end-to-end test coverage for projects with multiple TypeScript configs, path aliases, and project references.
-
Chores
- Added a changeset recording the patch release and fix.