Skip to content

Commit 2fbccfa

Browse files
committed
use stable stringify for state file
1 parent dd4de6a commit 2fbccfa

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

integration-tests/apply-multiple-patches/__snapshots__/apply-multiple-patches.test.ts.snap

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ END SNAPSHOT"
4545
exports[`Test apply-multiple-patches: 03: patch-package stores a state file of only the first patch if there was an error 1`] = `
4646
"SNAPSHOT: patch-package stores a state file of only the first patch if there was an error
4747
{
48-
\\"version\\": 0,
4948
\\"patches\\": [
5049
{
51-
\\"patchFilename\\": \\"left-pad+1.3.0+001+hello.patch\\",
50+
\\"didApply\\": true,
5251
\\"patchContentHash\\": \\"404c604ed830db6a0605f86cb9165ced136848f70986b23bf877bcf38968c1c9\\",
53-
\\"didApply\\": true
52+
\\"patchFilename\\": \\"left-pad+1.3.0+001+hello.patch\\"
5453
}
55-
]
54+
],
55+
\\"version\\": 0
5656
}END SNAPSHOT"
5757
`;
5858

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"@types/cross-spawn": "^6.0.0",
5353
"@types/fs-extra": "^9.0.0",
5454
"@types/jest": "^24.0.11",
55+
"@types/json-stable-stringify": "^1.0.34",
5556
"@types/minimist": "^1.2.2",
5657
"@types/node": "^12.0.0",
5758
"@types/rimraf": "^2.0.2",
@@ -75,6 +76,7 @@
7576
"cross-spawn": "^7.0.3",
7677
"find-yarn-workspace-root": "^2.0.0",
7778
"fs-extra": "^9.0.0",
79+
"json-stable-stringify": "^1.0.2",
7880
"klaw-sync": "^6.0.0",
7981
"minimist": "^1.2.6",
8082
"open": "^7.4.2",

src/stateFile.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { readFileSync, unlinkSync, writeFileSync } from "fs"
22
import { join } from "path"
33
import { PackageDetails } from "./PackageDetails"
4+
import stringify from "json-stable-stringify"
45
export interface PatchState {
56
patchFilename: string
67
patchContentHash: string
@@ -36,7 +37,7 @@ export function savePatchApplicationState(
3637
) {
3738
const fileName = join(packageDetails.path, STATE_FILE_NAME)
3839

39-
writeFileSync(fileName, JSON.stringify({ version, patches }, null, 2), "utf8")
40+
writeFileSync(fileName, stringify({ version, patches }, { space: 2 }), "utf8")
4041
}
4142

4243
export function clearPatchApplicationState(packageDetails: PackageDetails) {

yarn.lock

+17
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,11 @@
449449
dependencies:
450450
"@types/jest-diff" "*"
451451

452+
"@types/json-stable-stringify@^1.0.34":
453+
version "1.0.34"
454+
resolved "https://registry.yarnpkg.com/@types/json-stable-stringify/-/json-stable-stringify-1.0.34.tgz#c0fb25e4d957e0ee2e497c1f553d7f8bb668fd75"
455+
integrity sha512-s2cfwagOQAS8o06TcwKfr9Wx11dNGbH2E9vJz1cqV+a/LOyhWNLUNd6JSRYNzvB4d29UuJX2M0Dj9vE1T8fRXw==
456+
452457
"@types/keyv@*", "@types/keyv@^3.1.1":
453458
version "3.1.1"
454459
resolved "https://registry.yarnpkg.com/@types/keyv/-/keyv-3.1.1.tgz#e45a45324fca9dab716ab1230ee249c9fb52cfa7"
@@ -3282,6 +3287,13 @@ [email protected]:
32823287
version "0.2.3"
32833288
resolved "https://registry.yarnpkg.com/json-schema/-/json-schema-0.2.3.tgz#b480c892e59a2f05954ce727bd3f2a4e882f9e13"
32843289

3290+
json-stable-stringify@^1.0.2:
3291+
version "1.0.2"
3292+
resolved "https://registry.yarnpkg.com/json-stable-stringify/-/json-stable-stringify-1.0.2.tgz#e06f23128e0bbe342dc996ed5a19e28b57b580e0"
3293+
integrity sha512-eunSSaEnxV12z+Z73y/j5N37/In40GK4GmsSy+tEHJMxknvqnA7/djeYtAgW0GsWHUfg+847WJjKaEylk2y09g==
3294+
dependencies:
3295+
jsonify "^0.0.1"
3296+
32853297
json-stringify-safe@~5.0.1:
32863298
version "5.0.1"
32873299
resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb"
@@ -3302,6 +3314,11 @@ jsonfile@^6.0.1:
33023314
optionalDependencies:
33033315
graceful-fs "^4.1.6"
33043316

3317+
jsonify@^0.0.1:
3318+
version "0.0.1"
3319+
resolved "https://registry.yarnpkg.com/jsonify/-/jsonify-0.0.1.tgz#2aa3111dae3d34a0f151c63f3a45d995d9420978"
3320+
integrity sha512-2/Ki0GcmuqSrgFyelQq9M05y7PS0mEwuIzrf3f1fPqkVDVRvZrPZtVSMHxdgo8Aq0sxAOb/cr2aqqA3LeWHVPg==
3321+
33053322
jsprim@^1.2.2:
33063323
version "1.4.0"
33073324
resolved "https://registry.yarnpkg.com/jsprim/-/jsprim-1.4.0.tgz#a3b87e40298d8c380552d8cc7628a0bb95a22918"

0 commit comments

Comments
 (0)