Skip to content

Commit 502d89e

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 502d89e

10 files changed

Lines changed: 89 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
@@ -504,6 +504,21 @@ fn exclude_glob(pattern: &str, base: InputBase) -> UserInputEntry {
504504
UserInputEntry::GlobWithBase(GlobWithBase { pattern: Str::from(pattern), base })
505505
}
506506

507+
/// Cache input entries for the check command.
508+
/// The vp check subprocess is a full vp CLI process (not resolved to a binary like
509+
/// build/lint/fmt), so it accesses additional directories that must be excluded:
510+
/// - `.vite-temp`: config compilation cache, read+written during vp CLI startup
511+
/// - `.vite/task-cache`: task runner state files that change after each run
512+
fn check_cache_inputs() -> Vec<UserInputEntry> {
513+
vec![
514+
UserInputEntry::Auto(AutoInput { auto: true }),
515+
exclude_glob("!node_modules/.vite-temp/**", InputBase::Workspace),
516+
exclude_glob("!node_modules/.vite-temp/**", InputBase::Package),
517+
exclude_glob("!node_modules/.vite/task-cache/**", InputBase::Workspace),
518+
exclude_glob("!node_modules/.vite/task-cache/**", InputBase::Package),
519+
]
520+
}
521+
507522
/// Common cache input entries for build/pack commands.
508523
/// Excludes .vite-temp config files and dist output files that are both read and written.
509524
/// TODO: The hardcoded `!dist/**` exclusion is a temporary workaround. It will be replaced
@@ -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)