From a731b43d23e6abae5313b94af1c3bc7d6b99fbb4 Mon Sep 17 00:00:00 2001 From: "Terence D. Honles" Date: Sat, 26 Jun 2021 13:33:25 -0700 Subject: [PATCH] fix(@angular-devkit/build-angular): fix node 16 breaking when deleting the output path According to `rmdirSync` [1] the `recursive` option is deprecated. The wording looks like it was changed (compared to Node LTS [2]) to not include anything about ignoring errors on paths not existing. In the future the call should be `rmSync(..., {..., force: true})`, but when testing locally adding a "force" option does not restore the previous behavior. This isn't documented to work, but since the code original code is deprecated I was wondering if the underlying functionality was just passing all the options `rmSync` on Node 16. This change includes an existence check to skip deleting a non existent directory. closes: #21216 [1]: https://nodejs.org/api/fs.html#fs_fs_rmdirsync_path_options [2]: https://nodejs.org/docs/latest-v14.x/api/fs.html#fs_fs_rmdirsync_path_options --- .../build_angular/src/utils/delete-output-dir.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/angular_devkit/build_angular/src/utils/delete-output-dir.ts b/packages/angular_devkit/build_angular/src/utils/delete-output-dir.ts index dd783462e853..3ecd08995880 100644 --- a/packages/angular_devkit/build_angular/src/utils/delete-output-dir.ts +++ b/packages/angular_devkit/build_angular/src/utils/delete-output-dir.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import { rmdirSync } from 'fs'; +import { existsSync, rmdirSync } from 'fs'; import { resolve } from 'path'; /** @@ -18,5 +18,11 @@ 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 }); + // NOTE: `recursive: true` does not silence errors about existence on node + // v16. `rmdirSync` recursive is deprecated and when node v14.14.0 is + // the default `rmSync` should be used with `force: true` in addition + // to the existing options. + if (existsSync(resolvedOutputPath)) { + rmdirSync(resolvedOutputPath, { recursive: true, maxRetries: 3 }); + } }