summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--packages/opencode/package.json1
-rwxr-xr-xpackages/opencode/script/build.ts64
-rwxr-xr-xpackages/opencode/script/publish.ts81
-rw-r--r--packages/plugin/package.json3
-rw-r--r--turbo.json3
5 files changed, 83 insertions, 69 deletions
diff --git a/packages/opencode/package.json b/packages/opencode/package.json
index 513009d60..721659b1e 100644
--- a/packages/opencode/package.json
+++ b/packages/opencode/package.json
@@ -6,6 +6,7 @@
"private": true,
"scripts": {
"typecheck": "tsc --noEmit",
+ "build": "./script/build.ts",
"dev": "bun run --conditions=development ./src/index.ts"
},
"bin": {
diff --git a/packages/opencode/script/build.ts b/packages/opencode/script/build.ts
new file mode 100755
index 000000000..f54c8ab0d
--- /dev/null
+++ b/packages/opencode/script/build.ts
@@ -0,0 +1,64 @@
+#!/usr/bin/env bun
+const dir = new URL("..", import.meta.url).pathname
+process.chdir(dir)
+import { $ } from "bun"
+
+import pkg from "../package.json"
+
+const GOARCH: Record<string, string> = {
+ arm64: "arm64",
+ x64: "amd64",
+ "x64-baseline": "amd64",
+}
+
+const targets = [
+ ["windows", "x64"],
+ ["linux", "arm64"],
+ ["linux", "x64"],
+ ["linux", "x64-baseline"],
+ ["darwin", "x64"],
+ ["darwin", "x64-baseline"],
+ ["darwin", "arm64"],
+]
+
+await $`rm -rf dist`
+
+const binaries: Record<string, string> = {}
+const version = process.env["OPENCODE_VERSION"] ?? "dev"
+for (const [os, arch] of targets) {
+ console.log(`building ${os}-${arch}`)
+ const name = `${pkg.name}-${os}-${arch}`
+ await $`mkdir -p dist/${name}/bin`
+ await $`CGO_ENABLED=0 GOOS=${os} GOARCH=${GOARCH[arch]} go build -ldflags="-s -w -X main.Version=${version}" -o ../opencode/dist/${name}/bin/tui ../tui/cmd/opencode/main.go`.cwd(
+ "../tui",
+ )
+ await Bun.build({
+ compile: {
+ target: `bun-${os}-${arch}` as any,
+ outfile: `dist/${name}/bin/opencode`,
+ execArgv: [`--user-agent=opencode/${version}`, `--env-file=""`, `--`],
+ windows: {},
+ },
+ entrypoints: ["./src/index.ts"],
+ define: {
+ OPENCODE_VERSION: `'${version}'`,
+ OPENCODE_TUI_PATH: `'../../../dist/${name}/bin/tui'`,
+ },
+ })
+ await $`rm -rf ./dist/${name}/bin/tui`
+ await Bun.file(`dist/${name}/package.json`).write(
+ JSON.stringify(
+ {
+ name,
+ version,
+ os: [os === "windows" ? "win32" : os],
+ cpu: [arch],
+ },
+ null,
+ 2,
+ ),
+ )
+ binaries[name] = version
+}
+
+export { binaries }
diff --git a/packages/opencode/script/publish.ts b/packages/opencode/script/publish.ts
index 7be6af0b2..a0c3e1390 100755
--- a/packages/opencode/script/publish.ts
+++ b/packages/opencode/script/publish.ts
@@ -8,73 +8,15 @@ import pkg from "../package.json"
const dry = process.env["OPENCODE_DRY"] === "true"
const version = process.env["OPENCODE_VERSION"]!
const snapshot = process.env["OPENCODE_SNAPSHOT"] === "true"
+const npmTag = snapshot ? "snapshot" : "latest"
console.log(`publishing ${version}`)
-const GOARCH: Record<string, string> = {
- arm64: "arm64",
- x64: "amd64",
- "x64-baseline": "amd64",
-}
-
-const targets = [
- ["windows", "x64"],
- ["linux", "arm64"],
- ["linux", "x64"],
- ["linux", "x64-baseline"],
- ["darwin", "x64"],
- ["darwin", "x64-baseline"],
- ["darwin", "arm64"],
-]
-
-await $`rm -rf dist`
-
-const optionalDependencies: Record<string, string> = {}
-const npmTag = snapshot ? "snapshot" : "latest"
-for (const [os, arch] of targets) {
- console.log(`building ${os}-${arch}`)
- const name = `${pkg.name}-${os}-${arch}`
- await $`mkdir -p dist/${name}/bin`
- await $`CGO_ENABLED=0 GOOS=${os} GOARCH=${GOARCH[arch]} go build -ldflags="-s -w -X main.Version=${version}" -o ../opencode/dist/${name}/bin/tui ../tui/cmd/opencode/main.go`.cwd(
- "../tui",
- )
- await Bun.build({
- compile: {
- target: `bun-${os}-${arch}` as any,
- outfile: `dist/${name}/bin/opencode`,
- execArgv: [`--user-agent=opencode/${version}`, `--env-file=""`, `--`],
- windows: {},
- },
- entrypoints: ["./src/index.ts"],
- define: {
- OPENCODE_VERSION: `'${version}'`,
- OPENCODE_TUI_PATH: `'../../../dist/${name}/bin/tui'`,
- },
- })
- // await $`bun build --define OPENCODE_TUI_PATH="'../../../dist/${name}/bin/tui'" --define OPENCODE_VERSION="'${version}'" --compile --target=bun-${os}-${arch} --outfile=dist/${name}/bin/opencode ./src/index.ts`
- // Run the binary only if it matches current OS/arch
- if (
- process.platform === (os === "windows" ? "win32" : os) &&
- (process.arch === arch || (process.arch === "x64" && arch === "x64-baseline"))
- ) {
- console.log(`smoke test: running dist/${name}/bin/opencode --version`)
- await $`./dist/${name}/bin/opencode --version`
- }
- await $`rm -rf ./dist/${name}/bin/tui`
- await Bun.file(`dist/${name}/package.json`).write(
- JSON.stringify(
- {
- name,
- version,
- os: [os === "windows" ? "win32" : os],
- cpu: [arch],
- },
- null,
- 2,
- ),
- )
- if (!dry) await $`cd dist/${name} && chmod 777 -R . && bun publish --access public --tag ${npmTag}`
- optionalDependencies[name] = version
+const { binaries } = await import("./build.ts")
+{
+ const name = `${pkg.name}-${process.platform}-${process.arch}`
+ console.log(`smoke test: running dist/${name}/bin/opencode --version`)
+ await $`./dist/${name}/bin/opencode --version`
}
await $`mkdir -p ./dist/${pkg.name}`
@@ -93,16 +35,21 @@ await Bun.file(`./dist/${pkg.name}/package.json`).write(
postinstall: "node ./postinstall.mjs",
},
version,
- optionalDependencies,
+ optionalDependencies: binaries,
},
null,
2,
),
)
-if (!dry) await $`cd ./dist/${pkg.name} && bun publish --access public --tag ${npmTag}`
+if (!dry) {
+ for (const [name] of Object.entries(binaries)) {
+ await $`cd dist/${name} && chmod 777 -R . && bun publish --access public --tag ${npmTag}`
+ }
+ await $`cd ./dist/${pkg.name} && bun publish --access public --tag ${npmTag}`
+}
if (!snapshot) {
- for (const key of Object.keys(optionalDependencies)) {
+ for (const key of Object.keys(binaries)) {
await $`cd dist/${key}/bin && zip -r ../../${key}.zip *`
}
diff --git a/packages/plugin/package.json b/packages/plugin/package.json
index 52968bdcd..dece34fac 100644
--- a/packages/plugin/package.json
+++ b/packages/plugin/package.json
@@ -4,7 +4,8 @@
"version": "0.10.1",
"type": "module",
"scripts": {
- "typecheck": "tsc --noEmit"
+ "typecheck": "tsc --noEmit",
+ "build": "tsc"
},
"exports": {
".": {
diff --git a/turbo.json b/turbo.json
index 3fd3914b0..cd40493de 100644
--- a/turbo.json
+++ b/turbo.json
@@ -3,7 +3,8 @@
"tasks": {
"typecheck": {},
"build": {
- "dependsOn": ["^build"]
+ "dependsOn": ["^build"],
+ "outputs": ["dist/**"]
}
}
}