feat(config): recognize devbox.jsonc as a config filename (#2602) - #2950
Open
mikeland73 wants to merge 1 commit into
Open
feat(config): recognize devbox.jsonc as a config filename (#2602)#2950mikeland73 wants to merge 1 commit into
mikeland73 wants to merge 1 commit into
Conversation
devbox.json is parsed as JSONC and supports comments, but editors and
GitHub diffs flag comments in a .json file as syntax errors. Allow users
to name their config devbox.jsonc so standard tooling highlights it
correctly, without any per-repo configuration.
- Add configfile.AltName ("devbox.jsonc") and configfile.ValidNames, and
search both names during directory discovery (devbox.json wins when
both are present, preserving existing behavior).
- Make SaveTo preserve the config's original filename via a new
FileName() helper so `devbox add` and friends write back to
devbox.jsonc instead of creating a stray devbox.json. Configs without
an on-disk path (e.g. pulled from a URL) still default to devbox.json.
Closes #2602
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.
Summary
Fixes #2602 (cc @gjoseph92).
devbox.jsonis parsed as JSONC and supports comments, but editors and GitHub diffs treat comments in a.jsonfile as syntax errors and highlight them in red. This PR lets users name their configdevbox.jsoncso standard tooling highlights it correctly — with no per-repofiles.associationsor.gitattributesworkarounds.Changes (all in
internal/devconfig):configfile.AltName("devbox.jsonc") andconfigfile.ValidNames, and search both names during directory discovery.devbox.jsonis listed first, so it still wins when a directory happens to contain both files — existing projects are unaffected.SaveTopreserve the config's original filename via a newFileName()helper, sodevbox add(and anything else that rewrites the config) writes back todevbox.jsoncinstead of silently creating a straydevbox.json. Configs with no on-disk path (e.g. pulled from a URL) still default todevbox.json.Discovery is centralized in
searchDir, which already looped over a list of candidate filenames, so the change is small and localized.How was it tested?
go build ./...andgo vet ./internal/devconfig/...pass. Added unit tests:TestJSONCConfig(internal/devconfig/config_test.go):OpenandFinddiscoverdevbox.jsonc;devbox.jsonwins when both exist; saving writes back todevbox.jsoncwithout creating adevbox.json.TestFileName/TestSaveToPreservesFileName(internal/devconfig/configfile/file_test.go):FileName()maps each path to the right basename and falls back todevbox.json;SaveTowrites the expected filename.All new and pre-existing
internal/devconfigtests pass, except twoTestFindErrorpermission cases that also fail on unmodifiedmainwhen the suite runs as root (root bypasses0o000); they are unrelated to this change.Community Contribution License
All community contributions in this pull request are licensed to the project
maintainers under the terms of the
Apache 2 License.
By creating this pull request, I represent that I have the right to license the
contributions to the project maintainers under the Apache 2 License as stated in
the
Community Contribution License.
🤖 Generated with Claude Code
https://claude.ai/code/session_01554vf5pDDVmFCcAadatBea
Generated by Claude Code