fix(compile-sfc): Support project reference with folder, (#10908)

close #10907
This commit is contained in:
cyrilluce 2024-06-10 15:25:47 +08:00 committed by GitHub
parent d6990dc587
commit bdeac377c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 56 additions and 5 deletions

View File

@ -1022,6 +1022,53 @@ describe('resolveType', () => {
expect(deps && [...deps]).toStrictEqual(['/user.ts']) expect(deps && [...deps]).toStrictEqual(['/user.ts'])
}) })
test('ts module resolve w/ project reference folder', () => {
const files = {
'/tsconfig.json': JSON.stringify({
references: [
{
path: './web',
},
{
path: './empty',
},
{
path: './noexists-should-ignore',
},
],
}),
'/web/tsconfig.json': JSON.stringify({
include: ['../**/*.ts', '../**/*.vue'],
compilerOptions: {
composite: true,
paths: {
bar: ['../user.ts'],
},
},
}),
// tsconfig with no include / paths defined, should match nothing
'/empty/tsconfig.json': JSON.stringify({
compilerOptions: {
composite: true,
},
}),
'/user.ts': 'export type User = { bar: string }',
}
const { props, deps } = resolve(
`
import { User } from 'bar'
defineProps<User>()
`,
files,
)
expect(props).toStrictEqual({
bar: ['String'],
})
expect(deps && [...deps]).toStrictEqual(['/user.ts'])
})
test('ts module resolve w/ path aliased vue file', () => { test('ts module resolve w/ path aliased vue file', () => {
const files = { const files = {
'/tsconfig.json': JSON.stringify({ '/tsconfig.json': JSON.stringify({

View File

@ -1014,11 +1014,11 @@ function resolveWithTS(
(c.config.options.pathsBasePath as string) || (c.config.options.pathsBasePath as string) ||
dirname(c.config.options.configFilePath as string), dirname(c.config.options.configFilePath as string),
) )
const included: string[] = c.config.raw?.include const included: string[] | undefined = c.config.raw?.include
const excluded: string[] = c.config.raw?.exclude const excluded: string[] | undefined = c.config.raw?.exclude
if ( if (
(!included && (!base || containingFile.startsWith(base))) || (!included && (!base || containingFile.startsWith(base))) ||
included.some(p => isMatch(containingFile, joinPaths(base, p))) included?.some(p => isMatch(containingFile, joinPaths(base, p)))
) { ) {
if ( if (
excluded && excluded &&
@ -1089,8 +1089,12 @@ function loadTSConfig(
const res = [config] const res = [config]
if (config.projectReferences) { if (config.projectReferences) {
for (const ref of config.projectReferences) { for (const ref of config.projectReferences) {
tsConfigRefMap.set(ref.path, configPath) const refPath = ts.resolveProjectReferencePath(ref)
res.unshift(...loadTSConfig(ref.path, ts, fs)) if (!fs.fileExists(refPath)) {
continue
}
tsConfigRefMap.set(refPath, configPath)
res.unshift(...loadTSConfig(refPath, ts, fs))
} }
} }
return res return res