Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions crates/vite_task/src/session/execute/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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/") {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Writing hardcode rules here in vite-task doesn't look good. It makes sense that this global configuration should be passed in vite-plus

return None;
}

if !resolved_negatives.is_empty()
&& resolved_negatives.iter().any(|neg| neg.is_match(relative.as_str()))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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()}`);
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "cache-skip-vite-temp",
"private": true
}
Original file line number Diff line number Diff line change
@@ -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",
]
Original file line number Diff line number Diff line change
@@ -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';
Original file line number Diff line number Diff line change
@@ -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, <duration> saved.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const hello = 'world';
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"cache": true,
"tasks": {
"build": {
"command": "node build.mjs",
"cache": true
}
}
}
Loading