Skip to content

Commit a7e1c0c

Browse files
committed
fix: should re-emit all source files when change in watch mode
fix #383
1 parent 4e824cd commit a7e1c0c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/plugin.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
105105
let host: ts.CompilerHost | undefined
106106
let program: ts.Program | undefined
107107
let filter: ReturnType<typeof createFilter>
108+
let rootNames: string[] = []
108109
let rebuildProgram: () => ts.Program
109110

110111
let bundled = false
@@ -318,7 +319,7 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
318319

319320
filter = createFilter(include, exclude)
320321

321-
const rootNames = [
322+
rootNames = [
322323
...new Set(
323324
Object.values(entries)
324325
.map(entry => ensureAbsolute(entry, root))
@@ -376,10 +377,10 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
376377
await unwrapPromise(afterDiagnostic(diagnostics))
377378
}
378379

379-
rootNames.forEach(file => {
380+
for (const file of rootNames) {
380381
this.addWatchFile(file)
381382
rootFiles.add(file)
382-
})
383+
}
383384

384385
bundleDebug('create ts program')
385386
timeRecord += Date.now() - startTime
@@ -464,7 +465,11 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
464465
const sourceFile = host.getSourceFile(id, ts.ScriptTarget.ESNext)
465466

466467
if (sourceFile) {
467-
rootFiles.add(sourceFile.fileName)
468+
for (const file of rootNames) {
469+
rootFiles.add(file)
470+
}
471+
472+
rootFiles.add(normalizePath(sourceFile.fileName))
468473

469474
bundled = false
470475
timeRecord = 0

0 commit comments

Comments
 (0)