Skip to content

Commit 8afb687

Browse files
committed
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. [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
1 parent e2375c9 commit 8afb687

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
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 { existsSync, rmdirSync } from 'fs';
1010
import { resolve } from 'path';
1111

1212
/**
@@ -18,5 +18,11 @@ 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+
// NOTE: `recursive: true` does not silence errors about existence on node
22+
// v16. `rmdirSync` recursive is deprecated and when node v14.14.0 is
23+
// the default `rmSync` should be used with `force: true` in addition
24+
// to the existing options.
25+
if (existsSync(resolvedOutputPath)) {
26+
rmdirSync(resolvedOutputPath, { recursive: true, maxRetries: 3 });
27+
}
2228
}

0 commit comments

Comments
 (0)