Files
pnpm/cli/default-reporter
Mayank Maurya 3f0fb219b6 fix(default-reporter): erase trailing characters on progress line (#12351)
External processes like SSH passphrase prompts can write to the terminal between progress updates. The previous renderer used `ansi-diff`, which only overwrites the characters it knows changed, so leftover characters from the external output stayed visible on the progress line — e.g. `added 0sa':`, where `sa':` is a fragment of `Enter passphrase for key '.../.ssh/id_rsa':`.

Closes https://github.com/pnpm/pnpm/issues/12350

## Summary

The interactive (non-append-only) reporter now redraws the whole frame in place on each update instead of incrementally diffing it:

- return the cursor to the top-left of the previous frame (`ESC[<rows>A` followed by a carriage return, so the redraw starts at column 0 even if an external process left the cursor mid-line),
- erase from there to the end of the display (`ESC[0J`),
- reprint the frame — all in a single atomic write, so there is no flicker.

Because the whole region is erased on every frame, any characters an external process wrote in between are cleared. This matches pacquet's `Output::Frame` rendering (the column-reset hardening was applied to both stacks). The now-unused `ansi-diff` dependency has been removed.

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Zoltan Kochan <z@kochan.io>
2026-06-17 08:17:15 +02:00
..
2026-06-15 08:37:08 +02:00

@pnpm/cli.default-reporter

The default reporter of pnpm

Installation

pnpm add @pnpm/cli.default-reporter

Usage

import { streamParser } from '@pnpm/logger'
import { initDefaultReporter } from '@pnpm/cli.default-reporter'

const stopReporting = initDefaultReporter({
  context: {
    argv: [],
  },
  streamParser,
})

try {
  // calling some pnpm APIs
} finally {
  stopReporting()
}

pnpm-render bin

Installing this package exposes a pnpm-render bin that reads pnpm-shaped NDJSON from stdin and renders it through the default reporter. This lets external tools that emit pnpm:* log records reuse pnpm's renderer.

For example, pacquet emits the same wire format under --reporter=ndjson (to stderr), so its output can be piped through pnpm-render:

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

The redirect (2>&1 >/dev/null) is needed because pacquet writes the NDJSON stream to stderr.

An optional first positional argument sets the command name (defaults to install); pass it to match the verb the producer is running so command-specific renderers behave correctly:

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

Style Guide

  1. Never use blue or grey as font color as they are hard to read in many consoles.
    1. Use dim instead of grey
    2. Use cyan bright instead of blue
  2. Don't hide the CLI cursor. (It is easier to never hide but it is really needed only when scripts are running.)
  3. Don't use green and yellow to distinct something.

License

MIT