feat: bump package.json version - #1
Open
iamgio wants to merge 2 commits into
Open
Conversation
`version-file` overwrites its target with the bare version string, so it cannot be pointed at a JSON manifest without destroying it. npm-shaped projects were left to bump `package.json` themselves, outside the action. `bump-package-json` sets the manifest's `version` field instead, and adds it to the commit when `commit` is enabled. Only the version line is rewritten. Rather than parse and re-serialize, which would reformat the whole manifest, the script detects the file's own indentation and replaces the version anchored to it. Anchoring also keeps a nested `version` (in an `engines` block, say) from being mistaken for the manifest's own. A manifest whose version cannot be located that way, or which has no version field at all, falls back to a re-serialize that may reformat it; the script header says so. `keep-v-prefix` deliberately does not apply here: npm requires the version field to be plain semver, so the leading `v` is always stripped. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KKtvw5nBDdx6GoGaQWZaGe
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.
Problem
version-filewrites the bare version string over its target (printf '%s' "$version" > "$file"), so pointing it atpackage.jsonwould replace the manifest with1.2.3. npm-shaped projects had to bump the manifest themselves, outside the action — and if that step went missing, releases silently shipped with a stale version.Change
bump-package-json(defaultfalse) sets theversionfield of the rootpackage.json, and adds the manifest to the commit'sfile_patternwhencommit: 'true'.Only the version line changes. Rather than parse-and-re-serialize — which would reformat the whole manifest — the script detects the file's own indentation and replaces the version anchored to it. Run against a real 176-line
package.json:Byte-identical otherwise, and idempotent on re-run.
Anchoring to the top-level indent also keeps a nested
"version"— inside anenginesblock, say — from being mistaken for the manifest's own.Two decisions worth a look
keep-v-prefixdeliberately does not apply. npm requires the version field to be plain semver, sov1.2.3would be invalid. Thevis always stripped. Documented on both inputs.versionfield at all — the script parses, sets.version, and writes back with the detected indent. That path can reformat, and the script header says so. Failing a release over formatting seemed worse. Both paths are tested.Node does the JSON work — guaranteed present wherever Actions run, and the script errors clearly if it isn't. Invalid JSON exits 2 rather than writing a corrupted manifest.
Tests
12 new bats tests; suite is 57/57.
action.ymlparses, and all six referenced scripts exist and are executable (mirroring the CI check).Note for consumers
This adds an input, so it only takes effect once released and
v1moves. Passingbump-package-jsonto av1that predates it is a warning, not an error — the bump would silently not happen.🤖 Generated with Claude Code