Skip to content

Commit b0a695e

Browse files
committed
fix(unplugin-dts): publicRoot mismatch of TS 6.0 rootDir
TypeScript 6.0 changes the default rootDir settings from the public ancestor of source files to the directory of tsconfig.json. This causes the default value of publicRoot mismatched to the resolution after an internal TS compilation callback of file paths. When bundling types, the built .d.ts cannot add any import from the built entry which results in an empty module due to this mismatch. fix #467
1 parent 051f2ea commit b0a695e

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

packages/unplugin-dts/src/core/runtime.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { cpus } from 'node:os'
55

66
import ts from 'typescript'
77
import { createFilter } from '@rollup/pluginutils'
8+
import { compare } from 'compare-versions'
89
import { green, red, yellow } from 'kolorist'
910
import { loadProgramProcessor } from './processor'
1011
import { JsonResolver, SvelteResolver, VueResolver, parseResolvers } from './resolvers'
@@ -275,12 +276,16 @@ export class Runtime {
275276
? ensureAbsolute(resolveConfigDir(compilerOptions.rootDir, root), root)
276277
: compilerOptions.composite && compilerOptions.configFilePath
277278
? dirname(compilerOptions.configFilePath as string)
278-
: queryPublicPath(
279-
program
280-
.getSourceFiles()
281-
.filter(maybeEmitted)
282-
.map(sourceFile => sourceFile.fileName),
283-
)
279+
: compare(ts.version, '6.0.0', '>=')
280+
? configPath
281+
? dirname(configPath)
282+
: root
283+
: queryPublicPath(
284+
program
285+
.getSourceFiles()
286+
.filter(maybeEmitted)
287+
.map(sourceFile => sourceFile.fileName),
288+
)
284289
publicRoot = normalizePath(publicRoot)
285290

286291
let entryRoot = options.entryRoot || publicRoot

0 commit comments

Comments
 (0)