Skip to content

Commit 272b3c3

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 272b3c3

File tree

11 files changed

+136
-10
lines changed

11 files changed

+136
-10
lines changed

packages/cli/binding/src/cli.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -504,19 +504,30 @@ fn exclude_glob(pattern: &str, base: InputBase) -> UserInputEntry {
504504
UserInputEntry::GlobWithBase(GlobWithBase { pattern: Str::from(pattern), base })
505505
}
506506

507-
/// Common cache input entries for build/pack commands.
508-
/// Excludes .vite-temp config files and dist output files that are both read and written.
509-
/// TODO: The hardcoded `!dist/**` exclusion is a temporary workaround. It will be replaced
510-
/// by a runner-aware approach that automatically excludes task output directories.
511-
fn build_pack_cache_inputs() -> Vec<UserInputEntry> {
507+
/// Base cache input entries shared by synthesized commands.
508+
/// Includes auto-tracking and excludes directories that cause false cache invalidation:
509+
/// - `.vite-temp`: config compilation cache, read+written during vp CLI startup
510+
/// - `.vite/task-cache`: task runner state files that change after each run
511+
fn base_cache_inputs() -> Vec<UserInputEntry> {
512512
vec![
513513
UserInputEntry::Auto(AutoInput { auto: true }),
514514
exclude_glob("!node_modules/.vite-temp/**", InputBase::Workspace),
515515
exclude_glob("!node_modules/.vite-temp/**", InputBase::Package),
516-
exclude_glob("!dist/**", InputBase::Package),
516+
exclude_glob("!node_modules/.vite/task-cache/**", InputBase::Workspace),
517+
exclude_glob("!node_modules/.vite/task-cache/**", InputBase::Package),
517518
]
518519
}
519520

521+
/// Cache input entries for build/pack commands.
522+
/// Extends base inputs with dist output exclusion.
523+
/// TODO: The hardcoded `!dist/**` exclusion is a temporary workaround. It will be replaced
524+
/// by a runner-aware approach that automatically excludes task output directories.
525+
fn build_pack_cache_inputs() -> Vec<UserInputEntry> {
526+
let mut inputs = base_cache_inputs();
527+
inputs.push(exclude_glob("!dist/**", InputBase::Package));
528+
inputs
529+
}
530+
520531
fn merge_resolved_envs(
521532
envs: &Arc<FxHashMap<Arc<OsStr>, Arc<OsStr>>>,
522533
resolved_envs: Vec<(String, String)>,
@@ -587,10 +598,14 @@ impl CommandHandler for VitePlusCommandHandler {
587598
};
588599
match cli_args {
589600
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-
))
601+
// Check is a composite command (fmt + lint) — run as a subprocess in task scripts
602+
Ok(HandledCommand::Synthesized(command.to_synthetic_plan_request(
603+
UserCacheConfig::with_config(EnabledCacheConfig {
604+
env: Some(Box::new([Str::from("OXLINT_TSGOLINT_PATH")])),
605+
untracked_env: None,
606+
input: Some(base_cache_inputs()),
607+
}),
608+
)))
594609
}
595610
CLIArgs::Synthesizable(subcmd) => {
596611
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"commands": [
3+
"vp run check # first run should be cache miss",
4+
"vp run check # second run should be cache hit",
5+
"echo 'export const foo = 1;' > src/foo.js",
6+
"vp run check # third run should be cache miss after new file added"
7+
]
8+
}
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)