Navigation Menu

Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): handle ENOENT and ENOTDIR err…
Browse files Browse the repository at this point in the history
…ors when deleting outputs

Closes #21202

(cherry picked from commit 9a751f0)
  • Loading branch information
alan-agius4 committed Jun 28, 2021
1 parent 7dd0145 commit 8e52c9c
Showing 1 changed file with 19 additions and 2 deletions.
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import { rmdirSync } from 'fs';
import * as fs from 'fs';
import { resolve } from 'path';

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

rmdirSync(resolvedOutputPath, { recursive: true, maxRetries: 3 });
// The below should be removed and replace with just `rmSync` when support for Node.Js 12 is removed.
const { rmSync, rmdirSync } = fs as typeof fs & {
rmSync?: (
path: fs.PathLike,
options?: {
force?: boolean;
maxRetries?: number;
recursive?: boolean;
retryDelay?: number;
},
) => void;
};

if (rmSync) {
rmSync(resolvedOutputPath, { force: true, recursive: true, maxRetries: 3 });
} else {
rmdirSync(resolvedOutputPath, { recursive: true, maxRetries: 3 });
}
}

0 comments on commit 8e52c9c

Please sign in to comment.