mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
Replace strip-json-comments with jsonc-parser for better error reporting
This commit is contained in:
1 parent
e1890d0554
commit
e1a4a70d3d
13 files changed
+132
-34
No files matched your search
@@ -23,7 +23,7 @@
|
||||
"dotenv": "^17.2.3",
|
||||
"eventsource": "^4.1.0",
|
||||
"hono": "^4.11.7",
|
||||
"strip-json-comments": "^3.1.1",
|
||||
"jsonc-parser": "^3.3.1",
|
||||
"web-push": "^3.6.7",
|
||||
"zod": "^4.1.12"
|
||||
},
|
||||
|
||||
@@ -54,7 +54,7 @@ import {
|
||||
ENV
|
||||
} from '@opencode-manager/shared/config/env'
|
||||
import { OpenCodeConfigSchema } from '@opencode-manager/shared/schemas'
|
||||
import stripJsonComments from 'strip-json-comments'
|
||||
import { parse as parseJsonc } from 'jsonc-parser'
|
||||
|
||||
const { PORT, HOST } = ENV.SERVER
|
||||
const DB_PATH = getDatabasePath()
|
||||
@@ -90,7 +90,7 @@ async function ensureDefaultConfigExists(): Promise<void> {
|
||||
logger.info(`Found workspace config at ${workspaceConfigPath}, syncing to database...`)
|
||||
try {
|
||||
const rawContent = await readFileContent(workspaceConfigPath)
|
||||
const parsed = JSON.parse(stripJsonComments(rawContent))
|
||||
const parsed = parseJsonc(rawContent)
|
||||
const validation = OpenCodeConfigSchema.safeParse(parsed)
|
||||
|
||||
if (!validation.success) {
|
||||
@@ -123,7 +123,7 @@ async function ensureDefaultConfigExists(): Promise<void> {
|
||||
logger.info(`Found home config at ${homeConfigPath}, importing...`)
|
||||
try {
|
||||
const rawContent = await readFileContent(homeConfigPath)
|
||||
const parsed = JSON.parse(stripJsonComments(rawContent))
|
||||
const parsed = parseJsonc(rawContent)
|
||||
const validation = OpenCodeConfigSchema.safeParse(parsed)
|
||||
|
||||
if (validation.success) {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Database } from 'bun:sqlite'
|
||||
import { unlinkSync, existsSync } from 'fs'
|
||||
import { getOpenCodeConfigFilePath } from '@opencode-manager/shared/config/env'
|
||||
import { logger } from '../utils/logger'
|
||||
import stripJsonComments from 'strip-json-comments'
|
||||
import { parseJsonc } from '@opencode-manager/shared/utils'
|
||||
import type {
|
||||
UserPreferences,
|
||||
SettingsResponse,
|
||||
@@ -25,9 +25,6 @@ interface OpenCodeConfigResponseWithRaw {
|
||||
defaultConfig: OpenCodeConfigWithRaw | null
|
||||
}
|
||||
|
||||
function parseJsonc(content: string): unknown {
|
||||
return JSON.parse(stripJsonComments(content))
|
||||
}
|
||||
|
||||
export class SettingsService {
|
||||
private static lastKnownGoodConfigContent: string | null = null
|
||||
|
||||
Reference in new issue
Block a user