6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
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' ;
11
11
12
12
/**
13
13
* Delete an output directory, but error out if it's the root of the project.
14
14
*/
15
- export function deleteOutputDir ( root : string , outputPath : string ) : void {
15
+ export async function deleteOutputDir ( root : string , outputPath : string ) : Promise < void > {
16
16
const resolvedOutputPath = resolve ( root , outputPath ) ;
17
17
if ( resolvedOutputPath === root ) {
18
18
throw new Error ( 'Output path MUST not be project root directory!' ) ;
@@ -22,7 +22,7 @@ export function deleteOutputDir(root: string, outputPath: string): void {
22
22
// directory is mounted or symlinked. Instead the contents are removed.
23
23
let entries ;
24
24
try {
25
- entries = fs . readdirSync ( resolvedOutputPath ) ;
25
+ entries = await readdir ( resolvedOutputPath ) ;
26
26
} catch ( error ) {
27
27
if ( error instanceof Error && 'code' in error && error . code === 'ENOENT' ) {
28
28
return ;
@@ -31,6 +31,6 @@ export function deleteOutputDir(root: string, outputPath: string): void {
31
31
}
32
32
33
33
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 } ) ;
35
35
}
36
36
}
0 commit comments