Skip to content

Commit d78d989

Browse files
committed
fix(build): revert lazyCommand to static imports for Bun compile compatibility
1 parent 34b6df7 commit d78d989

1 file changed

Lines changed: 33 additions & 65 deletions

File tree

packages/opencode/src/index.ts

Lines changed: 33 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
import yargs from "yargs"
22
import { hideBin } from "yargs/helpers"
3+
import { McpCommand } from "./cli/cmd/mcp"
4+
import { TuiThreadCommand } from "./cli/cmd/tui"
5+
import { AttachCommand } from "./cli/cmd/attach"
6+
import { RunCommand } from "./cli/cmd/run"
7+
import { GenerateCommand } from "./cli/cmd/generate"
8+
import { DebugCommand } from "./cli/cmd/debug"
9+
import { ProvidersCommand } from "./cli/cmd/providers"
10+
import { AgentCommand } from "./cli/cmd/agent"
11+
import { UpgradeCommand } from "./cli/cmd/upgrade"
12+
import { UninstallCommand } from "./cli/cmd/uninstall"
13+
import { ServeCommand } from "./cli/cmd/serve"
14+
import { ModelsCommand } from "./cli/cmd/models"
15+
import { ExportCommand } from "./cli/cmd/export"
16+
import { SessionCommand } from "./cli/cmd/session"
17+
import { PluginCommand } from "./cli/cmd/plug"
18+
import { DbCommand } from "./cli/cmd/db"
319
import { UI } from "./cli/ui"
420
import { InstallationVersion } from "@opencode-ai/core/installation/version"
521
import { FormatError } from "./cli/error"
@@ -9,22 +25,6 @@ import { Heap } from "./cli/heap"
925

1026
const args = hideBin(process.argv)
1127

12-
function lazyCommand(command: string, modulePath: string, exportName: string) {
13-
return {
14-
command,
15-
builder: async (yargs: any) => {
16-
const mod = await import(modulePath)
17-
const cmd = mod[exportName]
18-
return cmd.builder ? cmd.builder(yargs) : yargs
19-
},
20-
handler: async (argv: any) => {
21-
const mod = await import(modulePath)
22-
const cmd = mod[exportName]
23-
return cmd.handler(argv)
24-
},
25-
}
26-
}
27-
2828
function show(out: string) {
2929
const text = out.trimStart()
3030
if (!text.startsWith("opencode ")) {
@@ -75,54 +75,22 @@ const cli = yargs(args)
7575
})
7676
.usage("")
7777
.completion("completion", "generate shell completion script")
78-
.command(
79-
lazyCommand("mcp", "./cli/cmd/mcp", "McpCommand"),
80-
)
81-
.command(
82-
lazyCommand("tui", "./cli/cmd/tui", "TuiThreadCommand"),
83-
)
84-
.command(
85-
lazyCommand("attach", "./cli/cmd/attach", "AttachCommand"),
86-
)
87-
.command(
88-
lazyCommand("run [message..]", "./cli/cmd/run", "RunCommand"),
89-
)
90-
.command(
91-
lazyCommand("generate", "./cli/cmd/generate", "GenerateCommand"),
92-
)
93-
.command(
94-
lazyCommand("debug", "./cli/cmd/debug", "DebugCommand"),
95-
)
96-
.command(
97-
lazyCommand("providers", "./cli/cmd/providers", "ProvidersCommand"),
98-
)
99-
.command(
100-
lazyCommand("agent", "./cli/cmd/agent", "AgentCommand"),
101-
)
102-
.command(
103-
lazyCommand("upgrade", "./cli/cmd/upgrade", "UpgradeCommand"),
104-
)
105-
.command(
106-
lazyCommand("uninstall", "./cli/cmd/uninstall", "UninstallCommand"),
107-
)
108-
.command(
109-
lazyCommand("serve", "./cli/cmd/serve", "ServeCommand"),
110-
)
111-
.command(
112-
lazyCommand("models", "./cli/cmd/models", "ModelsCommand"),
113-
)
114-
.command(
115-
lazyCommand("export", "./cli/cmd/export", "ExportCommand"),
116-
)
117-
.command(
118-
lazyCommand("session", "./cli/cmd/session", "SessionCommand"),
119-
)
120-
.command(
121-
lazyCommand("plug", "./cli/cmd/plug", "PluginCommand"),
122-
)
123-
.command(
124-
lazyCommand("db", "./cli/cmd/db", "DbCommand"),
125-
)
78+
.command(McpCommand)
79+
.command(TuiThreadCommand)
80+
.command(AttachCommand)
81+
.command(RunCommand)
82+
.command(GenerateCommand)
83+
.command(DebugCommand)
84+
.command(ProvidersCommand)
85+
.command(AgentCommand)
86+
.command(UpgradeCommand)
87+
.command(UninstallCommand)
88+
.command(ServeCommand)
89+
.command(ModelsCommand)
90+
.command(ExportCommand)
91+
.command(SessionCommand)
92+
.command(PluginCommand)
93+
.command(DbCommand)
12694
.fail((msg, err) => {
12795
if (
12896
msg?.startsWith("Unknown argument") ||
@@ -161,4 +129,4 @@ try {
161129
// run using `docker run --init`.
162130
// Explicitly exit to avoid any hanging subprocesses.
163131
process.exit()
164-
}
132+
}

0 commit comments

Comments
 (0)