From 3767fdfc1cf1789bfa5cab48f93fa9ec0f55cf12 Mon Sep 17 00:00:00 2001 From: qmhc <40221744+qmhc@users.noreply.github.com> Date: Fri, 4 Aug 2023 18:36:16 +0800 Subject: [PATCH] fix: ensure resolved type entry path ends with .d.ts --- src/plugin.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/plugin.ts b/src/plugin.ts index 49b1ac1..4905319 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -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' @@ -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