Skip to content

Commit

Permalink
fix(compiler-sfc): skip circular tsconfig project reference (vuejs#11382
Browse files Browse the repository at this point in the history
)
  • Loading branch information
cluezhang committed Aug 21, 2024
1 parent fbc0c42 commit 3516ceb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
43 changes: 43 additions & 0 deletions packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,49 @@ describe('resolveType', () => {
expect(deps && [...deps]).toStrictEqual(['/user.ts'])
})

// #11382
test('ts module resolve circular project reference', () => {
const files = {
'/tsconfig.json': JSON.stringify({
exclude: ['**/*.ts', '**/*.vue'],
references: [
{
path: './tsconfig.web.json',
},
],
}),
'/tsconfig.web.json': JSON.stringify({
include: ['**/*.ts', '**/*.vue'],
compilerOptions: {
composite: true,
paths: {
user: ['./user.ts'],
},
},
references: [
{
// circular reference
path: './tsconfig.json',
},
],
}),
'/user.ts': 'export type User = { bar: string }',
}

const { props, deps } = resolve(
`
import { User } from 'user'
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
7 changes: 6 additions & 1 deletion packages/compiler-sfc/src/script/resolveType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,7 @@ function loadTSConfig(
configPath: string,
ts: typeof TS,
fs: FS,
visited = new Set<string>(),
): TS.ParsedCommandLine[] {
// The only case where `fs` is NOT `ts.sys` is during tests.
// parse config host requires an extra `readDirectory` method
Expand All @@ -1089,14 +1090,18 @@ function loadTSConfig(
configPath,
)
const res = [config]
visited.add(configPath)
if (config.projectReferences) {
for (const ref of config.projectReferences) {
const refPath = ts.resolveProjectReferencePath(ref)
if (visited.has(refPath)) {
continue
}
if (!fs.fileExists(refPath)) {
continue
}
tsConfigRefMap.set(refPath, configPath)
res.unshift(...loadTSConfig(refPath, ts, fs))
res.unshift(...loadTSConfig(refPath, ts, fs, visited))
}
}
return res
Expand Down

0 comments on commit 3516ceb

Please sign in to comment.