Skip to content

Commit f48af93

Browse files
branchseerclaude
andauthored
feat(vite-plus): update vite-task integration for cacheScripts and RunConfig (#543)
Adapt vite-plus to the latest vite-task API changes: - Rename config field from `tasks` to `run` (now `RunConfig` with `cacheScripts` + `tasks`) - Update `UserConfigFile`/`UserConfigTasks` → `UserRunConfig` - `load_user_config_file` now returns `Option<UserRunConfig>` - Rename `task-config.ts` → `run-config.ts` - Point Cargo.toml to local ../vite-task via patch section - Add `cacheScripts: true` to existing tests to preserve cache behavior - Add snap tests for cacheScripts disabled (default) and enabled Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent bdf958b commit f48af93

24 files changed

Lines changed: 228 additions & 83 deletions

File tree

Cargo.lock

Lines changed: 17 additions & 17 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
@@ -71,7 +71,7 @@ dunce = "1.0.5"
7171
fast-glob = "1.0.0"
7272
flate2 = { version = "=1.1.5", features = ["zlib-rs"] }
7373
form_urlencoded = "1.2.1"
74-
fspy = { git = "ssh://git@github.com/voidzero-dev/vite-task.git", rev = "d1824f23d28fdac7024c80c25f8e84b24b4f7704" }
74+
fspy = { git = "ssh://git@github.com/voidzero-dev/vite-task.git", rev = "5ea9649f48940bf01493b74fa1d03fa484a41b41" }
7575
futures = "0.3.31"
7676
futures-util = "0.3.31"
7777
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 = "d1824f23d28fdac7024c80c25f8e84b24b4f7704" }
158+
vite_glob = { git = "ssh://git@github.com/voidzero-dev/vite-task.git", rev = "5ea9649f48940bf01493b74fa1d03fa484a41b41" }
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 = "d1824f23d28fdac7024c80c25f8e84b24b4f7704" }
163-
vite_str = { git = "ssh://git@github.com/voidzero-dev/vite-task.git", rev = "d1824f23d28fdac7024c80c25f8e84b24b4f7704" }
164-
vite_task = { git = "ssh://git@github.com/voidzero-dev/vite-task.git", rev = "d1824f23d28fdac7024c80c25f8e84b24b4f7704" }
165-
vite_workspace = { git = "ssh://git@github.com/voidzero-dev/vite-task.git", rev = "d1824f23d28fdac7024c80c25f8e84b24b4f7704" }
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" }
166166
walkdir = "2.5.0"
167167
wax = "0.6.0"
168168
which = "8.0.0"

