Skip to content

Commit 4929974

Browse files
committed
feat(compiler-sfc): support ${configDir} in paths for TypeScript 5.5+
1 parent 532cfae commit 4929974

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

packages/compiler-sfc/src/script/resolveType.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,13 @@ function resolveWithTS(
10291029
if (configs.length === 1) {
10301030
matchedConfig = configs[0]
10311031
} else {
1032+
const [major, minor] = ts.versionMajorMinor.split('.').map(Number)
1033+
function getPattern(base: string, p: string): string {
1034+
return p.startsWith('${configDir}') && major >= 5 && minor >= 5
1035+
? // ts 5.5+ supports ${configDir} in paths
1036+
p.replace('${configDir}', dirname(configPath!))
1037+
: joinPaths(base, p)
1038+
}
10321039
// resolve which config matches the current file
10331040
for (const c of configs) {
10341041
const base = normalizePath(
@@ -1039,11 +1046,11 @@ function resolveWithTS(
10391046
const excluded: string[] | undefined = c.config.raw?.exclude
10401047
if (
10411048
(!included && (!base || containingFile.startsWith(base))) ||
1042-
included?.some(p => isMatch(containingFile, joinPaths(base, p)))
1049+
included?.some(p => isMatch(containingFile, getPattern(base, p)))
10431050
) {
10441051
if (
10451052
excluded &&
1046-
excluded.some(p => isMatch(containingFile, joinPaths(base, p)))
1053+
excluded.some(p => isMatch(containingFile, getPattern(base, p)))
10471054
) {
10481055
continue
10491056
}

0 commit comments

Comments
 (0)