summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Cournoyer <maxim@guixotic.coop>2026-06-11 15:50:48 +0900
committerAndreas Enge <andreas@enge.fr>2026-07-08 18:33:27 +0200
commitef58e493c341ff4f61fb8caf4e14f02fd28c55d3 (patch)
tree54890fea35d0631a96e06dcfa6da1afdf345991c
parent230a8b05a844a67f2eeb0f554301d1fe2b52a937 (diff)
build/node: Preserve field order of modified JSON files.
* guix/build/node-build-system.scm (with-atomic-json-file-replacement): Call json->scm with #:ordered #t. * tests/node.scm ("modify-json, ordering"): New test. ("delete-dev-dependencies/except"): Adjust expected output accordingly. Change-Id: I9cf0475a7bac0cad8f5fd3d479c50eb35eac3f32
-rw-r--r--guix/build/node-build-system.scm2
-rw-r--r--tests/node.scm13
2 files changed, 12 insertions, 3 deletions
diff --git a/guix/build/node-build-system.scm b/guix/build/node-build-system.scm
index ac7af1a016d..08623f97756 100644
--- a/guix/build/node-build-system.scm
+++ b/guix/build/node-build-system.scm
@@ -58,7 +58,7 @@ argument---the result of parsing FILE's contents as JSON---and should produce
58a value to be written as JSON to the replacement FILE." 58a value to be written as JSON to the replacement FILE."
59 (with-atomic-file-replacement file 59 (with-atomic-file-replacement file
60 (lambda (in out) 60 (lambda (in out)
61 (scm->json (proc (json->scm in)) out #:pretty #t)))) 61 (scm->json (proc (json->scm in #:ordered #t)) out #:pretty #t))))
62 62
63(define* (modify-json #:key (file "package.json") #:rest all-arguments) 63(define* (modify-json #:key (file "package.json") #:rest all-arguments)
64 "Provide package.json modifying callbacks such as (delete-dependencies ...)" 64 "Provide package.json modifying callbacks such as (delete-dependencies ...)"
diff --git a/tests/node.scm b/tests/node.scm
index 5159d530a12..7328ac91e8e 100644
--- a/tests/node.scm
+++ b/tests/node.scm
@@ -76,6 +76,15 @@ It also returns the data as an alist directly."
76 76
77(test-begin "node related tests") 77(test-begin "node related tests")
78 78
79(test-equal "modify-json, ordering"
80 '(("mkdirp" . ">=1.0.0")
81 ("react" . "^16.8.0"))
82 (assoc-ref (modify-json* (modify-json-fields
83 '("peerDependencies.react")
84 (lambda (field-path data key)
85 data)))
86 "peerDependencies"))
87
79(test-equal "delete-dependencies" 88(test-equal "delete-dependencies"
80 '(("domelementtype" . "^3.0.0")) 89 '(("domelementtype" . "^3.0.0"))
81 (assoc-ref (modify-json* 90 (assoc-ref (modify-json*
@@ -89,8 +98,8 @@ It also returns the data as an alist directly."
89 "dependencies")) 98 "dependencies"))
90 99
91(test-equal "delete-dev-dependencies/except" 100(test-equal "delete-dev-dependencies/except"
92 '(("@types/node" . "^25.9.2") 101 '(("typescript" . "^5.9.3")
93 ("typescript" . "^5.9.3")) 102 ("@types/node" . "^25.9.2"))
94 (assoc-ref (modify-json* 103 (assoc-ref (modify-json*
95 (delete-dev-dependencies/except 104 (delete-dev-dependencies/except
96 '("typescript" "@types/node"))) 105 '("typescript" "@types/node")))