Skip to content

feat(default-reporter): add pnpm-render bin to render NDJSON from stdin#11530

Merged
zkochan merged 7 commits into
mainfrom
default-reporter-cli
May 7, 2026
Merged

feat(default-reporter): add pnpm-render bin to render NDJSON from stdin#11530
zkochan merged 7 commits into
mainfrom
default-reporter-cli

Conversation

@zkochan

@zkochan zkochan commented May 7, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds a pnpm-render bin to @pnpm/cli.default-reporter that reads pnpm-shaped NDJSON from stdin and pipes it through the default reporter, so external tools that emit pnpm:* log records can reuse pnpm's renderer.
  • Optional first positional arg sets the command name (defaults to install), e.g. pnpm-render add for piping output from pacquet add.

Motivation

Pacquet emits pnpm-shaped --reporter=ndjson output for forward-compatibility with pnpm's renderer, but there was no way to actually render it. With this bin:

pacquet install --reporter=ndjson 2>&1 >/dev/null | pnpm-render

(pacquet writes NDJSON to stderr, so the redirect is needed.)

Test plan

  • Smoke-tested with hand-crafted NDJSON: progress, stats, summary all render
  • End-to-end against pacquet install --reporter=ndjson: progress + context block render correctly
  • Confirm published-package layout includes `bin/pnpm-render.mjs` and the bin field

Written by an agent (Claude Code, claude-opus-4-7).

Summary by CodeRabbit

  • New Features

    • Added a pnpm-render CLI that reads pnpm-shaped NDJSON from stdin and renders it (optional first argument sets command name; defaults to "install").
  • Documentation

    • Added README usage examples and guidance on stdin/stdout/stderr handling for pnpm-render.
  • Tests

    • Added tests verifying pnpm-render handles valid NDJSON and ignores malformed input.
  • Chores

    • Included the CLI in the published package and updated spelling list to include "pacquet".

zkochan added 2 commits May 7, 2026 22:49
Adds a `default-reporter` bin to `@pnpm/cli.default-reporter` that reads
pnpm-shaped NDJSON from stdin and pipes it through the default reporter.
This lets external tools that emit `pnpm:*` log records (e.g. pacquet's
`--reporter=ndjson`) reuse pnpm's renderer.

Usage: `pacquet install --reporter=ndjson 2>&1 >/dev/null | default-reporter`

Optional first positional argument sets the command name (defaults to
`install`).
@coderabbitai

coderabbitai Bot commented May 7, 2026

Copy link
Copy Markdown

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: cd261dd4-d328-4b5c-9e10-69ce06c639da

📥 Commits

Reviewing files that changed from the base of the PR and between abaef3d and 83d85c7.

📒 Files selected for processing (1)
  • cli/default-reporter/src/cli.ts

📝 Walkthrough

Walkthrough

Adds a pnpm-render CLI binary and entrypoint, implements runCli to parse pnpm-shaped NDJSON from stdin and emit logs to the default reporter, and includes Jest tests, README docs, a changeset, and a cspell update.

Changes

pnpm-render CLI Binary

Layer / File(s) Summary
Package Configuration
cli/default-reporter/package.json
Added bin dir to files and declared pnpm-renderbin/pnpm-render.mjs.
CLI Core Logic
cli/default-reporter/src/cli.ts
Added runCli(argv) that initializes the default reporter, reads stdin NDJSON line-by-line, JSON-parses and validates object logs, emits them to the reporter, and ensures cleanup.
Binary Entrypoint
cli/default-reporter/bin/pnpm-render.mjs
New executable script that forwards CLI args to runCli and handles errors by printing to stderr and exiting with code 1.
Tests / Validation
cli/default-reporter/test/cli.ts
Jest tests spawn the bin, feed valid and mixed malformed NDJSON, assert rendered progress output, and include runBin helper.
Documentation & Metadata
cli/default-reporter/README.md, .changeset/default-reporter-bin.md, cspell.json
Added README usage examples and redirection notes, created a changeset for a minor release, and added "pacquet" to cspell words.

Sequence Diagram

sequenceDiagram
  participant User
  participant Shell
  participant pnpmRender as pnpm-render
  participant Parser
  participant Reporter
  participant Stdout
  User->>Shell: run pnpm-render [cmd]
  Shell->>pnpmRender: spawn process
  pnpmRender->>Parser: read stdin NDJSON lines
  Parser->>Reporter: emit Log objects
  Reporter->>Stdout: render output lines
  pnpmRender->>Reporter: close()
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Poem

🐰 A tiny renderer hops to life,
It listens to NDJSON strife,
A tick, a parse, a progress shown,
From stdin streams the output grown,
pnpm-render hops — the logs find home.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and specifically describes the main change: adding a new pnpm-render binary to the default-reporter that renders NDJSON from stdin.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch default-reporter-cli

Comment @coderabbitai help to get the list of available commands and usage tips.

