fix: Preserve standard package.json fields during bump#393
fix: Preserve standard package.json fields during bump#393ainsleyclark merged 2 commits intomainfrom
Conversation
When the payload bump command updated dependencies, it was removing the exports and imports fields from package.json. This was because these fields were missing from the PackageJSON struct definition. Added Exports and Imports fields to the PackageJSON struct to ensure they are preserved when reading and writing package.json files. These are now properly handled during dependency updates. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Added strongly-typed fields for Types, Typings, and PublishConfig to the PackageJSON struct. These are commonly-used standard npm package.json fields that should be explicitly handled alongside Exports and Imports. - Types/Typings: TypeScript type declaration file paths - PublishConfig: npm publishing configuration (registry, access, etc.) All fields are now properly preserved during package.json read/write operations. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Review summary
Excellent fix that correctly addresses the issue of package.json fields being lost during read/write operations. The implementation is minimal, type-safe, and follows existing patterns in the codebase. All tests pass and the fix is non-breaking. Critical issues 🔴None Warnings 🟡None Suggestions 🟢Consider adding explicit test coverage for the new fields The existing Suggested test implementationt.Run("Preserves TypeScript and publishing fields", func(t *testing.T) {
t.Parallel()
fs := afero.NewMemMapFs()
path := "package.json"
original := `{
"name": "test-app",
"version": "1.0.0",
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.cjs"
}
},
"imports": {
"#internal": "./src/internal.js"
},
"types": "./dist/index.d.ts",
"typings": "./types/index.d.ts",
"publishConfig": {
"access": "public"
},
"dependencies": {
"react": "^18.0.0"
}
}`
err := afero.WriteFile(fs, path, []byte(original), 0o644)
require.NoError(t, err)
// Read and modify
pkg, err := Read(fs, path)
require.NoError(t, err)
pkg.Dependencies["react"] = "^18.2.0"
// Write back
err = Write(fs, path, pkg)
require.NoError(t, err)
// Read again and verify
data, err := afero.ReadFile(fs, path)
require.NoError(t, err)
assert.Contains(t, string(data), "exports")
assert.Contains(t, string(data), "imports")
assert.Contains(t, string(data), "types")
assert.Contains(t, string(data), "typings")
assert.Contains(t, string(data), "publishConfig")
})This would provide explicit documentation that these fields are now preserved and catch regressions if someone accidentally removes them. Technical review notes: ✅ Type choices are appropriate:
✅ Consistent with existing patterns: The implementation mirrors how ✅ JSON tags follow conventions: All have ✅ Non-breaking change: Purely additive, doesn't modify existing behaviour ✅ Aligns with npm specification: All five fields are standard package.json fields defined in the npm documentation |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #393 +/- ##
==========================================
+ Coverage 64.59% 69.94% +5.35%
==========================================
Files 154 185 +31
Lines 6064 7394 +1330
==========================================
+ Hits 3917 5172 +1255
+ Misses 2064 2025 -39
- Partials 83 197 +114 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
Fixed an issue where the
webkit payload bumpcommand was removing theexports,imports,types,typings, andpublishConfigfields from package.json files.These fields were not defined in the
PackageJSONstruct, causing them to be lost during read/write operations despite being captured in therawmap.Changes
Added the following fields to the
PackageJSONstruct ininternal/pkgjson/definition.go:Exports- Package export conditions (ESM/CommonJS entry points)Imports- Package import mappingsTypes/Typings- TypeScript type declaration file pathsPublishConfig- npm publishing configurationThese are now properly preserved during package.json operations.
Testing
ReadWritetest verifies that fields are preserved during round-trip operations🤖 Generated with Claude Code