Skip to content

Commit

Permalink
fix: should re-emit all source files when change in watch mode
Browse files Browse the repository at this point in the history
  • Loading branch information
qmhc committed Sep 30, 2024
1 parent 4e824cd commit a7e1c0c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof createFilter>
let rootNames: string[] = []
let rebuildProgram: () => ts.Program

let bundled = false
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a7e1c0c

Please sign in to comment.