|
9 | 9 | import type { BuilderContext, BuilderOutput } from '@angular-devkit/architect';
|
10 | 10 | import type { Config, ConfigOptions, FilePattern, InlinePluginDef, Server } from 'karma';
|
11 | 11 | import { randomUUID } from 'node:crypto';
|
| 12 | +import { rmSync } from 'node:fs'; |
12 | 13 | import * as fs from 'node:fs/promises';
|
13 | 14 | import path from 'node:path';
|
14 | 15 | import { ReadableStream } from 'node:stream/web';
|
@@ -104,8 +105,15 @@ async function initializeApplication(
|
104 | 105 | > {
|
105 | 106 | const karma = await import('karma');
|
106 | 107 | const projectSourceRoot = await getProjectSourceRoot(context);
|
| 108 | + |
| 109 | + // Setup temporary output path and ensure it is empty |
107 | 110 | const outputPath = path.join(context.workspaceRoot, 'dist/test-out', randomUUID());
|
108 | 111 | 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); |
109 | 117 |
|
110 | 118 | const { buildOptions, mainName } = await setupBuildOptions(
|
111 | 119 | options,
|
|
0 commit comments