Skip to content

Commit 7d8516d

Browse files
committed
fix(cli): enable cache support for vp check in task runner
When `vp check` was used as a script (e.g., `"check": "vp check"`) and run via `vp run check` with `run: { cache: true }`, cache was always disabled because the command handler forced `UserCacheConfig::disabled()`. Change the Check handler to use `UserCacheConfig::with_config(...)` with auto input tracking and task-cache directory exclusions, matching the pattern used by other synthesized commands (build, lint, fmt).
1 parent f47d2a4 commit 7d8516d

File tree

6 files changed

+53
-4
lines changed

6 files changed

+53
-4
lines changed

packages/cli/binding/src/cli.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -587,10 +587,23 @@ impl CommandHandler for VitePlusCommandHandler {
587587
};
588588
match cli_args {
589589
CLIArgs::Synthesizable(SynthesizableSubcommand::Check { .. }) => {
590-
// Check is a composite command — run as a subprocess in task scripts
591-
Ok(HandledCommand::Synthesized(
592-
command.to_synthetic_plan_request(UserCacheConfig::disabled()),
593-
))
590+
// Check is a composite command (fmt + lint) — run as a subprocess in task scripts.
591+
// Exclude .vite-temp (config compilation cache, read+written by the vp CLI
592+
// subprocess) and .vite/task-cache (the task runner's own state files that
593+
// change after each run) from auto-tracking to avoid false cache invalidation.
594+
Ok(HandledCommand::Synthesized(command.to_synthetic_plan_request(
595+
UserCacheConfig::with_config(EnabledCacheConfig {
596+
env: Some(Box::new([Str::from("OXLINT_TSGOLINT_PATH")])),
597+
untracked_env: None,
598+
input: Some(vec![
599+
UserInputEntry::Auto(AutoInput { auto: true }),
600+
exclude_glob("!node_modules/.vite-temp/**", InputBase::Workspace),
601+
exclude_glob("!node_modules/.vite-temp/**", InputBase::Package),
602+
exclude_glob("!node_modules/.vite/task-cache/**", InputBase::Workspace),
603+
exclude_glob("!node_modules/.vite/task-cache/**", InputBase::Package),
604+
]),
605+
}),
606+
)))
594607
}
595608
CLIArgs::Synthesizable(subcmd) => {
596609
let resolved =
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "check-cache-enabled-test",
3+
"type": "module",
4+
"scripts": {
5+
"check": "vp check"
6+
}
7+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
> vp run check # first run should be cache miss
2+
$ vp check
3+
pass: All 4 files are correctly formatted (<variable>ms, <variable> threads)
4+
pass: Found no warnings or lint errors in 2 files (<variable>ms, <variable> threads)
5+
6+
7+
> vp run check # second run should be cache hit
8+
$ vp check ◉ cache hit, replaying
9+
pass: All 4 files are correctly formatted (<variable>ms, <variable> threads)
10+
pass: Found no warnings or lint errors in 2 files (<variable>ms, <variable> threads)
11+
12+
---
13+
vp run: cache hit, <variable>ms saved.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function hello() {
2+
return "hello";
3+
}
4+
5+
export { hello };
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"commands": [
3+
"vp run check # first run should be cache miss",
4+
"vp run check # second run should be cache hit"
5+
]
6+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default {
2+
run: {
3+
cache: true,
4+
},
5+
};

0 commit comments

Comments
 (0)