Skip to content

Commit

Permalink
fix: ensure resolved type entry path ends with .d.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
qmhc committed Aug 4, 2023
1 parent 0c2c199 commit 3767fdf
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,9 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
}
} else {
logger.warn(
yellow(
`\n${cyan(
'[vite:dts]'
)} You are building a library that may not need to generate declaration files.\n`
)
`\n${logPrefix} ${yellow(
'You are building a library that may not need to generate declaration files.'
)}\n`
)

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

const typesPath = types ? resolve(root, types) : resolve(outDir, indexName)
let typesPath = types ? resolve(root, types) : resolve(outDir, indexName)

if (!multiple && !dtsRE.test(typesPath)) {
logger.warn(
`\n${logPrefix} ${yellow(
"The resolved path of type entry is not ending with '.d.ts'."
)}\n`
)

typesPath = `${typesPath.replace(tjsRE, '')}.d.${extPrefix(typesPath)}ts`
}

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

0 comments on commit 3767fdf

Please sign in to comment.