Skip to content

Commit

Permalink
fix: only clean vue suffix when no duplicated name
Browse files Browse the repository at this point in the history
fix #372
  • Loading branch information
qmhc committed Aug 26, 2024
1 parent 38758f7 commit 068e711
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
const rollupConfig = { ...(options.rollupConfig || {}) }
rollupConfig.bundledPackages = rollupConfig.bundledPackages || options.bundledPackages || []

const cleanPath = (path: string) => {
return cleanVueFileName ? path.replace('.vue.d.ts', '.d.ts') : path
const cleanPath = (path: string, emittedFiles: Map<string, string>) => {
return !emittedFiles.has(path) && cleanVueFileName ? path.replace('.vue.d.ts', '.d.ts') : path
}

return {
Expand Down Expand Up @@ -645,7 +645,10 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
const types = findTypesPath(pkg.publishConfig, pkg)
const multiple = entryNames.length > 1

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

if (!multiple && !dtsRE.test(typesPath)) {
logger.warn(
Expand All @@ -658,12 +661,14 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
}

for (const name of entryNames) {
const entryDtsPath = multiple ? cleanPath(resolve(outDir, tsToDts(name))) : typesPath
const entryDtsPath = multiple
? cleanPath(resolve(outDir, tsToDts(name)), emittedFiles)
: typesPath

if (existsSync(entryDtsPath)) continue

const sourceEntry = normalizePath(
cleanPath(resolve(outDir, relative(entryRoot, tsToDts(entries[name]))))
cleanPath(resolve(outDir, relative(entryRoot, tsToDts(entries[name]))), emittedFiles)
)

let fromPath = normalizePath(relative(dirname(entryDtsPath), sourceEntry))
Expand All @@ -683,7 +688,7 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
}
}

await writeOutput(cleanPath(entryDtsPath), content, outDir)
await writeOutput(cleanPath(entryDtsPath, emittedFiles), content, outDir)
}

bundleDebug('insert index')
Expand Down Expand Up @@ -719,7 +724,7 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {

if (multiple) {
await runParallel(cpus().length, entryNames, async name => {
await rollup(cleanPath(resolve(outDir, tsToDts(name))))
await rollup(cleanPath(resolve(outDir, tsToDts(name)), emittedFiles))
})
} else {
await rollup(typesPath)
Expand Down

0 comments on commit 068e711

Please sign in to comment.