Skip to content

Commit 21a32db

Browse files
branchseerclaude
andcommitted
Simplify Args to Task/Tool; remove execute_synthetic and Lint/Test/EnvTest
- Args now only has Task (forwarded to session.main) and Tool (finds vtt in PATH and synthesizes a plan request) - Remove session.execute_synthetic and all related test fixtures (exec-api, e2e-env-test) - Convert builtin-different-cwd to use print-cwd, lint-dot-git and e2e-lint-cache to use print-file, builtin-non-zero-exit to use replace-file-content with missing searchValue - Update plan fixtures from vt lint to vt tool print lint, and vt env-test to TEST_VAR=val vt tool print-env Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5ac130d commit 21a32db

File tree

54 files changed

+1261
-318
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1261
-318
lines changed

crates/vite_task_bin/src/lib.rs

Lines changed: 11 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::{
66
};
77

88
use clap::Parser;
9-
use rustc_hash::FxHashMap;
109
use vite_path::AbsolutePath;
1110
use vite_str::Str;
1211
use vite_task::{
@@ -47,66 +46,14 @@ pub fn find_executable(
4746
Ok(executable_path.into_os_string().into())
4847
}
4948

50-
/// Create a synthetic plan request for running a tool from `node_modules/.bin`.
51-
///
52-
/// # Errors
53-
///
54-
/// Returns an error if the executable cannot be found.
55-
fn synthesize_node_modules_bin_task(
56-
executable_name: &str,
57-
args: &[Str],
58-
envs: &Arc<FxHashMap<Arc<OsStr>, Arc<OsStr>>>,
59-
cwd: &Arc<AbsolutePath>,
60-
) -> anyhow::Result<SyntheticPlanRequest> {
61-
Ok(SyntheticPlanRequest {
62-
program: find_executable(get_path_env(envs), cwd, executable_name)?,
63-
args: args.into(),
64-
cache_config: UserCacheConfig::with_config(EnabledCacheConfig {
65-
env: None,
66-
untracked_env: None,
67-
input: None,
68-
}),
69-
envs: Arc::clone(envs),
70-
})
71-
}
72-
73-
/// Create a synthetic plan request for running a `vtt` subcommand.
74-
///
75-
/// # Errors
76-
///
77-
/// Returns an error if the `vtt` executable cannot be found.
78-
fn synthesize_vtt_task(
79-
subcommand: &str,
80-
args: &[Str],
81-
cache_config: UserCacheConfig,
82-
envs: &Arc<FxHashMap<Arc<OsStr>, Arc<OsStr>>>,
83-
cwd: &Arc<AbsolutePath>,
84-
) -> anyhow::Result<SyntheticPlanRequest> {
85-
let mut full_args = vec![Str::from(subcommand)];
86-
full_args.extend_from_slice(args);
87-
Ok(SyntheticPlanRequest {
88-
program: find_executable(get_path_env(envs), cwd, "vtt")?,
89-
args: full_args.into(),
90-
cache_config,
91-
envs: Arc::clone(envs),
92-
})
93-
}
94-
9549
#[derive(Debug, Parser)]
9650
#[command(name = "vt", version)]
9751
pub enum Args {
98-
Lint {
52+
/// Run a tool via vtt.
53+
Tool {
9954
#[clap(trailing_var_arg = true, allow_hyphen_values = true)]
10055
args: Vec<Str>,
10156
},
102-
Test {
103-
#[clap(trailing_var_arg = true, allow_hyphen_values = true)]
104-
args: Vec<Str>,
105-
},
106-
EnvTest {
107-
name: Str,
108-
value: Str,
109-
},
11057
#[command(flatten)]
11158
Task(Command),
11259
}
@@ -131,32 +78,18 @@ impl vite_task::CommandHandler for CommandHandler {
13178
std::iter::once(command.program.as_str()).chain(command.args.iter().map(Str::as_str)),
13279
)?;
13380
match args {
134-
Args::Lint { args } => Ok(HandledCommand::Synthesized(
135-
synthesize_node_modules_bin_task("oxlint", &args, &command.envs, &command.cwd)?,
136-
)),
137-
Args::Test { args } => Ok(HandledCommand::Synthesized(
138-
synthesize_node_modules_bin_task("vitest", &args, &command.envs, &command.cwd)?,
139-
)),
140-
Args::EnvTest { name, value } => {
141-
let mut envs = FxHashMap::clone(&command.envs);
142-
envs.insert(
143-
Arc::from(OsStr::new(name.as_str())),
144-
Arc::from(OsStr::new(value.as_str())),
145-
);
146-
let envs = Arc::new(envs);
147-
148-
let untracked = vec![name.clone()];
149-
Ok(HandledCommand::Synthesized(synthesize_vtt_task(
150-
"print-env",
151-
std::slice::from_ref(&name),
152-
UserCacheConfig::with_config(EnabledCacheConfig {
81+
Args::Tool { args } => {
82+
let program = find_executable(get_path_env(&command.envs), &command.cwd, "vtt")?;
83+
Ok(HandledCommand::Synthesized(SyntheticPlanRequest {
84+
program,
85+
args: args.into_iter().filter(|a| a.as_str() != "--").collect(),
86+
cache_config: UserCacheConfig::with_config(EnabledCacheConfig {
15387
env: None,
154-
untracked_env: Some(untracked),
88+
untracked_env: None,
15589
input: None,
15690
}),
157-
&envs,
158-
&command.cwd,
159-
)?))
91+
envs: Arc::clone(&command.envs),
92+
}))
16093
}
16194
Args::Task(parsed) => Ok(HandledCommand::ViteTaskCommand(parsed)),
16295
}

crates/vite_task_bin/src/main.rs

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
use std::{process::ExitCode, sync::Arc};
1+
use std::process::ExitCode;
22

33
use clap::Parser;
4-
use vite_str::Str;
5-
use vite_task::{
6-
EnabledCacheConfig, ExitStatus, Session, UserCacheConfig, get_path_env,
7-
plan_request::SyntheticPlanRequest,
8-
};
4+
use vite_task::{ExitStatus, Session};
95
use vite_task_bin::{Args, OwnedSessionConfig};
106

117
#[tokio::main]
128
async fn main() -> anyhow::Result<ExitCode> {
13-
#[expect(clippy::large_futures, reason = "top-level await in main, no alternative")]
149
let exit_status = run().await?;
1510
Ok(exit_status.0.into())
1611
}
@@ -21,35 +16,7 @@ async fn run() -> anyhow::Result<ExitStatus> {
2116
let session = Session::init(owned_config.as_config())?;
2217
match args {
2318
Args::Task(parsed) => session.main(parsed).await,
24-
args => {
25-
// If env FOO is set, run `vtt print-env FOO` via Session::exec before proceeding.
26-
// In vite-plus, Session::exec is used for auto-install.
27-
let envs = session.envs();
28-
if envs.contains_key(std::ffi::OsStr::new("FOO")) {
29-
let program =
30-
vite_task_bin::find_executable(get_path_env(envs), session.cwd(), "vtt")?;
31-
let request = SyntheticPlanRequest {
32-
program,
33-
args: [Str::from("print-env"), Str::from("FOO")].into(),
34-
cache_config: UserCacheConfig::with_config({
35-
EnabledCacheConfig {
36-
env: Some(Box::from([Str::from("FOO")])),
37-
untracked_env: None,
38-
input: None,
39-
}
40-
}),
41-
envs: Arc::clone(envs),
42-
};
43-
let cache_key: Arc<[Str]> = Arc::from([Str::from("print-env-foo")]);
44-
#[expect(
45-
clippy::large_futures,
46-
reason = "execute_synthetic produces a large future"
47-
)]
48-
let status = session.execute_synthetic(request, cache_key, true).await?;
49-
if status != ExitStatus::SUCCESS {
50-
return Ok(status);
51-
}
52-
}
19+
args @ Args::Tool { .. } => {
5320
#[expect(clippy::print_stdout, reason = "CLI binary output for non-task commands")]
5421
{
5522
println!("{args:?}");

crates/vite_task_bin/src/vtt.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn main() {
1111
if args.len() < 2 {
1212
eprintln!("Usage: vtt <subcommand> [args...]");
1313
eprintln!(
14-
"Subcommands: check-tty, print, print-env, print-file, read-stdin, replace-file-content, touch-file"
14+
"Subcommands: check-tty, print, print-cwd, print-env, print-file, read-stdin, replace-file-content, touch-file"
1515
);
1616
std::process::exit(1);
1717
}
@@ -25,6 +25,7 @@ fn main() {
2525
cmd_print(&args[2..]);
2626
Ok(())
2727
}
28+
"print-cwd" => cmd_print_cwd(),
2829
"print-env" => cmd_print_env(&args[2..]),
2930
"print-file" => cmd_print_file(&args[2..]),
3031
"read-stdin" => cmd_read_stdin(),
@@ -56,6 +57,12 @@ fn cmd_print(args: &[String]) {
5657
println!("{}", args.join(" "));
5758
}
5859

60+
fn cmd_print_cwd() -> Result<(), Box<dyn std::error::Error>> {
61+
let cwd = std::env::current_dir()?;
62+
println!("{}", cwd.display());
63+
Ok(())
64+
}
65+
5966
fn cmd_print_env(args: &[String]) -> Result<(), Box<dyn std::error::Error>> {
6067
if args.is_empty() {
6168
return Err("Usage: vtt print-env <VAR_NAME>".into());

crates/vite_task_bin/tests/e2e_snapshots/fixtures/builtin-different-cwd/.gitignore

Lines changed: 0 additions & 7 deletions
This file was deleted.

crates/vite_task_bin/tests/e2e_snapshots/fixtures/builtin-different-cwd/folder1/a.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

crates/vite_task_bin/tests/e2e_snapshots/fixtures/builtin-different-cwd/folder2/a.js

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"scripts": {
3-
"lint": "vt lint"
3+
"cwd1": "cd folder1 && vt tool print-cwd",
4+
"cwd2": "cd folder2 && vt tool print-cwd"
45
}
56
}
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
# Tests that tasks have separate cache per cwd
1+
# Tests that synthetic tasks have separate cache per cwd
22

33
[[e2e]]
44
name = "builtin different cwd"
55
steps = [
6-
"cd folder1 && vt run lint # cache miss in folder1",
7-
"cd folder2 && vt run lint # cache miss in folder2",
8-
"echo 'console.log(1);' > folder2/a.js # modify folder2",
9-
"cd folder1 && vt run lint # cache hit",
10-
"cd folder2 && vt run lint # cache miss",
6+
"vt run cwd1 # cache miss in folder1",
7+
"vt run cwd2 # cache miss in folder2 (different cwd)",
8+
"vt run cwd1 # cache hit in folder1",
9+
"vt run cwd2 # cache hit in folder2",
1110
]

crates/vite_task_bin/tests/e2e_snapshots/fixtures/builtin-different-cwd/snapshots/builtin different cwd.snap

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,21 @@
22
source: crates/vite_task_bin/tests/e2e_snapshots/main.rs
33
expression: e2e_outputs
44
---
5-
[1]> cd folder1 && vt run lint # cache miss in folder1
6-
Error: Invalid vite task command: vt with args ["lint"] under cwd "<workspace>/"
5+
> vt run cwd1 # cache miss in folder1
6+
~/folder1$ vt tool print-cwd
7+
<workspace>/folder1
8+
> vt run cwd2 # cache miss in folder2 (different cwd)
9+
~/folder2$ vt tool print-cwd
10+
<workspace>/folder2
11+
> vt run cwd1 # cache hit in folder1
12+
~/folder1$ vt tool print-cwd ◉ cache hit, replaying
13+
<workspace>/folder1
714

8-
Caused by:
9-
cannot find binary path
10-
[1]> cd folder2 && vt run lint # cache miss in folder2
11-
Error: Invalid vite task command: vt with args ["lint"] under cwd "<workspace>/"
12-
13-
Caused by:
14-
cannot find binary path
15-
> echo 'console.log(1);' > folder2/a.js # modify folder2
16-
17-
[1]> cd folder1 && vt run lint # cache hit
18-
Error: Invalid vite task command: vt with args ["lint"] under cwd "<workspace>/"
19-
20-
Caused by:
21-
cannot find binary path
22-
[1]> cd folder2 && vt run lint # cache miss
23-
Error: Invalid vite task command: vt with args ["lint"] under cwd "<workspace>/"
15+
---
16+
vt run: cache hit.
17+
> vt run cwd2 # cache hit in folder2
18+
~/folder2$ vt tool print-cwd ◉ cache hit, replaying
19+
<workspace>/folder2
2420

25-
Caused by:
26-
cannot find binary path
21+
---
22+
vt run: cache hit.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "builtin-non-zero-exit-test",
33
"scripts": {
4-
"lint": "vt lint"
4+
"lint": "vt tool replace-file-content bad.js NOTFOUND replacement"
55
}
66
}

0 commit comments

Comments
 (0)