`default-reporter` was too generic for a globally-installed binary;
`pnpm-render` is namespaced and reflects what the bin does — render
pnpm-shaped NDJSON from stdin.
@zkochan zkochan changed the title feat(default-reporter): add bin to render NDJSON from stdin feat(default-reporter): add pnpm-render bin to render NDJSON from stdin May 7, 2026
zkochan added 2 commits May 7, 2026 23:10
Spawns the bin, pipes NDJSON, and asserts the rendered "Progress: resolved"
line appears on stdout. Also exercises the malformed-line path. Catches
regressions in the bin wiring (path, package.json bin entry, stdin parsing,
clean shutdown on EOF) that the existing toOutput$ unit tests can't cover.

Also fixes a race in src/cli.ts: initDefaultReporter registers its 'data'
listener via setTimeout(0), so emitting events before the next tick
dropped them. runCli now waits one tick before reading stdin.

Documents the bin and the pacquet pipe usage in the README.
@zkochan zkochan marked this pull request as ready for review May 7, 2026 23:03
Copilot AI review requested due to automatic review settings May 7, 2026 23:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new pnpm-render executable to @pnpm/cli.default-reporter that reads pnpm-shaped NDJSON from stdin and renders it using pnpm’s default reporter, enabling external tools (e.g. pacquet) to reuse pnpm’s renderer.

Changes:

  • Introduces a small CLI (runCli) that parses NDJSON lines from stdin and forwards them into initDefaultReporter.
  • Adds the published pnpm-render bin entry + packaged bin/ script, plus documentation and a changeset.
  • Adds Jest coverage for basic stdin rendering and non-JSON line handling.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
cspell.json Adds pacquet to spellcheck allowlist.
cli/default-reporter/test/cli.ts Adds Jest tests that spawn the new pnpm-render bin and pipe NDJSON to stdin.
cli/default-reporter/src/cli.ts Implements the new stdin-driven renderer CLI (runCli).
cli/default-reporter/README.md Documents pnpm-render usage and piping example with pacquet.
cli/default-reporter/package.json Publishes the new bin and ensures bin/ is included in package files.
cli/default-reporter/bin/pnpm-render.mjs Adds the executable entrypoint invoking runCli.
.changeset/default-reporter-bin.md Declares a minor release and documents the new bin.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cli/default-reporter/test/cli.ts
Comment thread cli/default-reporter/src/cli.ts
Comment thread cli/default-reporter/src/cli.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cli/default-reporter/test/cli.ts`:
- Around line 44-49: The Promise awaiting the child process uses
child.on('exit', ...) which can fire before stdout/stderr are fully drained;
change the listener to child.on('close', (code) => { resolve(code) }) so the
Promise resolves only after all stdio streams are closed (keep child.on('error',
reject') intact); update the variable handling around exitCode/new Promise to
use the 'close' event on the child process instead of 'exit'.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b6fdfc1a-e99a-4732-ba3d-da0a3c4b1885

📥 Commits

Reviewing files that changed from the base of the PR and between 8eb1be4 and 1db5649.

📒 Files selected for processing (7)
  • .changeset/default-reporter-bin.md
  • cli/default-reporter/README.md
  • cli/default-reporter/bin/pnpm-render.mjs
  • cli/default-reporter/package.json
  • cli/default-reporter/src/cli.ts
  • cli/default-reporter/test/cli.ts
  • cspell.json

Comment thread cli/default-reporter/test/cli.ts
zkochan added 2 commits May 8, 2026 01:39
- Drop throttleProgress: with no live producer, closing on stdin EOF can
  drop the trailing throttle emission and lose the final progress state.
- Guard against valid-but-non-object JSON (e.g. `null`, numbers, strings):
  these would propagate to the reporter and crash on `log.name` access.
- In the test, wait for child 'close' instead of 'exit' so stdout/stderr
  are fully drained before assertions run.
Restoring throttleProgress: 200 — rxjs throttleTime emits its pending
trailing value when the source completes, and the standard pnpm:stage
importing_done event completes the per-requirer progress stream (see
reportProgress.ts). So for producers that emit importing_done at end of
install (e.g. pacquet), the final progress value renders correctly. The
remaining lossy case — a truncated stream without importing_done — is
narrow and not worth losing redraw throttling for live producers.
Copilot AI review requested due to automatic review settings May 7, 2026 23:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

Comment thread cli/default-reporter/src/cli.ts
@zkochan zkochan merged commit 6836547 into main May 7, 2026
14 checks passed
@zkochan zkochan deleted the default-reporter-cli branch May 7, 2026 23:56
zkochan added a commit that referenced this pull request May 8, 2026
…in (#11530)

- Adds a `pnpm-render` bin to `@pnpm/cli.default-reporter` that reads pnpm-shaped NDJSON from stdin and pipes it through the default reporter, so external tools that emit `pnpm:*` log records can reuse pnpm's renderer.
- Optional first positional arg sets the command name (defaults to `install`), e.g. `pnpm-render add` for piping output from `pacquet add`.

## Motivation

[Pacquet](https://github.com/pnpm/pacquet) emits pnpm-shaped `--reporter=ndjson` output for forward-compatibility with pnpm's renderer, but there was no way to actually render it. With this bin:

```sh
pacquet install --reporter=ndjson 2>&1 >/dev/null | pnpm-render
```

(pacquet writes NDJSON to stderr, so the redirect is needed.)
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.

2 participants