Skip to content

Commit ddcfd46

Browse files
wan9chicodex
andauthored
test(e2e): use patched vite for portable build cache (#496)
## Motivation The portable Vite build cache e2e should exercise the default `vite build` path, not the `--configLoader runner` workaround. This PR uses a pnpm patch for `vite@8.1.0` that includes the bundled config temp-dir fix from vitejs/vite#22800. With that patch in place, the fixture can run plain `vite build` and still verify that a copied task cache is reused after restore. Co-authored-by: GPT-5 Codex <codex@openai.com>
1 parent 6cfa6e4 commit ddcfd46

6 files changed

Lines changed: 64 additions & 30 deletions

File tree

‎crates/vite_task_bin/tests/e2e_snapshots/fixtures/vite_build_cache/portable_clone/vite-task.json‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
22
"tasks": {
33
"build": {
4-
// TODO: --configLoader runner works around a Vite config-loader bug that makes this cache non-portable.
5-
"command": "vite build --configLoader runner",
4+
"command": "vite build",
65
"cache": true
76
}
87
}

‎crates/vite_task_bin/tests/e2e_snapshots/fixtures/vite_build_cache/portable_origin/vite-task.json‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
22
"tasks": {
33
"build": {
4-
// TODO: --configLoader runner works around a Vite config-loader bug that makes this cache non-portable.
5-
"command": "vite build --configLoader runner",
4+
"command": "vite build",
65
"cache": true
76
}
87
}

‎crates/vite_task_bin/tests/e2e_snapshots/fixtures/vite_build_cache/snapshots/vite_build_cache_is_portable_across_workspace_roots.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Two identical plain Vite workspaces run from different absolute roots. The test
77
origin workspace root: cache miss populates its default cache
88

99
```
10-
$ vite build --configLoader runner
10+
$ vite build
1111
```
1212

1313
## `cd portable_origin && vtt stat-file dist/assets/index.js`
@@ -30,7 +30,7 @@ copy-paste the cache directory to simulate upload/download
3030
clone workspace root: cache hit from the origin root
3131

3232
```
33-
$ vite build --configLoader runner ◉ cache hit, replaying
33+
$ vite build ◉ cache hit, replaying
3434
3535
---
3636
vt run: cache hit.

‎patches/vite@8.1.0.patch‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
diff --git a/dist/node/chunks/node.js b/dist/node/chunks/node.js
2+
index 8d6dbaf1f21914bcf02576f8a5f13546a3dcdce8..49b30abd781d906c2cbc47e6c035f00f70b26554 100644
3+
--- a/dist/node/chunks/node.js
4+
+++ b/dist/node/chunks/node.js
5+
@@ -35651,17 +35651,19 @@ const _require = createRequire(
6+
);
7+
async function loadConfigFromBundledFile(fileName, bundledCode, isESM) {
8+
if (isESM) {
9+
- let nodeModulesDir = typeof process.versions.deno === "string" ? void 0 : findNearestNodeModules(path.dirname(fileName));
10+
- if (nodeModulesDir) try {
11+
- await fsp.mkdir(path.resolve(nodeModulesDir, ".vite-temp/"), { recursive: true });
12+
+ const nodeModulesDir = typeof process.versions.deno === "string" ? void 0 : findNearestNodeModules(path.dirname(fileName));
13+
+ let viteTempDir = nodeModulesDir ? path.resolve(nodeModulesDir, ".vite-temp") : void 0;
14+
+ if (viteTempDir) try {
15+
+ await fsp.mkdir(viteTempDir, { recursive: true });
16+
} catch (e) {
17+
- if (e.code === "EACCES") nodeModulesDir = void 0;
18+
+ if (e.code === "EACCES") viteTempDir = void 0;
19+
else throw e;
20+
}
21+
const hash = `timestamp-${Date.now()}-${Math.random().toString(16).slice(2)}`;
22+
- const tempFileName = nodeModulesDir ? path.resolve(nodeModulesDir, `.vite-temp/${path.basename(fileName)}.${hash}.mjs`) : `${fileName}.${hash}.mjs`;
23+
- ignoreInput(tempFileName);
24+
- ignoreOutput(tempFileName);
25+
+ const tempFileName = viteTempDir ? path.resolve(viteTempDir, `${path.basename(fileName)}.${hash}.mjs`) : `${fileName}.${hash}.mjs`;
26+
+ const pathToIgnore = viteTempDir ?? tempFileName;
27+
+ ignoreInput(pathToIgnore);
28+
+ ignoreOutput(pathToIgnore);
29+
await fsp.writeFile(tempFileName, bundledCode);
30+
try {
31+
return (await import(pathToFileURL(tempFileName).href)).default;

‎pnpm-lock.yaml‎

Lines changed: 27 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pnpm-workspace.yaml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ overrides:
2424
# override above routes vite to the Vite+ toolchain fork, which does not carry
2525
# the integration — so scope vite-task-tools' `vite` to a real upstream build.
2626
vite-task-tools>vite: ^8.1.0
27+
patchedDependencies:
28+
vite@8.1.0: patches/vite@8.1.0.patch
2729
peerDependencyRules:
2830
allowAny:
2931
- vite

0 commit comments

Comments
 (0)