Skip to content

Conversation

@leey0818
Copy link

@leey0818 leey0818 commented Oct 28, 2025

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 6697e04. 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.

@changeset-bot
Copy link

changeset-bot bot commented Oct 28, 2025

🦋 Changeset detected

Latest commit: 2be84ae

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
eslint-import-resolver-typescript Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented Oct 28, 2025

Walkthrough

Moved the resolver cache lookup in src/index.ts so the cache is checked only after a tsconfig path has been matched. Added an e2e test fixture with multiple tsconfigs and example backend/frontend/shared files to exercise resolver behavior with project references and path aliases.

Changes

Cohort / File(s) Change Summary
Core resolver logic
src/index.ts
Reordered resolver cache lookup: the cache is now consulted immediately after a tsconfig match for the current file (allowing tsconfig matching to run before a cached resolver can short-circuit resolver creation)
E2E ESLint config
tests/e2e/multipleTsconfigsWithReferences/.eslintrc.cjs
New ESLint config that constructs a project array with two tsconfig paths and exports the base config invoked with that array
E2E tsconfigs
tests/e2e/multipleTsconfigsWithReferences/tsconfig.json, tests/e2e/multipleTsconfigsWithReferences/tsconfig.node.json, tests/e2e/multipleTsconfigsWithReferences/tsconfig.web.json
Added multi-project TypeScript configs with references, composite: true, baseUrl, and paths aliases for backend/frontend/shared setups
E2E backend sources
tests/e2e/multipleTsconfigsWithReferences/backend/index.ts, tests/e2e/multipleTsconfigsWithReferences/backend/utils.ts
Added backend entry showing varied import styles and a new exported utility utilA
E2E frontend sources
tests/e2e/multipleTsconfigsWithReferences/frontend/component.tsx, tests/e2e/multipleTsconfigsWithReferences/frontend/index.tsx
Added a default-exporting React component and a frontend entry demonstrating varied import styles and path aliases
E2E shared sources
tests/e2e/multipleTsconfigsWithReferences/shared-utils/helper.ts
Added exported helper helperB used by multiple projects
Changeset
.changeset/large-insects-kiss.md
New changeset describing a patch release and noting the fix: "check tsconfig matching before using resolver."

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant File as Source File
  participant TSConfigs as tsconfig loop
  participant Cache as Resolver Cache
  participant Resolver as resolver creation

  Note over File,TSConfigs: Old flow
  File->>TSConfigs: iterate tsconfigs
  TSConfigs->>Cache: check cache (early)
  alt cached resolver found
    Cache-->>Resolver: return cached resolver (break)
  else
    TSConfigs->>Resolver: match tsconfig -> create resolver
  end

  Note over File,TSConfigs: New flow (this PR)
  File->>TSConfigs: iterate tsconfigs
  TSConfigs->>TSConfigs: perform tsconfig match
  alt tsconfig matched
    TSConfigs->>Cache: check cache for matched tsconfig
    alt cached resolver found
      Cache-->>Resolver: return cached resolver (break)
    else
      TSConfigs->>Resolver: create and assign resolver
    end
  else
    TSConfigs->>TSConfigs: continue loop
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Pay particular attention to src/index.ts cache reordering and any edge cases around keying/normalizing cache entries and breaking the loop.
  • Verify the tsconfig paths/references in the new e2e fixtures match intended resolution scenarios.
  • Confirm imports in test files correctly exercise alias and relative resolution.

Possibly related PRs

Suggested labels

bug

Suggested reviewers

  • JounQin
  • SukkaW

Poem

🐰 A cache that waited just a tad,
For tsconfig to show what it had,
Backends, frontends, shared in line,
Resolvers humming — now they find,
References linked, and paths so glad 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "fix: check tsconfig matching before using resolver" accurately describes the main change in the pull request. The core modification in src/index.ts relocates the resolver cache lookup to occur after a tsconfig path has been matched, ensuring the correct tsconfig is identified before a cached resolver is used. The title is concise, specific, and clearly communicates the fix without vague language, making it immediately understandable to teammates reviewing the commit history. The supporting test additions (multipleTsconfigsWithReferences) validate this fix but do not change the primary intent described in the title.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6697e04 and 2be84ae.

