Skip to content

Commit 9a751f0

Browse files
committed
fix(@angular-devkit/build-angular): handle ENOENT and ENOTDIR errors when deleting outputs
Closes #21202
1 parent fd4ae0f commit 9a751f0

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

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

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

9-
import { rmdirSync } from 'fs';
9+
import * as fs from 'fs';
1010
import { resolve } from 'path';
1111

1212
/**
@@ -18,5 +18,22 @@ export function deleteOutputDir(root: string, outputPath: string): void {
1818
throw new Error('Output path MUST not be project root directory!');
1919
}
2020

21-
rmdirSync(resolvedOutputPath, { recursive: true, maxRetries: 3 });
21+
// The below should be removed and replace with just `rmSync` when support for Node.Js 12 is removed.
22+
const { rmSync, rmdirSync } = fs as typeof fs & {
23+
rmSync?: (
24+
path: fs.PathLike,
25+
options?: {
26+
force?: boolean;
27+
maxRetries?: number;
28+
recursive?: boolean;
29+
retryDelay?: number;
30+
},
31+
) => void;
32+
};
33+
34+
if (rmSync) {
35+
rmSync(resolvedOutputPath, { force: true, recursive: true, maxRetries: 3 });
36+
} else {
37+
rmdirSync(resolvedOutputPath, { recursive: true, maxRetries: 3 });
38+
}
2239
}

0 commit comments

Comments
 (0)