feat(config): discover devbox.json in a .config subdirectory#2889
Open
mikeland73 wants to merge 1 commit into
Open
feat(config): discover devbox.json in a .config subdirectory#2889mikeland73 wants to merge 1 commit into
mikeland73 wants to merge 1 commit into
Conversation
Look for the project config in `.config/devbox.json` in addition to a top-level `devbox.json`, so users can keep the project root tidy by moving devbox's files into `.config`. A top-level `devbox.json` always takes precedence when both exist. This complements DEVBOX_CONFIG (already supported) and addresses the auto-discovery half of #2792. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L4HytKeYVy9zYHadK7TfWN
Contributor
There was a problem hiding this comment.
Pull request overview
Adds support for auto-discovering devbox.json when it lives under a project’s .config/ subdirectory, addressing the remaining “auto-discovery” portion of issue #2792 (with DEVBOX_CONFIG already handled in #2838).
Changes:
- Extend
internal/devconfig.searchDirto try bothdevbox.jsonand.config/devbox.json, with top-leveldevbox.jsontaking precedence. - Add unit tests ensuring
.config/devbox.jsondiscovery works for bothOpenand parent-directoryFind, and that precedence rules are enforced.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| internal/devconfig/config.go | Adds .config/devbox.json as a second candidate path in config discovery, preserving precedence of top-level devbox.json. |
| internal/devconfig/config_test.go | Adds TestOpenDotConfig to cover discovery in .config, precedence vs top-level config, and parent-walking behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
Addresses the auto-discovery half of #2792.
That issue asks to make the location of
devbox.jsonmore flexible so users can keep the project root tidy — either via an env var and/or by looking for the config in an alternative place such as./.config/devbox.json. The env-var half is already supported (DEVBOX_CONFIG, merged in #2838). This PR adds the remaining piece: auto-discovery of.config/devbox.json.Change
searchDir(ininternal/devconfig/config.go) already had atry []stringlist of candidate config filenames that previously contained onlydevbox.json. This PR adds.config/devbox.jsonas a second candidate:Behavior:
devbox.jsonalways takes precedence over.config/devbox.json(it's tried first).searchDiris used by bothOpenandFind, this works when running from the project directory and when walking up parent directories..config/devbox.json, that directory (.config) becomes the project directory, so devbox's generated files (.devbox/,devbox.lock) live alongside it inside.config— keeping the repository root clean, which is the goal of the issue.Tests
Added
TestOpenDotConfigininternal/devconfig/config_test.go:FindsConfigInDotConfigDir— config in.config/devbox.jsonis discovered.TopLevelConfigTakesPrecedence— a rootdevbox.jsonwins when both exist.FindWalksUpToParentDotConfig—Findfrom a child dir locates a parent's.config/devbox.json.All pass. (Two unrelated pre-existing tests —
TestFindError/PermissionsandTestFindError/ExactFilePermissions— fail in a root environment becausechmod 0o000doesn't restrict root; they fail identically onmainand are untouched by this change.)Notes / scope
This intentionally focuses on the core discovery path used by
Open/Find, which is what the CLI commands rely on. If maintainers would prefer the project root to remain the parent of.config(keeping.devboxat the top level instead of inside.config), that's a larger change to how the project directory is derived from the config path and can be a follow-up — happy to adjust based on preference.cc @eknowles (issue reporter)
🤖 Generated with Claude Code
https://claude.ai/code/session_01L4HytKeYVy9zYHadK7TfWN
Generated by Claude Code