Skip to content

Commit fe23bd3

Browse files
branchseerclaude
andcommitted
Remove json-patch command; use replace-file-content instead
replace-file-content now errors with exit 1 when searchValue is not found. All test fixtures converted from json-patch to replace-file-content. Removes json-patch and serde_json dependencies from vite_task_tools. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3f39751 commit fe23bd3

25 files changed

+146
-220
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ 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"
8584
jsonc-parser = { version = "0.29.0", features = ["serde"] }
8685
libc = "0.2.172"
8786
memmap2 = "0.9.7"
@@ -147,7 +146,6 @@ vite_task = { path = "crates/vite_task" }
147146
vite_task_bin = { path = "crates/vite_task_bin" }
148147
vite_task_graph = { path = "crates/vite_task_graph" }
149148
vite_task_plan = { path = "crates/vite_task_plan" }
150-
vite_task_tools = { path = "crates/vite_task_tools" }
151149
vite_workspace = { path = "crates/vite_workspace" }
152150
vt100 = "0.16.2"
153151
wax = "0.7.0"

crates/vite_task_bin/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ tokio = { workspace = true, features = ["full"] }
2525
vite_path = { workspace = true }
2626
vite_str = { workspace = true }
2727
vite_task = { workspace = true }
28-
vite_task_tools = { workspace = true }
2928
which = { workspace = true }
3029

3130
[dev-dependencies]

crates/vite_task_bin/src/vtt.rs

