Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions nix/scripts/bun-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import fs from "fs"

const version = "@VERSION@"
const pkg = path.join(process.cwd(), "packages/opencode")
const parser = fs.realpathSync(path.join(pkg, "./node_modules/@opentui/core/parser.worker.js"))
const parser = path.join(pkg, "./node_modules/@opentui/core/lib/tree-sitter/parser.worker.js")
const worker = "./src/cli/cmd/tui/worker.ts"
const target = process.env["BUN_COMPILE_TARGET"]

if (!target) {
throw new Error("BUN_COMPILE_TARGET not set")
}

if (!fs.existsSync(parser)) {
throw new Error(`Parser worker not found at: ${parser}`)
}

process.chdir(pkg)

const manifestName = "opencode-assets.manifest"
Expand Down Expand Up @@ -46,6 +50,8 @@ const addAsset = async (p: string) => {

removeTrackedAssets()

const workerBunfsPath = "./" + path.relative(pkg, parser).split(path.sep).join("/")

const result = await Bun.build({
conditions: ["browser"],
tsconfig: "./tsconfig.json",
Expand All @@ -54,7 +60,7 @@ const result = await Bun.build({
entrypoints: ["./src/index.ts", parser, worker],
define: {
OPENCODE_VERSION: `'@VERSION@'`,
OTUI_TREE_SITTER_WORKER_PATH: "/$bunfs/root/" + path.relative(pkg, parser).replace(/\\/g, "/"),
OTUI_TREE_SITTER_WORKER_PATH: `'${workerBunfsPath}'`,
OPENCODE_CHANNEL: "'latest'",
},
compile: {
Expand Down
19 changes: 14 additions & 5 deletions packages/opencode/script/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import pkg from "../package.json"
import { Script } from "@opencode-ai/script"

const singleFlag = process.argv.includes("--single")
const skipInstall = process.argv.includes("--skip-install")

const allTargets: {
os: string
Expand Down Expand Up @@ -83,8 +84,10 @@ const targets = singleFlag
await $`rm -rf dist`

const binaries: Record<string, string> = {}
await $`bun install --os="*" --cpu="*" @opentui/core@${pkg.dependencies["@opentui/core"]}`
await $`bun install --os="*" --cpu="*" @parcel/watcher@${pkg.dependencies["@parcel/watcher"]}`
if (!skipInstall) {
await $`bun install --os="*" --cpu="*" @opentui/core@${pkg.dependencies["@opentui/core"]}`
await $`bun install --os="*" --cpu="*" @parcel/watcher@${pkg.dependencies["@parcel/watcher"]}`
}
for (const item of targets) {
const name = [
pkg.name,
Expand All @@ -99,9 +102,15 @@ for (const item of targets) {
console.log(`building ${name}`)
await $`mkdir -p dist/${name}/bin`

const parserWorker = fs.realpathSync(path.resolve(dir, "./node_modules/@opentui/core/parser.worker.js"))
const parserWorker = path.resolve(dir, "./node_modules/@opentui/core/lib/tree-sitter/parser.worker.js")
const workerPath = "./src/cli/cmd/tui/worker.ts"

if (!fs.existsSync(parserWorker)) {
throw new Error(`Parser worker not found at: ${parserWorker}`)
}

const workerBunfsPath = "./" + path.relative(dir, parserWorker).split(path.sep).join("/")

await Bun.build({
conditions: ["browser"],
tsconfig: "./tsconfig.json",
Expand All @@ -116,8 +125,8 @@ for (const item of targets) {
entrypoints: ["./src/index.ts", parserWorker, workerPath],
define: {
OPENCODE_VERSION: `'${Script.version}'`,
OTUI_TREE_SITTER_WORKER_PATH: "/$bunfs/root/" + path.relative(dir, parserWorker).replaceAll("\\", "/"),
OPENCODE_WORKER_PATH: workerPath,
OTUI_TREE_SITTER_WORKER_PATH: `'${workerBunfsPath}'`,
OPENCODE_WORKER_PATH: `'${workerPath}'`,
OPENCODE_CHANNEL: `'${Script.channel}'`,
},
})
Expand Down
Loading