Skip to content
Open
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
3 changes: 2 additions & 1 deletion packages/opencode/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ const layer = Layer.effect(
yield* Effect.promise(() => resolveLoadedPlugins(data, options.path))
if (!data.$schema) {
data.$schema = "https://opencode.ai/config.json"
const updated = text.replace(/^\s*\{/, '{\n "$schema": "https://opencode.ai/config.json",')
const comma = Object.keys(parsed).length ? "," : ""
const updated = text.replace(/^\s*\{/, `{\n "$schema": "https://opencode.ai/config.json"${comma}`)
yield* fs.writeFileString(options.path, updated).pipe(Effect.catch(() => Effect.void))
}
return data
Expand Down
13 changes: 13 additions & 0 deletions packages/opencode/test/config/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,19 @@ it.instance("preserves env variables when adding $schema to config", () =>
),
)

it.instance("adds $schema to an empty JSON config without a trailing comma", () =>
Effect.gen(function* () {
const test = yield* TestInstance
const file = path.join(test.directory, "opencode.json")
yield* FSUtil.use.writeWithDirs(file, "{}")

yield* Config.use.get()

const content = yield* FSUtil.use.readFileString(file)
expect(JSON.parse(content)).toEqual({ $schema: "https://opencode.ai/config.json" })
}),
)

it.instance("handles file inclusion substitution", () =>
Effect.gen(function* () {
const test = yield* TestInstance
Expand Down
Loading