Migrate deprecated nested shell object to top-level fields#2841
Open
mikeland73 wants to merge 1 commit into
Open
Migrate deprecated nested shell object to top-level fields#2841mikeland73 wants to merge 1 commit into
mikeland73 wants to merge 1 commit into
Conversation
Move init_hook and scripts to the top level of devbox.json. The nested "shell" object is still accepted for backward compatibility, but is now deprecated and emits a warning on load. - Add top-level init_hook and scripts fields to ConfigFile. Accessors (InitHook, Scripts) read the top-level fields first and fall back to the deprecated shell.* fields. - Warn when a config still nests init_hook/scripts under "shell". - Add `devbox config fmt` to format and modernize devbox.json. It migrates the deprecated "shell" object to top-level fields via the hujson AST, preserving comments and formatting. - Update DefaultConfig (devbox init) and the JSON schema to use the new top-level layout; mark "shell" as deprecated in the schema. - Add unit tests for backward compat / migration and an integration testscript for `devbox config fmt`. https://claude.ai/code/session_017QEtLcEdV7hPXvH7XYkyai
Contributor
There was a problem hiding this comment.
Pull request overview
This PR migrates devbox.json shell configuration toward top-level init_hook and scripts fields while keeping legacy shell configs readable.
Changes:
- Adds top-level config fields and backward-compatible accessors for legacy
shell.init_hook/shell.scripts. - Implements shell-field migration and a new
devbox config fmtcommand. - Updates schema, defaults, warning behavior, and tests for the new layout.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
internal/devconfig/configfile/file.go |
Adds top-level fields, deprecation detection, and migration entry point. |
internal/devconfig/configfile/scripts.go |
Reads scripts from both legacy and top-level locations. |
internal/devconfig/configfile/ast.go |
Adds AST migration from nested shell to top-level fields. |
internal/devconfig/config.go |
Updates generated default config layout. |
internal/devbox/devbox.go |
Emits deprecation warning for legacy shell configs. |
internal/boxcli/config_fmt.go |
Adds devbox config fmt command. |
internal/boxcli/root.go |
Registers the new config command group. |
.schema/devbox.schema.json |
Documents top-level fields and deprecates nested shell. |
internal/devconfig/configfile/shell_migration_test.go, testscripts/config/fmt.test.txt |
Adds unit and integration coverage for migration behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+493
to
+495
| // Don't clobber a field that already exists at the top level. | ||
| if c.memberIndex(rootObj, key) != -1 { | ||
| continue |
Comment on lines
+497
to
+502
| member := shellObj.Members[srcIdx] | ||
| // Ensure the migrated field starts on its own line. | ||
| if !slices.Contains(member.Name.BeforeExtra, '\n') { | ||
| member.Name.BeforeExtra = append([]byte{'\n'}, member.Name.BeforeExtra...) | ||
| } | ||
| rootObj.Members = append(rootObj.Members, member) |
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
This PR adds support for migrating the deprecated nested
shellobject indevbox.jsonto modern top-levelinit_hookandscriptsfields. The changes include:init_hookandscriptsas first-class fields in the config schema, replacing the nestedshell.init_hookandshell.scriptsstructureshellobject remains readable for existing configs; accessors fall back to deprecated fields when top-level fields are absentMigrateShell()method that moves nested shell fields to the top level while preserving comments and formattingdevbox config fmtcommand to automatically migrate configs and reformat them to canonical layoutshellfield, directing them to rundevbox config fmtshellobject as deprecated and document the new top-level fieldsHow was it tested?
shell_migration_test.gocovering:testscripts/config/fmt.test.txtverifying thedevbox config fmtcommand migrates configs correctly and is idempotentCommunity 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.
https://claude.ai/code/session_017QEtLcEdV7hPXvH7XYkyai