Files
oh-my-opencode/src/hooks/auto-update-checker/checker/plugin-entry.ts
T
YeonGyu-Kim 7f4055ab37 fix(auto-update): treat only explicit semver pins as user-pinned
Fixes #1920

Installer-written exact versions (e.g., oh-my-opencode@3.5.2) were incorrectly treated as user-pinned, blocking auto-updates for all installer users.

Fix isPinned to only block auto-update when pinnedVersion is an explicit semver string (user's intent). Channel tags (latest, beta, next) and bare package name all allow auto-update.

Fix installer fallback to return bare PACKAGE_NAME for stable versions and PACKAGE_NAME@{channel} for prerelease versions, preserving channel tracking.
2026-02-21 04:09:50 +09:00

43 lines
1.3 KiB
TypeScript

import * as fs from "node:fs"
import type { OpencodeConfig } from "../types"
import { PACKAGE_NAME } from "../constants"
import { getConfigPaths } from "./config-paths"
import { stripJsonComments } from "./jsonc-strip"
export interface PluginEntryInfo {
entry: string
isPinned: boolean
pinnedVersion: string | null
configPath: string
}
function isExplicitVersionPin(pinnedVersion: string): boolean {
return /^\d+\.\d+\.\d+/.test(pinnedVersion)
}
export function findPluginEntry(directory: string): PluginEntryInfo | null {
for (const configPath of getConfigPaths(directory)) {
try {
if (!fs.existsSync(configPath)) continue
const content = fs.readFileSync(configPath, "utf-8")
const config = JSON.parse(stripJsonComments(content)) as OpencodeConfig
const plugins = config.plugin ?? []
for (const entry of plugins) {
if (entry === PACKAGE_NAME) {
return { entry, isPinned: false, pinnedVersion: null, configPath }
}
if (entry.startsWith(`${PACKAGE_NAME}@`)) {
const pinnedVersion = entry.slice(PACKAGE_NAME.length + 1)
const isPinned = isExplicitVersionPin(pinnedVersion)
return { entry, isPinned, pinnedVersion, configPath }
}
}
} catch {
continue
}
}
return null
}