Skip to content

Commit bdeac37

Browse files
authoredJun 10, 2024··
fix(compile-sfc): Support project reference with folder, (#10908)
close #10907
1 parent d6990dc commit bdeac37

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed
 

‎packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts

+47
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,53 @@ describe('resolveType', () => {
10221022
expect(deps && [...deps]).toStrictEqual(['/user.ts'])
10231023
})
10241024

1025+
test('ts module resolve w/ project reference folder', () => {
1026+
const files = {
1027+
'/tsconfig.json': JSON.stringify({
1028+
references: [
1029+
{
1030+
path: './web',
1031+
},
1032+
{
1033+
path: './empty',
1034+
},
1035+
{
1036+
path: './noexists-should-ignore',
1037+
},
1038+
],
1039+
}),
1040+
'/web/tsconfig.json': JSON.stringify({
1041+
include: ['../**/*.ts', '../**/*.vue'],
1042+
compilerOptions: {
1043+
composite: true,
1044+
paths: {
1045+
bar: ['../user.ts'],
1046+
},
1047+
},
1048+
}),
1049+
// tsconfig with no include / paths defined, should match nothing
1050+
'/empty/tsconfig.json': JSON.stringify({
1051+
compilerOptions: {
1052+
composite: true,
1053+
},
1054+
}),
1055+
'/user.ts': 'export type User = { bar: string }',
1056+
}
1057+
1058+
const { props, deps } = resolve(
1059+
`
1060+
import { User } from 'bar'
1061+
defineProps<User>()
1062+
`,
1063+
files,
1064+
)
1065+
1066+
expect(props).toStrictEqual({
1067+
bar: ['String'],
1068+
})
1069+
expect(deps && [...deps]).toStrictEqual(['/user.ts'])
1070+
})
1071+
10251072
test('ts module resolve w/ path aliased vue file', () => {
10261073
const files = {
10271074
'/tsconfig.json': JSON.stringify({

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

+9-5
Original file line numberDiff line numberDiff line change
@@ -1014,11 +1014,11 @@ function resolveWithTS(
10141014
(c.config.options.pathsBasePath as string) ||
10151015
dirname(c.config.options.configFilePath as string),
10161016
)
1017-
const included: string[] = c.config.raw?.include
1018-
const excluded: string[] = c.config.raw?.exclude
1017+
const included: string[] | undefined = c.config.raw?.include
1018+
const excluded: string[] | undefined = c.config.raw?.exclude
10191019
if (
10201020
(!included && (!base || containingFile.startsWith(base))) ||
1021-
included.some(p => isMatch(containingFile, joinPaths(base, p)))
1021+
included?.some(p => isMatch(containingFile, joinPaths(base, p)))
10221022
) {
10231023
if (
10241024
excluded &&
@@ -1089,8 +1089,12 @@ function loadTSConfig(
10891089
const res = [config]
10901090
if (config.projectReferences) {
10911091
for (const ref of config.projectReferences) {
1092-
tsConfigRefMap.set(ref.path, configPath)
1093-
res.unshift(...loadTSConfig(ref.path, ts, fs))
1092+
const refPath = ts.resolveProjectReferencePath(ref)
1093+
if (!fs.fileExists(refPath)) {
1094+
continue
1095+
}
1096+
tsConfigRefMap.set(refPath, configPath)
1097+
res.unshift(...loadTSConfig(refPath, ts, fs))
10941098
}
10951099
}
10961100
return res

0 commit comments

Comments
 (0)
Please sign in to comment.