Skip to content

Commit 3767fdf

Browse files
committedAug 4, 2023
fix: ensure resolved type entry path ends with .d.ts
1 parent 0c2c199 commit 3767fdf

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed
 

‎src/plugin.ts

+14-6
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,9 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
188188
}
189189
} else {
190190
logger.warn(
191-
yellow(
192-
`\n${cyan(
193-
'[vite:dts]'
194-
)} You are building a library that may not need to generate declaration files.\n`
195-
)
191+
`\n${logPrefix} ${yellow(
192+
'You are building a library that may not need to generate declaration files.'
193+
)}\n`
196194
)
197195

198196
libName = '_default'
@@ -547,7 +545,17 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
547545
(pkg.exports?.['.'] || pkg.exports?.['./'])?.types
548546
const multiple = entryNames.length > 1
549547

550-
const typesPath = types ? resolve(root, types) : resolve(outDir, indexName)
548+
let typesPath = types ? resolve(root, types) : resolve(outDir, indexName)
549+
550+
if (!multiple && !dtsRE.test(typesPath)) {
551+
logger.warn(
552+
`\n${logPrefix} ${yellow(
553+
"The resolved path of type entry is not ending with '.d.ts'."
554+
)}\n`
555+
)
556+
557+
typesPath = `${typesPath.replace(tjsRE, '')}.d.${extPrefix(typesPath)}ts`
558+
}
551559

552560
for (const name of entryNames) {
553561
const path = multiple ? resolve(outDir, `${name.replace(tsRE, '')}.d.ts`) : typesPath

0 commit comments

Comments
 (0)
Please sign in to comment.