]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
feat(compiler-sfc): support ${configDir} in paths for TypeScript 5.5+
authordaiwei <daiwei521@126.com>
Wed, 18 Jun 2025 03:36:29 +0000 (11:36 +0800)
committerdaiwei <daiwei521@126.com>
Wed, 18 Jun 2025 03:36:29 +0000 (11:36 +0800)
packages/compiler-sfc/src/script/resolveType.ts

index 85832dfc39a02128c28a081fbfd80729a159e9b9..60b23ca8a63613c9871ef475c5ce639b57f8cade 100644 (file)
@@ -1029,6 +1029,13 @@ function resolveWithTS(
     if (configs.length === 1) {
       matchedConfig = configs[0]
     } else {
+      const [major, minor] = ts.versionMajorMinor.split('.').map(Number)
+      function getPattern(base: string, p: string): string {
+        return p.startsWith('${configDir}') && major >= 5 && minor >= 5
+          ? // ts 5.5+ supports ${configDir} in paths
+            p.replace('${configDir}', dirname(configPath!))
+          : joinPaths(base, p)
+      }
       // resolve which config matches the current file
       for (const c of configs) {
         const base = normalizePath(
@@ -1039,11 +1046,11 @@ function resolveWithTS(
         const excluded: string[] | undefined = c.config.raw?.exclude
         if (
           (!included && (!base || containingFile.startsWith(base))) ||
-          included?.some(p => isMatch(containingFile, joinPaths(base, p)))
+          included?.some(p => isMatch(containingFile, getPattern(base, p)))
         ) {
           if (
             excluded &&
-            excluded.some(p => isMatch(containingFile, joinPaths(base, p)))
+            excluded.some(p => isMatch(containingFile, getPattern(base, p)))
           ) {
             continue
           }