Skip to content

Commit 664e6c7

Browse files
committed
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.
1 parent c7e73fa commit 664e6c7

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

packages/schematics/angular/utility/json-file.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,16 @@ export class JSONFile {
9595
},
9696
});
9797

98-
this.content = applyEdits(this.content, edits);
99-
this.host.overwrite(this.path, this.content);
100-
this._jsonAst = undefined;
98+
if (edits.length > 0) {
99+
const editedContent = applyEdits(this.content, edits);
100+
101+
// Update the file content if it changed
102+
if (editedContent !== this.content) {
103+
this.content = editedContent;
104+
this.host.overwrite(this.path, editedContent);
105+
this._jsonAst = undefined;
106+
}
107+
}
101108
}
102109

103110
remove(jsonPath: JSONPath): void {

0 commit comments

Comments
 (0)