Skip to content

Commit ef5d82a

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. (cherry picked from commit 1c2d49e)
1 parent 9004951 commit ef5d82a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

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

Lines changed: 7 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 type { IncomingMessage, ServerResponse } from 'node:http';
1415
import { createRequire } from 'node:module';
@@ -386,6 +387,12 @@ async function initializeApplication(
386387
const outputPath = path.join(context.workspaceRoot, 'dist/test-out', randomUUID());
387388
const projectSourceRoot = await getProjectSourceRoot(context);
388389

390+
// Setup exit cleanup for temporary directory
391+
const handleProcessExit = () => rmSync(outputPath, { recursive: true, force: true });
392+
process.once('exit', handleProcessExit);
393+
process.once('SIGINT', handleProcessExit);
394+
process.once('uncaughtException', handleProcessExit);
395+
389396
const [karma, entryPoints] = await Promise.all([
390397
import('karma'),
391398
collectEntrypoints(options, context, projectSourceRoot),

0 commit comments

Comments
 (0)