fix(preload): keep zod out of sandbox bundle
This commit is contained in:
1 parent
fa006524c2
commit
710448a75f
4 files changed
+19
-7
No files matched your search
@@ -58,6 +58,7 @@ oldreference/
|
|||||||
!/docs/architecture/*.md
|
!/docs/architecture/*.md
|
||||||
!/CLAUDE.md
|
!/CLAUDE.md
|
||||||
!/AGENTS.md
|
!/AGENTS.md
|
||||||
|
!/问题.md
|
||||||
!/.planning/**/*.md
|
!/.planning/**/*.md
|
||||||
!/src/main/prompt-builder/**/*.md
|
!/src/main/prompt-builder/**/*.md
|
||||||
!/scripts/README.md
|
!/scripts/README.md
|
||||||
|
|||||||
@@ -22,10 +22,7 @@ export default defineConfig({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
preload: {
|
preload: {
|
||||||
// zod is bundled into preload because preload runs as sandboxed CJS
|
plugins: [externalizeDepsPlugin()],
|
||||||
// and cannot resolve externalized ESM deps at runtime. Inlining keeps
|
|
||||||
// IPC Zod validation working inside the preload layer.
|
|
||||||
plugins: [externalizeDepsPlugin({ exclude: ["zod"] })],
|
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
"@shared": resolve("src/shared"),
|
"@shared": resolve("src/shared"),
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import { contextBridge, ipcRenderer } from "electron";
|
import { contextBridge, ipcRenderer } from "electron";
|
||||||
|
import { IPC_CHANNELS } from "@shared/contracts/channels";
|
||||||
|
import type { DesktopApi } from "@shared/contracts/desktop-api";
|
||||||
import {
|
import {
|
||||||
IPC_CHANNELS,
|
|
||||||
PRELOAD_FORWARDERS,
|
PRELOAD_FORWARDERS,
|
||||||
mapPreloadInvokeArgs,
|
mapPreloadInvokeArgs,
|
||||||
type DesktopApi,
|
|
||||||
type PreloadForwardedApi,
|
type PreloadForwardedApi,
|
||||||
} from "@shared/contracts";
|
} from "@shared/contracts/preload-forwarders";
|
||||||
import type { DesktopEvent } from "@shared/types";
|
import type { DesktopEvent } from "@shared/types";
|
||||||
|
|
||||||
function createForwardedApi(): PreloadForwardedApi {
|
function createForwardedApi(): PreloadForwardedApi {
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { readFileSync } from "node:fs";
|
||||||
|
import { join } from "node:path";
|
||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
describe("preload bundling contract", () => {
|
||||||
|
it("keeps Zod validation on the main-process IPC boundary", () => {
|
||||||
|
const configSource = readFileSync(join(process.cwd(), "electron.vite.config.ts"), "utf8");
|
||||||
|
const preloadSource = readFileSync(join(process.cwd(), "src/preload/index.ts"), "utf8");
|
||||||
|
|
||||||
|
expect(configSource).not.toContain('exclude: ["zod"]');
|
||||||
|
expect(preloadSource).not.toContain('from "@shared/contracts"');
|
||||||
|
expect(preloadSource).not.toMatch(/from ["']zod["']|require\(["']zod["']\)/);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in new issue
Block a user