From a7e1c0cb80cf25056e02e04414af9412eeeea750 Mon Sep 17 00:00:00 2001 From: qmhc Date: Mon, 30 Sep 2024 18:20:06 +0800 Subject: [PATCH] fix: should re-emit all source files when change in watch mode fix #383 --- src/plugin.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/plugin.ts b/src/plugin.ts index e5a23be..dbe613d 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -105,6 +105,7 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin { let host: ts.CompilerHost | undefined let program: ts.Program | undefined let filter: ReturnType + let rootNames: string[] = [] let rebuildProgram: () => ts.Program let bundled = false @@ -318,7 +319,7 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin { filter = createFilter(include, exclude) - const rootNames = [ + rootNames = [ ...new Set( Object.values(entries) .map(entry => ensureAbsolute(entry, root)) @@ -376,10 +377,10 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin { await unwrapPromise(afterDiagnostic(diagnostics)) } - rootNames.forEach(file => { + for (const file of rootNames) { this.addWatchFile(file) rootFiles.add(file) - }) + } bundleDebug('create ts program') timeRecord += Date.now() - startTime @@ -464,7 +465,11 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin { const sourceFile = host.getSourceFile(id, ts.ScriptTarget.ESNext) if (sourceFile) { - rootFiles.add(sourceFile.fileName) + for (const file of rootNames) { + rootFiles.add(file) + } + + rootFiles.add(normalizePath(sourceFile.fileName)) bundled = false timeRecord = 0