@different-ai/opencode-browser 4.2.3 → 4.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +36 -11
- package/extension/manifest.json +1 -1
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -289,6 +289,10 @@ Find it at ${color("cyan", "chrome://extensions")}:
|
|
|
289
289
|
.replace(/^\s*\/\/.*$/gm, "");
|
|
290
290
|
}
|
|
291
291
|
|
|
292
|
+
function sanitizeJson(contents) {
|
|
293
|
+
return stripJsoncComments(contents).replace(/,\s*(\]|\})/g, "$1");
|
|
294
|
+
}
|
|
295
|
+
|
|
292
296
|
function findOpenCodeConfigPath(configDir) {
|
|
293
297
|
const jsoncPath = join(configDir, "opencode.jsonc");
|
|
294
298
|
if (existsSync(jsoncPath)) return jsoncPath;
|
|
@@ -338,17 +342,38 @@ Find it at ${color("cyan", "chrome://extensions")}:
|
|
|
338
342
|
|
|
339
343
|
if (shouldUpdate) {
|
|
340
344
|
try {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
345
|
+
let config = { $schema: "https://opencode.ai/config.json", plugin: [] };
|
|
346
|
+
let canWriteConfig = true;
|
|
347
|
+
|
|
348
|
+
if (hasExistingConfig) {
|
|
349
|
+
const rawConfig = readFileSync(configPath, "utf-8");
|
|
350
|
+
try {
|
|
351
|
+
config = JSON.parse(sanitizeJson(rawConfig));
|
|
352
|
+
} catch (e) {
|
|
353
|
+
error(`Failed to parse ${configPath}: ${e.message}`);
|
|
354
|
+
const shouldOverwrite = await confirm("Config is invalid JSON. Back up and recreate it?");
|
|
355
|
+
if (shouldOverwrite) {
|
|
356
|
+
const backupPath = `${configPath}.bak-${Date.now()}`;
|
|
357
|
+
writeFileSync(backupPath, rawConfig);
|
|
358
|
+
warn(`Backed up invalid config to ${backupPath}`);
|
|
359
|
+
config = { $schema: "https://opencode.ai/config.json", plugin: [] };
|
|
360
|
+
} else {
|
|
361
|
+
canWriteConfig = false;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (canWriteConfig) {
|
|
367
|
+
config.plugin = normalizePlugins(config.plugin);
|
|
368
|
+
if (!config.plugin.includes(desiredPlugin)) config.plugin.push(desiredPlugin);
|
|
369
|
+
if (typeof config.$schema !== "string") config.$schema = "https://opencode.ai/config.json";
|
|
370
|
+
|
|
371
|
+
ensureDir(configDir);
|
|
372
|
+
writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n");
|
|
373
|
+
success(`Updated ${configPath} with plugin`);
|
|
374
|
+
} else {
|
|
375
|
+
warn(`Skipped updating ${configPath}. Fix JSON manually and rerun install.`);
|
|
376
|
+
}
|
|
352
377
|
} catch (e) {
|
|
353
378
|
error(`Failed to update ${configPath}: ${e.message}`);
|
|
354
379
|
}
|
package/extension/manifest.json
CHANGED