Skip to content

Commit a72e61b

Browse files
committed
fix(cache): add Package-scoped negative globs to prevent cache miss in monorepos
In monorepos, each package has its own node_modules/. When vp build/test/pack run, Vite creates .vite-temp/ config files and dist/ outputs that are both read and written during execution. The existing !node_modules/.vite-temp/** glob at Workspace scope only matched the workspace root, not package-level paths, causing perpetual cache misses due to read-write overlap detection. - Build: add Package-scoped !node_modules/.vite-temp/** and !dist/** - Test: add Package-scoped !node_modules/.vite-temp/** and !node_modules/.vite/**/results.json - Pack: add Package-scoped !node_modules/.vite-temp/** and !dist/**
1 parent 845b05b commit a72e61b

7 files changed

Lines changed: 64 additions & 1 deletion

File tree

packages/cli/binding/src/cli.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,14 @@ impl SubcommandResolver {
338338
pattern: Str::from("!node_modules/.vite-temp/**"),
339339
base: InputBase::Workspace,
340340
}),
341+
UserInputEntry::GlobWithBase(GlobWithBase {
342+
pattern: Str::from("!node_modules/.vite-temp/**"),
343+
base: InputBase::Package,
344+
}),
345+
UserInputEntry::GlobWithBase(GlobWithBase {
346+
pattern: Str::from("!dist/**"),
347+
base: InputBase::Package,
348+
}),
341349
]),
342350
}),
343351
envs: merge_resolved_envs_with_version(envs, resolved.envs),
@@ -366,7 +374,17 @@ impl SubcommandResolver {
366374
cache_config: UserCacheConfig::with_config(EnabledCacheConfig {
367375
env: None,
368376
untracked_env: None,
369-
input: None,
377+
input: Some(vec![
378+
UserInputEntry::Auto(AutoInput { auto: true }),
379+
UserInputEntry::GlobWithBase(GlobWithBase {
380+
pattern: Str::from("!node_modules/.vite-temp/**"),
381+
base: InputBase::Package,
382+
}),
383+
UserInputEntry::GlobWithBase(GlobWithBase {
384+
pattern: Str::from("!node_modules/.vite/vitest/**/results.json"),
385+
base: InputBase::Package,
386+
}),
387+
]),
370388
}),
371389
envs: merge_resolved_envs_with_version(envs, resolved.envs),
372390
})
@@ -396,6 +414,14 @@ impl SubcommandResolver {
396414
pattern: Str::from("!node_modules/.vite-temp/**"),
397415
base: InputBase::Workspace,
398416
}),
417+
UserInputEntry::GlobWithBase(GlobWithBase {
418+
pattern: Str::from("!node_modules/.vite-temp/**"),
419+
base: InputBase::Package,
420+
}),
421+
UserInputEntry::GlobWithBase(GlobWithBase {
422+
pattern: Str::from("!dist/**"),
423+
base: InputBase::Package,
424+
}),
399425
]),
400426
}),
401427
envs: merge_resolved_envs(envs, resolved.envs),
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "cache-monorepo-missing",
3+
"private": true,
4+
"workspaces": [
5+
"packages/*"
6+
],
7+
"scripts": {
8+
"ready": "vp run -r build"
9+
},
10+
"packageManager": "pnpm@10.32.1"
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "lib",
3+
"private": true,
4+
"scripts": {
5+
"build": "vp pack"
6+
}
7+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function add(a: number, b: number): number {
2+
return a + b;
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { defineConfig } from 'vite-plus';
2+
3+
export default defineConfig({});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
> vp run --cache ready # first run
2+
> vp run --cache ready 2>&1 | grep -E 'cache hit|modified' # second run should all hit cache
3+
~/packages/lib$ vp pack ◉ cache hit, replaying
4+
vp run: cache hit, <variable>ms saved.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"commands": [
3+
{
4+
"command": "vp run --cache ready # first run",
5+
"ignoreOutput": true
6+
},
7+
"vp run --cache ready 2>&1 | grep -E 'cache hit|modified' # second run should all hit cache"
8+
]
9+
}

0 commit comments

Comments
 (0)