@pnpm/cli.default-reporter 1100.3.3 → 1100.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import createDiffer from 'ansi-diff';
1
2
  import * as Rx from 'rxjs';
2
3
  import { filter, map, mergeAll } from 'rxjs/operators';
3
4
  import { EOL } from './constants.js';
@@ -5,10 +6,9 @@ import { mergeOutputs } from './mergeOutputs.js';
5
6
  import { reporterForClient } from './reporterForClient/index.js';
6
7
  import { formatWarn } from './reporterForClient/utils/formatWarn.js';
7
8
  export { formatWarn };
8
- // ANSI "erase from cursor to end of display". Emitted before reprinting each
9
- // frame so that anything an external process (e.g. an SSH passphrase prompt)
10
- // wrote to the terminal between progress updates is cleared instead of bleeding
11
- // into the progress output.
9
+ // ANSI "erase from cursor to end of display". Appended after each
10
+ // differential update so that anything an external process (e.g. an SSH
11
+ // passphrase prompt) wrote below the rendered frame is cleared.
12
12
  const ERASE_TO_END_OF_DISPLAY = '\x1b[0J';
13
13
  export function initDefaultReporter(opts) {
14
14
  const proc = opts.context.process ?? process;
@@ -36,6 +36,12 @@ export function initDefaultReporter(opts) {
36
36
  subscription.unsubscribe();
37
37
  };
38
38
  }
39
+ const stream = opts.useStderr ? proc.stderr : proc.stdout;
40
+ const write = stream.write.bind(stream);
41
+ const diff = createDiffer({
42
+ height: stream.rows,
43
+ width: stream.columns ?? outputMaxWidth,
44
+ });
39
45
  const subscription = output$
40
46
  .subscribe({
41
47
  complete() { }, // eslint-disable-line:no-empty
@@ -44,42 +50,26 @@ export function initDefaultReporter(opts) {
44
50
  },
45
51
  next: logUpdate,
46
52
  });
47
- const write = opts.useStderr
48
- ? proc.stderr.write.bind(proc.stderr)
49
- : proc.stdout.write.bind(proc.stdout);
50
- let prevRows = 0;
51
53
  function logUpdate(view) {
52
54
  // A new line should always be appended in case a prompt needs to appear.
53
55
  // Without a new line the prompt will be joined with the previous output.
54
56
  // An example of such prompt may be seen by running: pnpm update --interactive
55
57
  if (!view.endsWith(EOL))
56
58
  view += EOL;
57
- // Redraw the whole frame in place: return the cursor to the top-left of the
58
- // previous frame, erase everything below it, then reprint. The `\r` resets
59
- // the column to 0 (cursor-up alone keeps the column) so the redraw starts
60
- // cleanly even when an external process left the cursor mid-line. Doing it
61
- // in a single write keeps the redraw atomic (no flicker) and clears any
62
- // characters an external process wrote in between.
63
- const moveToFrameTop = prevRows > 0 ? `\x1b[${prevRows}A\r` : '\r';
64
- write(`${moveToFrameTop}${ERASE_TO_END_OF_DISPLAY}${view}`);
65
- prevRows = countRows(view);
59
+ // `\r` resets the column to 0 in case an external process (e.g. an SSH
60
+ // passphrase prompt) left the cursor mid-line. `ansi-diff` then writes
61
+ // only the differential the characters that actually changed between
62
+ // the previous frame and this one so sticky blocks like the lockfile
63
+ // verdict and deprecation warnings are not re-written on every progress
64
+ // tick. `\x1b[K` erases trailing characters on the current line;
65
+ // `\x1b[0J` erases anything an external process wrote below the
66
+ // rendered frame.
67
+ write(`\r${diff.update(view)}\x1b[K${ERASE_TO_END_OF_DISPLAY}`);
66
68
  }
67
69
  return () => {
68
70
  subscription.unsubscribe();
69
71
  };
70
72
  }
71
- // Number of terminal rows a frame occupies. The frame always ends with a
72
- // newline, so this also equals how far below the frame's top the cursor rests
73
- // after printing it. Lines are assumed not to soft-wrap, matching how the
74
- // progress output is width-constrained before it reaches here.
75
- function countRows(frame) {
76
- let rows = 0;
77
- for (let i = 0; i < frame.length; i++) {
78
- if (frame.charCodeAt(i) === 10 /* \n */)
79
- rows++;
80
- }
81
- return rows;
82
- }
83
73
  export function toOutput$(opts) {
84
74
  opts = opts || {};
85
75
  const contextPushStream = new Rx.Subject();
@@ -180,6 +180,10 @@ function formatLine(maxWidth, logObj) {
180
180
  function cutLine(line, maxLength) {
181
181
  if (!line)
182
182
  return '';
183
+ // Streamed lifecycle output is printed in full (maxLength is Infinity).
184
+ // cli-truncate rejects a non-finite width, so skip truncation in that case.
185
+ if (!Number.isFinite(maxLength))
186
+ return line;
183
187
  return cliTruncate(line, maxLength);
184
188
  }
185
189
  function aggregateOutput(source) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pnpm/cli.default-reporter",
3
- "version": "1100.3.3",
3
+ "version": "1100.3.4",
4
4
  "description": "The default reporter of pnpm",
5
5
  "keywords": [
6
6
  "pnpm",
@@ -33,6 +33,7 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@pnpm/util.lex-comparator": "^4.0.1",
36
+ "ansi-diff": "^1.2.0",
36
37
  "boxen": "npm:@zkochan/boxen@5.1.2",
37
38
  "chalk": "^5.6.2",
38
39
  "cli-truncate": "^6.0.0",
@@ -45,10 +46,10 @@
45
46
  "stacktracey": "^2.2.0",
46
47
  "string-length": "^7.0.1",
47
48
  "@pnpm/cli.meta": "1100.0.8",
48
- "@pnpm/config.reader": "1101.10.1",
49
+ "@pnpm/config.reader": "1101.11.0",
49
50
  "@pnpm/deps.inspection.peers-issues-renderer": "1100.0.6",
50
- "@pnpm/error": "1100.0.1",
51
51
  "@pnpm/core-loggers": "1100.2.1",
52
+ "@pnpm/error": "1100.0.1",
52
53
  "@pnpm/installing.dedupe.issues-renderer": "1100.0.1",
53
54
  "@pnpm/installing.dedupe.types": "1100.0.1",
54
55
  "@pnpm/types": "1101.3.2"
@@ -64,8 +65,8 @@
64
65
  "ghooks": "2.0.4",
65
66
  "load-json-file": "^7.0.1",
66
67
  "normalize-newline": "5.0.0",
67
- "@pnpm/cli.default-reporter": "1100.3.3",
68
- "@pnpm/logger": "1100.0.0"
68
+ "@pnpm/logger": "1100.0.0",
69
+ "@pnpm/cli.default-reporter": "1100.3.4"
69
70
  },
70
71
  "engines": {
71
72
  "node": ">=22.13"