Lines changed: 117 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,119 @@
1+
// This is a standalone test utility binary that deliberately uses std types
2+
// rather than the project's custom types (vite_str, vite_path, etc.).
3+
#![expect(clippy::disallowed_types, reason = "standalone test utility uses std types")]
4+
#![expect(clippy::disallowed_macros, reason = "standalone test utility uses std macros")]
5+
#![expect(clippy::disallowed_methods, reason = "standalone test utility uses std methods")]
6+
#![expect(clippy::print_stderr, reason = "CLI tool error output")]
7+
#![expect(clippy::print_stdout, reason = "CLI tool output")]
8+
19
fn main() {
2-
vite_task_tools::main();
10+
let args: Vec<String> = std::env::args().collect();
11+
if args.len() < 2 {
12+
eprintln!("Usage: vtt <subcommand> [args...]");
13+
eprintln!(
14+
"Subcommands: check-tty, print, print-env, print-file, read-stdin, replace-file-content, touch-file"
15+
);
16+
std::process::exit(1);
17+
}
18+
19+
let result: Result<(), Box<dyn std::error::Error>> = match args[1].as_str() {
20+
"check-tty" => {
21+
cmd_check_tty();
22+
Ok(())
23+
}
24+
"print" => {
25+
cmd_print(&args[2..]);
26+
Ok(())
27+
}
28+
"print-env" => cmd_print_env(&args[2..]),
29+
"print-file" => cmd_print_file(&args[2..]),
30+
"read-stdin" => cmd_read_stdin(),
31+
"replace-file-content" => cmd_replace_file_content(&args[2..]),
32+
"touch-file" => cmd_touch_file(&args[2..]),
33+
other => {
34+
eprintln!("Unknown subcommand: {other}");
35+
std::process::exit(1);
36+
}
37+
};
38+
39+
if let Err(err) = result {
40+
eprintln!("{err}");
41+
std::process::exit(1);
42+
}
43+
}
44+
45+
fn cmd_check_tty() {
46+
use std::io::IsTerminal as _;
47+
let stdin_tty = if std::io::stdin().is_terminal() { "tty" } else { "not-tty" };
48+
let stdout_tty = if std::io::stdout().is_terminal() { "tty" } else { "not-tty" };
49+
let stderr_tty = if std::io::stderr().is_terminal() { "tty" } else { "not-tty" };
50+
println!("stdin:{stdin_tty}");
51+
println!("stdout:{stdout_tty}");
52+
println!("stderr:{stderr_tty}");
53+
}
54+
55+
fn cmd_print(args: &[String]) {
56+
println!("{}", args.join(" "));
57+
}
58+
59+
fn cmd_print_env(args: &[String]) -> Result<(), Box<dyn std::error::Error>> {
60+
if args.is_empty() {
61+
return Err("Usage: vtt print-env <VAR_NAME>".into());
62+
}
63+
let value = std::env::var(&args[0]).unwrap_or_else(|_| "(undefined)".to_string());
64+
println!("{value}");
65+
Ok(())
66+
}
67+
68+
fn cmd_print_file(args: &[String]) -> Result<(), Box<dyn std::error::Error>> {
69+
use std::io::Write as _;
70+
let stdout = std::io::stdout();
71+
let mut out = stdout.lock();
72+
for file in args {
73+
match std::fs::read(file) {
74+
Ok(content) => out.write_all(&content)?,
75+
Err(_) => eprintln!("{file}: not found"),
76+
}
77+
}
78+
Ok(())
79+
}
80+
81+
fn cmd_read_stdin() -> Result<(), Box<dyn std::error::Error>> {
82+
use std::io::{Read as _, Write as _};
83+
let mut stdin = std::io::stdin().lock();
84+
let mut stdout = std::io::stdout().lock();
85+
let mut buf = [0u8; 8192];
86+
loop {
87+
match stdin.read(&mut buf) {
88+
Ok(0) | Err(_) => break,
89+
Ok(n) => stdout.write_all(&buf[..n])?,
90+
}
91+
}
92+
Ok(())
93+
}
94+
95+
fn cmd_replace_file_content(args: &[String]) -> Result<(), Box<dyn std::error::Error>> {
96+
if args.len() < 3 {
97+
return Err("Usage: vtt replace-file-content <filename> <searchValue> <newValue>".into());
98+
}
99+
let filename = &args[0];
100+
let search_value = &args[1];
101+
let new_value = &args[2];
102+
103+
let filepath = std::path::Path::new(filename).canonicalize()?;
104+
let content = std::fs::read_to_string(&filepath)?;
105+
if !content.contains(search_value) {
106+
return Err(std::format!("searchValue not found in {filename}: {search_value:?}").into());
107+
}
108+
let new_content = content.replacen(search_value, new_value, 1);
109+
std::fs::write(&filepath, new_content)?;
110+
Ok(())
111+
}
112+
113+
fn cmd_touch_file(args: &[String]) -> Result<(), Box<dyn std::error::Error>> {
114+
if args.is_empty() {
115+
return Err("Usage: vtt touch-file <filename>".into());
116+
}
117+
let _file = std::fs::OpenOptions::new().read(true).write(true).open(&args[0])?;
118+
Ok(())
3119
}

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-patch package.json '[{\"op\":\"add\",\"path\":\"/scripts/script2\",\"value\":\"vtt print world\"}]' # change script2",
8+
"vtt replace-file-content package.json '\"script2\": \"vtt print hello\"' '\"script2\": \"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-patch package.json '[{"op":"add","path":"/scripts/script2","value":"vtt print world"}]' # change script2
14+
> vtt replace-file-content package.json '"script2": "vtt print hello"' '"script2": "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-patch vite-task.json '[{\"op\":\"replace\",\"path\":\"/tasks/task/command\",\"value\":\"vtt print baz && vtt print bar\"}]' # change first subtask",
7+
"vtt replace-file-content vite-task.json 'vtt print foo && vtt print bar' 'vtt print baz && vtt print bar' # change first subtask",
88
"vt run task # first: cache miss, second: cache hit",
9-
"vtt json-patch vite-task.json '[{\"op\":\"replace\",\"path\":\"/tasks/task/command\",\"value\":\"vtt print bar\"}]' # remove first subtask",
9+
"vtt replace-file-content vite-task.json 'vtt print baz && vtt print bar' '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-patch vite-task.json '[{"op":"replace","path":"/tasks/task/command","value":"vtt print baz && vtt print bar"}]' # change first subtask
14+
> vtt replace-file-content vite-task.json 'vtt print foo && vtt print bar' '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-patch vite-task.json '[{"op":"replace","path":"/tasks/task/command","value":"vtt print bar"}]' # remove first subtask
25+
> vtt replace-file-content vite-task.json 'vtt print baz && vtt print bar' '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-patch vite-task.json '[{\"op\":\"add\",\"path\":\"/tasks/test/untrackedEnv\",\"value\":[\"MY_UNTRACKED\"]}]' # add untracked env",
22+
"""vtt replace-file-content vite-task.json '"cache": true' '"cache": true, "untrackedEnv": ["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-patch vite-task.json '[{\"op\":\"add\",\"path\":\"/tasks/test/untrackedEnv\",\"value\":[\"MY_UNTRACKED\"]}]' # setup",
29+
"""vtt replace-file-content vite-task.json '"cache": true' '"cache": true, "untrackedEnv": ["MY_UNTRACKED"]' # setup""",
3030
"vt run test # cache miss",
31-
"vtt json-patch vite-task.json '[{\"op\":\"remove\",\"path\":\"/tasks/test/untrackedEnv\"}]' # remove untracked env",
31+
"""vtt replace-file-content vite-task.json '"cache": true, "untrackedEnv": ["MY_UNTRACKED"]' '"cache": true' # 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-patch vite-task.json '[{\"op\":\"add\",\"path\":\"/tasks/test/cwd\",\"value\":\"subfolder\"}]' # change cwd",
41+
"""vtt replace-file-content vite-task.json '"cache": true' '"cache": true, "cwd": "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-patch vite-task.json '[{\"op\":\"add\",\"path\":\"/tasks/test/input\",\"value\":[\"test.txt\"]}]' # change input config",
61+
"""vtt replace-file-content vite-task.json '"cache": true' '"cache": true, "input": ["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-patch vite-task.json '[{"op":"add","path":"/tasks/test/cwd","value":"subfolder"}]' # change cwd
12+
> vtt replace-file-content vite-task.json '"cache": true' '"cache": true, "cwd": "subfolder"' # change cwd
1313

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

0 commit comments

Comments
 (0)