Skip to content

Commit 21c9590

Browse files
committed
fix(cli): enable cache support for vp check in task runner (#1328)
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 6242b49 commit 21c9590

11 files changed

Lines changed: 135 additions & 4 deletions

File tree

packages/cli/binding/src/cli.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,21 @@ fn build_pack_cache_inputs() -> Vec<UserInputEntry> {
517517
]
518518
}
519519

520+
/// Cache input entries for the check command.
521+
/// The vp check subprocess is a full vp CLI process (not resolved to a binary like
522+
/// build/lint/fmt), so it accesses additional directories that must be excluded:
523+
/// - `.vite-temp`: config compilation cache, read+written during vp CLI startup
524+
/// - `.vite/task-cache`: task runner state files that change after each run
525+
fn check_cache_inputs() -> Vec<UserInputEntry> {
526+
vec![
527+
UserInputEntry::Auto(AutoInput { auto: true }),
528+
exclude_glob("!node_modules/.vite-temp/**", InputBase::Workspace),
529+
exclude_glob("!node_modules/.vite-temp/**", InputBase::Package),
530+
exclude_glob("!node_modules/.vite/task-cache/**", InputBase::Workspace),
531+
exclude_glob("!node_modules/.vite/task-cache/**", InputBase::Package),
532+
]
533+
}
534+
520535
fn merge_resolved_envs(
521536
envs: &Arc<FxHashMap<Arc<OsStr>, Arc<OsStr>>>,
522537
resolved_envs: Vec<(String, String)>,
@@ -587,10 +602,14 @@ impl CommandHandler for VitePlusCommandHandler {
587602
};
588603
match cli_args {
589604
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-
))
605+
// Check is a composite command (fmt + lint) — run as a subprocess in task scripts
606+
Ok(HandledCommand::Synthesized(command.to_synthetic_plan_request(
607+
UserCacheConfig::with_config(EnabledCacheConfig {
608+
env: Some(Box::new([Str::from("OXLINT_TSGOLINT_PATH")])),
609+
untracked_env: None,
610+
input: Some(check_cache_inputs()),
611+
}),
612+
)))
594613
}
595614
CLIArgs::Synthesizable(subcmd) => {
596615
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-disabled-test",
3+
"type": "module",
4+
"scripts": {
5+
"check": "vp check"
6+
}
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
> vp run check # vp check should have cache disabled without run.cache
2+
$ vp check ⊘ cache disabled
3+
pass: All 3 files are correctly formatted (<variable>ms, <variable> threads)
4+
pass: Found no warnings or lint errors in 1 file (<variable>ms, <variable> threads)
5+
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"commands": ["vp run check # vp check should have cache disabled without run.cache"]
3+
}
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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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.
14+
15+
> echo 'export const foo = 1;' > src/foo.js
16+
> vp run check # third run should be cache miss after new file added
17+
$ vp check ○ cache miss: 'foo.js' added in 'src', executing
18+
pass: All 5 files are correctly formatted (<variable>ms, <variable> threads)
19+
pass: Found no warnings or lint errors in 3 files (<variable>ms, <variable> threads)
20+
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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"ignoredPlatforms": ["win32"],
3+
"commands": [
4+
"vp run check # first run should be cache miss",
5+
"vp run check # second run should be cache hit",
6+
"echo 'export const foo = 1;' > src/foo.js",
7+
"vp run check # third run should be cache miss after new file added"
8+
]
9+
}
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)