Skip to content

fix: Preserve standard package.json fields during bump#393

Merged
ainsleyclark merged 2 commits intomainfrom
fix/preserve-package-json-exports
Jan 31, 2026
Merged

fix: Preserve standard package.json fields during bump#393
ainsleyclark merged 2 commits intomainfrom
fix/preserve-package-json-exports

Conversation

@ainsleyclark
Copy link
Contributor

Summary

Fixed an issue where the webkit payload bump command was removing the exports, imports, types, typings, and publishConfig fields from package.json files.

These fields were not defined in the PackageJSON struct, causing them to be lost during read/write operations despite being captured in the raw map.

Changes

Added the following fields to the PackageJSON struct in internal/pkgjson/definition.go:

  • Exports - Package export conditions (ESM/CommonJS entry points)
  • Imports - Package import mappings
  • Types / Typings - TypeScript type declaration file paths
  • PublishConfig - npm publishing configuration

These are now properly preserved during package.json operations.

Testing

  • All existing pkgjson tests pass
  • The ReadWrite test verifies that fields are preserved during round-trip operations
  • No breaking changes

🤖 Generated with Claude Code

ainsleyclark and others added 2 commits January 31, 2026 07:47
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>
@claude
Copy link

claude bot commented Jan 31, 2026

Review summary

  • Overall score: 9/10
  • Critical issues: 0
  • Warnings: 0
  • Suggestions: 1
  • Recommendation: ✅ Approve

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 TestReadWrite/Preserves_all_fields test validates round-trip preservation, but it doesn't explicitly test the five new fields (exports, imports, types, typings, publishConfig). Consider adding a dedicated test case in internal/pkgjson/io_test.go:

Suggested test implementation
t.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:

  • Exports and Imports as any: Correct, as these can be strings or complex objects
  • Types and Typings as string: Correct, these are always file paths
  • PublishConfig as any: Correct, it's an object with various possible fields

Consistent with existing patterns: The implementation mirrors how Browser, Bin, and other flexible fields are handled

JSON tags follow conventions: All have omitempty which prevents empty values from being written

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

@ainsleyclark ainsleyclark merged commit 00562d3 into main Jan 31, 2026
4 checks passed
@ainsleyclark ainsleyclark deleted the fix/preserve-package-json-exports branch January 31, 2026 07:59
@codecov
Copy link

codecov bot commented Jan 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.94%. Comparing base (7f6b060) to head (f48ca55).
⚠️ Report is 480 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant