88 NPM_FETCH_TIMEOUT ,
99 INSTALLED_PACKAGE_JSON ,
1010 USER_OPENCODE_CONFIG ,
11+ USER_OPENCODE_CONFIG_JSONC ,
1112} from "./constants"
1213import { log } from "../../shared/logger"
1314
@@ -16,13 +17,22 @@ export function isLocalDevMode(directory: string): boolean {
1617}
1718
1819function stripJsonComments ( json : string ) : string {
19- return json . replace ( / ^ \s * \/ \/ .* $ / gm, "" ) . replace ( / , ( \s * [ } \] ] ) / g, "$1" )
20+ return json
21+ . replace ( / \\ " | " (?: \\ " | [ ^ " ] ) * " | ( \/ \/ .* | \/ \* [ \s \S ] * ?\* \/ ) / g, ( m , g ) => ( g ? "" : m ) )
22+ . replace ( / , ( \s * [ } \] ] ) / g, "$1" )
2023}
2124
22- export function getLocalDevPath ( directory : string ) : string | null {
23- const projectConfig = path . join ( directory , ".opencode" , "opencode.json" )
25+ function getConfigPaths ( directory : string ) : string [ ] {
26+ return [
27+ path . join ( directory , ".opencode" , "opencode.json" ) ,
28+ path . join ( directory , ".opencode" , "opencode.jsonc" ) ,
29+ USER_OPENCODE_CONFIG ,
30+ USER_OPENCODE_CONFIG_JSONC ,
31+ ]
32+ }
2433
25- for ( const configPath of [ projectConfig , USER_OPENCODE_CONFIG ] ) {
34+ export function getLocalDevPath ( directory : string ) : string | null {
35+ for ( const configPath of getConfigPaths ( directory ) ) {
2636 try {
2737 if ( ! fs . existsSync ( configPath ) ) continue
2838 const content = fs . readFileSync ( configPath , "utf-8" )
@@ -31,7 +41,11 @@ export function getLocalDevPath(directory: string): string | null {
3141
3242 for ( const entry of plugins ) {
3343 if ( entry . startsWith ( "file://" ) && entry . includes ( PACKAGE_NAME ) ) {
34- return entry . replace ( "file://" , "" )
44+ try {
45+ return fileURLToPath ( entry )
46+ } catch {
47+ return entry . replace ( "file://" , "" )
48+ }
3549 }
3650 }
3751 } catch {
@@ -86,9 +100,7 @@ export interface PluginEntryInfo {
86100}
87101
88102export function findPluginEntry ( directory : string ) : PluginEntryInfo | null {
89- const projectConfig = path . join ( directory , ".opencode" , "opencode.json" )
90-
91- for ( const configPath of [ projectConfig , USER_OPENCODE_CONFIG ] ) {
103+ for ( const configPath of getConfigPaths ( directory ) ) {
92104 try {
93105 if ( ! fs . existsSync ( configPath ) ) continue
94106 const content = fs . readFileSync ( configPath , "utf-8" )
@@ -170,7 +182,6 @@ export async function checkForUpdate(directory: string): Promise<UpdateCheckResu
170182 return { needsUpdate : false , currentVersion : null , latestVersion : null , isLocalDev : false , isPinned : false }
171183 }
172184
173- // Respect version pinning
174185 if ( pluginInfo . isPinned ) {
175186 log ( `[auto-update-checker] Version pinned to ${ pluginInfo . pinnedVersion } , skipping update check` )
176187 return { needsUpdate : false , currentVersion : pluginInfo . pinnedVersion , latestVersion : null , isLocalDev : false , isPinned : true }
@@ -190,6 +201,5 @@ export async function checkForUpdate(directory: string): Promise<UpdateCheckResu
190201
191202 const needsUpdate = currentVersion !== latestVersion
192203 log ( `[auto-update-checker] Current: ${ currentVersion } , Latest: ${ latestVersion } , NeedsUpdate: ${ needsUpdate } ` )
193-
194204 return { needsUpdate, currentVersion, latestVersion, isLocalDev : false , isPinned : false }
195205}
0 commit comments