Skip to content

Commit 1c2d49e

Browse files
committed
fix(@angular/build): cleanup karma temporary directory after process exit
The temporary directory created for the karma builder will now be cleaned up after the process exits.
1 parent 7362199 commit 1c2d49e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

packages/angular/build/src/builders/karma/application_builder.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import type { BuilderContext, BuilderOutput } from '@angular-devkit/architect';
1010
import type { Config, ConfigOptions, FilePattern, InlinePluginDef, Server } from 'karma';
1111
import { randomUUID } from 'node:crypto';
12+
import { rmSync } from 'node:fs';
1213
import * as fs from 'node:fs/promises';
1314
import path from 'node:path';
1415
import { ReadableStream } from 'node:stream/web';
@@ -104,8 +105,15 @@ async function initializeApplication(
104105
> {
105106
const karma = await import('karma');
106107
const projectSourceRoot = await getProjectSourceRoot(context);
108+
109+
// Setup temporary output path and ensure it is empty
107110
const outputPath = path.join(context.workspaceRoot, 'dist/test-out', randomUUID());
108111
await fs.rm(outputPath, { recursive: true, force: true });
112+
// Setup exit cleanup for temporary directory
113+
const handleProcessExit = () => rmSync(outputPath, { recursive: true, force: true });
114+
process.once('exit', handleProcessExit);
115+
process.once('SIGINT', handleProcessExit);
116+
process.once('uncaughtException', handleProcessExit);
109117

110118
const { buildOptions, mainName } = await setupBuildOptions(
111119
options,

0 commit comments

Comments
 (0)