From 5b8350e5787c6fcb62ca09878a7cd075616d6af8 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Thu, 29 May 2025 12:31:54 -0400 Subject: [PATCH] fix(@schematics/angular): only overwrite JSON file if actually changed The JSON file helper utility used within the Angular schematics now contains additional checks when attempting to modify a file to avoid overwriting a file if no actual changes will occur after a modify request. --- packages/schematics/angular/utility/json-file.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/schematics/angular/utility/json-file.ts b/packages/schematics/angular/utility/json-file.ts index dffb7a94f997..e7c767745b90 100644 --- a/packages/schematics/angular/utility/json-file.ts +++ b/packages/schematics/angular/utility/json-file.ts @@ -95,9 +95,16 @@ export class JSONFile { }, }); - this.content = applyEdits(this.content, edits); - this.host.overwrite(this.path, this.content); - this._jsonAst = undefined; + if (edits.length > 0) { + const editedContent = applyEdits(this.content, edits); + + // Update the file content if it changed + if (editedContent !== this.content) { + this.content = editedContent; + this.host.overwrite(this.path, editedContent); + this._jsonAst = undefined; + } + } } remove(jsonPath: JSONPath): void {