fix: 隔离 Workbench Vite 依赖缓存

This commit is contained in:
root
2026-07-21 04:13:37 +02:00
parent ad9a8524a8
commit 8cd1019478
2 changed files with 16 additions and 1 deletions
@@ -1,6 +1,6 @@
import { describe, expect, test } from "bun:test";
import { parseWorkbenchNativeRuntimeConfig } from "../vite.config";
import { nativeViteCacheDir, parseWorkbenchNativeRuntimeConfig } from "../vite.config";
const validConfig = {
displayTime: { timeZone: "Asia/Shanghai", locale: "zh-CN", label: "北京时间" },
@@ -19,4 +19,13 @@ describe("Workbench native Vite runtime config", () => {
test("fails closed when required runtime capabilities are missing", () => {
expect(() => parseWorkbenchNativeRuntimeConfig(JSON.stringify({ displayTime: validConfig.displayTime, workbench: {} }))).toThrow("workbench.realtimeFeatures");
});
test("isolates Vite optimizer caches by native runtime", () => {
const workbench = nativeViteCacheDir({ nativeApiUrl: "http://127.0.0.1:6677", nativeCaseRunEnabled: false });
const caserun = nativeViteCacheDir({ nativeApiUrl: "", nativeCaseRunEnabled: true });
const cloudWeb = nativeViteCacheDir({ nativeApiUrl: "", nativeCaseRunEnabled: false });
expect(new Set([workbench, caserun, cloudWeb]).size).toBe(3);
expect(workbench).toBe(".state/vite/workbench");
});
});
+6
View File
@@ -31,6 +31,7 @@ export default defineConfig(({ mode }) => {
: undefined;
return {
cacheDir: nativeViteCacheDir({ nativeApiUrl, nativeCaseRunEnabled }),
plugins: [
...(nativeApiUrl ? [nativeRuntimeConfigPlugin(nativeRuntimeConfig)] : []),
...(nativeCaseRunEnabled ? [nativeCaseRunRuntimeConfigPlugin()] : []),
@@ -65,6 +66,11 @@ export default defineConfig(({ mode }) => {
};
});
export function nativeViteCacheDir(input: { nativeApiUrl: string; nativeCaseRunEnabled: boolean }): string {
const runtime = input.nativeApiUrl ? "workbench" : input.nativeCaseRunEnabled ? "caserun" : "cloud-web";
return `.state/vite/${runtime}`;
}
function nativeRuntimeConfigPlugin(serialized: string): Plugin {
const config = parseWorkbenchNativeRuntimeConfig(serialized);
const inlineJson = JSON.stringify(config).replace(/</gu, "\\u003c");