summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDax <[email protected]>2026-04-17 17:30:50 -0400
committerGitHub <[email protected]>2026-04-17 17:30:50 -0400
commitcded68a2e2e233b8026c50408771b25d0f4e9682 (patch)
tree8b3197bad097086fbd45c997698bc50e492d876a
parent0068ccec35493e2657678a4ab0654a278bd14685 (diff)
downloadopencode-cded68a2e2e233b8026c50408771b25d0f4e9682.tar.gz
opencode-cded68a2e2e233b8026c50408771b25d0f4e9682.zip
refactor(npm): use object-based package spec for install API (#23181)
-rw-r--r--packages/opencode/src/cli/cmd/tui/config/tui.ts7
-rw-r--r--packages/opencode/src/config/config.ts7
-rw-r--r--packages/opencode/src/npm/index.ts16
3 files changed, 23 insertions, 7 deletions
diff --git a/packages/opencode/src/cli/cmd/tui/config/tui.ts b/packages/opencode/src/cli/cmd/tui/config/tui.ts
index 179046e02..9d5cd65bf 100644
--- a/packages/opencode/src/cli/cmd/tui/config/tui.ts
+++ b/packages/opencode/src/cli/cmd/tui/config/tui.ts
@@ -158,7 +158,12 @@ export const layer = Layer.effect(
(dir) =>
npm
.install(dir, {
- add: ["@opencode-ai/plugin" + (InstallationLocal ? "" : "@" + InstallationVersion)],
+ add: [
+ {
+ name: "@opencode-ai/plugin",
+ version: InstallationLocal ? undefined : InstallationVersion,
+ },
+ ],
})
.pipe(Effect.forkScoped),
{
diff --git a/packages/opencode/src/config/config.ts b/packages/opencode/src/config/config.ts
index 0f6d71f44..a2d62eaa5 100644
--- a/packages/opencode/src/config/config.ts
+++ b/packages/opencode/src/config/config.ts
@@ -518,7 +518,12 @@ export const layer = Layer.effect(
const dep = yield* npmSvc
.install(dir, {
- add: ["@opencode-ai/plugin" + (InstallationLocal ? "" : "@" + InstallationVersion)],
+ add: [
+ {
+ name: "@opencode-ai/plugin",
+ version: InstallationLocal ? undefined : InstallationVersion,
+ },
+ ],
})
.pipe(
Effect.exit,
diff --git a/packages/opencode/src/npm/index.ts b/packages/opencode/src/npm/index.ts
index f24259819..d92099bc3 100644
--- a/packages/opencode/src/npm/index.ts
+++ b/packages/opencode/src/npm/index.ts
@@ -25,7 +25,12 @@ export interface Interface {
readonly add: (pkg: string) => Effect.Effect<EntryPoint, InstallFailedError | EffectFlock.LockError>
readonly install: (
dir: string,
- input?: { add: string[] },
+ input?: {
+ add: {
+ name: string
+ version?: string
+ }[]
+ },
) => Effect.Effect<void, EffectFlock.LockError | InstallFailedError>
readonly outdated: (pkg: string, cachedVersion: string) => Effect.Effect<boolean>
readonly which: (pkg: string) => Effect.Effect<Option.Option<string>>
@@ -137,17 +142,18 @@ export const layer = Layer.effect(
return resolveEntryPoint(first.name, first.path)
}, Effect.scoped)
- const install = Effect.fn("Npm.install")(function* (dir: string, input?: { add: string[] }) {
+ const install: Interface["install"] = Effect.fn("Npm.install")(function* (dir, input) {
const canWrite = yield* afs.access(dir, { writable: true }).pipe(
Effect.as(true),
Effect.orElseSucceed(() => false),
)
if (!canWrite) return
+ const add = input?.add.map((pkg) => [pkg.name, pkg.version].filter(Boolean).join("@")) ?? []
yield* Effect.gen(function* () {
const nodeModulesExists = yield* afs.existsSafe(path.join(dir, "node_modules"))
if (!nodeModulesExists) {
- yield* reify({ add: input?.add, dir })
+ yield* reify({ add, dir })
return
}
}).pipe(Effect.withSpan("Npm.checkNodeModules"))
@@ -163,7 +169,7 @@ export const layer = Layer.effect(
...Object.keys(pkgAny?.devDependencies || {}),
...Object.keys(pkgAny?.peerDependencies || {}),
...Object.keys(pkgAny?.optionalDependencies || {}),
- ...(input?.add || []),
+ ...(input?.add || []).map((pkg) => pkg.name),
])
const root = lockAny?.packages?.[""] || {}
@@ -176,7 +182,7 @@ export const layer = Layer.effect(
for (const name of declared) {
if (!locked.has(name)) {
- yield* reify({ dir, add: input?.add })
+ yield* reify({ dir, add })
return
}
}