Skip to content

Commit

Permalink
fix(compile-sfc): Support project reference with folder, fix #10907
Browse files Browse the repository at this point in the history
  • Loading branch information
cluezhang committed May 11, 2024
1 parent b2b5f57 commit 4db98d3
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
47 changes: 47 additions & 0 deletions packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,53 @@ describe('resolveType', () => {
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', () => {
const files = {
'/tsconfig.json': JSON.stringify({
Expand Down
10 changes: 7 additions & 3 deletions packages/compiler-sfc/src/script/resolveType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ function resolveWithTS(
const excluded: string[] = c.config.raw?.exclude
if (
(!included && (!base || containingFile.startsWith(base))) ||
included.some(p => isMatch(containingFile, joinPaths(base, p)))
included?.some(p => isMatch(containingFile, joinPaths(base, p)))
) {
if (
excluded &&
Expand Down Expand Up @@ -1080,8 +1080,12 @@ function loadTSConfig(
const res = [config]
if (config.projectReferences) {
for (const ref of config.projectReferences) {
tsConfigRefMap.set(ref.path, configPath)
res.unshift(...loadTSConfig(ref.path, ts, fs))
const refPath = ts.resolveProjectReferencePath(ref)
if (!fs.fileExists(refPath)) {
continue
}
tsConfigRefMap.set(refPath, configPath)
res.unshift(...loadTSConfig(refPath, ts, fs))
}
}
return res
Expand Down

0 comments on commit 4db98d3

Please sign in to comment.