Skip to content

Commit 5f52b6c

Browse files
committed
fix(cache): exclude node_modules/.vite-temp from cache input tracking (#1096)
## Summary - Bump vite-task to [2663222c](voidzero-dev/vite-task#296) which merges synthetic task's `input` config with parent cache config and supports `GlobWithBase` with `InputBase::Workspace` - Add `!node_modules/.vite-temp/**` negative input glob (workspace-root-relative) to Pack and Build subcommands - Update test for `trailing_var_arg` CLI parsing change - Add comprehensive snap tests for cache behavior Vite writes transient compiled config files to `node_modules/.vite-temp/` during builds. These files were tracked by fspy as both read and written, causing a read-write overlap that prevented caching ("not cached because it modified its input"). The fix passes `!node_modules/.vite-temp/**` as a `GlobWithBase { base: InputBase::Workspace }` negative glob via `EnabledCacheConfig.input` on Pack and Build subcommands. vite-task PR [#296](voidzero-dev/vite-task#296) ensures this glob is resolved relative to the workspace root and merged into the parent task's input config. vite-task changelog: voidzero-dev/vite-task@69cc6eb...2663222#diff-06572a96a58dc510037d5efa622f9bec8519bc1beab13c9f251e97e657a9d4ed ## Snap tests | Test | Verifies | | --- | --- | | `command-pack-monorepo` | cache hit (root + sub dir), source change miss, direct `vp pack` not cached | | `vp-build-cache` | cache hit via `vp run`, direct `vp build` not cached | | `vp-build-cache-monorepo` | cache hit (root + sub dir), source change miss, direct `vp build` not cached | | `vp-pack-cache-disabled` | `cache: false` disables caching for `vp pack` | | `vp-build-cache-disabled` | `cache: false` disables caching for `vp build` | ## Test plan - [x] `cargo check` and `cargo test` pass (with `-D warnings`) - [x] All snap tests pass locally - [x] CI passes on all platforms Closes #1095 🤖 Generated with [Claude Code](https://claude.com/claude-code)
1 parent 60ea46e commit 5f52b6c

File tree

36 files changed

+372
-96
lines changed

36 files changed

+372
-96
lines changed

Cargo.lock

Lines changed: 18 additions & 18 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
@@ -85,7 +85,7 @@ dunce = "1.0.5"
8585
fast-glob = "1.0.0"
8686
flate2 = { version = "=1.1.9", features = ["zlib-rs"] }
8787
form_urlencoded = "1.2.1"
88-
fspy = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "69cc6eba95a3b7f25f7d4d32c3f29b1386995907" }
88+
fspy = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "2663222c6b5bf4be8ca60e1c2e5bd6619596f414" }
8989
futures = "0.3.31"
9090
futures-util = "0.3.31"
9191
glob = "0.3.2"
@@ -185,15 +185,15 @@ vfs = "0.13.0"
185185
vite_command = { path = "crates/vite_command" }
186186
vite_error = { path = "crates/vite_error" }
187187
vite_js_runtime = { path = "crates/vite_js_runtime" }
188-
vite_glob = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "69cc6eba95a3b7f25f7d4d32c3f29b1386995907" }
188+
vite_glob = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "2663222c6b5bf4be8ca60e1c2e5bd6619596f414" }
189189
vite_install = { path = "crates/vite_install" }
190190
vite_migration = { path = "crates/vite_migration" }
191191
vite_shared = { path = "crates/vite_shared" }
192192
vite_static_config = { path = "crates/vite_static_config" }
193-
vite_path = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "69cc6eba95a3b7f25f7d4d32c3f29b1386995907" }
194-
vite_str = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "69cc6eba95a3b7f25f7d4d32c3f29b1386995907" }
195-
vite_task = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "69cc6eba95a3b7f25f7d4d32c3f29b1386995907" }
196-
vite_workspace = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "69cc6eba95a3b7f25f7d4d32c3f29b1386995907" }
193+
vite_path = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "2663222c6b5bf4be8ca60e1c2e5bd6619596f414" }
194+
vite_str = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "2663222c6b5bf4be8ca60e1c2e5bd6619596f414" }
195+
vite_task = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "2663222c6b5bf4be8ca60e1c2e5bd6619596f414" }
196+
vite_workspace = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "2663222c6b5bf4be8ca60e1c2e5bd6619596f414" }
197197
walkdir = "2.5.0"
198198
wax = "0.6.0"
199199
which = "8.0.0"

