mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-19 08:39:02 +03:00
fix(cli): let plugin add install GUI-only packages (#59492)
This commit is contained in:
committed by
GitHub
Unverified
parent
542e6835ce
commit
6b1bc48148
@@ -18,10 +18,9 @@ export default Runtime.handler(
|
||||
return yield* Effect.fail(new Error("Plugin target must be an npm registry package or Git package specifier"))
|
||||
const npm = yield* Npm.Service
|
||||
const installed = yield* npm.add(input.package)
|
||||
const entrypoints = Host.resolve(installed)
|
||||
const target = configurationTarget(entrypoints.server, entrypoints.tui)
|
||||
const target = configurationTarget(Host.resolve(installed))
|
||||
if (!target)
|
||||
return yield* Effect.fail(new Error(`Plugin package has no server or TUI entrypoint: ${input.package}`))
|
||||
return yield* Effect.fail(new Error(`Plugin package has no server, GUI, or TUI entrypoint: ${input.package}`))
|
||||
|
||||
if (target === "server") {
|
||||
const global = yield* Global.Service
|
||||
@@ -44,9 +43,11 @@ export default Runtime.handler(
|
||||
}),
|
||||
)
|
||||
|
||||
export function configurationTarget(server?: string, tui?: string) {
|
||||
if (server) return "server" as const
|
||||
if (tui) return "tui" as const
|
||||
// The server lists packages with a server or GUI part, and the TUI loads their TUI parts from that list; the desktop
|
||||
// app reads GUI parts only from the global opencode.json. Only a TUI-only package belongs in the TUI's own config.
|
||||
export function configurationTarget(entrypoints: Host.Entrypoints) {
|
||||
if (entrypoints.server || entrypoints.gui) return "server" as const
|
||||
if (entrypoints.tui) return "tui" as const
|
||||
}
|
||||
|
||||
export async function writePluginConfig(configPath: string, spec: string) {
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { expect, test } from "bun:test"
|
||||
import { mkdir, writeFile } from "node:fs/promises"
|
||||
import path from "node:path"
|
||||
import { Host } from "@opencode/plugin/host"
|
||||
import { configurationTarget } from "../src/commands/handlers/plugin/add"
|
||||
import { tmpdir } from "./fixture/tmpdir"
|
||||
|
||||
const name = "@fixture/plugin"
|
||||
const parts = {
|
||||
server: { ".": "./index.js" },
|
||||
tui: { "./tui": "./tui.js" },
|
||||
gui: { "./gui-experimental": "./gui-experimental.cjs" },
|
||||
}
|
||||
|
||||
test.each([
|
||||
{ parts: ["gui"] as const, target: "server" },
|
||||
{ parts: ["tui", "gui"] as const, target: "server" },
|
||||
{ parts: ["server"] as const, target: "server" },
|
||||
{ parts: ["server", "tui", "gui"] as const, target: "server" },
|
||||
{ parts: ["tui"] as const, target: "tui" },
|
||||
{ parts: [] as const, target: undefined },
|
||||
])("configures a package with $parts parts in the $target config", async (input) => {
|
||||
await using root = await tmpdir()
|
||||
const directory = path.join(root.path, "node_modules", name)
|
||||
const exports = Object.assign({}, ...input.parts.map((part) => parts[part]))
|
||||
await mkdir(directory, { recursive: true })
|
||||
await Promise.all([
|
||||
writeFile(path.join(directory, "package.json"), JSON.stringify({ name, exports })),
|
||||
...Object.values(exports).map((file) => writeFile(path.join(directory, String(file)), "")),
|
||||
])
|
||||
|
||||
expect(configurationTarget(Host.resolve({ directory, name }))).toBe(input.target)
|
||||
})
|
||||
Reference in New Issue
Block a user