Skip to content

fix(compiler-sfc): support ${configDir} in paths for TypeScript 5.5+ #13491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

edison1105
Copy link
Member

@edison1105 edison1105 commented Jun 18, 2025

close #13484

Summary by CodeRabbit

  • New Features

    • Added support for the ${configDir} variable in TypeScript path mappings and include/exclude patterns when using TypeScript 5.5 or higher.
  • Tests

    • Introduced a new test case to verify correct handling of ${configDir} in complex tsconfig setups with project references and path aliases.

Copy link

coderabbitai bot commented Jun 18, 2025

Walkthrough

A new test case was added to verify TypeScript's ${configDir} variable resolution in path mappings and include patterns when using extended tsconfig files and project references. The resolution logic in the compiler was updated to handle ${configDir} correctly for TypeScript 5.5 and above, ensuring proper path normalization.

Changes

File(s) Change Summary
packages/compiler-sfc/tests/compileScript/resolveType.spec.ts Added a test for ${configDir} resolution in extended tsconfig with project references.
packages/compiler-sfc/src/script/resolveType.ts Enhanced logic to resolve ${configDir} in include/exclude patterns for TypeScript >= 5.5.

Sequence Diagram(s)

sequenceDiagram
    participant TestRunner
    participant Compiler
    participant TypeScript
    participant FileSystem

    TestRunner->>Compiler: Compile Vue SFC with extended tsconfig using ${configDir}
    Compiler->>TypeScript: Load tsconfig(s) and parse version
    TypeScript-->>Compiler: Return config with include/exclude patterns
    Compiler->>FileSystem: Resolve paths with ${configDir} if TS >= 5.5
    FileSystem-->>Compiler: Return normalized file paths
    Compiler-->>TestRunner: Return resolved types and dependency info
Loading

Assessment against linked issues

