Skip to content

Commit 2b5409b

Browse files
committed
refactor(@angular-devkit/build-angular): update deleteOutputDir to use FS promise APIs
As per commit title.
1 parent 0003420 commit 2b5409b

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

packages/angular_devkit/build_angular/src/builders/browser/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ async function initialize(
107107
}
108108

109109
if (options.deleteOutputPath) {
110-
deleteOutputDir(context.workspaceRoot, originalOutputPath);
110+
await deleteOutputDir(context.workspaceRoot, originalOutputPath);
111111
}
112112

113113
return { config: transformedConfig || config, projectRoot, projectSourceRoot, i18n };

packages/angular_devkit/build_angular/src/builders/server/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ async function initialize(
217217
);
218218

219219
if (options.deleteOutputPath) {
220-
deleteOutputDir(context.workspaceRoot, originalOutputPath);
220+
await deleteOutputDir(context.workspaceRoot, originalOutputPath);
221221
}
222222

223223
const transformedConfig = (await webpackConfigurationTransform?.(config)) ?? config;

packages/angular_devkit/build_angular/src/utils/delete-output-dir.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import * as fs from 'fs';
10-
import { join, resolve } from 'path';
9+
import { readdir, rm } from 'node:fs/promises';
10+
import { join, resolve } from 'node:path';
1111

1212
/**
1313
* Delete an output directory, but error out if it's the root of the project.
1414
*/
15-
export function deleteOutputDir(root: string, outputPath: string): void {
15+
export async function deleteOutputDir(root: string, outputPath: string): Promise<void> {
1616
const resolvedOutputPath = resolve(root, outputPath);
1717
if (resolvedOutputPath === root) {
1818
throw new Error('Output path MUST not be project root directory!');
@@ -22,7 +22,7 @@ export function deleteOutputDir(root: string, outputPath: string): void {
2222
// directory is mounted or symlinked. Instead the contents are removed.
2323
let entries;
2424
try {
25-
entries = fs.readdirSync(resolvedOutputPath);
25+
entries = await readdir(resolvedOutputPath);
2626
} catch (error) {
2727
if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {
2828
return;
@@ -31,6 +31,6 @@ export function deleteOutputDir(root: string, outputPath: string): void {
3131
}
3232

3333
for (const entry of entries) {
34-
fs.rmSync(join(resolvedOutputPath, entry), { force: true, recursive: true, maxRetries: 3 });
34+
await rm(join(resolvedOutputPath, entry), { force: true, recursive: true, maxRetries: 3 });
3535
}
3636
}

0 commit comments

Comments
 (0)