From ffd0eed36cf20d3fbefc1e451b5a7c2b3ca44cd6 Mon Sep 17 00:00:00 2001 From: MK Date: Sun, 22 Mar 2026 19:24:40 +0800 Subject: [PATCH 1/2] 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 https://github.com/voidzero-dev/vite-plus/issues/1095 --- crates/vite_task/src/session/execute/spawn.rs | 5 +++++ .../fixtures/cache-skip-vite-temp/build.mjs | 18 ++++++++++++++++++ .../fixtures/cache-skip-vite-temp/package.json | 4 ++++ .../cache-skip-vite-temp/snapshots.toml | 18 ++++++++++++++++++ .../source change still causes cache miss.snap | 12 ++++++++++++ ...mp read-write does not prevent caching.snap | 13 +++++++++++++ .../fixtures/cache-skip-vite-temp/src/index.ts | 1 + .../cache-skip-vite-temp/vite-task.json | 9 +++++++++ 8 files changed, 80 insertions(+) create mode 100644 crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/build.mjs create mode 100644 crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/package.json create mode 100644 crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/snapshots.toml create mode 100644 crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/snapshots/source change still causes cache miss.snap create mode 100644 crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/snapshots/vite-temp read-write does not prevent caching.snap create mode 100644 crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/src/index.ts create mode 100644 crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/vite-task.json diff --git a/crates/vite_task/src/session/execute/spawn.rs b/crates/vite_task/src/session/execute/spawn.rs index 99ebae87..88f67ff8 100644 --- a/crates/vite_task/src/session/execute/spawn.rs +++ b/crates/vite_task/src/session/execute/spawn.rs @@ -211,6 +211,11 @@ pub async fn spawn_with_tracking( return None; } + // Skip Vite temp config files (transient build artifacts) + if relative.as_str().contains("node_modules/.vite-temp/") { + return None; + } + if !resolved_negatives.is_empty() && resolved_negatives.iter().any(|neg| neg.is_match(relative.as_str())) { diff --git a/crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/build.mjs b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/build.mjs new file mode 100644 index 00000000..cef1041d --- /dev/null +++ b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/build.mjs @@ -0,0 +1,18 @@ +// Simulates Vite's behavior during build: +// 1. Reads the source file (tracked as input by fspy) +// 2. Writes a temp config to node_modules/.vite-temp/ (also tracked by fspy) +// Without the .vite-temp exclusion, step 2 causes a read-write overlap +// that prevents caching. + +import { readFileSync, writeFileSync, mkdirSync } from 'node:fs'; + +// Read source (tracked as input) +const source = readFileSync('src/index.ts', 'utf-8'); + +// Simulate Vite writing temp config (read-write to .vite-temp) +const tempDir = 'node_modules/.vite-temp'; +mkdirSync(tempDir, { recursive: true }); +const tempFile = `${tempDir}/vite.config.ts.timestamp-${Date.now()}.mjs`; +writeFileSync(tempFile, `// compiled config\nexport default {};`); + +console.log(`built: ${source.trim()}`); diff --git a/crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/package.json b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/package.json new file mode 100644 index 00000000..a72136cd --- /dev/null +++ b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/package.json @@ -0,0 +1,4 @@ +{ + "name": "cache-skip-vite-temp", + "private": true +} diff --git a/crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/snapshots.toml b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/snapshots.toml new file mode 100644 index 00000000..d787c894 --- /dev/null +++ b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/snapshots.toml @@ -0,0 +1,18 @@ +# Tests that node_modules/.vite-temp/ is excluded from fspy tracking, +# so tasks writing to .vite-temp (like Vite config compilation) are still cached. +# See: https://github.com/voidzero-dev/vite-plus/issues/1095 + +[[e2e]] +name = "vite-temp read-write does not prevent caching" +steps = [ + "vt run build # first run: cache miss", + "vt run build # second run: should hit cache despite .vite-temp write", +] + +[[e2e]] +name = "source change still causes cache miss" +steps = [ + "vt run build # first run: cache miss", + "replace-file-content src/index.ts world universe # modify real source", + "vt run build # cache miss: source changed", +] diff --git a/crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/snapshots/source change still causes cache miss.snap b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/snapshots/source change still causes cache miss.snap new file mode 100644 index 00000000..67c22eef --- /dev/null +++ b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/snapshots/source change still causes cache miss.snap @@ -0,0 +1,12 @@ +--- +source: crates/vite_task_bin/tests/e2e_snapshots/main.rs +expression: e2e_outputs +--- +> vt run build # first run: cache miss +$ node build.mjs +built: export const hello = "world"; +> replace-file-content src/index.ts world universe # modify real source + +> vt run build # cache miss: source changed +$ node build.mjs ○ cache miss: 'src/index.ts' modified, executing +built: export const hello = "universe"; diff --git a/crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/snapshots/vite-temp read-write does not prevent caching.snap b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/snapshots/vite-temp read-write does not prevent caching.snap new file mode 100644 index 00000000..60a5011c --- /dev/null +++ b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/snapshots/vite-temp read-write does not prevent caching.snap @@ -0,0 +1,13 @@ +--- +source: crates/vite_task_bin/tests/e2e_snapshots/main.rs +expression: e2e_outputs +--- +> vt run build # first run: cache miss +$ node build.mjs +built: export const hello = "world"; +> vt run build # second run: should hit cache despite .vite-temp write +$ node build.mjs ◉ cache hit, replaying +built: export const hello = "world"; + +--- +vt run: cache hit, saved. diff --git a/crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/src/index.ts b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/src/index.ts new file mode 100644 index 00000000..35f468bf --- /dev/null +++ b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/src/index.ts @@ -0,0 +1 @@ +export const hello = 'world'; diff --git a/crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/vite-task.json b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/vite-task.json new file mode 100644 index 00000000..5426ee1e --- /dev/null +++ b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/vite-task.json @@ -0,0 +1,9 @@ +{ + "cache": true, + "tasks": { + "build": { + "command": "node build.mjs", + "cache": true + } + } +} From d70bd7ec238b0c6619599257bb7d762fdf36aa8e Mon Sep 17 00:00:00 2001 From: MK Date: Sun, 22 Mar 2026 19:31:58 +0800 Subject: [PATCH 2/2] fix: update snapshots to match formatted source quotes --- .../snapshots/source change still causes cache miss.snap | 4 ++-- .../vite-temp read-write does not prevent caching.snap | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/snapshots/source change still causes cache miss.snap b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/snapshots/source change still causes cache miss.snap index 67c22eef..00dc2fd2 100644 --- a/crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/snapshots/source change still causes cache miss.snap +++ b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/snapshots/source change still causes cache miss.snap @@ -4,9 +4,9 @@ expression: e2e_outputs --- > vt run build # first run: cache miss $ node build.mjs -built: export const hello = "world"; +built: export const hello = 'world'; > replace-file-content src/index.ts world universe # modify real source > vt run build # cache miss: source changed $ node build.mjs ○ cache miss: 'src/index.ts' modified, executing -built: export const hello = "universe"; +built: export const hello = 'universe'; diff --git a/crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/snapshots/vite-temp read-write does not prevent caching.snap b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/snapshots/vite-temp read-write does not prevent caching.snap index 60a5011c..7b8ce5c4 100644 --- a/crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/snapshots/vite-temp read-write does not prevent caching.snap +++ b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-skip-vite-temp/snapshots/vite-temp read-write does not prevent caching.snap @@ -4,10 +4,10 @@ expression: e2e_outputs --- > vt run build # first run: cache miss $ node build.mjs -built: export const hello = "world"; +built: export const hello = 'world'; > vt run build # second run: should hit cache despite .vite-temp write $ node build.mjs ◉ cache hit, replaying -built: export const hello = "world"; +built: export const hello = 'world'; --- vt run: cache hit, saved.