GeezerVison is showing github.com — Revert "fix(cli): prevent repeated updates and npm cache growth" (#45… · jinhuang712/opencode@f8b0191
This repository was archived by the owner on Oct 29, 2026. It is now read-only.
File treeExpand file treeCollapse file tree Open diff view settings packages/cli/src/services
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/cli/src/services/fixtures/updater.ts -58Lines changed: 0 additions & 58 deletions Collapse file Copy file name to clipboardExpand all lines: packages/cli/src/services/updater-action.ts +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -5,9 +5,9 @@ const maximumComponent = "9007199254740991" | 5 | 5 | const versionPattern = | 6 | 6 | /^v?([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/ | 7 | 7 |
| 8 | | -export function action(current: string, latest: string, policy: Policy, installed = current): Action { | | 8 | +export function action(current: string, latest: string, policy: Policy): Action { | 9 | 9 | if (policy === false) return "none" | 10 | | - const currentVersion = parseReleaseVersion(installed) | | 10 | + const currentVersion = parseReleaseVersion(current) | 11 | 11 | const latestVersion = parseReleaseVersion(latest) | 12 | 12 | if (!currentVersion || !latestVersion || sameRelease(currentVersion, latestVersion)) return "none" | 13 | 13 | // Major upgrades are never installed automatically. | |
Collapse file Copy file name to clipboardExpand all lines: packages/cli/src/services/updater.test.ts -30Lines changed: 0 additions & 30 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { describe, expect, test } from "bun:test" | 2 | | -import path from "node:path" | 3 | 2 | import { action } from "./updater-action" | 4 | 3 | import { decodePolicy } from "./updater" | 5 | 4 |
| 6 | 5 | describe("updater", () => { | 7 | | - test("remembers successful installs across checks and accepts the next release", async () => { | 8 | | - // Isolate compiled version constants and the update endpoint from other tests. | 9 | | - const child = Bun.spawn( | 10 | | - [ | 11 | | - process.execPath, | 12 | | - "--define", | 13 | | - 'OPENCODE_VERSION="0.0.0-next-16473"', | 14 | | - "--define", | 15 | | - 'OPENCODE_CHANNEL="beta"', | 16 | | - path.join(import.meta.dir, "fixtures/updater.ts"), | 17 | | - ], | 18 | | - { env: { ...process.env, OPENCODE_DISABLE_AUTOUPDATE: "" }, stdout: "pipe", stderr: "pipe" }, | 19 | | - ) | 20 | | - const [code, stdout, stderr] = await Promise.all([ | 21 | | - child.exited, | 22 | | - new Response(child.stdout).text(), | 23 | | - new Response(child.stderr).text(), | 24 | | - ]) | 25 | | - expect(code, stdout + stderr).toBe(0) | 26 | | - }) | 27 | | - | 28 | 6 | test("reads autoupdate from JSONC", () => { | 29 | 7 | expect(decodePolicy('{ // preference\n "autoupdate": "notify",\n}')).toBe("notify") | 30 | 8 | expect(decodePolicy('{ "autoupdate": false }')).toBe(false) | @@ -54,14 +32,6 @@ describe("updater", () => { | 54 | 32 | expect(action("1.2.3", "1.2.3", true)).toBe("none") | 55 | 33 | }) | 56 | 34 |
| 57 | | - test("skips an installed update but still accepts the next release", () => { | 58 | | - const current = "0.0.0-next-16473" | 59 | | - const installed = "0.0.0-beta-17498" | 60 | | - expect(action(current, installed, true)).toBe("upgrade") | 61 | | - expect(action(current, installed, true, installed)).toBe("none") | 62 | | - expect(action(current, "0.0.0-beta-17499", true, installed)).toBe("upgrade") | 63 | | - }) | 64 | | - | 65 | 35 | test("upgrades when latest is lower (rollback)", () => { | 66 | 36 | expect(action("1.2.4", "1.2.3", true)).toBe("upgrade") | 67 | 37 | }) | |
Collapse file Copy file name to clipboardExpand all lines: packages/cli/src/services/updater.ts +11-15Lines changed: 11 additions & 15 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { Global } from "@opencode-ai/util/global" | 2 | 2 | import { AppProcess } from "@opencode-ai/util/process" | 3 | 3 | import { OPENCODE_CHANNEL, OPENCODE_LOCAL, OPENCODE_VERSION } from "../version" | 4 | | -import { Context, Duration, Effect, FileSystem, Layer, Ref } from "effect" | | 4 | +import { Context, Duration, Effect, FileSystem, Layer } from "effect" | 5 | 5 | import { ChildProcess } from "effect/unstable/process" | 6 | 6 | import { parse, type ParseError } from "jsonc-parser" | 7 | 7 | import path from "node:path" | @@ -38,7 +38,6 @@ export const layer = Layer.effect( | 38 | 38 | const fs = yield* FileSystem.FileSystem | 39 | 39 | const global = yield* Global.Service | 40 | 40 | const appProcess = yield* AppProcess.Service | 41 | | - const installed = yield* Ref.make(OPENCODE_VERSION) | 42 | 41 | const channel = OPENCODE_CHANNEL.replace(/[^a-zA-Z0-9._-]/g, "-") | 43 | 42 |
| 44 | 43 | const readPolicy = Effect.fnUntraced(function* () { | @@ -113,20 +112,18 @@ export const layer = Layer.effect( | 113 | 112 |
| 114 | 113 | const upgrade = Effect.fnUntraced(function* (method: Method, version: string) { | 115 | 114 | const target = `${packageName}@${version}` | 116 | | - const commands: Record<Exclude<Method, "bun" | "curl" | "npm">, string[]> = { | | 115 | + const commands: Record<Exclude<Method, "bun" | "curl">, string[]> = { | | 116 | + npm: ["npm", "install", "--global", target], | 117 | 117 | pnpm: ["pnpm", "add", "--global", `--allow-build=${packageName}`, target], | 118 | 118 | yarn: ["yarn", "global", "add", target], | 119 | 119 | } | 120 | 120 | const result = yield* Effect.scoped( | 121 | 121 | Effect.gen(function* () { | 122 | | - if (method === "bun" || method === "npm") { | | 122 | + if (method === "bun") { | | 123 | + // Bun does not prune old versions from its shared package cache. | 123 | 124 | yield* fs.makeDirectory(global.cache, { recursive: true }) | 124 | 125 | const cache = yield* fs.makeTempDirectoryScoped({ directory: global.cache, prefix: "update-" }) | 125 | | - const command = | 126 | | - method === "bun" | 127 | | - ? ["bun", "install", "--global", "--trust", "--cache-dir", cache, target] | 128 | | - : ["npm", "install", "--global", "--cache", cache, target] | 129 | | - return yield* run(command, "5 minutes") | | 126 | + return yield* run(["bun", "install", "--global", "--trust", "--cache-dir", cache, target], "5 minutes") | 130 | 127 | } | 131 | 128 | if (method === "curl") { | 132 | 129 | yield* fs.makeDirectory(global.cache, { recursive: true }) | @@ -159,19 +156,18 @@ export const layer = Layer.effect( | 159 | 156 |
| 160 | 157 | return yield* Effect.gen(function* () { | 161 | 158 | const version = yield* latest() | 162 | | - const current = yield* Ref.get(installed) | 163 | 159 | yield* Effect.logInfo("update check", { | 164 | | - current, | | 160 | + current: OPENCODE_VERSION, | 165 | 161 | latest: version, | 166 | 162 | }) | 167 | | - const next = action(OPENCODE_VERSION, version, policy, current) | | 163 | + const next = action(OPENCODE_VERSION, version, policy) | 168 | 164 | if (next === "none") return yield* Effect.logInfo("update check done", { action: "up-to-date" }) | 169 | | - if (next === "notify") return yield* Effect.logInfo("OpenCode update available", { current, latest: version }) | | 165 | + if (next === "notify") | | 166 | + return yield* Effect.logInfo("OpenCode update available", { current: OPENCODE_VERSION, latest: version }) | 170 | 167 | const detected = yield* method() | 171 | 168 | if (!detected) return yield* Effect.logWarning("automatic update skipped: installation method not found") | 172 | 169 | yield* upgrade(detected, version) | 173 | | - yield* Ref.set(installed, version) | 174 | | - yield* Effect.logInfo("updated OpenCode", { from: current, to: version, method: detected }) | | 170 | + yield* Effect.logInfo("updated OpenCode", { from: OPENCODE_VERSION, to: version, method: detected }) | 175 | 171 | }) | 176 | 172 | }, | 177 | 173 | Effect.catchCause((cause) => Effect.logWarning("automatic update failed", { cause })), | |
|