📒 Files selected for processing (1)
  • .changeset/large-insects-kiss.md (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .changeset/large-insects-kiss.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Lint and Test with Node.js 24 on windows-latest
  • GitHub Check: Lint and Test with Node.js 22 on windows-latest
  • GitHub Check: Lint and Test with Node.js 18 on windows-latest
  • GitHub Check: Lint and Test with Node.js 20 on windows-latest

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Oct 28, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 28, 2025

Open in StackBlitz

npm i https://pkg.pr.new/eslint-import-resolver-typescript@473

commit: 2be84ae

Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed everything up to 6697e04 in 2 minutes and 42 seconds. Click for details.
  • Reviewed 155 lines of code in 10 files
  • Skipped 1 files when reviewing.
  • Skipped posting 12 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. src/index.ts:125
  • Draft comment:
    Reordered the resolver cache check after tsconfig matching to ensure the correct tsconfig is used. Consider adding an inline comment explaining this reordering for clarity.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 20% vs. threshold = 50% The reordering does appear intentional and meaningful - we now only check the resolver cache after confirming the tsconfig matches the file. However, suggesting to add an explanatory comment is more of a nice-to-have than a critical issue. The code flow is already fairly clear from the structure and existing logging statements. The comment correctly identifies a meaningful code change, but requesting additional documentation is more of a preference than a clear issue. The existing code may already be sufficiently self-documenting. While documentation can be helpful, the code structure and existing log statements already make the flow clear. An additional inline comment isn't strictly necessary. This comment should be removed as it's suggesting an optional documentation improvement rather than pointing out a clear code issue that needs to be fixed.
2. tests/e2e/__snapshots__/e2e.spec.ts.snap:67
  • Draft comment:
    New snapshot for 'multipleTsconfigsWithReferences' has been added and appears correct.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
3. tests/e2e/multipleTsconfigsWithReferences/.eslintrc.cjs:3
  • Draft comment:
    ESLint config correctly specifies the projects array with both tsconfig files.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
4. tests/e2e/multipleTsconfigsWithReferences/backend/index.ts:1
  • Draft comment:
    Backend test file demonstrates proper use of both relative imports and tsconfig path mappings. Looks good.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
5. tests/e2e/multipleTsconfigsWithReferences/backend/utils.ts:1
  • Draft comment:
    Backend utility file is simple and correct.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
6. tests/e2e/multipleTsconfigsWithReferences/frontend/component.tsx:1
  • Draft comment:
    Frontend component file is minimal and defined correctly.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
7. tests/e2e/multipleTsconfigsWithReferences/frontend/index.tsx:1
  • Draft comment:
    Frontend index file properly tests both relative imports and tsconfig path mappings; no issues observed.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
8. tests/e2e/multipleTsconfigsWithReferences/shared-utils/helper.ts:1
  • Draft comment:
    Shared utility helper is defined correctly.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
9. tests/e2e/multipleTsconfigsWithReferences/tsconfig.node.json:5
  • Draft comment:
    tsconfig.node.json is properly configured with the correct 'include' patterns and path mappings for backend and shared utils.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
10. tests/e2e/multipleTsconfigsWithReferences/tsconfig.web.json:5
  • Draft comment:
    tsconfig.web.json is correctly set up for frontend with JSX and shared utils path mappings.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
11. tests/e2e/multipleTsconfigsWithReferences/backend/index.ts:8
  • Draft comment:
    Typographical suggestion: Consider changing "node_module" to "node_modules" in this comment for consistency with common terminology.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% While the suggestion is technically correct (the plural form 'node_modules' is more common), this is an extremely minor documentation issue. The comment is clear enough as is and doesn't impact code functionality. The rules specifically say not to make purely informative comments and to avoid obvious or unimportant changes. The typo could theoretically confuse new developers about the correct terminology. Also, since this is a new file, it's better to start with correct terminology. The meaning is still perfectly clear despite the minor typo, and fixing it provides no real value. This is exactly the kind of nitpicky comment that clutters PR reviews. Delete this comment as it's purely cosmetic, doesn't affect functionality, and violates the rule about not making purely informative comments.
12. tests/e2e/multipleTsconfigsWithReferences/frontend/index.tsx:8
  • Draft comment:
    Typographical note: The comment says "import from node_module". Consider using "node_modules" to reflect the standard naming convention.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% While technically correct that "node_modules" is the standard term, this is just a comment typo that doesn't affect functionality. The comment is purely informative and doesn't require any actual code changes. According to the rules, we should not make purely informative comments or comments about unimportant issues. The typo could potentially confuse future developers about the correct terminology. Comments are part of code documentation. The difference is minor and obvious enough that it wouldn't cause real confusion. The meaning is clear even with the typo. Delete the comment as it's purely informative and about an unimportant typo that doesn't affect functionality.

Workflow ID: wflow_hzWW56KfTjK9lpxB

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant