fix: preserve unknown wrangler config fields on save#8
Merged
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.
Summary
wrangler.jsoncis loaded and saved by the CLIProblem
Users reported that configuration sections were being "stripped away" from
wrangler.jsonc, including reports involving the Workers AI binding and other Wrangler-managed settings.At first glance this can look like a linter or editor-save race, but the actual failure mode is inside
flare-edge-cliitself.Root Cause
The CLI currently loads
wrangler.jsoncinto a narrow typed Go struct and then writes it back through JSON marshaling.That means any field not explicitly modeled in
internal/domain/config/wrangler.gois lost on save.So whenever a command rewrites Wrangler config, unsupported sections can disappear, including custom or newer Wrangler keys. The effect is especially visible in projects where users or other tools add fields that
flare-edge-clidoes not yet know about.Fix
This PR updates the Wrangler config model to preserve unknown fields during JSON unmarshal and marshal:
WranglerConfignow stores unknown top-level fields in an internal raw mapWranglerEnvConfignow stores unknown env-level fields in an internal raw mapThis keeps the CLI’s typed behavior for the fields it owns while avoiding destructive rewrites for fields it does not model.
Scope
This fix benefits every command path that saves
wrangler.jsonc, not just one command. That includes flows such as:Testing
go test ./internal/domain/configgo test ./...Added regression tests to verify that:
Important Note
This PR preserves unknown fields, but it does not preserve comments or original formatting/order. The file is still rewritten as normalized JSON output. That is a separate follow-up if we want true JSONC comment-preserving edits.