eslint-import-resolver-typescript icon indicating copy to clipboard operation
eslint-import-resolver-typescript copied to clipboard

fix: check tsconfig matching before using resolver

Open leey0818 opened this issue 1 month ago • 4 comments

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.ts to 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 use tsconfig.node.json with @backend/* paths
    • Frontend files (frontend/**/*) correctly use tsconfig.web.json with @frontend/* paths
    • Both configurations properly resolve shared utilities via @shared/* paths
  • Updated test snapshots

[!IMPORTANT] Fix resolver cache check order in src/index.ts to ensure correct tsconfig is identified before using cached resolver, with new e2e test added.

  • Behavior:
    • Reorder resolver cache check in resolve() in src/index.ts to occur after tsconfig matching, ensuring correct tsconfig is identified before using cached resolver.
  • Tests:
    • Add e2e test multipleTsconfigsWithReferences to verify correct tsconfig usage for backend and frontend files.
    • Backend files use tsconfig.node.json and frontend files use tsconfig.web.json, both resolving shared utilities via @shared/* paths.
  • Misc:
    • Update test snapshots to reflect new test case.

This description was created by Ellipsis 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.

leey0818 avatar Oct 28 '25 08:10 leey0818