Skip to content

fix(publish): report the version from the re-read manifest - #10202

Open
ShryukGrandhi wants to merge 1 commit into
npm:latestfrom
ShryukGrandhi:fix/issue-2756-bug-changing-version-in-prepublishonly-s
Open

ShryukGrandhi wants to merge 1 commit into
npm:latestfrom
ShryukGrandhi:fix/issue-2756-bug-changing-version-in-prepublishonly-s

Conversation

@ShryukGrandhi

Copy link
Copy Markdown

Summary

When a prepublishOnly script bumps the version (e.g. npm version patch), npm publish uploads the new version but prints the old one in the tarball details and the final + pkg@version line.

The publish command reads the manifest, runs prepublishOnly, packs, and then re-reads the manifest so the latest package.json is sent to the registry. The tarball summary (pkgContents) was computed from the first read, so its name/version/filename were stale.

Changes

  • lib/commands/publish.js: compute pkgContents after the manifest is re-read instead of before.
  • test/lib/commands/publish.js: add a test where prepublishOnly bumps the version from 1.0.0 to 1.0.1 and assert the output shows 1.0.1.

Testing

  • The new test fails before the change (output shows @npmcli/test-package@1.0.0) and passes after.
  • node node_modules/.bin/tap --no-coverage test/lib/commands/publish.js test/lib/commands/stage/index.js passes.
  • npx eslint lib/commands/publish.js test/lib/commands/publish.js is clean.

Fixes #2756

Signed-off-by: ShryukGrandhi <85529990+ShryukGrandhi@users.noreply.github.com>
@ShryukGrandhi
ShryukGrandhi requested a review from a team as a code owner November 2, 2026 04:45
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.

[BUG] Changing version in prepublishOnly-Script has incorrect output

1 participant