File tree Expand file tree Collapse file tree 1 file changed +13
-7
lines changed
Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,17 @@ export default function typescript(options: RollupTypescriptOptions = {}): Plugi
5353 }
5454 autoOutDir = null ;
5555 } ;
56+ // Ensure the TypeScript watch program is closed and temp outDir is cleaned
57+ // even if closing throws. Call this from lifecycle hooks that need teardown.
58+ const closeProgramAndCleanup = ( ) => {
59+ try {
60+ // ESLint doesn't understand optional chaining
61+ // eslint-disable-next-line
62+ program ?. close ( ) ;
63+ } finally {
64+ cleanupAutoOutDir ( ) ;
65+ }
66+ } ;
5667
5768 const parsedOptions = parseTypescriptConfig ( ts , tsconfig , compilerOptions , noForceEmit ) ;
5869
@@ -182,18 +193,13 @@ export default function typescript(options: RollupTypescriptOptions = {}): Plugi
182193
183194 buildEnd ( ) {
184195 if ( this . meta . watchMode !== true ) {
185- // ESLint doesn't understand optional chaining
186- // eslint-disable-next-line
187- program ?. close ( ) ;
188- cleanupAutoOutDir ( ) ;
196+ closeProgramAndCleanup ( ) ;
189197 }
190198 } ,
191199
192200 // Ensure program is closed and temp outDir is removed exactly once when watch stops
193201 closeWatcher ( ) {
194- // eslint-disable-next-line
195- program ?. close ( ) ;
196- cleanupAutoOutDir ( ) ;
202+ closeProgramAndCleanup ( ) ;
197203 } ,
198204
199205 renderStart ( outputOptions ) {
You can’t perform that action at this time.
0 commit comments