Skip to content

Commit

Permalink
use stable stringify for state file
Browse files Browse the repository at this point in the history
  • Loading branch information
ds300 committed Jul 12, 2023
1 parent dd4de6a commit 2fbccfa
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ END SNAPSHOT"
exports[`Test apply-multiple-patches: 03: patch-package stores a state file of only the first patch if there was an error 1`] = `
"SNAPSHOT: patch-package stores a state file of only the first patch if there was an error
{
\\"version\\": 0,
\\"patches\\": [
{
\\"patchFilename\\": \\"left-pad+1.3.0+001+hello.patch\\",
\\"didApply\\": true,
\\"patchContentHash\\": \\"404c604ed830db6a0605f86cb9165ced136848f70986b23bf877bcf38968c1c9\\",
\\"didApply\\": true
\\"patchFilename\\": \\"left-pad+1.3.0+001+hello.patch\\"
}
]
],
\\"version\\": 0
}END SNAPSHOT"
`;

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"@types/cross-spawn": "^6.0.0",
"@types/fs-extra": "^9.0.0",
"@types/jest": "^24.0.11",
"@types/json-stable-stringify": "^1.0.34",
"@types/minimist": "^1.2.2",
"@types/node": "^12.0.0",
"@types/rimraf": "^2.0.2",
Expand All @@ -75,6 +76,7 @@
"cross-spawn": "^7.0.3",
"find-yarn-workspace-root": "^2.0.0",
"fs-extra": "^9.0.0",
"json-stable-stringify": "^1.0.2",
"klaw-sync": "^6.0.0",
"minimist": "^1.2.6",
"open": "^7.4.2",
Expand Down
3 changes: 2 additions & 1 deletion src/stateFile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { readFileSync, unlinkSync, writeFileSync } from "fs"
import { join } from "path"
import { PackageDetails } from "./PackageDetails"
import stringify from "json-stable-stringify"
export interface PatchState {
patchFilename: string
patchContentHash: string
Expand Down Expand Up @@ -36,7 +37,7 @@ export function savePatchApplicationState(
) {
const fileName = join(packageDetails.path, STATE_FILE_NAME)

writeFileSync(fileName, JSON.stringify({ version, patches }, null, 2), "utf8")
writeFileSync(fileName, stringify({ version, patches }, { space: 2 }), "utf8")
}

export function clearPatchApplicationState(packageDetails: PackageDetails) {
Expand Down
17 changes: 17 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,11 @@
dependencies:
"@types/jest-diff" "*"

"@types/json-stable-stringify@^1.0.34":
version "1.0.34"
resolved "https://registry.yarnpkg.com/@types/json-stable-stringify/-/json-stable-stringify-1.0.34.tgz#c0fb25e4d957e0ee2e497c1f553d7f8bb668fd75"
integrity sha512-s2cfwagOQAS8o06TcwKfr9Wx11dNGbH2E9vJz1cqV+a/LOyhWNLUNd6JSRYNzvB4d29UuJX2M0Dj9vE1T8fRXw==

"@types/keyv@*", "@types/keyv@^3.1.1":
version "3.1.1"
resolved "https://registry.yarnpkg.com/@types/keyv/-/keyv-3.1.1.tgz#e45a45324fca9dab716ab1230ee249c9fb52cfa7"
Expand Down Expand Up @@ -3282,6 +3287,13 @@ json-schema@0.2.3:
version "0.2.3"
resolved "https://registry.yarnpkg.com/json-schema/-/json-schema-0.2.3.tgz#b480c892e59a2f05954ce727bd3f2a4e882f9e13"

json-stable-stringify@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/json-stable-stringify/-/json-stable-stringify-1.0.2.tgz#e06f23128e0bbe342dc996ed5a19e28b57b580e0"
integrity sha512-eunSSaEnxV12z+Z73y/j5N37/In40GK4GmsSy+tEHJMxknvqnA7/djeYtAgW0GsWHUfg+847WJjKaEylk2y09g==
dependencies:
jsonify "^0.0.1"

json-stringify-safe@~5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb"
Expand All @@ -3302,6 +3314,11 @@ jsonfile@^6.0.1:
optionalDependencies:
graceful-fs "^4.1.6"

jsonify@^0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/jsonify/-/jsonify-0.0.1.tgz#2aa3111dae3d34a0f151c63f3a45d995d9420978"
integrity sha512-2/Ki0GcmuqSrgFyelQq9M05y7PS0mEwuIzrf3f1fPqkVDVRvZrPZtVSMHxdgo8Aq0sxAOb/cr2aqqA3LeWHVPg==

jsprim@^1.2.2:
version "1.4.0"
resolved "https://registry.yarnpkg.com/jsprim/-/jsprim-1.4.0.tgz#a3b87e40298d8c380552d8cc7628a0bb95a22918"
Expand Down

0 comments on commit 2fbccfa

Please sign in to comment.