MCPcopy Index your code
hub / github.com/angular/angular-cli / modify

Method modify

packages/schematics/angular/utility/json-file.ts:74–108  ·  view source on GitHub ↗
(
    jsonPath: JSONPath,
    value: JsonValue | undefined,
    insertInOrder?: InsertionIndex | false,
  )

Source from the content-addressed store, hash-verified

72 }
73
74 modify(
75 jsonPath: JSONPath,
76 value: JsonValue | undefined,
77 insertInOrder?: InsertionIndex | false,
78 ): void {
79 let getInsertionIndex: InsertionIndex | undefined;
80 if (insertInOrder === undefined) {
81 const property = jsonPath.slice(-1)[0];
82 getInsertionIndex = (properties) =>
83 [...properties, property].sort().findIndex((p) => p === property);
84 } else if (insertInOrder !== false) {
85 getInsertionIndex = insertInOrder;
86 }
87
88 const edits = modify(this.content, jsonPath, value, {
89 getInsertionIndex,
90
91 formattingOptions: {
92 eol: this.eol,
93 insertSpaces: true,
94 tabSize: 2,
95 },
96 });
97
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 }
108 }
109
110 remove(jsonPath: JSONPath): void {
111 if (this.get(jsonPath) !== undefined) {

Callers 14

updateTsConfigFunction · 0.95
addTsProjectReferenceFunction · 0.95
updateTsConfigRuleFunction · 0.95
addPackageJsonDependencyFunction · 0.95
removeMethod · 0.95
addTsProjectReferenceFunction · 0.95
updateTsConfigTypesFunction · 0.95
updateBuildTargetFunction · 0.95
updateTsConfigFileFunction · 0.95

Calls 1

overwriteMethod · 0.65

Tested by

no test coverage detected