Compare commits

...

1 Commits

Author SHA1 Message Date
Kit Langton 0c7b38107a perf(cli): load semver lazily for update checks 2026-08-13 21:42:05 -04:00
3 changed files with 15 additions and 11 deletions
@@ -0,0 +1,12 @@
import semver from "semver"
import type { Policy } from "./updater"
export type Action = "none" | "upgrade"
export function action(current: string, latest: string, policy: Policy): Action {
if (policy === false) return "none"
if (!semver.valid(current) || !semver.valid(latest) || semver.eq(latest, current)) return "none"
// Major upgrades are never installed automatically.
if (semver.major(latest) !== semver.major(current)) return "none"
return "upgrade"
}
+2 -1
View File
@@ -1,5 +1,6 @@
import { describe, expect, test } from "bun:test"
import { action, decodePolicy } from "./updater"
import { action } from "./updater-action"
import { decodePolicy } from "./updater"
describe("updater", () => {
test("reads autoupdate from JSONC", () => {
+1 -10
View File
@@ -5,12 +5,10 @@ import { Context, Duration, Effect, FileSystem, Layer } from "effect"
import { ChildProcess } from "effect/unstable/process"
import { parse, type ParseError } from "jsonc-parser"
import path from "node:path"
import semver from "semver"
declare const OPENCODE_CLI_NAME: string | undefined
export type Policy = boolean | "notify"
export type Action = "none" | "upgrade"
type Method = "npm" | "pnpm" | "bun" | "yarn"
const packageName =
@@ -34,14 +32,6 @@ export function decodePolicy(text: string): Policy | undefined {
if (typeof value === "boolean" || value === "notify") return value
}
export function action(current: string, latest: string, policy: Policy): Action {
if (policy === false) return "none"
if (!semver.valid(current) || !semver.valid(latest) || semver.eq(latest, current)) return "none"
// Major upgrades are never installed automatically.
if (semver.major(latest) !== semver.major(current)) return "none"
return "upgrade"
}
export const layer = Layer.effect(
Service,
Effect.gen(function* () {
@@ -150,6 +140,7 @@ export const layer = Layer.effect(
current: OPENCODE_VERSION,
latest: version,
})
const { action } = yield* Effect.promise(() => import("./updater-action"))
const next = action(OPENCODE_VERSION, version, policy)
if (next === "none") return yield* Effect.logInfo("update check done", { action: "up-to-date" })
const detected = yield* method()