fix: handle trailing commas in config JSON during installation and uninstallation - #3
Open
thaikolja wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Description
Summary
Fixes a
SyntaxError: Expected double-quoted property name in JSONerror during installation/uninstallation whenopencode.jsoncontains trailing commas (a common issue in hand-edited JSON configuration files).Root Cause
When executing
install-opencode.shorinstall-opencode.ps1(as well as the corresponding uninstall scripts), the script attempts to parse~/.config/opencode/opencode.jsonusing standard JSON parsers (JSON.parsein Node.js,ConvertFrom-Jsonin PowerShell). If the JSON file contains trailing commas, standard parsers throw a syntax error and terminate script execution.Changes
install-opencode.sh&uninstall-opencode.sh:JSON.parsein atry...catchblock.content.replace(/,\s*([\]}])/g, "$1")) to strip trailing commas before parsing JSON in Node.js.install-opencode.ps1&uninstall-opencode.ps1:ConvertFrom-Jsonin atry...catchblock.$content -replace ',\s*([\]}])', '$1') to strip trailing commas before parsing JSON in PowerShell.Verification
opencode.jsonconfiguration containing trailing commas (e.g.,"caveman-compress": "allow",}).install-opencode.sh) and PowerShell (install-opencode.ps1) scripts parse the file gracefully, apply configuration changes, and write back clean valid JSON.uninstall-opencode.shanduninstall-opencode.ps1successfully process files with trailing commas.