Skip to content

Commit d8c9f6e

Browse files
clydinfilipesilva
authored andcommitted
fix(@angular/cli): update the update command to fully support Node.js v16
Node.js v16's `fs.rmdir` will now throw an `ENOENT` error if the path does not exist. `fs.rm` is now the preferred option when using Node.js v16 but since this function is not available on Node.js v12 both are tried with `fs.rm` given preference. In the case of the update command, the usage was guarded by a try/catch block with the downside of leaving the `fs.rmdir` being that a deprecation warning would be shown when running the command which is not ideal.
1 parent b7416d5 commit d8c9f6e

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

packages/angular/cli/commands/update-impl.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -656,10 +656,32 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
656656
try {
657657
// Remove existing node modules directory to provide a stronger guarantee that packages
658658
// will be hoisted into the correct locations.
659-
await fs.promises.rmdir(path.join(this.context.root, 'node_modules'), {
660-
recursive: true,
661-
maxRetries: 3,
662-
});
659+
660+
// The below should be removed and replaced with just `rm` when support for Node.Js 12 is removed.
661+
const { rm, rmdir } = fs.promises as typeof fs.promises & {
662+
rm?: (
663+
path: fs.PathLike,
664+
options?: {
665+
force?: boolean;
666+
maxRetries?: number;
667+
recursive?: boolean;
668+
retryDelay?: number;
669+
},
670+
) => Promise<void>;
671+
};
672+
673+
if (rm) {
674+
await rm(path.join(this.context.root, 'node_modules'), {
675+
force: true,
676+
recursive: true,
677+
maxRetries: 3,
678+
});
679+
} else {
680+
await rmdir(path.join(this.context.root, 'node_modules'), {
681+
recursive: true,
682+
maxRetries: 3,
683+
});
684+
}
663685
} catch {}
664686

665687
const result = await installAllPackages(

0 commit comments

Comments
 (0)