mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-18 15:28:48 +03:00
fix(desktop): bundle selected main-process dependencies (#45774)
This commit is contained in:
committed by
GitHub
Unverified
parent
84fa689686
commit
4681c734b2
@@ -416,10 +416,7 @@
|
||||
"name": "@opencode-ai/desktop",
|
||||
"version": "1.18.15",
|
||||
"dependencies": {
|
||||
"@effect/platform-node": "catalog:",
|
||||
"@zip.js/zip.js": "2.7.62",
|
||||
"drizzle-orm": "catalog:",
|
||||
"effect": "catalog:",
|
||||
"electron-context-menu": "4.1.2",
|
||||
"electron-log": "^5",
|
||||
"electron-store": "11.0.2",
|
||||
@@ -429,6 +426,7 @@
|
||||
"devDependencies": {
|
||||
"@actions/artifact": "4.0.0",
|
||||
"@brendonovich/vite-plugin-opencode": "0.1.1",
|
||||
"@effect/platform-node": "catalog:",
|
||||
"@lydell/node-pty": "catalog:",
|
||||
"@opencode-ai/app": "workspace:*",
|
||||
"@opencode-ai/client": "workspace:*",
|
||||
@@ -442,6 +440,8 @@
|
||||
"@types/node": "catalog:",
|
||||
"@typescript/native-preview": "catalog:",
|
||||
"@valibot/to-json-schema": "1.6.0",
|
||||
"drizzle-orm": "catalog:",
|
||||
"effect": "catalog:",
|
||||
"electron": "42.10.1",
|
||||
"electron-builder": "26.15.2",
|
||||
"electron-vite": "6.0.0-beta.1",
|
||||
@@ -466,6 +466,7 @@
|
||||
"@parcel/watcher-linux-x64-musl": "2.5.1",
|
||||
"@parcel/watcher-win32-arm64": "2.5.1",
|
||||
"@parcel/watcher-win32-x64": "2.5.1",
|
||||
"msgpackr-extract": "3.0.4",
|
||||
},
|
||||
},
|
||||
"packages/enterprise": {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { expect, test } from "bun:test"
|
||||
import { loadConfigFromFile } from "electron-vite"
|
||||
import { loadConfigFromFile, MainConfigFactory } from "electron-vite"
|
||||
import { build } from "vite"
|
||||
import pkg from "./package.json"
|
||||
|
||||
test.each(["build", "serve"] as const)("configures minification for %s", async (command) => {
|
||||
const result = await loadConfigFromFile(
|
||||
@@ -12,3 +14,48 @@ test.each(["build", "serve"] as const)("configures minification for %s", async (
|
||||
expect(result?.config.renderer?.build?.minify).toBe(command === "build")
|
||||
expect(result?.config.renderer?.build?.sourcemap).toBe(true)
|
||||
})
|
||||
|
||||
test("does not package external copies of bundled dependencies", () => {
|
||||
for (const name of ["effect", "@effect/platform-node", "@effect/platform-node-shared", "drizzle-orm"]) {
|
||||
expect(Object.keys(pkg.dependencies)).not.toContain(name)
|
||||
expect(Object.keys(pkg.optionalDependencies)).not.toContain(name)
|
||||
}
|
||||
expect(pkg.devDependencies.effect).toBe("catalog:")
|
||||
expect(pkg.devDependencies["@effect/platform-node"]).toBe("catalog:")
|
||||
expect(pkg.devDependencies["drizzle-orm"]).toBe("catalog:")
|
||||
expect(pkg.optionalDependencies["msgpackr-extract"]).toBe("3.0.4")
|
||||
})
|
||||
|
||||
test("bundles one Effect runtime and Drizzle while keeping native dependencies external", async () => {
|
||||
const result = await loadConfigFromFile(
|
||||
{ command: "build", mode: "production" },
|
||||
`${import.meta.dirname}/electron.vite.config.ts`,
|
||||
)
|
||||
if (!result.config.main) throw new Error("Missing main-process build configuration")
|
||||
const config = await new MainConfigFactory(
|
||||
result.config.main,
|
||||
{ configFile: false, mode: "production" },
|
||||
{ root: import.meta.dirname },
|
||||
).build()
|
||||
config.build = { ...config.build, write: false }
|
||||
config.logLevel = "silent"
|
||||
const output = await build(config)
|
||||
const chunks = (Array.isArray(output) ? output : [output]).flatMap((result) =>
|
||||
"output" in result ? result.output.filter((item) => item.type === "chunk") : [],
|
||||
)
|
||||
expect(chunks.length).toBeGreaterThan(0)
|
||||
const imports = chunks.flatMap((chunk) => [...chunk.imports, ...chunk.dynamicImports])
|
||||
const modules = chunks.flatMap((chunk) => Object.keys(chunk.modules))
|
||||
for (const name of ["effect", "@effect/platform-node", "@effect/platform-node-shared", "drizzle-orm"]) {
|
||||
expect(imports.filter((id) => id === name || id.startsWith(`${name}/`))).toEqual([])
|
||||
expect(modules.some((id) => id.includes(`/node_modules/${name}/`))).toBe(true)
|
||||
}
|
||||
const effect = modules.filter((id) => id.includes("/node_modules/effect/"))
|
||||
expect(new Set(effect.map((id) => id.split("/node_modules/effect/")[0])).size).toBe(1)
|
||||
expect(new Set(effect).size).toBe(effect.length)
|
||||
expect(imports).toContain("electron")
|
||||
expect(imports).toContain("node:sqlite")
|
||||
expect(imports).toContain(`@lydell/node-pty-${process.platform}-${process.arch}`)
|
||||
expect(modules.some((id) => id.includes("/node_modules/msgpackr-extract/"))).toBe(false)
|
||||
expect(chunks.some((chunk) => chunk.code.includes("msgpackr-extract"))).toBe(true)
|
||||
}, 30_000)
|
||||
|
||||
@@ -30,6 +30,9 @@ const sentry =
|
||||
|
||||
export default defineConfig(({ command }) => ({
|
||||
main: {
|
||||
resolve: {
|
||||
dedupe: ["effect"],
|
||||
},
|
||||
define: {
|
||||
"import.meta.env.OPENCODE_CHANNEL": JSON.stringify(channel),
|
||||
},
|
||||
@@ -50,7 +53,11 @@ const require = __cjs_mod__.createRequire(import.meta.url);
|
||||
`,
|
||||
},
|
||||
},
|
||||
externalizeDeps: { include: [nodePtyPkg] },
|
||||
externalizeDeps: {
|
||||
// Bundle the Effect family together; native MessagePack acceleration stays optional and external.
|
||||
exclude: ["effect", "@effect/platform-node", "@effect/platform-node-shared", "drizzle-orm"],
|
||||
include: [nodePtyPkg, "msgpackr-extract"],
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
{
|
||||
|
||||
@@ -23,19 +23,17 @@
|
||||
},
|
||||
"main": "./out/main/index.js",
|
||||
"dependencies": {
|
||||
"@effect/platform-node": "catalog:",
|
||||
"@zip.js/zip.js": "2.7.62",
|
||||
"effect": "catalog:",
|
||||
"electron-context-menu": "4.1.2",
|
||||
"electron-log": "^5",
|
||||
"electron-store": "11.0.2",
|
||||
"electron-updater": "6.8.9",
|
||||
"electron-window-state": "^5.0.3",
|
||||
"drizzle-orm": "catalog:"
|
||||
"electron-window-state": "^5.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@actions/artifact": "4.0.0",
|
||||
"@brendonovich/vite-plugin-opencode": "0.1.1",
|
||||
"@effect/platform-node": "catalog:",
|
||||
"@lydell/node-pty": "catalog:",
|
||||
"@opencode-ai/app": "workspace:*",
|
||||
"@opencode-ai/client": "workspace:*",
|
||||
@@ -49,6 +47,8 @@
|
||||
"@types/node": "catalog:",
|
||||
"@typescript/native-preview": "catalog:",
|
||||
"@valibot/to-json-schema": "1.6.0",
|
||||
"drizzle-orm": "catalog:",
|
||||
"effect": "catalog:",
|
||||
"electron": "42.10.1",
|
||||
"electron-builder": "26.15.2",
|
||||
"electron-vite": "6.0.0-beta.1",
|
||||
@@ -72,6 +72,7 @@
|
||||
"@parcel/watcher-linux-x64-glibc": "2.5.1",
|
||||
"@parcel/watcher-linux-x64-musl": "2.5.1",
|
||||
"@parcel/watcher-win32-arm64": "2.5.1",
|
||||
"@parcel/watcher-win32-x64": "2.5.1"
|
||||
"@parcel/watcher-win32-x64": "2.5.1",
|
||||
"msgpackr-extract": "3.0.4"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user