packages/cli/binding/src/cli.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use vite_str::Str;
1616
use vite_task::{
1717
CLIArgs, LabeledReporter, Session, SessionCallbacks, TaskSynthesizer,
1818
config::{
19-
UserConfigFile,
20-
user::{EnabledCacheConfig, UserCacheConfig, UserConfigTasks, UserTaskOptions},
19+
UserRunConfig,
20+
user::{EnabledCacheConfig, UserCacheConfig, UserTaskOptions},
2121
},
2222
loader::UserConfigLoader,
2323
plan_request::SyntheticPlanRequest,
@@ -31,7 +31,7 @@ pub struct ResolvedUniversalViteConfig {
3131
pub config_file: Option<String>,
3232
pub lint: Option<serde_json::Value>,
3333
pub fmt: Option<serde_json::Value>,
34-
pub tasks: Option<serde_json::Value>,
34+
pub run: Option<serde_json::Value>,
3535
}
3636

3737
/// Result type for resolved commands from JavaScript
@@ -591,7 +591,7 @@ impl UserConfigLoader for VitePlusConfigLoader {
591591
async fn load_user_config_file(
592592
&self,
593593
package_path: &AbsolutePath,
594-
) -> anyhow::Result<UserConfigFile> {
594+
) -> anyhow::Result<Option<UserRunConfig>> {
595595
let package_path_str = package_path
596596
.as_path()
597597
.to_str()
@@ -603,12 +603,11 @@ impl UserConfigLoader for VitePlusConfigLoader {
603603
tracing::error!("Failed to parse vite config: {config_json}");
604604
})?;
605605

606-
let tasks = if let Some(tasks) = resolved.tasks {
607-
serde_json::from_value(tasks)?
608-
} else {
609-
UserConfigTasks::default()
606+
let run_config = match resolved.run {
607+
Some(run) => serde_json::from_value(run)?,
608+
None => UserRunConfig::default(),
610609
};
611-
Ok(UserConfigFile { tasks })
610+
Ok(Some(run_config))
612611
}
613612
}
614613

@@ -869,25 +868,25 @@ pub fn init_tracing() {
869868
mod tests {
870869
use std::path::PathBuf;
871870

872-
use vite_task::config::user::UserConfigTasks;
871+
use vite_task::config::UserRunConfig;
873872

874873
#[test]
875-
fn task_config_types_in_sync() {
874+
fn run_config_types_in_sync() {
876875
// Remove \r for cross-platform consistency
877-
let ts_type = UserConfigTasks::TS_TYPE.replace('\r', "");
876+
let ts_type = UserRunConfig::TS_TYPE.replace('\r', "");
878877
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
879-
let task_config_path = PathBuf::from(manifest_dir).join("../src/task-config.ts");
878+
let run_config_path = PathBuf::from(manifest_dir).join("../src/run-config.ts");
880879

881880
if std::env::var("VITE_UPDATE_TASK_TYPES").as_deref() == Ok("1") {
882-
std::fs::write(&task_config_path, &ts_type).expect("Failed to write task-config.ts");
881+
std::fs::write(&run_config_path, &ts_type).expect("Failed to write run-config.ts");
883882
} else {
884-
let current = std::fs::read_to_string(&task_config_path)
885-
.expect("Failed to read task-config.ts")
883+
let current = std::fs::read_to_string(&run_config_path)
884+
.expect("Failed to read run-config.ts")
886885
.replace('\r', "");
887886
pretty_assertions::assert_eq!(
888887
current,
889888
ts_type,
890-
"task-config.ts is out of sync. Run `VITE_UPDATE_TASK_TYPES=1 cargo test -p vite-plus-cli task_config_types_in_sync` to update."
889+
"run-config.ts is out of sync. Run `VITE_UPDATE_TASK_TYPES=1 cargo test -p vite-plus-cli run_config_types_in_sync` to update."
891890
);
892891
}
893892
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('hello from script');
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "cache-scripts-default-test",
3+
"scripts": {
4+
"hello": "node hello.mjs"
5+
}
6+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
> vite run hello # cache should be disabled by default for package.json scripts
2+
$ node hello.mjs ⊘ cache disabled: no cache config
3+
hello from script
4+
5+
6+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
7+
Vite+ Task Runner • Execution Summary
8+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
9+
10+
Statistics: 1 tasks • 0 cache hits • 0 cache misses • 1 cache disabled
11+
Performance: 0% cache hit rate
12+
13+
Task Details:
14+
────────────────────────────────────────────────
15+
[1] cache-scripts-default-test#hello: $ node hello.mjs ✓
16+
→ Cache disabled in task configuration
17+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
18+
19+
> vite run hello # second run should also show cache disabled
20+
$ node hello.mjs ⊘ cache disabled: no cache config
21+
hello from script
22+
23+
24+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
25+
Vite+ Task Runner • Execution Summary
26+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
27+
28+
Statistics: 1 tasks • 0 cache hits • 0 cache misses • 1 cache disabled
29+
Performance: 0% cache hit rate
30+
31+
Task Details:
32+
────────────────────────────────────────────────
33+
[1] cache-scripts-default-test#hello: $ node hello.mjs ✓
34+
→ Cache disabled in task configuration
35+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"env": {
3+
"VITE_DISABLE_AUTO_INSTALL": "1"
4+
},
5+
"commands": [
6+
"vite run hello # cache should be disabled by default for package.json scripts",
7+
"vite run hello # second run should also show cache disabled"
8+
]
9+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('hello from script');
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "cache-scripts-enabled-test",
3+
"scripts": {
4+
"hello": "node hello.mjs"
5+
}
6+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
> vite run hello # first run should be cache miss
2+
$ node hello.mjs
3+
hello from script
4+
5+
6+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
7+
Vite+ Task Runner • Execution Summary
8+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
9+
10+
Statistics: 1 tasks • 0 cache hits • 1 cache misses
11+
Performance: 0% cache hit rate
12+
13+
Task Details:
14+
────────────────────────────────────────────────
15+
[1] cache-scripts-enabled-test#hello: $ node hello.mjs ✓
16+
→ Cache miss: no previous cache entry found
17+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
18+
19+
> vite run hello # second run should be cache hit
20+
$ node hello.mjs ✓ cache hit, replaying
21+
hello from script
22+
23+
24+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
25+
Vite+ Task Runner • Execution Summary
26+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
27+
28+
Statistics: 1 tasks • 1 cache hits • 0 cache misses
29+
Performance: 100% cache hit rate, <variable>ms saved in total
30+
31+
Task Details:
32+
────────────────────────────────────────────────
33+
[1] cache-scripts-enabled-test#hello: $ node hello.mjs ✓
34+
→ Cache hit - output replayed - <variable>ms saved
35+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

0 commit comments

Comments
 (0)