Skip to content

Commit 12efba8

Browse files
authored
feat(vite-plus): integrate new vite-task CommandHandler API (#551)
## Summary - Built-in subcommands (lint, build, test, etc.) now execute directly without a vite-task session - CommandHandler intercepts `vp` commands in task scripts and synthesizes them - New two-path execution: direct subcommand vs vite-task session (run/cache) - Snap tests updated for the new architecture ## Test plan - [x] `cargo check -p vite-plus-cli` passes - [x] `cargo test -p vite-plus-cli` passes - [x] `pnpm bootstrap-cli` builds successfully - [x] `pnpm -F vite-plus snap-test` — all 34 tests pass - [x] New `vp-run-expansion` snap test validates CommandHandler integration 🤖 Generated with [Claude Code](https://claude.com/claude-code)
1 parent 112894b commit 12efba8

52 files changed

Lines changed: 768 additions & 396 deletions

File tree

Some content is hidden

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

Cargo.lock

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

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ dunce = "1.0.5"
6868
fast-glob = "1.0.0"
6969
flate2 = { version = "=1.1.5", features = ["zlib-rs"] }
7070
form_urlencoded = "1.2.1"
71-
fspy = { git = "ssh://git@github.com/voidzero-dev/vite-task.git", rev = "5ea9649f48940bf01493b74fa1d03fa484a41b41" }
71+
fspy = { git = "ssh://git@github.com/voidzero-dev/vite-task.git", rev = "6e3aa68cef28ba447647e98874ad56df2c612ad3" }
7272
futures = "0.3.31"
7373
futures-util = "0.3.31"
7474
glob = "0.3.2"
@@ -155,14 +155,14 @@ vfs = "0.12.1"
155155
vite_command = { path = "crates/vite_command" }
156156
vite_error = { path = "crates/vite_error" }
157157
vite_js_runtime = { path = "crates/vite_js_runtime" }
158-
vite_glob = { git = "ssh://git@github.com/voidzero-dev/vite-task.git", rev = "5ea9649f48940bf01493b74fa1d03fa484a41b41" }
158+
vite_glob = { git = "ssh://git@github.com/voidzero-dev/vite-task.git", rev = "6e3aa68cef28ba447647e98874ad56df2c612ad3" }
159159
vite_install = { path = "crates/vite_install" }
160160
vite_migration = { path = "crates/vite_migration" }
161161
vite_shared = { path = "crates/vite_shared" }
162-
vite_path = { git = "ssh://git@github.com/voidzero-dev/vite-task.git", rev = "5ea9649f48940bf01493b74fa1d03fa484a41b41" }
163-
vite_str = { git = "ssh://git@github.com/voidzero-dev/vite-task.git", rev = "5ea9649f48940bf01493b74fa1d03fa484a41b41" }
164-
vite_task = { git = "ssh://git@github.com/voidzero-dev/vite-task.git", rev = "5ea9649f48940bf01493b74fa1d03fa484a41b41" }
165-
vite_workspace = { git = "ssh://git@github.com/voidzero-dev/vite-task.git", rev = "5ea9649f48940bf01493b74fa1d03fa484a41b41" }
162+
vite_path = { git = "ssh://git@github.com/voidzero-dev/vite-task.git", rev = "6e3aa68cef28ba447647e98874ad56df2c612ad3" }
163+
vite_str = { git = "ssh://git@github.com/voidzero-dev/vite-task.git", rev = "6e3aa68cef28ba447647e98874ad56df2c612ad3" }
164+
vite_task = { git = "ssh://git@github.com/voidzero-dev/vite-task.git", rev = "6e3aa68cef28ba447647e98874ad56df2c612ad3" }
165+
vite_workspace = { git = "ssh://git@github.com/voidzero-dev/vite-task.git", rev = "6e3aa68cef28ba447647e98874ad56df2c612ad3" }
166166
walkdir = "2.5.0"
167167
wax = "0.6.0"
168168
which = "8.0.0"

bench/benches/workspace_load.rs

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,51 @@
1-
use std::{
2-
collections::HashMap, convert::Infallible, ffi::OsStr, hint::black_box, path::PathBuf,
3-
sync::Arc,
4-
};
1+
use std::{collections::HashMap, ffi::OsStr, hint::black_box, path::PathBuf, sync::Arc};
52

63
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
74
use tokio::runtime::Runtime;
85
use vite_path::{AbsolutePath, AbsolutePathBuf};
9-
use vite_task::{Session, SessionCallbacks, plan_request::SyntheticPlanRequest};
6+
use vite_task::{
7+
CommandHandler, HandledCommand, Session, SessionCallbacks, plan_request::ScriptCommand,
8+
};
109

11-
/// A no-op task synthesizer for benchmarking purposes.
10+
/// A no-op command handler for benchmarking purposes.
1211
#[derive(Debug, Default)]
13-
struct NoOpTaskSynthesizer;
12+
struct NoOpCommandHandler;
1413

1514
#[async_trait::async_trait(?Send)]
16-
impl vite_task::TaskSynthesizer<Infallible> for NoOpTaskSynthesizer {
17-
fn should_synthesize_for_program(&self, _program: &str) -> bool {
18-
false
15+
impl CommandHandler for NoOpCommandHandler {
16+
async fn handle_command(
17+
&mut self,
18+
_command: &mut ScriptCommand,
19+
) -> anyhow::Result<HandledCommand> {
20+
Ok(HandledCommand::Verbatim)
1921
}
22+
}
2023

21-
async fn synthesize_task(
22-
&mut self,
23-
subcommand: Infallible,
24-
_envs: &Arc<HashMap<Arc<OsStr>, Arc<OsStr>>>,
25-
_cwd: &Arc<AbsolutePath>,
26-
) -> anyhow::Result<SyntheticPlanRequest> {
27-
match subcommand {}
24+
/// A no-op user config loader for benchmarking.
25+
#[derive(Debug, Default)]
26+
struct NoOpUserConfigLoader;
27+
28+
#[async_trait::async_trait(?Send)]
29+
impl vite_task::loader::UserConfigLoader for NoOpUserConfigLoader {
30+
async fn load_user_config_file(
31+
&self,
32+
_package_path: &AbsolutePath,
33+
) -> anyhow::Result<Option<vite_task::config::UserRunConfig>> {
34+
Ok(None)
2835
}
2936
}
3037

3138
/// Owned session callbacks for benchmarking.
3239
#[derive(Default)]
3340
struct BenchSessionCallbacks {
34-
task_synthesizer: NoOpTaskSynthesizer,
35-
user_config_loader: vite_task::loader::JsonUserConfigLoader,
41+
command_handler: NoOpCommandHandler,
42+
user_config_loader: NoOpUserConfigLoader,
3643
}
3744

3845
impl BenchSessionCallbacks {
39-
fn as_callbacks(&mut self) -> SessionCallbacks<'_, Infallible> {
46+
fn as_callbacks(&mut self) -> SessionCallbacks<'_> {
4047
SessionCallbacks {
41-
task_synthesizer: &mut self.task_synthesizer,
48+
command_handler: &mut self.command_handler,
4249
user_config_loader: &mut self.user_config_loader,
4350
}
4451
}

crates/vite_command/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ where
146146
}
147147

148148
#[cfg(unix)]
149-
fn fix_stdio_streams() {
149+
pub fn fix_stdio_streams() {
150150
// libuv may mark stdin/stdout/stderr as close-on-exec, which interferes with Rust's subprocess spawning.
151151
// As a workaround, we clear the FD_CLOEXEC flag on these file descriptors to prevent them from being closed when spawning child processes.
152152
//

packages/cli/binding/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ serde = { workspace = true, features = ["derive"] }
2020
serde_json = { workspace = true }
2121
tokio = { workspace = true, features = ["fs"] }
2222
tracing = { workspace = true }
23+
vite_command = { workspace = true }
2324
vite_error = { workspace = true }
2425
vite_install = { workspace = true }
2526
vite_path = { workspace = true }
2627
vite_shared = { workspace = true }
2728
vite_str = { workspace = true }
2829
vite_task = { workspace = true }
2930
vite_workspace = { workspace = true }
31+
which = { workspace = true }
3032

3133
rolldown_binding = { workspace = true, optional = true }
3234

0 commit comments

Comments
 (0)