perf(@angular-devkit/build-angular): asynchronously delete output path in esbuild builder

When using the esbuild-based browser application builder, the output path is deleted
prior to performing a build to ensure a clean output with only the built files. The
deletion will now be performed asynchronously using the Node.js promised-based API.
This should provide a small performance improvement for projects with large output
directories.
This commit is contained in:
Charles Lyding 2023-04-11 16:21:14 -04:00 committed by angular-robot[bot]
parent 11fa1221f0
commit df49c359de

View File

@ -12,7 +12,6 @@ import assert from 'node:assert';
import { constants as fsConstants } from 'node:fs';
import fs from 'node:fs/promises';
import path from 'node:path';
import { deleteOutputDir } from '../../utils';
import { copyAssets } from '../../utils/copy-assets';
import { assertIsError } from '../../utils/error';
import { transformSupportedBrowsersToTargets } from '../../utils/esbuild-targets';
@ -623,7 +622,13 @@ export async function* buildEsbuildBrowser(
if (shouldWriteResult) {
// Clean output path if enabled
if (userOptions.deleteOutputPath) {
deleteOutputDir(normalizedOptions.workspaceRoot, userOptions.outputPath);
if (normalizedOptions.outputPath === normalizedOptions.workspaceRoot) {
context.logger.error('Output path MUST not be workspace root directory!');
return;
}
await fs.rm(normalizedOptions.outputPath, { force: true, recursive: true, maxRetries: 3 });
}
// Create output directory if needed