Skip to content

Commit 9012668

Browse files
committed
refactor(typescript): centralize temp outDir cleanup into a helper
- Deduplicate try/catch cleanup in buildEnd and closeWatcher via local function - No behavior change; preserves watch vs non-watch cleanup semantics Refs #1920
1 parent e1fa4f0 commit 9012668

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

packages/typescript/src/index.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ export default function typescript(options: RollupTypescriptOptions = {}): Plugi
4343
const emittedFiles = new Map<string, string>();
4444
const watchProgramHelper = new WatchProgramHelper();
4545
let autoOutDir: string | null = null;
46+
// Centralize temp outDir cleanup to avoid duplication/drift across hooks
47+
const cleanupAutoOutDir = () => {
48+
if (!autoOutDir) return;
49+
try {
50+
fs.rmSync(autoOutDir, { recursive: true, force: true });
51+
} catch {
52+
// ignore cleanup failures
53+
}
54+
autoOutDir = null;
55+
};
4656

4757
const parsedOptions = parseTypescriptConfig(ts, tsconfig, compilerOptions, noForceEmit);
4858

@@ -175,29 +185,15 @@ export default function typescript(options: RollupTypescriptOptions = {}): Plugi
175185
// ESLint doesn't understand optional chaining
176186
// eslint-disable-next-line
177187
program?.close();
178-
if (autoOutDir) {
179-
try {
180-
fs.rmSync(autoOutDir, { recursive: true, force: true });
181-
} catch {
182-
// ignore cleanup failures
183-
}
184-
autoOutDir = null;
185-
}
188+
cleanupAutoOutDir();
186189
}
187190
},
188191

189192
// Ensure program is closed and temp outDir is removed exactly once when watch stops
190193
closeWatcher() {
191194
// eslint-disable-next-line
192195
program?.close();
193-
if (autoOutDir) {
194-
try {
195-
fs.rmSync(autoOutDir, { recursive: true, force: true });
196-
} catch {
197-
// ignore cleanup failures
198-
}
199-
autoOutDir = null;
200-
}
196+
cleanupAutoOutDir();
201197
},
202198

203199
renderStart(outputOptions) {

0 commit comments

Comments
 (0)