Objective Addressed Explanation
Correctly resolve ${configDir} in extended tsconfig files (paths/include) for Vue SFC type resolution (#13484)

Suggested labels

ready to merge, scope: sfc

Suggested reviewers

  • LittleSound

Poem

A hop and a skip, the config resolved right,
No more confusion in TypeScript’s sight!
With ${configDir} mapped, the tests all pass,
The compiler now leaps through the greenest grass.
🐇✨

Hooray for clean paths, and code without fear—
The Vue is much brighter, now bugs disappear!

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 101 kB 38.4 kB 34.6 kB
vue.global.prod.js 159 kB 58.5 kB 52.2 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 46.7 kB 18.2 kB 16.7 kB
createApp 54.6 kB 21.3 kB 19.4 kB
createSSRApp 58.9 kB 23 kB 21 kB
defineCustomElement 59.6 kB 22.9 kB 20.9 kB
overall 68.7 kB 26.4 kB 24.1 kB

Copy link

pkg-pr-new bot commented Jun 18, 2025

Open in StackBlitz

@vue/compiler-core

npm i https://pkg.pr.new/@vue/compiler-core@13491

@vue/compiler-dom

npm i https://pkg.pr.new/@vue/compiler-dom@13491

@vue/compiler-sfc

npm i https://pkg.pr.new/@vue/compiler-sfc@13491

@vue/compiler-ssr

npm i https://pkg.pr.new/@vue/compiler-ssr@13491

@vue/reactivity

npm i https://pkg.pr.new/@vue/reactivity@13491

@vue/runtime-core

npm i https://pkg.pr.new/@vue/runtime-core@13491

@vue/runtime-dom

npm i https://pkg.pr.new/@vue/runtime-dom@13491

@vue/server-renderer

npm i https://pkg.pr.new/@vue/server-renderer@13491

@vue/shared

npm i https://pkg.pr.new/@vue/shared@13491

vue

npm i https://pkg.pr.new/vue@13491

@vue/compat

npm i https://pkg.pr.new/@vue/compat@13491

commit: 7588b4d

@edison1105 edison1105 marked this pull request as ready for review June 18, 2025 06:41
@edison1105 edison1105 added scope: sfc 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. labels Jun 18, 2025
@edison1105 edison1105 changed the title feat(compiler-sfc): support ${configDir} in paths for TypeScript 5.5+ fix(compiler-sfc): support ${configDir} in paths for TypeScript 5.5+ Jun 18, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/compiler-sfc/src/script/resolveType.ts (1)

1048-1054: Minor style improvement – use optional chaining

Static-analysis already hints at it. The manual excluded && … can be trimmed:

-          if (
-            excluded &&
-            excluded.some(p => isMatch(containingFile, getPattern(base, p)))
-          ) {
+          if (
+            excluded?.some(p => isMatch(containingFile, getPattern(base, p)))
+          ) {
             continue
           }

Touches no logic, just terser & consistent with the included?.some above.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 532cfae and 5fab826.

📒 Files selected for processing (2)
  • packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts (1 hunks)
  • packages/compiler-sfc/src/script/resolveType.ts (2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/compiler-sfc/src/script/resolveType.ts

[error] 1052-1053: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Redirect rules
  • GitHub Check: Header rules
  • GitHub Check: Pages changed
🔇 Additional comments (1)
packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts (1)

1158-1195: 👍 Robust regression test

The new case accurately reproduces #13484 and guards the compiler against future regressions in ${configDir} handling. No concerns.

edison1105 and others added 2 commits June 18, 2025 14:46
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@edison1105 edison1105 force-pushed the edison/feat/resolveConfigDir branch from 1024d53 to 7588b4d Compare June 18, 2025 06:50
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/compiler-sfc/src/script/resolveType.ts (2)

1032-1039: Minor refactor opportunity: lift helper + version parsing out of the loop

const [major, minor] = … and function getPattern… are recreated every time resolveWithTS is invoked. They only depend on ts.versionMajorMinor and configPath, both of which are invariant during a single compiler run. Hoisting them to the outer scope of resolveWithTS (or caching the parsed tuple) would avoid unnecessary re-allocation and keep the loop body slimmer.

Not critical, just a readability / micro-perf improvement.


1050-1055: Use optional chaining to streamline excluded check

Small readability tweak: the explicit null check can be replaced with optional chaining.

-          if (
-            excluded &&
-            excluded.some(p => isMatch(containingFile, getPattern(base, p)))
-          ) {
+          if (
+            excluded?.some(p => isMatch(containingFile, getPattern(base, p)))
+          ) {

No behavioural change; simply reduces nesting.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5fab826 and 1024d53.

📒 Files selected for processing (1)
  • packages/compiler-sfc/src/script/resolveType.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/compiler-sfc/src/script/resolveType.ts (1)
packages/compiler-sfc/src/script/utils.ts (2)
  • normalizePath (107-109)
  • joinPaths (111-112)
🪛 Biome (1.9.4)
packages/compiler-sfc/src/script/resolveType.ts

[error] 1053-1054: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (1)
packages/compiler-sfc/src/script/resolveType.ts (1)

1032-1038: Version-guard correctly future-proofed — looks good

The new supportsConfigDir check (major > 5 || (major === 5 && minor >= 5)) removes the earlier logical gap for TS 6.x+ and resolves the concern raised in the previous review.
Implementation is clear and side-effect-free.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/compiler-sfc/src/script/resolveType.ts (2)

1032-1039: Protect against pre-release version strings & compute once

Good call switching to major > 5 || (major === 5 && minor >= 5) – it future-proofs the guard.
Two minor nits:

  1. Number('5.5-beta') becomes NaN, disabling the feature for nightly/beta drops.
    Use parseInt (or a regex) to strip non-digits first.

  2. supportsConfigDir is recalculated on every getPattern invocation although it’s invariant – lift it outside the arrow for micro clarity.

-const [major, minor] = ts.versionMajorMinor.split('.').map(Number)
+const [majorRaw, minorRaw] = ts.versionMajorMinor.split('.')
+const major = parseInt(majorRaw, 10)
+const minor = parseInt(minorRaw, 10)

-const getPattern = (base: string, p: string) => {
-  // ts 5.5+ supports ${configDir} in paths
-  const supportsConfigDir = major > 5 || (major === 5 && minor >= 5)
+// ts 5.5+ supports ${configDir} in paths
+const supportsConfigDir = major > 5 || (major === 5 && minor >= 5)
+
+const getPattern = (base: string, p: string) => {

1049-1055: Use optional chaining to quiet lint & improve readability

Biome flags this pattern check; a terse optional-chain keeps the meaning while removing an explicit null-guard:

-        if (
-          (!included && (!base || containingFile.startsWith(base))) ||
-          included?.some(p => isMatch(containingFile, getPattern(base, p)))
-        ) {
+        if (
+          (!included && (!base || containingFile.startsWith(base))) ||
+          included?.some(p => isMatch(containingFile, getPattern(base, p)))
+        ) {
           if (
-            excluded &&
-            excluded.some(p => isMatch(containingFile, getPattern(base, p)))
+            excluded?.some(p =>
+              isMatch(containingFile, getPattern(base, p)),
+            )
           ) {

This is purely stylistic – feel free to keep the existing guard if you prefer explicit checks.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1024d53 and 7588b4d.

📒 Files selected for processing (1)
  • packages/compiler-sfc/src/script/resolveType.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/compiler-sfc/src/script/resolveType.ts (1)
packages/compiler-sfc/src/script/utils.ts (2)
  • normalizePath (107-109)
  • joinPaths (111-112)
🪛 Biome (1.9.4)
packages/compiler-sfc/src/script/resolveType.ts

[error] 1053-1054: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: continuous-release
  • GitHub Check: test / e2e-test
  • GitHub Check: test / unit-test-windows

@edison1105 edison1105 added the ready to merge The PR is ready to be merged. label Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. ready to merge The PR is ready to be merged. scope: sfc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vue compiler does not correctly resolve ${configDir} from extended tsconfigs
1 participant