Skip to content

Commit bb14537

Browse files
branchseerclaude
andcommitted
Rename json-edit to json-patch using the json-patch crate (RFC 6902)
Replace custom path/value parsing with standard JSON Patch operations, reducing ~150 lines of hand-rolled code to a 4-line implementation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ebfb5f1 commit bb14537

File tree

15 files changed

+50
-162
lines changed

15 files changed

+50
-162
lines changed

Cargo.lock

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ fspy_shared_unix = { path = "crates/fspy_shared_unix" }
8181
futures = "0.3.31"
8282
futures-util = "0.3.31"
8383
insta = "1.44.3"
84+
json-patch = "4.1.0"
8485
jsonc-parser = { version = "0.29.0", features = ["serde"] }
8586
libc = "0.2.172"
8687
memmap2 = "0.9.7"

crates/vite_task_bin/tests/e2e_snapshots/fixtures/associate-existing-cache/snapshots.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ name = "associate existing cache"
55
steps = [
66
"vt run script1 # cache miss",
77
"vt run script2 # cache hit, same command as script1",
8-
"vtt json-edit package.json '_.scripts.script2 = \"vtt print world\"' # change script2",
8+
"vtt json-patch package.json '[{\"op\":\"add\",\"path\":\"/scripts/script2\",\"value\":\"vtt print world\"}]' # change script2",
99
"vt run script2 # cache miss",
1010
]

crates/vite_task_bin/tests/e2e_snapshots/fixtures/associate-existing-cache/snapshots/associate existing cache.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ hello
1111

1212
---
1313
vt run: cache hit.
14-
> vtt json-edit package.json '_.scripts.script2 = "vtt print world"' # change script2
14+
> vtt json-patch package.json '[{"op":"add","path":"/scripts/script2","value":"vtt print world"}]' # change script2
1515

1616
> vt run script2 # cache miss
1717
$ vtt print worldcache miss: args changed, executing

crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-miss-command-change/snapshots.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
name = "cache miss command change"
55
steps = [
66
"vt run task # cache miss",
7-
"vtt json-edit vite-task.json '_.tasks.task.command = \"vtt print baz && vtt print bar\"' # change first subtask",
7+
"vtt json-patch vite-task.json '[{\"op\":\"replace\",\"path\":\"/tasks/task/command\",\"value\":\"vtt print baz && vtt print bar\"}]' # change first subtask",
88
"vt run task # first: cache miss, second: cache hit",
9-
"vtt json-edit vite-task.json '_.tasks.task.command = \"vtt print bar\"' # remove first subtask",
9+
"vtt json-patch vite-task.json '[{\"op\":\"replace\",\"path\":\"/tasks/task/command\",\"value\":\"vtt print bar\"}]' # remove first subtask",
1010
"vt run task # cache hit",
1111
]

crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-miss-command-change/snapshots/cache miss command change.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ bar
1111

1212
---
1313
vt run: 0/2 cache hit (0%). (Run `vt run --last-details` for full details)
14-
> vtt json-edit vite-task.json '_.tasks.task.command = "vtt print baz && vtt print bar"' # change first subtask
14+
> vtt json-patch vite-task.json '[{"op":"replace","path":"/tasks/task/command","value":"vtt print baz && vtt print bar"}]' # change first subtask
1515

1616
> vt run task # first: cache miss, second: cache hit
1717
$ vtt print bazcache miss: args changed, executing
@@ -22,7 +22,7 @@ bar
2222

2323
---
2424
vt run: 1/2 cache hit (50%). (Run `vt run --last-details` for full details)
25-
> vtt json-edit vite-task.json '_.tasks.task.command = "vtt print bar"' # remove first subtask
25+
> vtt json-patch vite-task.json '[{"op":"replace","path":"/tasks/task/command","value":"vtt print bar"}]' # remove first subtask
2626

2727
> vt run task # cache hit
2828
$ vtt print barcache hit, replaying

crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-miss-reasons/snapshots.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ steps = ["MY_ENV=1 vt run test # cache miss", "vt run test # cache miss: env rem
1919
name = "untracked env added"
2020
steps = [
2121
"vt run test # cache miss",
22-
"vtt json-edit vite-task.json \"_.tasks.test.untrackedEnv = ['MY_UNTRACKED']\" # add untracked env",
22+
"vtt json-patch vite-task.json '[{\"op\":\"add\",\"path\":\"/tasks/test/untrackedEnv\",\"value\":[\"MY_UNTRACKED\"]}]' # add untracked env",
2323
"vt run test # cache miss: untracked env added",
2424
]
2525

2626
[[e2e]]
2727
name = "untracked env removed"
2828
steps = [
29-
"vtt json-edit vite-task.json \"_.tasks.test.untrackedEnv = ['MY_UNTRACKED']\" # setup",
29+
"vtt json-patch vite-task.json '[{\"op\":\"add\",\"path\":\"/tasks/test/untrackedEnv\",\"value\":[\"MY_UNTRACKED\"]}]' # setup",
3030
"vt run test # cache miss",
31-
"vtt json-edit vite-task.json \"delete _.tasks.test.untrackedEnv\" # remove untracked env",
31+
"vtt json-patch vite-task.json '[{\"op\":\"remove\",\"path\":\"/tasks/test/untrackedEnv\"}]' # remove untracked env",
3232
"vt run test # cache miss: untracked env removed",
3333
]
3434

@@ -38,7 +38,7 @@ steps = [
3838
"vt run test # cache miss",
3939
"mkdir -p subfolder",
4040
"cp test.txt subfolder/test.txt",
41-
"vtt json-edit vite-task.json \"_.tasks.test.cwd = 'subfolder'\" # change cwd",
41+
"vtt json-patch vite-task.json '[{\"op\":\"add\",\"path\":\"/tasks/test/cwd\",\"value\":\"subfolder\"}]' # change cwd",
4242
"vt run test # cache miss: cwd changed",
4343
]
4444

@@ -58,7 +58,7 @@ steps = [
5858
name = "input config changed"
5959
steps = [
6060
"vt run test # cache miss",
61-
"vtt json-edit vite-task.json \"_.tasks.test.input = ['test.txt']\" # change input config",
61+
"vtt json-patch vite-task.json '[{\"op\":\"add\",\"path\":\"/tasks/test/input\",\"value\":[\"test.txt\"]}]' # change input config",
6262
"vt run test # cache miss: configuration changed",
6363
]
6464

crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-miss-reasons/snapshots/cwd changed.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ initial content
99

1010
> cp test.txt subfolder/test.txt
1111

12-
> vtt json-edit vite-task.json "_.tasks.test.cwd = 'subfolder'" # change cwd
12+
> vtt json-patch vite-task.json '[{"op":"add","path":"/tasks/test/cwd","value":"subfolder"}]' # change cwd
1313

1414
> vt run test # cache miss: cwd changed
1515
~/subfolder$ vtt print-file test.txtcache miss: working directory changed, executing

crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-miss-reasons/snapshots/input config changed.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ expression: e2e_outputs
55
> vt run test # cache miss
66
$ vtt print-file test.txt
77
initial content
8-
> vtt json-edit vite-task.json "_.tasks.test.input = ['test.txt']" # change input config
8+
> vtt json-patch vite-task.json '[{"op":"add","path":"/tasks/test/input","value":["test.txt"]}]' # change input config
99

1010
> vt run test # cache miss: configuration changed
1111
$ vtt print-file test.txtcache miss: input configuration changed, executing

crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-miss-reasons/snapshots/untracked env added.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ expression: e2e_outputs
55
> vt run test # cache miss
66
$ vtt print-file test.txt
77
initial content
8-
> vtt json-edit vite-task.json "_.tasks.test.untrackedEnv = ['MY_UNTRACKED']" # add untracked env
8+
> vtt json-patch vite-task.json '[{"op":"add","path":"/tasks/test/untrackedEnv","value":["MY_UNTRACKED"]}]' # add untracked env
99

1010
> vt run test # cache miss: untracked env added
1111
$ vtt print-file test.txtcache miss: untracked env config changed, executing

0 commit comments

Comments
 (0)