Explorar el Código

opencode: provide channel to web build (#28612)

Brendan Allan hace 3 meses
padre
commit
7d5e91b801

+ 10 - 0
packages/app/vite.js

@@ -5,6 +5,13 @@ import { fileURLToPath } from "url"
 
 
 const theme = fileURLToPath(new URL("./public/oc-theme-preload.js", import.meta.url))
 const theme = fileURLToPath(new URL("./public/oc-theme-preload.js", import.meta.url))
 
 
+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"
+})()
+
 /**
 /**
  * @type {import("vite").PluginOption}
  * @type {import("vite").PluginOption}
  */
  */
@@ -18,6 +25,9 @@ export default [
             "@": fileURLToPath(new URL("./src", import.meta.url)),
             "@": fileURLToPath(new URL("./src", import.meta.url)),
           },
           },
         },
         },
+        define: {
+          "import.meta.env.VITE_OPENCODE_CHANNEL": JSON.stringify(channel),
+        },
         worker: {
         worker: {
           format: "es",
           format: "es",
         },
         },

+ 3 - 5
packages/desktop/electron.vite.config.ts

@@ -3,14 +3,15 @@ import { defineConfig } from "electron-vite"
 import appPlugin from "@opencode-ai/app/vite"
 import appPlugin from "@opencode-ai/app/vite"
 import * as fs from "node:fs/promises"
 import * as fs from "node:fs/promises"
 
 
+const OPENCODE_SERVER_DIST = "../opencode/dist/node"
+
 const channel = (() => {
 const channel = (() => {
   const raw = process.env.OPENCODE_CHANNEL
   const raw = process.env.OPENCODE_CHANNEL
   if (raw === "dev" || raw === "beta" || raw === "prod") return raw
   if (raw === "dev" || raw === "beta" || raw === "prod") return raw
+  if (process.env.OPENCODE_CHANNEL === "latest") return "prod"
   return "dev"
   return "dev"
 })()
 })()
 
 
-const OPENCODE_SERVER_DIST = "../opencode/dist/node"
-
 const nodePtyPkg = `@lydell/node-pty-${process.platform}-${process.arch}`
 const nodePtyPkg = `@lydell/node-pty-${process.platform}-${process.arch}`
 
 
 const sentry =
 const sentry =
@@ -82,9 +83,6 @@ export default defineConfig({
     plugins: [appPlugin, sentry],
     plugins: [appPlugin, sentry],
     publicDir: "../../../app/public",
     publicDir: "../../../app/public",
     root: "src/renderer",
     root: "src/renderer",
-    define: {
-      "import.meta.env.VITE_OPENCODE_CHANNEL": JSON.stringify(channel),
-    },
     build: {
     build: {
       sourcemap: true,
       sourcemap: true,
       rollupOptions: {
       rollupOptions: {

+ 1 - 1
packages/opencode/script/build.ts

@@ -58,7 +58,7 @@ const createEmbeddedWebUIBundle = async () => {
   console.log(`Building Web UI to embed in the binary`)
   console.log(`Building Web UI to embed in the binary`)
   const appDir = path.join(import.meta.dirname, "../../app")
   const appDir = path.join(import.meta.dirname, "../../app")
   const dist = path.join(appDir, "dist")
   const dist = path.join(appDir, "dist")
-  await $`bun run --cwd ${appDir} build`
+  await $`OPENCODE_CHANNEL=${Script.channel} bun run --cwd ${appDir} build`
   const files = (await Array.fromAsync(new Bun.Glob("**/*").scan({ cwd: dist })))
   const files = (await Array.fromAsync(new Bun.Glob("**/*").scan({ cwd: dist })))
     .map((file) => file.replaceAll("\\", "/"))
     .map((file) => file.replaceAll("\\", "/"))
     .filter((file) => !file.endsWith(".map"))
     .filter((file) => !file.endsWith(".map"))