feat(publish): restore npm-CLI-compatible --json stdout for publish#11478
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (8)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughRestores npm-CLI-compatible JSON stdout for ChangesPublish JSON Output Restoration
Sequence DiagramsequenceDiagram
participant CLI as CLI (pnpm)
participant Handler as publish.handler
participant Pack as pack()
participant PubPkg as publishPackedPkg()
participant Recursive as recursivePublish()
participant Stdout as stdout / pnpm-publish-summary.json
CLI->>Handler: pnpm publish --json (or -r / --report-summary)
Handler->>Pack: pack(manifest, ...)
Pack->>Pack: compute contents + unpackedSize
Pack-->>Handler: PackResult { publishedManifest, tarballPath, contents, unpackedSize }
Handler->>PubPkg: publishPackedPkg(tarballPath, contents, unpackedSize, ...)
PubPkg->>PubPkg: compute size, shasum, integrity, bundled, files
PubPkg-->>Handler: PublishSummary {...}
Handler->>Recursive: (if recursive) recursivePublish(...) collects PublishSummary items
Handler->>Stdout: emit JSON (PublishSummary | [PublishSummary] | envelope file)
Stdout-->>CLI: machine-readable output (or writes pnpm-publish-summary.json)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Comment |
c9f2bba to
1a239da
Compare
deae83c to
a7746df
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
a7746df to
d3192a2
Compare
There was a problem hiding this comment.
Pull request overview
Restores machine-readable --json stdout for pnpm publish (regression in pnpm 11 vs pnpm 10) by returning and serializing an npm-CLI-shaped per-package publish summary, and aligns recursive publish --report-summary entries to the same shape.
Changes:
- Introduces a
PublishSummaryreturned frompublishPackedPkg()(hashes, sizes, file list, bundled deps) and plumbs it through single and recursive publish flows. - Makes
publish.handleremit serialized JSON (objectfor single publish,arrayfor recursive) via{ output, exitCode }. - Updates/extends tests to assert stdout JSON output and the upgraded report-summary per-package shape.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| releasing/commands/src/publish/pack.ts | Computes unpackedSize during pack so publish can report npm-compatible size metadata. |
| releasing/commands/src/publish/publishPackedPkg.ts | Adds PublishSummary generation (hashes, integrity, file list, bundled deps) and returns it to callers. |
| releasing/commands/src/publish/publish.ts | Emits JSON to stdout when --json is set; propagates single/recursive publish summaries. |
| releasing/commands/src/publish/recursivePublish.ts | Collects per-package publish summaries and returns them (and writes them into report-summary). |
| releasing/commands/test/publish/publish.ts | Adds coverage asserting pnpm publish --json returns a parseable per-package summary on stdout. |
| releasing/commands/test/publish/recursivePublish.ts | Updates report-summary assertions and adds tests for -r --json stdout and upgraded report-summary entries. |
| releasing/commands/test/publish/FailedToPublishError.test.ts | Updates mocked PackResult to include the new unpackedSize field. |
| releasing/commands/test/publish/snapshots/recursivePublish.ts.snap | Removes obsolete snapshot in favor of more stable assertions. |
| .changeset/restore-publish-json-stdout.md | Documents the restored JSON contract and publishes patch releases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
pnpm 10 transitively emitted an npm-CLI-shaped per-package JSON object on stdout for `pnpm publish --json` because the publish command shelled out to npm. pnpm 11 (pnpm#10591) reimplemented publish natively and the new handler returned undefined, so `--json` now produces 0 bytes on stdout on success — silently breaking downstream tooling that grepped that contract. The most impactful regression is `nx release publish`, which parses stdout JSON to confirm success; under `--nx-bail=true` it aborts the rest of a release run when JSON is missing (see nrwl/nx#35575). This restores the contract for both single-package and recursive publish, and aligns `--report-summary` to use the same per-package shape: - `pnpm publish --json` → single object `{ id, name, version, size, unpackedSize, shasum, integrity, filename, files, entryCount, bundled }`, mirroring `npm publish --json`. - `pnpm publish -r --json` → array of those objects, mirroring `pnpm pack --json`'s shape choice for single vs multi. - `pnpm publish -r --report-summary` → existing `pnpm-publish-summary.json` envelope `{ publishedPackages: [...] }` is preserved, but each entry is upgraded to the same per-package shape (additive — `name` and `version` are still present). Implementation: - `pack.api()` computes `unpackedSize` while it still has the filesMap. - `publishPackedPkg` returns a `PublishSummary` (SHA-1 `shasum` + SHA-512 `integrity` via `node:crypto`, no new deps) instead of `void`. - `bundled` normalizes `bundledDependencies` / `bundleDependencies` per npm's semantics (including `true` → all dep names). - `recursivePublish` collects per-package `PublishSummary` objects and returns them; the existing manifest-pick fallback is kept for paths that don't produce a summary. - `publish.handler` returns `{ output, exitCode }` with the serialized summary (object or array) when `opts.json` is set; main.ts already writes `output` to stdout. Refs pnpm#11476 Refs nrwl/nx#35575 Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-019df90f-8f75-763f-b528-4602e870a972
d3192a2 to
38342b7
Compare
…11478) pnpm 10 transitively emitted an npm-CLI-shaped per-package JSON object on stdout for `pnpm publish --json` because the publish command shelled out to npm. pnpm 11 (#10591) reimplemented publish natively and the new handler returned undefined, so `--json` now produces 0 bytes on stdout on success — silently breaking downstream tooling that grepped that contract. The most impactful regression is `nx release publish`, which parses stdout JSON to confirm success; under `--nx-bail=true` it aborts the rest of a release run when JSON is missing (see nrwl/nx#35575). This restores the contract for both single-package and recursive publish, and aligns `--report-summary` to use the same per-package shape: - `pnpm publish --json` → single object `{ id, name, version, size, unpackedSize, shasum, integrity, filename, files, entryCount, bundled }`, mirroring `npm publish --json`. - `pnpm publish -r --json` → array of those objects, mirroring `pnpm pack --json`'s shape choice for single vs multi. - `pnpm publish -r --report-summary` → existing `pnpm-publish-summary.json` envelope `{ publishedPackages: [...] }` is preserved, but each entry is upgraded to the same per-package shape (additive — `name` and `version` are still present). Implementation: - `pack.api()` computes `unpackedSize` while it still has the filesMap. - `publishPackedPkg` returns a `PublishSummary` (SHA-1 `shasum` + SHA-512 `integrity` via `node:crypto`, no new deps) instead of `void`. - `bundled` normalizes `bundledDependencies` / `bundleDependencies` per npm's semantics (including `true` → all dep names). - `recursivePublish` collects per-package `PublishSummary` objects and returns them; the existing manifest-pick fallback is kept for paths that don't produce a summary. - `publish.handler` returns `{ output, exitCode }` with the serialized summary (object or array) when `opts.json` is set; main.ts already writes `output` to stdout. Refs #11476 Refs nrwl/nx#35575 Amp-Thread-ID: https://ampcode.com/threads/T-019df90f-8f75-763f-b528-4602e870a972 Co-authored-by: Charlie Croom <charlie+amp@noreply.com> Co-authored-by: Amp <amp@ampcode.com>
Summary
Restores npm-CLI-compatible
--jsonstdout output forpnpm publish, and aligns--report-summaryto use the same per-package shape.Fixes #11476.
Background
pnpm 10 transitively emitted an npm-CLI-shaped per-package JSON object on stdout for
pnpm publish --jsonbecause the publish command shelled out to npm. pnpm 11 (#10591) reimplemented publish natively and the new handler returnedundefined, so--jsonnow produces 0 bytes on stdout on success — silently breaking downstream tooling that relied on that contract.The most impactful regression is
nx release publish, which parses stdout JSON to confirm success. Under the default--nx-bail=true, it aborts the rest of a release run when JSON is missing — leaving releases partially-published with no surfaced error. Full impact write-up: nrwl/nx#35575.Output shape
pnpm publish --json{ id, name, version, size, unpackedSize, shasum, integrity, filename, files, entryCount, bundled }, mirroringnpm publish --jsonpnpm publish -r --jsonpnpm pack --json's shape choicepnpm publish -r --report-summarypnpm-publish-summary.jsonenvelope{ publishedPackages: [...] }is preserved, but each entry is upgraded to the same per-package shape — additive, sincenameandversionare still presentThere was no usable contract for
-r --jsonbefore this change (pnpm 10 emitted multiple JSON objects interleaved with reporter noise per shelled-out npm call, which isn't parseable), so emitting the array is strictly an improvement.Implementation
pack.api()computesunpackedSizewhile it still has the filesMap.publishPackedPkgreturns aPublishSummary(SHA-1shasum+ SHA-512integrityvianode:crypto, no new deps) instead ofvoid.bundledis normalized frombundledDependencies/bundleDependenciesper npm's semantics (includingtrue→ expand to all dep names).recursivePublishcollects per-packagePublishSummaryobjects and returns them; the existing manifest-pick fallback is kept for paths that don't produce a summary.publish.handlerreturns{ output, exitCode }with the serialized summary (object or array) whenopts.jsonis set;pnpm/src/main.tsalready writesoutputto stdout.patchto@pnpm/releasing.commandsandpnpm) is included.Notes
pnpm publish <tarball>direct path:files,entryCount, andunpackedSizeare reported as empty/zero because the contents list and uncompressed sizes aren't available without re-reading the tarball. Easy to wire up if reviewers prefer.Verification
I checked open pnpm PRs for
publish --json,publishPackedPkg, and references to #11476 / #10591 — no open PR is already pursuing this fix.Related
npm publishwithlibnpmpublish#10591🤖 Authored with assistance from Amp.
Summary by CodeRabbit
New Features
pnpm publish --jsonnow emits npm-compatible per-package JSON summaries (includes size, unpackedSize, shasum, integrity, filename, files, entryCount, bundled).pnpm publish -r --jsonandpnpm publish -r --report-summary) now produce arrays or summary files using the per-package summary shape.Documentation
Tests