Skip to content

Commit b615ca4

Browse files
authored
Merge pull request #1019 from dkundel/dkundel/fix-memory-json-patch
fix: change JSON patch implementation for memory improvement
2 parents d837eb9 + 37a4a65 commit b615ca4

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ x
1515

1616
<!-- Your comment below this -->
1717

18+
- Changed JSON patch implementation for better memory performance. [@dkundel] **Breaking:** `JSONPatchForFile` will
19+
return a different order of operations than previously. It will also return a `path` with the index of the element
20+
inserted into an array for `add` operations.
21+
1822
<!-- Your comment above this -->
1923

2024
# 9.3.1
@@ -1729,6 +1733,7 @@ Not usable for others, only stubs of classes etc. - [@orta]
17291733
[@danielrosenwasser]: https://github.com/DanielRosenwasser
17301734
[@davidbrunow]: https://github.com/davidbrunow
17311735
[@dfalling]: https://github.com/dfalling
1736+
[@dkundel]: https://github.com/dkundel
17321737
[@f-meloni]: https://github.com/f-meloni
17331738
[@fbartho]: https://github.com/fbartho
17341739
[@fwal]: https://github.com/fwal

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
"chalk": "^2.3.0",
142142
"commander": "^2.18.0",
143143
"debug": "^4.1.1",
144+
"fast-json-patch": "^3.0.0-1",
144145
"get-stdin": "^6.0.0",
145146
"gitlab": "^10.0.1",
146147
"http-proxy-agent": "^2.1.0",
@@ -169,7 +170,6 @@
169170
"prettyjson": "^1.2.1",
170171
"readline-sync": "^1.4.9",
171172
"require-from-string": "^2.0.2",
172-
"rfc6902": "^3.0.1",
173173
"supports-hyperlinks": "^1.0.1"
174174
},
175175
"optionalDependencies": {},

source/platforms/git/gitJSONToGitDSL.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import isobject from "lodash.isobject"
66
import keys from "lodash.keys"
77
import memoize from "lodash.memoize"
88

9-
import * as jsonDiff from "rfc6902"
9+
import * as jsonDiff from "fast-json-patch"
1010
import jsonpointer from "jsonpointer"
1111
import JSON5 from "json5"
1212

@@ -88,7 +88,7 @@ export const gitJSONToGitDSL = (gitJSONRep: GitJSONDSL, config: GitJSONToGitDSLC
8888
return {
8989
before: baseFile === "" ? null : baseJSON,
9090
after: headFile === "" ? null : headJSON,
91-
diff: jsonDiff.createPatch(baseJSON, headJSON) as JSONPatchOperation[],
91+
diff: jsonDiff.compare(baseJSON, headJSON) as JSONPatchOperation[],
9292
}
9393
}
9494

source/platforms/github/_tests/_github_git.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ describe("the dangerfile gitDSL", () => {
222222
expect(empty).toEqual({
223223
before: before,
224224
after: null,
225-
diff: [{ op: "remove", path: "/a" }, { op: "remove", path: "/b" }, { op: "remove", path: "/c" }],
225+
diff: [{ op: "remove", path: "/c" }, { op: "remove", path: "/b" }, { op: "remove", path: "/a" }],
226226
})
227227
})
228228

@@ -251,9 +251,9 @@ describe("the dangerfile gitDSL", () => {
251251
before,
252252
after,
253253
diff: [
254-
{ op: "replace", path: "/a", value: "o, world" },
254+
{ op: "add", path: "/c/3", value: "four" },
255255
{ op: "replace", path: "/b", value: 3 },
256-
{ op: "add", path: "/c/-", value: "four" },
256+
{ op: "replace", path: "/a", value: "o, world" },
257257
],
258258
})
259259
})

yarn.lock

+5-5
Original file line numberDiff line numberDiff line change
@@ -3892,6 +3892,11 @@ fast-glob@^3.0.3:
38923892
merge2 "^1.3.0"
38933893
micromatch "^4.0.2"
38943894

3895+
fast-json-patch@^3.0.0-1:
3896+
version "3.0.0-1"
3897+
resolved "https://registry.yarnpkg.com/fast-json-patch/-/fast-json-patch-3.0.0-1.tgz#4c68f2e7acfbab6d29d1719c44be51899c93dabb"
3898+
integrity sha512-6pdFb07cknxvPzCeLsFHStEy+MysPJPgZQ9LbQ/2O67unQF93SNqfdSqnPPl71YMHX+AD8gbl7iuoGFzHEdDuw==
3899+
38953900
[email protected], fast-json-stable-stringify@^2.0.0:
38963901
version "2.0.0"
38973902
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#d5142c0caee6b1189f87d3a76111064f86c8bbf2"
@@ -8342,11 +8347,6 @@ reusify@^1.0.0:
83428347
resolved "https://registry.yarnpkg.com/reusify/-/reusify-1.0.4.tgz#90da382b1e126efc02146e90845a88db12925d76"
83438348
integrity sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==
83448349

8345-
rfc6902@^3.0.1:
8346-
version "3.0.1"
8347-
resolved "https://registry.yarnpkg.com/rfc6902/-/rfc6902-3.0.1.tgz#03a3d38329dbc266fbc92aa7fc14546d7839e89f"
8348-
integrity sha512-a4t5OlaOgAejBg48/lkyQMcV6EWpljjSjmXAtSXLhw83x1OhlcVGLMLf//GoUSpHsWt8x/7oxaf5FEGM9QH/iQ==
8349-
83508350
right-align@^0.1.1:
83518351
version "0.1.3"
83528352
resolved "https://registry.yarnpkg.com/right-align/-/right-align-0.1.3.tgz#61339b722fe6a3515689210d24e14c96148613ef"

0 commit comments

Comments
 (0)