Co-authored-by: Frank <frank@anoma.ly> Co-authored-by: Aarav Sareen <96787824+arvsrn@users.noreply.github.com> Co-authored-by: Brendan Allan <git@brendonovich.dev> Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Jack <jack@anoma.ly> Co-authored-by: Brendan Allan <14191578+Brendonovich@users.noreply.github.com> Co-authored-by: Shoubhit Dash <shoubhit2005@gmail.com> Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com> Co-authored-by: James Long <longster@gmail.com> Co-authored-by: Dustin Deus <deusdustin@gmail.com> Co-authored-by: starptech <starptech@starptechs-MBP.fritz.box> Co-authored-by: Luke Parker <10430890+Hona@users.noreply.github.com> Co-authored-by: 𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴 <little-frank@opencord.local> Co-authored-by: Dax <mail@thdxr.com> Co-authored-by: usrnk1 <7547651+usrnk1@users.noreply.github.com> Co-authored-by: Jay <53023+jayair@users.noreply.github.com> Co-authored-by: runvip <164729189+runvip@users.noreply.github.com> Co-authored-by: opencode <opencode@sst.dev> Co-authored-by: Julian Coy <julian@ex-machina.co> Co-authored-by: Vladimir Glafirov <vglafirov@gitlab.com> Co-authored-by: Adam <2363879+adamdotdevin@users.noreply.github.com> Co-authored-by: Kit Langton <kit.langton@gmail.com> Co-authored-by: Simon Klee <hello@simonklee.dk> Co-authored-by: Jay <air@live.ca> Co-authored-by: David Hill <1879069+iamdavidhill@users.noreply.github.com>
106 lines
3 KiB
TypeScript
106 lines
3 KiB
TypeScript
import { sentryVitePlugin } from "@sentry/vite-plugin"
|
|
import { defineConfig } from "electron-vite"
|
|
import appPlugin from "@opencode-ai/app/vite"
|
|
import * as fs from "node:fs/promises"
|
|
|
|
const OPENCODE_SERVER_DIST = "../opencode/dist/node"
|
|
|
|
const channel = (() => {
|
|
const raw = process.env.OPENCODE_CHANNEL
|
|
if (raw === "dev" || raw === "beta" || raw === "prod") return raw
|
|
if (process.env.OPENCODE_CHANNEL === "latest") return "prod"
|
|
return "dev"
|
|
})()
|
|
|
|
const nodePtyPkg = `@lydell/node-pty-${process.platform}-${process.arch}`
|
|
|
|
const sentry =
|
|
process.env.SENTRY_AUTH_TOKEN && process.env.SENTRY_ORG && process.env.SENTRY_PROJECT
|
|
? sentryVitePlugin({
|
|
authToken: process.env.SENTRY_AUTH_TOKEN,
|
|
org: process.env.SENTRY_ORG,
|
|
project: process.env.SENTRY_PROJECT,
|
|
telemetry: false,
|
|
release: {
|
|
name: process.env.SENTRY_RELEASE ?? process.env.VITE_SENTRY_RELEASE,
|
|
},
|
|
sourcemaps: {
|
|
assets: "./out/renderer/**",
|
|
filesToDeleteAfterUpload: "./out/renderer/**/*.map",
|
|
},
|
|
})
|
|
: false
|
|
|
|
export default defineConfig({
|
|
main: {
|
|
define: {
|
|
"import.meta.env.OPENCODE_CHANNEL": JSON.stringify(channel),
|
|
},
|
|
build: {
|
|
rollupOptions: {
|
|
input: { index: "src/main/index.ts", sidecar: "src/main/sidecar.ts" },
|
|
// Keep this identical to electron-vite's Node 20.11+ shim. Its regex insertion can
|
|
// corrupt bundled TypeScript, while a Rollup banner places the shim safely.
|
|
output: {
|
|
banner: `
|
|
// -- CommonJS Shims --
|
|
import __cjs_mod__ from 'node:module';
|
|
const __filename = import.meta.filename;
|
|
const __dirname = import.meta.dirname;
|
|
const require = __cjs_mod__.createRequire(import.meta.url);
|
|
`,
|
|
},
|
|
},
|
|
externalizeDeps: { include: [nodePtyPkg] },
|
|
},
|
|
plugins: [
|
|
{
|
|
name: "opencode:node-pty-narrower",
|
|
enforce: "pre",
|
|
resolveId(s) {
|
|
if (s === "@lydell/node-pty") return nodePtyPkg
|
|
},
|
|
},
|
|
{
|
|
name: "opencode:virtual-server-module",
|
|
enforce: "pre",
|
|
resolveId(id) {
|
|
if (id === "virtual:opencode-server") return this.resolve(`${OPENCODE_SERVER_DIST}/node.js`)
|
|
},
|
|
},
|
|
{
|
|
name: "opencode:copy-server-assets",
|
|
async writeBundle() {
|
|
for (const l of await fs.readdir(OPENCODE_SERVER_DIST)) {
|
|
if (!l.endsWith(".wasm")) continue
|
|
await fs.writeFile(`./out/main/chunks/${l}`, await fs.readFile(`${OPENCODE_SERVER_DIST}/${l}`))
|
|
}
|
|
},
|
|
},
|
|
],
|
|
},
|
|
preload: {
|
|
build: {
|
|
rollupOptions: {
|
|
input: { index: "src/preload/index.ts" },
|
|
output: {
|
|
format: "cjs",
|
|
entryFileNames: "[name].js",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
renderer: {
|
|
plugins: [appPlugin, sentry],
|
|
publicDir: "../../../app/public",
|
|
root: "src/renderer",
|
|
build: {
|
|
sourcemap: true,
|
|
rollupOptions: {
|
|
input: {
|
|
main: "src/renderer/index.html",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
})
|