Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions src/hooks/auto-update-checker/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
NPM_FETCH_TIMEOUT,
INSTALLED_PACKAGE_JSON,
USER_OPENCODE_CONFIG,
USER_OPENCODE_CONFIG_JSONC,
} from "./constants"
import { log } from "../../shared/logger"

Expand All @@ -16,13 +17,22 @@ export function isLocalDevMode(directory: string): boolean {
}

function stripJsonComments(json: string): string {
return json.replace(/^\s*\/\/.*$/gm, "").replace(/,(\s*[}\]])/g, "$1")
return json
.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, (m, g) => (g ? "" : m))
.replace(/,(\s*[}\]])/g, "$1")
}

export function getLocalDevPath(directory: string): string | null {
const projectConfig = path.join(directory, ".opencode", "opencode.json")
function getConfigPaths(directory: string): string[] {
return [
path.join(directory, ".opencode", "opencode.json"),
path.join(directory, ".opencode", "opencode.jsonc"),
USER_OPENCODE_CONFIG,
USER_OPENCODE_CONFIG_JSONC,
]
}

for (const configPath of [projectConfig, USER_OPENCODE_CONFIG]) {
export function getLocalDevPath(directory: string): string | null {
for (const configPath of getConfigPaths(directory)) {
try {
if (!fs.existsSync(configPath)) continue
const content = fs.readFileSync(configPath, "utf-8")
Expand All @@ -31,7 +41,11 @@ export function getLocalDevPath(directory: string): string | null {

for (const entry of plugins) {
if (entry.startsWith("file://") && entry.includes(PACKAGE_NAME)) {
return entry.replace("file://", "")
try {
return fileURLToPath(entry)
} catch {
return entry.replace("file://", "")
}
}
}
} catch {
Expand Down Expand Up @@ -86,9 +100,7 @@ export interface PluginEntryInfo {
}

export function findPluginEntry(directory: string): PluginEntryInfo | null {
const projectConfig = path.join(directory, ".opencode", "opencode.json")

for (const configPath of [projectConfig, USER_OPENCODE_CONFIG]) {
for (const configPath of getConfigPaths(directory)) {
try {
if (!fs.existsSync(configPath)) continue
const content = fs.readFileSync(configPath, "utf-8")
Expand Down Expand Up @@ -170,7 +182,6 @@ export async function checkForUpdate(directory: string): Promise<UpdateCheckResu
return { needsUpdate: false, currentVersion: null, latestVersion: null, isLocalDev: false, isPinned: false }
}

// Respect version pinning
if (pluginInfo.isPinned) {
log(`[auto-update-checker] Version pinned to ${pluginInfo.pinnedVersion}, skipping update check`)
return { needsUpdate: false, currentVersion: pluginInfo.pinnedVersion, latestVersion: null, isLocalDev: false, isPinned: true }
Expand All @@ -190,6 +201,5 @@ export async function checkForUpdate(directory: string): Promise<UpdateCheckResu

const needsUpdate = currentVersion !== latestVersion
log(`[auto-update-checker] Current: ${currentVersion}, Latest: ${latestVersion}, NeedsUpdate: ${needsUpdate}`)

return { needsUpdate, currentVersion, latestVersion, isLocalDev: false, isPinned: false }
}
1 change: 1 addition & 0 deletions src/hooks/auto-update-checker/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ function getUserConfigDir(): string {

export const USER_CONFIG_DIR = getUserConfigDir()
export const USER_OPENCODE_CONFIG = path.join(USER_CONFIG_DIR, "opencode", "opencode.json")
export const USER_OPENCODE_CONFIG_JSONC = path.join(USER_CONFIG_DIR, "opencode", "opencode.jsonc")