Skip to content

fix: installer failing on opencode.jsonc files with trailing commas#49

Merged
justin-carper merged 2 commits into
mainfrom
bryn/fix/handle-trailing-commas
Jun 24, 2026
Merged

fix: installer failing on opencode.jsonc files with trailing commas#49
justin-carper merged 2 commits into
mainfrom
bryn/fix/handle-trailing-commas

Conversation

@sk-bryn

@sk-bryn sk-bryn commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

The auto-generated opencode.jsonc often contains trailing commas, which is valid JSONC but rejected by JSON.parse. This caused the one-liner installer to fail for many users without a clear path to recovery.

The fix adds a string-context-aware trailing comma stripper that runs after comment removal, before JSON.parse. Commas inside string values are never touched — only true trailing commas (those immediately before a closing ] or }) are removed.

The logic is extracted into a typed module (src/jsonc.ts) so it can be unit tested independently from the self-contained bash script that inlines it. The test suite covers the full parsing pipeline, including a reproduction of the exact input shape from the bug report.

@sk-bryn sk-bryn requested a review from justin-carper June 24, 2026 16:37
@sk-bryn sk-bryn changed the title Fix installer failing on opencode.jsonc files with trailing commas fix: installer failing on opencode.jsonc files with trailing commas Jun 24, 2026
@sk-bryn sk-bryn force-pushed the bryn/fix/handle-trailing-commas branch from b9d0953 to b81e546 Compare June 24, 2026 16:45
sk-bryn added 2 commits June 24, 2026 14:06
The auto-generated opencode.jsonc often contains trailing commas, which
is valid JSONC but rejected by JSON.parse. This caused the one-liner
installer to fail for many users without a clear path to recovery.

The fix adds a string-context-aware trailing comma stripper that runs
after comment removal, before JSON.parse. The logic is extracted into a
typed module (src/jsonc.ts) so it can be unit tested independently from
the self-contained bash script that inlines it.
Array indexing returns number | undefined under strict TS config;
use a non-null assertion where the valid index is guaranteed by the test setup.
@sk-bryn sk-bryn force-pushed the bryn/fix/handle-trailing-commas branch from b81e546 to 6a411d0 Compare June 24, 2026 18:07
@sk-bryn sk-bryn requested a review from Copilot June 24, 2026 18:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes the one-liner installer failing when opencode.jsonc contains JSONC-valid trailing commas by stripping trailing commas (string-aware) after comment removal and before JSON.parse.

Changes:

  • Add src/jsonc.ts with scan() (comment stripper + index map) and removeTrailingCommas() (string-aware trailing comma remover).
  • Add a comprehensive vitest suite covering both helpers and the end-to-end parsing pipeline (scan → removeTrailingCommas → JSON.parse), including a real-world reproduction.
  • Update install.sh to apply removeTrailingCommas() to the comment-stripped JSON before parsing, and document that the JS in the installer is a copy of src/jsonc.ts.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
test/jsonc.test.ts Adds unit + pipeline tests for comment stripping and trailing-comma removal, including bug reproduction.
src/jsonc.ts Introduces typed JSONC utilities (scan, removeTrailingCommas) intended to stay in sync with installer logic.
install.sh Applies trailing-comma stripping before JSON.parse so JSONC configs with trailing commas no longer break installation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@justin-carper justin-carper merged commit d66a5d1 into main Jun 24, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants