summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDax <[email protected]>2026-03-19 21:35:07 -0400
committerGitHub <[email protected]>2026-03-19 21:35:07 -0400
commit92cd908fb54de951097efea8ad97ee4dc1b97c37 (patch)
treeaed67649420e082ac4398733a9c00429e2eac6a2
parent6fcc970def1434b095a20f5e79820fd3894883bd (diff)
downloadopencode-92cd908fb54de951097efea8ad97ee4dc1b97c37.tar.gz
opencode-92cd908fb54de951097efea8ad97ee4dc1b97c37.zip
feat: add Node.js entry point and build script (#18324)
-rw-r--r--packages/opencode/script/build-node.ts54
-rw-r--r--packages/opencode/src/node.ts1
2 files changed, 55 insertions, 0 deletions
diff --git a/packages/opencode/script/build-node.ts b/packages/opencode/script/build-node.ts
new file mode 100644
index 000000000..17bc86307
--- /dev/null
+++ b/packages/opencode/script/build-node.ts
@@ -0,0 +1,54 @@
+#!/usr/bin/env bun
+
+import fs from "fs"
+import path from "path"
+import { fileURLToPath } from "url"
+
+const __filename = fileURLToPath(import.meta.url)
+const __dirname = path.dirname(__filename)
+const dir = path.resolve(__dirname, "..")
+
+process.chdir(dir)
+
+// Load migrations from migration directories
+const migrationDirs = (
+ await fs.promises.readdir(path.join(dir, "migration"), {
+ withFileTypes: true,
+ })
+)
+ .filter((entry) => entry.isDirectory() && /^\d{4}\d{2}\d{2}\d{2}\d{2}\d{2}/.test(entry.name))
+ .map((entry) => entry.name)
+ .sort()
+
+const migrations = await Promise.all(
+ migrationDirs.map(async (name) => {
+ const file = path.join(dir, "migration", name, "migration.sql")
+ const sql = await Bun.file(file).text()
+ const match = /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/.exec(name)
+ const timestamp = match
+ ? Date.UTC(
+ Number(match[1]),
+ Number(match[2]) - 1,
+ Number(match[3]),
+ Number(match[4]),
+ Number(match[5]),
+ Number(match[6]),
+ )
+ : 0
+ return { sql, timestamp, name }
+ }),
+)
+console.log(`Loaded ${migrations.length} migrations`)
+
+await Bun.build({
+ target: "node",
+ entrypoints: ["./src/node.ts"],
+ outdir: "./dist",
+ format: "esm",
+ external: ["jsonc-parser"],
+ define: {
+ OPENCODE_MIGRATIONS: JSON.stringify(migrations),
+ },
+})
+
+console.log("Build complete")
diff --git a/packages/opencode/src/node.ts b/packages/opencode/src/node.ts
new file mode 100644
index 000000000..b0e653d6c
--- /dev/null
+++ b/packages/opencode/src/node.ts
@@ -0,0 +1 @@
+export { Server } from "./server/server"