packages/cli/binding/src/cli.rs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ use vite_task::{
2323
Command, CommandHandler, ExitStatus, HandledCommand, ScriptCommand, Session, SessionConfig,
2424
config::{
2525
UserRunConfig,
26-
user::{EnabledCacheConfig, UserCacheConfig},
26+
user::{
27+
AutoInput, EnabledCacheConfig, GlobWithBase, InputBase, UserCacheConfig, UserInputEntry,
28+
},
2729
},
2830
loader::UserConfigLoader,
2931
plan_request::SyntheticPlanRequest,
@@ -329,7 +331,13 @@ impl SubcommandResolver {
329331
cache_config: UserCacheConfig::with_config(EnabledCacheConfig {
330332
env: Some(Box::new([Str::from("VITE_*")])),
331333
untracked_env: None,
332-
input: None,
334+
input: Some(vec![
335+
UserInputEntry::Auto(AutoInput { auto: true }),
336+
UserInputEntry::GlobWithBase(GlobWithBase {
337+
pattern: Str::from("!node_modules/.vite-temp/**"),
338+
base: InputBase::Workspace,
339+
}),
340+
]),
333341
}),
334342
envs: merge_resolved_envs_with_version(envs, resolved.envs),
335343
})
@@ -381,7 +389,13 @@ impl SubcommandResolver {
381389
cache_config: UserCacheConfig::with_config(EnabledCacheConfig {
382390
env: None,
383391
untracked_env: None,
384-
input: None,
392+
input: Some(vec![
393+
UserInputEntry::Auto(AutoInput { auto: true }),
394+
UserInputEntry::GlobWithBase(GlobWithBase {
395+
pattern: Str::from("!node_modules/.vite-temp/**"),
396+
base: InputBase::Workspace,
397+
}),
398+
]),
385399
}),
386400
envs: merge_resolved_envs(envs, resolved.envs),
387401
})
@@ -1534,7 +1548,7 @@ mod tests {
15341548

15351549
use clap::Parser;
15361550
use serde_json::json;
1537-
use vite_task::config::UserRunConfig;
1551+
use vite_task::{Command, config::UserRunConfig};
15381552

15391553
use super::{
15401554
CLIArgs, LintMessageKind, SynthesizableSubcommand, extract_unknown_argument,
@@ -1570,11 +1584,13 @@ mod tests {
15701584
}
15711585

15721586
#[test]
1573-
fn unknown_argument_detected_with_pass_as_value_hint() {
1574-
let error =
1575-
CLIArgs::try_parse_from(["vp", "run", "--yolo"]).expect_err("Expected parse error");
1576-
assert_eq!(extract_unknown_argument(&error).as_deref(), Some("--yolo"));
1577-
assert!(has_pass_as_value_suggestion(&error));
1587+
fn run_accepts_unknown_flags_as_task_args() {
1588+
// After trailing_var_arg change, unknown flags like --yolo are
1589+
// accepted as task arguments instead of producing a parse error.
1590+
let args = CLIArgs::try_parse_from(["vp", "run", "--yolo"]).unwrap();
1591+
let debug = vite_str::format!("{args:?}");
1592+
assert!(debug.contains("\"--yolo\""), "Expected --yolo in task args, got: {debug}",);
1593+
assert!(matches!(args, CLIArgs::ViteTask(Command::Run(_))));
15781594
}
15791595

15801596
#[test]
Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,41 @@
1-
> vp run hello#build # should build the library
1+
> vp run hello#build # should build the library from root
22
> ls packages/hello/dist # should have the library
33
index.cjs
44

5-
> vp run hello#build 2>&1 # should hit cache but not working for now
6-
~/packages/hello$ vp pack
7-
ℹ entry: src/index.ts
8-
ℹ Build start
9-
ℹ Cleaning 1 files
10-
ℹ dist/index.cjs <variable> kB │ gzip: <variable> kB
11-
ℹ 1 files, total: <variable> kB
12-
✔ Build complete in <variable>ms
5+
> vp run hello#build 2>&1 | grep 'cache hit' # should hit cache from root
6+
~/packages/hello$ vp pack ◉ cache hit, replaying
7+
vp run: cache hit, <variable>ms saved.
138

14-
---
15-
vp run: hello#build not cached because it modified its input. (Run `vp run --last-details` for full details)
9+
> cd packages/hello && vp run build 2>&1 | grep 'cache hit' # should hit cache from sub dir
10+
~/packages/hello$ vp pack ◉ cache hit, replaying
11+
vp run: cache hit, <variable>ms saved.
1612

17-
> vp run array-config#build # should build the library supports array config
13+
> cd packages/hello && vp pack 2>&1 # direct vp pack should not be cached
14+
> cd packages/hello && vp pack 2>&1 | grep -c 'cache' || echo 'no cache' # direct vp pack has no cache
15+
0
16+
no cache
17+
18+
> echo 'export function hello() { console.log("changed"); }' > packages/hello/src/hello.ts
19+
> vp run hello#build 2>&1 | grep 'cache miss' # should miss cache after source change
20+
~/packages/hello$ vp pack ○ cache miss: 'packages/hello/src/hello.ts' modified, executing
21+
22+
> cd packages/array-config && vp run build # should build the library from sub dir
1823
> ls packages/array-config/dist # should have the library
1924
index.d.mts
2025
index.mjs
2126

22-
> vp run array-config#build 2>&1 # should hit cache but not working
23-
~/packages/array-config$ vp pack
24-
ℹ entry: src/sub/index.ts
25-
ℹ Build start
26-
ℹ Cleaning 2 files
27-
ℹ dist/index.mjs <variable> kB │ gzip: <variable> kB
28-
ℹ dist/index.d.mts <variable> kB │ gzip: <variable> kB
29-
ℹ 2 files, total: <variable> kB
30-
✔ Build complete in <variable>ms
27+
> cd packages/array-config && vp run build 2>&1 | grep 'cache hit' # should hit cache from sub dir
28+
~/packages/array-config$ vp pack ◉ cache hit, replaying
29+
vp run: cache hit, <variable>ms saved.
3130

32-
---
33-
vp run: array-config#build not cached because it modified its input. (Run `vp run --last-details` for full details)
31+
> vp run array-config#build 2>&1 | grep 'cache hit' # should hit cache from root after sub dir build
32+
~/packages/array-config$ vp pack ◉ cache hit, replaying
33+
vp run: cache hit, <variable>ms saved.
3434

35-
> vp run default-config#build # should build the library supports default config
35+
> vp run default-config#build # should build the library from root
3636
> ls packages/default-config/dist # should have the library
3737
index.mjs
3838

39-
> vp run default-config#build 2>&1 # should hit cache but not working
40-
~/packages/default-config$ vp pack
41-
ℹ entry: src/index.ts
42-
ℹ Build start
43-
ℹ Cleaning 1 files
44-
ℹ dist/index.mjs <variable> kB │ gzip: <variable> kB
45-
ℹ 1 files, total: <variable> kB
46-
✔ Build complete in <variable>ms
47-
48-
---
49-
vp run: default-config#build not cached because it modified its input. (Run `vp run --last-details` for full details)
39+
> cd packages/default-config && vp run build 2>&1 | grep 'cache hit' # should hit cache from sub dir
40+
~/packages/default-config$ vp pack ◉ cache hit, replaying
41+
vp run: cache hit, <variable>ms saved.
Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
11
{
2-
"ignoredPlatforms": ["win32"],
32
"commands": [
43
{
5-
"command": "vp run hello#build # should build the library",
4+
"command": "vp run hello#build # should build the library from root",
65
"ignoreOutput": true
76
},
87
"ls packages/hello/dist # should have the library",
9-
"vp run hello#build 2>&1 # should hit cache but not working for now",
8+
"vp run hello#build 2>&1 | grep 'cache hit' # should hit cache from root",
9+
"cd packages/hello && vp run build 2>&1 | grep 'cache hit' # should hit cache from sub dir",
1010
{
11-
"command": "vp run array-config#build # should build the library supports array config",
11+
"command": "cd packages/hello && vp pack 2>&1 # direct vp pack should not be cached",
12+
"ignoreOutput": true
13+
},
14+
"cd packages/hello && vp pack 2>&1 | grep -c 'cache' || echo 'no cache' # direct vp pack has no cache",
15+
"echo 'export function hello() { console.log(\"changed\"); }' > packages/hello/src/hello.ts",
16+
"vp run hello#build 2>&1 | grep 'cache miss' # should miss cache after source change",
17+
{
18+
"command": "cd packages/array-config && vp run build # should build the library from sub dir",
1219
"ignoreOutput": true
1320
},
1421
"ls packages/array-config/dist # should have the library",
15-
"vp run array-config#build 2>&1 # should hit cache but not working",
22+
"cd packages/array-config && vp run build 2>&1 | grep 'cache hit' # should hit cache from sub dir",
23+
"vp run array-config#build 2>&1 | grep 'cache hit' # should hit cache from root after sub dir build",
1624
{
17-
"command": "vp run default-config#build # should build the library supports default config",
25+
"command": "vp run default-config#build # should build the library from root",
1826
"ignoreOutput": true
1927
},
2028
"ls packages/default-config/dist # should have the library",
21-
"vp run default-config#build 2>&1 # should hit cache but not working"
29+
"cd packages/default-config && vp run build 2>&1 | grep 'cache hit' # should hit cache from sub dir"
2230
]
2331
}

packages/cli/snap-tests/command-pack/snap.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,17 @@ $ vp pack src/index.ts
5959
ℹ 1 files, total: <variable> kB
6060
✔ Build complete in <variable>ms
6161

62-
---
63-
vp run: command-pack#pack not cached because it modified its input. (Run `vp run --last-details` for full details)
6462

6563
> ls dist # should have the library
6664
index.mjs
6765

6866
> vp run pack # should hit cache
69-
$ vp pack src/index.ts
67+
$ vp pack src/index.ts ◉ cache hit, replaying
7068
ℹ entry: src/index.ts
7169
ℹ Build start
72-
ℹ Cleaning 1 files
7370
ℹ dist/index.mjs <variable> kB │ gzip: <variable> kB
7471
ℹ 1 files, total: <variable> kB
7572
✔ Build complete in <variable>ms
7673

7774
---
78-
vp run: command-pack#pack not cached because it modified its input. (Run `vp run --last-details` for full details)
75+
vp run: cache hit, <variable>ms saved.

0 commit comments

Comments
 (0)