Skip to content

Commit ffd0eed

Browse files
committed
fix: skip node_modules/.vite-temp/ from fspy tracking
Vite writes transient compiled config files to node_modules/.vite-temp/ during builds. These files are both read and written by the build process, causing fspy to detect a read-write overlap that prevents caching with "not cached because it modified its input". Exclude node_modules/.vite-temp/ paths from fspy tracking, similar to the existing .git exclusion. These are ephemeral build artifacts that should never affect cache correctness. Closes voidzero-dev/vite-plus#1095
1 parent 69cc6eb commit ffd0eed

8 files changed

Lines changed: 80 additions & 0 deletions

File tree

crates/vite_task/src/session/execute/spawn.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@ pub async fn spawn_with_tracking(
211211
return None;
212212
}
213213

214+
// Skip Vite temp config files (transient build artifacts)
215+
if relative.as_str().contains("node_modules/.vite-temp/") {
216+
return None;
217+
}
218+
214219
if !resolved_negatives.is_empty()
215220
&& resolved_negatives.iter().any(|neg| neg.is_match(relative.as_str()))
216221
{
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Simulates Vite's behavior during build:
2+
// 1. Reads the source file (tracked as input by fspy)
3+
// 2. Writes a temp config to node_modules/.vite-temp/ (also tracked by fspy)
4+
// Without the .vite-temp exclusion, step 2 causes a read-write overlap
5+
// that prevents caching.
6+
7+
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
8+
9+
// Read source (tracked as input)
10+
const source = readFileSync('src/index.ts', 'utf-8');
11+
12+
// Simulate Vite writing temp config (read-write to .vite-temp)
13+
const tempDir = 'node_modules/.vite-temp';
14+
mkdirSync(tempDir, { recursive: true });
15+
const tempFile = `${tempDir}/vite.config.ts.timestamp-${Date.now()}.mjs`;
16+
writeFileSync(tempFile, `// compiled config\nexport default {};`);
17+
18+
console.log(`built: ${source.trim()}`);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "cache-skip-vite-temp",
3+
"private": true
4+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Tests that node_modules/.vite-temp/ is excluded from fspy tracking,
2+
# so tasks writing to .vite-temp (like Vite config compilation) are still cached.
3+
# See: https://github.com/voidzero-dev/vite-plus/issues/1095
4+
5+
[[e2e]]
6+
name = "vite-temp read-write does not prevent caching"
7+
steps = [
8+
"vt run build # first run: cache miss",
9+
"vt run build # second run: should hit cache despite .vite-temp write",
10+
]
11+
12+
[[e2e]]
13+
name = "source change still causes cache miss"
14+
steps = [
15+
"vt run build # first run: cache miss",
16+
"replace-file-content src/index.ts world universe # modify real source",
17+
"vt run build # cache miss: source changed",
18+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
source: crates/vite_task_bin/tests/e2e_snapshots/main.rs
3+
expression: e2e_outputs
4+
---
5+
> vt run build # first run: cache miss
6+
$ node build.mjs
7+
built: export const hello = "world";
8+
> replace-file-content src/index.ts world universe # modify real source
9+
10+
> vt run build # cache miss: source changed
11+
$ node build.mjscache miss: 'src/index.ts' modified, executing
12+
built: export const hello = "universe";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
source: crates/vite_task_bin/tests/e2e_snapshots/main.rs
3+
expression: e2e_outputs
4+
---
5+
> vt run build # first run: cache miss
6+
$ node build.mjs
7+
built: export const hello = "world";
8+
> vt run build # second run: should hit cache despite .vite-temp write
9+
$ node build.mjscache hit, replaying
10+
built: export const hello = "world";
11+
12+
---
13+
vt run: cache hit, <duration> saved.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const hello = 'world';
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"cache": true,
3+
"tasks": {
4+
"build": {
5+
"command": "node build.mjs",
6+
"cache": true
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)