@pnpm/cli.default-reporter 1100.3.7 → 1100.3.8

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.
Files changed (62) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/lib/index.js +20 -1
  3. package/package.json +4 -4
  4. package/lib/cli.d.ts +0 -1
  5. package/lib/cli.js +0 -50
  6. package/lib/constants.d.ts +0 -1
  7. package/lib/constants.js +0 -4
  8. package/lib/index.d.ts +0 -54
  9. package/lib/mergeOutputs.d.ts +0 -4
  10. package/lib/mergeOutputs.js +0 -69
  11. package/lib/reportError.d.ts +0 -3
  12. package/lib/reportError.js +0 -426
  13. package/lib/reporterForClient/index.d.ts +0 -53
  14. package/lib/reporterForClient/index.js +0 -98
  15. package/lib/reporterForClient/outputConstants.d.ts +0 -4
  16. package/lib/reporterForClient/outputConstants.js +0 -6
  17. package/lib/reporterForClient/pkgsDiff.d.ts +0 -36
  18. package/lib/reporterForClient/pkgsDiff.js +0 -113
  19. package/lib/reporterForClient/reportBigTarballsProgress.d.ts +0 -8
  20. package/lib/reporterForClient/reportBigTarballsProgress.js +0 -26
  21. package/lib/reporterForClient/reportContext.d.ts +0 -10
  22. package/lib/reporterForClient/reportContext.js +0 -34
  23. package/lib/reporterForClient/reportDeprecations.d.ts +0 -11
  24. package/lib/reporterForClient/reportDeprecations.js +0 -27
  25. package/lib/reporterForClient/reportExecutionTime.d.ts +0 -6
  26. package/lib/reporterForClient/reportExecutionTime.js +0 -13
  27. package/lib/reporterForClient/reportHooks.d.ts +0 -8
  28. package/lib/reporterForClient/reportHooks.js +0 -12
  29. package/lib/reporterForClient/reportIgnoredBuilds.d.ts +0 -11
  30. package/lib/reporterForClient/reportIgnoredBuilds.js +0 -21
  31. package/lib/reporterForClient/reportInstallChecks.d.ts +0 -7
  32. package/lib/reporterForClient/reportInstallChecks.js +0 -19
  33. package/lib/reporterForClient/reportInstallingConfigDeps.d.ts +0 -5
  34. package/lib/reporterForClient/reportInstallingConfigDeps.js +0 -18
  35. package/lib/reporterForClient/reportLifecycleScripts.d.ts +0 -13
  36. package/lib/reporterForClient/reportLifecycleScripts.js +0 -197
  37. package/lib/reporterForClient/reportLockfileVerification.d.ts +0 -15
  38. package/lib/reporterForClient/reportLockfileVerification.js +0 -73
  39. package/lib/reporterForClient/reportMisc.d.ts +0 -17
  40. package/lib/reporterForClient/reportMisc.js +0 -69
  41. package/lib/reporterForClient/reportPeerDependencyIssues.d.ts +0 -7
  42. package/lib/reporterForClient/reportPeerDependencyIssues.js +0 -11
  43. package/lib/reporterForClient/reportProgress.d.ts +0 -16
  44. package/lib/reporterForClient/reportProgress.js +0 -123
  45. package/lib/reporterForClient/reportRequestRetry.d.ts +0 -5
  46. package/lib/reporterForClient/reportRequestRetry.js +0 -18
  47. package/lib/reporterForClient/reportScope.d.ts +0 -8
  48. package/lib/reporterForClient/reportScope.js +0 -41
  49. package/lib/reporterForClient/reportSkippedOptionalDependencies.d.ts +0 -7
  50. package/lib/reporterForClient/reportSkippedOptionalDependencies.js +0 -8
  51. package/lib/reporterForClient/reportStats.d.ts +0 -13
  52. package/lib/reporterForClient/reportStats.js +0 -143
  53. package/lib/reporterForClient/reportSummary.d.ts +0 -19
  54. package/lib/reporterForClient/reportSummary.js +0 -79
  55. package/lib/reporterForClient/reportUpdateCheck.d.ts +0 -8
  56. package/lib/reporterForClient/reportUpdateCheck.js +0 -42
  57. package/lib/reporterForClient/utils/formatPrefix.d.ts +0 -2
  58. package/lib/reporterForClient/utils/formatPrefix.js +0 -19
  59. package/lib/reporterForClient/utils/formatWarn.d.ts +0 -1
  60. package/lib/reporterForClient/utils/formatWarn.js +0 -5
  61. package/lib/reporterForClient/utils/zooming.d.ts +0 -4
  62. package/lib/reporterForClient/utils/zooming.js +0 -13
@@ -1,73 +0,0 @@
1
- import path from 'node:path';
2
- import chalk from 'chalk';
3
- import normalize from 'normalize-path';
4
- import prettyMs from 'pretty-ms';
5
- import * as Rx from 'rxjs';
6
- import { map } from 'rxjs/operators';
7
- export function reportLockfileVerification(lockfileVerification$, opts) {
8
- const expectedDir = opts.workspaceDir ?? opts.cwd;
9
- // A single inner observable so the `done` message overwrites the
10
- // transient `started` message when the reporter redraws in place. In
11
- // appendOnly mode both lines are printed.
12
- return Rx.of(lockfileVerification$.pipe(map((log) => {
13
- const path_ = formatLockfilePath(log.lockfilePath, opts.cwd, expectedDir);
14
- if (log.status === 'cached') {
15
- return {
16
- msg: `${chalk.green('✓')} Lockfile${path_} passes supply-chain policies (${formatCachedVerdict(log.verifiedAt)})`,
17
- };
18
- }
19
- const entries = `${log.entries} ${log.entries === 1 ? 'entry' : 'entries'}`;
20
- switch (log.status) {
21
- case 'started':
22
- return {
23
- msg: `${chalk.cyan('?')} Verifying lockfile${path_} against supply-chain policies (${entries})...`,
24
- };
25
- case 'done':
26
- return {
27
- msg: `${chalk.green('✓')} Lockfile${path_} passes supply-chain policies (${entries} in ${prettyMs(log.elapsedMs)})`,
28
- };
29
- case 'failed':
30
- // Brief one-liner so the transient `started` frame doesn't
31
- // stay on screen above the detailed PnpmError block that the
32
- // error reporter prints next.
33
- return {
34
- msg: `${chalk.red('✗')} Lockfile${path_} failed supply-chain policy check (${entries} in ${prettyMs(log.elapsedMs)})`,
35
- };
36
- }
37
- })));
38
- }
39
- // Relative "verified 2h ago" when the cached record carries a parseable
40
- // timestamp; the timeless "previously verified" otherwise. The elapsed
41
- // time is clamped at zero so a clock that moved backwards between the
42
- // verification run and this install doesn't render a negative age.
43
- function formatCachedVerdict(verifiedAt) {
44
- if (verifiedAt == null)
45
- return 'previously verified';
46
- const elapsedMs = Date.now() - Date.parse(verifiedAt);
47
- if (Number.isNaN(elapsedMs))
48
- return 'previously verified';
49
- return `verified ${prettyMs(Math.max(elapsedMs, 0), { compact: true })} ago`;
50
- }
51
- // Returns a leading-space-prefixed `at <path>` suffix only when the
52
- // lockfile sits outside the obvious project/workspace root — otherwise
53
- // the path is implied and printing it would just add noise to every
54
- // install. Empty string when the path is omitted or matches the
55
- // expected location.
56
- //
57
- // Uses `path.relative` rather than a strict `===` between
58
- // `path.dirname(lockfilePath)` and `expectedDir`: relative path
59
- // computation normalizes slash direction and trailing separators, so
60
- // a workspaceDir like `C:/repo/` correctly matches a lockfilePath at
61
- // `C:\repo\pnpm-lock.yaml` on Windows. The lockfile is considered
62
- // "inside the expected dir" when the relative path is a bare file
63
- // name (no separator) that doesn't escape upward.
64
- function formatLockfilePath(lockfilePath, cwd, expectedDir) {
65
- if (lockfilePath == null)
66
- return '';
67
- const fromExpected = path.relative(expectedDir, lockfilePath);
68
- const isDirectChild = !fromExpected.includes(path.sep) && !fromExpected.startsWith('..');
69
- if (isDirectChild)
70
- return '';
71
- return ` at ${normalize(path.relative(cwd, lockfilePath))}`;
72
- }
73
- //# sourceMappingURL=reportLockfileVerification.js.map
@@ -1,17 +0,0 @@
1
- import type { Config } from '@pnpm/config.reader';
2
- import type { Log, RegistryLog } from '@pnpm/core-loggers';
3
- import type { LogLevel } from '@pnpm/logger';
4
- import * as Rx from 'rxjs';
5
- export declare const LOG_LEVEL_NUMBER: Record<LogLevel, number>;
6
- export declare function reportMisc(log$: {
7
- registry: Rx.Observable<RegistryLog>;
8
- other: Rx.Observable<Log>;
9
- }, opts: {
10
- appendOnly: boolean;
11
- cwd: string;
12
- logLevel?: LogLevel;
13
- config?: Config;
14
- zoomOutCurrent: boolean;
15
- }): Rx.Observable<Rx.Observable<{
16
- msg: string;
17
- }>>;
@@ -1,69 +0,0 @@
1
- import os from 'node:os';
2
- import * as Rx from 'rxjs';
3
- import { filter, map } from 'rxjs/operators';
4
- import { reportError } from '../reportError.js';
5
- import { formatWarn } from './utils/formatWarn.js';
6
- import { autozoom } from './utils/zooming.js';
7
- // eslint-disable:object-literal-sort-keys
8
- export const LOG_LEVEL_NUMBER = {
9
- error: 0,
10
- warn: 1,
11
- info: 2,
12
- debug: 3,
13
- };
14
- // eslint-enable:object-literal-sort-keys
15
- const MAX_SHOWN_WARNINGS = 5;
16
- export function reportMisc(log$, opts) {
17
- const maxLogLevel = LOG_LEVEL_NUMBER[opts.logLevel ?? 'info'] ?? LOG_LEVEL_NUMBER['info'];
18
- const reportWarning = makeWarningReporter(opts);
19
- return Rx.merge(log$.registry, log$.other).pipe(filter((obj) => LOG_LEVEL_NUMBER[obj.level] <= maxLogLevel &&
20
- (obj.level !== 'info' || !obj['prefix'] || obj['prefix'] === opts.cwd)), map((obj) => {
21
- switch (obj.level) {
22
- case 'warn': {
23
- return reportWarning(obj);
24
- }
25
- case 'error': {
26
- const errorOutput = reportError(obj, opts.config);
27
- if (!errorOutput)
28
- return Rx.NEVER;
29
- if (obj['prefix'] && obj['prefix'] !== opts.cwd) {
30
- return Rx.of({
31
- msg: `${obj['prefix']}:` + os.EOL + errorOutput,
32
- });
33
- }
34
- return Rx.of({ msg: errorOutput });
35
- }
36
- default:
37
- return Rx.of({ msg: obj.message });
38
- }
39
- }));
40
- }
41
- // Sometimes, when installing new dependencies that rely on many peer dependencies,
42
- // or when running installation on a huge monorepo, there will be hundreds or thousands of warnings.
43
- // Printing many messages to the terminal is expensive and reduces speed,
44
- // so pnpm will only print a few warnings and report the total number of the unprinted warnings.
45
- function makeWarningReporter(opts) {
46
- let warningsCounter = 0;
47
- let collapsedWarnings;
48
- return (obj) => {
49
- warningsCounter++;
50
- if (opts.appendOnly || warningsCounter <= MAX_SHOWN_WARNINGS) {
51
- return Rx.of({ msg: autozoom(opts.cwd, obj.prefix, formatWarn(obj.message), opts) });
52
- }
53
- const warningMsg = formatWarn(`${warningsCounter - MAX_SHOWN_WARNINGS} other warnings`);
54
- if (!collapsedWarnings) {
55
- collapsedWarnings = new Rx.Subject();
56
- // For some reason, without using setTimeout, the warning summary is printed above the rest of the warnings
57
- // Even though the summary event happens last. Probably a bug in "most".
58
- setTimeout(() => {
59
- collapsedWarnings.next({ msg: warningMsg });
60
- }, 0);
61
- return Rx.from(collapsedWarnings);
62
- }
63
- setTimeout(() => {
64
- collapsedWarnings.next({ msg: warningMsg });
65
- }, 0);
66
- return Rx.NEVER;
67
- };
68
- }
69
- //# sourceMappingURL=reportMisc.js.map
@@ -1,7 +0,0 @@
1
- import type { PeerDependencyIssuesLog } from '@pnpm/core-loggers';
2
- import * as Rx from 'rxjs';
3
- export declare function reportPeerDependencyIssues(log$: {
4
- peerDependencyIssues: Rx.Observable<PeerDependencyIssuesLog>;
5
- }): Rx.Observable<Rx.Observable<{
6
- msg: string;
7
- }>>;
@@ -1,11 +0,0 @@
1
- import * as Rx from 'rxjs';
2
- import { map, take } from 'rxjs/operators';
3
- import { formatWarn } from './utils/formatWarn.js';
4
- export function reportPeerDependencyIssues(log$) {
5
- return log$.peerDependencyIssues.pipe(take(1), map(() => {
6
- return Rx.of({
7
- msg: formatWarn('Issues with peer dependencies found. Run "pnpm peers check" to list them.'),
8
- });
9
- }));
10
- }
11
- //# sourceMappingURL=reportPeerDependencyIssues.js.map
@@ -1,16 +0,0 @@
1
- import type { ProgressLog, StageLog } from '@pnpm/core-loggers';
2
- import * as Rx from 'rxjs';
3
- export interface StatusMessage {
4
- msg: string;
5
- fixed: boolean;
6
- done?: boolean;
7
- }
8
- export declare function reportProgress(log$: {
9
- progress: Rx.Observable<ProgressLog>;
10
- stage: Rx.Observable<StageLog>;
11
- }, opts: {
12
- cwd: string;
13
- throttle?: Rx.OperatorFunction<any, any>;
14
- hideAddedPkgsProgress?: boolean;
15
- hideProgressPrefix?: boolean;
16
- }): Rx.Observable<Rx.Observable<StatusMessage>>;
@@ -1,123 +0,0 @@
1
- import * as Rx from 'rxjs';
2
- import { filter, map, mapTo, startWith, take, takeWhile } from 'rxjs/operators';
3
- import { hlValue } from './outputConstants.js';
4
- import { zoomOut } from './utils/zooming.js';
5
- export function reportProgress(log$, opts) {
6
- const progressOutput = throttledProgressOutput.bind(null, opts);
7
- return getModulesInstallProgress$(log$.stage, log$.progress).pipe(map(opts.hideProgressPrefix
8
- ? ({ importingDone$, progress$ }) => progressOutput(importingDone$, progress$)
9
- : ({ importingDone$, progress$, requirer }) => {
10
- const output$ = progressOutput(importingDone$, progress$);
11
- if (requirer === opts.cwd) {
12
- return output$;
13
- }
14
- return output$.pipe(map((msg) => {
15
- msg['msg'] = zoomOut(opts.cwd, requirer, msg['msg']);
16
- return msg;
17
- }));
18
- }));
19
- }
20
- function throttledProgressOutput(opts, importingDone$, progress$) {
21
- if (opts.throttle != null) {
22
- progress$ = progress$.pipe(opts.throttle);
23
- }
24
- const combinedProgress = Rx.combineLatest(progress$, importingDone$)
25
- // Avoid logs after all resolved packages were downloaded.
26
- // Fixing issue: https://github.com/pnpm/pnpm/issues/1028#issuecomment-364782901
27
- .pipe(takeWhile(([, importingDone]) => !importingDone, true));
28
- return combinedProgress.pipe(map(opts.hideAddedPkgsProgress ? createStatusMessageWithoutAdded : createStatusMessage));
29
- }
30
- function getModulesInstallProgress$(stage$, progress$) {
31
- const modulesInstallProgressPushStream = new Rx.Subject();
32
- const progressStatsPushStreamByRequirer = getProgressStatsPushStreamByRequirer(progress$);
33
- const stagePushStreamByRequirer = {};
34
- stage$
35
- .forEach((log) => {
36
- if (!stagePushStreamByRequirer[log.prefix]) {
37
- stagePushStreamByRequirer[log.prefix] = new Rx.Subject();
38
- if (!progressStatsPushStreamByRequirer[log.prefix]) {
39
- progressStatsPushStreamByRequirer[log.prefix] = new Rx.Subject();
40
- }
41
- modulesInstallProgressPushStream.next({
42
- importingDone$: stage$ToImportingDone$(Rx.from(stagePushStreamByRequirer[log.prefix])),
43
- progress$: Rx.from(progressStatsPushStreamByRequirer[log.prefix]),
44
- requirer: log.prefix,
45
- });
46
- }
47
- stagePushStreamByRequirer[log.prefix].next(log);
48
- if (log.stage === 'importing_done') {
49
- progressStatsPushStreamByRequirer[log.prefix].complete();
50
- stagePushStreamByRequirer[log.prefix].complete();
51
- }
52
- })
53
- .catch(() => { });
54
- return Rx.from(modulesInstallProgressPushStream);
55
- }
56
- function stage$ToImportingDone$(stage$) {
57
- return stage$
58
- .pipe(filter((log) => log.stage === 'importing_done'), mapTo(true), take(1), startWith(false));
59
- }
60
- function getProgressStatsPushStreamByRequirer(progress$) {
61
- const progressStatsPushStreamByRequirer = {};
62
- const previousProgressStatsByRequirer = {};
63
- progress$
64
- .forEach((log) => {
65
- if (!previousProgressStatsByRequirer[log.requester]) {
66
- previousProgressStatsByRequirer[log.requester] = {
67
- fetched: 0,
68
- imported: 0,
69
- resolved: 0,
70
- reused: 0,
71
- };
72
- }
73
- switch (log.status) {
74
- case 'resolved':
75
- previousProgressStatsByRequirer[log.requester].resolved++;
76
- break;
77
- case 'fetched':
78
- previousProgressStatsByRequirer[log.requester].fetched++;
79
- break;
80
- case 'found_in_store':
81
- previousProgressStatsByRequirer[log.requester].reused++;
82
- break;
83
- case 'imported':
84
- previousProgressStatsByRequirer[log.requester].imported++;
85
- break;
86
- }
87
- if (!progressStatsPushStreamByRequirer[log.requester]) {
88
- progressStatsPushStreamByRequirer[log.requester] = new Rx.Subject();
89
- }
90
- progressStatsPushStreamByRequirer[log.requester].next(previousProgressStatsByRequirer[log.requester]);
91
- })
92
- .catch(() => { });
93
- return progressStatsPushStreamByRequirer;
94
- }
95
- function createStatusMessage([progress, importingDone]) {
96
- const msg = `Progress: resolved ${hlValue(progress.resolved.toString())}, reused ${hlValue(progress.reused.toString())}, downloaded ${hlValue(progress.fetched.toString())}, added ${hlValue(progress.imported.toString())}`;
97
- if (importingDone) {
98
- return {
99
- done: true,
100
- fixed: false,
101
- msg: `${msg}, done`,
102
- };
103
- }
104
- return {
105
- fixed: true,
106
- msg,
107
- };
108
- }
109
- function createStatusMessageWithoutAdded([progress, importingDone]) {
110
- const msg = `Progress: resolved ${hlValue(progress.resolved.toString())}, reused ${hlValue(progress.reused.toString())}, downloaded ${hlValue(progress.fetched.toString())}`;
111
- if (importingDone) {
112
- return {
113
- done: true,
114
- fixed: false,
115
- msg: `${msg}, done`,
116
- };
117
- }
118
- return {
119
- fixed: true,
120
- msg,
121
- };
122
- }
123
- //# sourceMappingURL=reportProgress.js.map
@@ -1,5 +0,0 @@
1
- import type { RequestRetryLog } from '@pnpm/core-loggers';
2
- import * as Rx from 'rxjs';
3
- export declare function reportRequestRetry(requestRetry$: Rx.Observable<RequestRetryLog>): Rx.Observable<Rx.Observable<{
4
- msg: string;
5
- }>>;
@@ -1,18 +0,0 @@
1
- import prettyMilliseconds from 'pretty-ms';
2
- import * as Rx from 'rxjs';
3
- import { map } from 'rxjs/operators';
4
- import { formatWarn } from './utils/formatWarn.js';
5
- export function reportRequestRetry(requestRetry$) {
6
- return requestRetry$.pipe(map((log) => {
7
- const retriesLeft = log.maxRetries - log.attempt + 1;
8
- // Extract error code from various possible locations
9
- // HTTP status codes are numeric, system error codes are strings
10
- const errorCode = log.error.status ?? log.error.statusCode ?? log.error.code ?? log.error.errno ??
11
- log.error.cause?.code ?? log.error.cause?.errno ?? 'unknown';
12
- const msg = `${log.method} ${log.url} error (${errorCode}). \
13
- Will retry in ${prettyMilliseconds(log.timeout, { verbose: true })}. \
14
- ${retriesLeft} retries left.`;
15
- return Rx.of({ msg: formatWarn(msg) });
16
- }));
17
- }
18
- //# sourceMappingURL=reportRequestRetry.js.map
@@ -1,8 +0,0 @@
1
- import type { ScopeLog } from '@pnpm/core-loggers';
2
- import * as Rx from 'rxjs';
3
- export declare function reportScope(scope$: Rx.Observable<ScopeLog>, opts: {
4
- isRecursive: boolean;
5
- cmd: string;
6
- }): Rx.Observable<Rx.Observable<{
7
- msg: string;
8
- }>>;
@@ -1,41 +0,0 @@
1
- import * as Rx from 'rxjs';
2
- import { map, take } from 'rxjs/operators';
3
- const COMMANDS_THAT_REPORT_SCOPE = new Set([
4
- 'install',
5
- 'link',
6
- 'prune',
7
- 'rebuild',
8
- 'remove',
9
- 'unlink',
10
- 'update',
11
- 'run',
12
- 'test',
13
- ]);
14
- export function reportScope(scope$, opts) {
15
- if (!COMMANDS_THAT_REPORT_SCOPE.has(opts.cmd)) {
16
- return Rx.NEVER;
17
- }
18
- return scope$.pipe(take(1), map((log) => {
19
- if (log.selected === 1) {
20
- return Rx.NEVER;
21
- }
22
- let msg = 'Scope: ';
23
- if (log.selected === log.total) {
24
- msg += `all ${log.total}`;
25
- }
26
- else {
27
- msg += `${log.selected}`;
28
- if (log.total) {
29
- msg += ` of ${log.total}`;
30
- }
31
- }
32
- if (log.workspacePrefix) {
33
- msg += ' workspace projects';
34
- }
35
- else {
36
- msg += ' projects';
37
- }
38
- return Rx.of({ msg });
39
- }));
40
- }
41
- //# sourceMappingURL=reportScope.js.map
@@ -1,7 +0,0 @@
1
- import type { SkippedOptionalDependencyLog } from '@pnpm/core-loggers';
2
- import * as Rx from 'rxjs';
3
- export declare function reportSkippedOptionalDependencies(skippedOptionalDependency$: Rx.Observable<SkippedOptionalDependencyLog>, opts: {
4
- cwd: string;
5
- }): Rx.Observable<Rx.Observable<{
6
- msg: string;
7
- }>>;
@@ -1,8 +0,0 @@
1
- import * as Rx from 'rxjs';
2
- import { filter, map } from 'rxjs/operators';
3
- export function reportSkippedOptionalDependencies(skippedOptionalDependency$, opts) {
4
- return skippedOptionalDependency$.pipe(filter((log) => Boolean(log['prefix'] === opts.cwd && log.parents && log.parents.length === 0)), map((log) => Rx.of({
5
- msg: `info: ${log.package.id || log.package.name && (`${log.package.name}@${log.package.version}`) || log.package.bareSpecifier} is an optional dependency and failed compatibility check. Excluding it from installation.`,
6
- })));
7
- }
8
- //# sourceMappingURL=reportSkippedOptionalDependencies.js.map
@@ -1,13 +0,0 @@
1
- import type { StatsLog } from '@pnpm/core-loggers';
2
- import * as Rx from 'rxjs';
3
- export declare function reportStats(log$: {
4
- stats: Rx.Observable<StatsLog>;
5
- }, opts: {
6
- cmd: string;
7
- cwd: string;
8
- isRecursive: boolean;
9
- width: number;
10
- hideProgressPrefix?: boolean;
11
- }): Array<Rx.Observable<Rx.Observable<{
12
- msg: string;
13
- }>>>;
@@ -1,143 +0,0 @@
1
- import chalk from 'chalk';
2
- import { repeat } from 'ramda';
3
- import * as Rx from 'rxjs';
4
- import { filter, map, reduce, take } from 'rxjs/operators';
5
- import stringLength from 'string-length';
6
- import { EOL } from '../constants.js';
7
- import { ADDED_CHAR, REMOVED_CHAR, } from './outputConstants.js';
8
- import { zoomOut } from './utils/zooming.js';
9
- export function reportStats(log$, opts) {
10
- if (opts.hideProgressPrefix) {
11
- return [statsForCurrentPackage(log$.stats, {
12
- cmd: opts.cmd,
13
- width: opts.width,
14
- })];
15
- }
16
- const stats$ = opts.isRecursive
17
- ? log$.stats
18
- : log$.stats.pipe(filter((log) => log.prefix !== opts.cwd));
19
- const outputs = [
20
- statsForNotCurrentPackage(stats$, {
21
- cmd: opts.cmd,
22
- currentPrefix: opts.cwd,
23
- width: opts.width,
24
- }),
25
- ];
26
- if (!opts.isRecursive) {
27
- outputs.push(statsForCurrentPackage(log$.stats.pipe(filter((log) => log.prefix === opts.cwd)), {
28
- cmd: opts.cmd,
29
- width: opts.width,
30
- }));
31
- }
32
- return outputs;
33
- }
34
- function statsForCurrentPackage(stats$, opts) {
35
- return stats$.pipe(take((opts.cmd === 'install' || opts.cmd === 'install-test' || opts.cmd === 'add' || opts.cmd === 'update' || opts.cmd === 'dlx') ? 2 : 1), reduce((acc, log) => {
36
- if (typeof log['added'] === 'number') {
37
- acc['added'] = log['added'];
38
- }
39
- else if (typeof log['removed'] === 'number') {
40
- acc['removed'] = log['removed'];
41
- }
42
- return acc;
43
- }, {}), map((stats) => {
44
- if (!stats['removed'] && !stats['added']) {
45
- if (opts.cmd === 'link') {
46
- return Rx.NEVER;
47
- }
48
- return Rx.of({ msg: 'Already up to date' });
49
- }
50
- let msg = 'Packages:';
51
- if (stats['added']) {
52
- msg += ' ' + chalk.green(`+${stats['added'].toString()}`);
53
- }
54
- if (stats['removed']) {
55
- msg += ' ' + chalk.red(`-${stats['removed'].toString()}`);
56
- }
57
- msg += EOL + printPlusesAndMinuses(opts.width, (stats['added'] ?? 0), (stats['removed'] ?? 0));
58
- return Rx.of({ msg });
59
- }));
60
- }
61
- function statsForNotCurrentPackage(stats$, opts) {
62
- const stats = {};
63
- const cookedStats$ = (opts.cmd !== 'remove'
64
- ? stats$.pipe(map((log) => {
65
- // As of pnpm v2.9.0, during `pnpm recursive link`, logging of removed stats happens twice
66
- // 1. during linking
67
- // 2. during installing
68
- // Hence, the stats are added before reported
69
- const { prefix } = log;
70
- if (!stats[prefix]) {
71
- stats[prefix] = log;
72
- return { seed: stats, value: null };
73
- }
74
- else if (typeof stats[prefix].added === 'number' && typeof log['added'] === 'number') {
75
- stats[prefix].added += log['added'];
76
- return { seed: stats, value: null };
77
- }
78
- else if (typeof stats[prefix].removed === 'number' && typeof log['removed'] === 'number') {
79
- stats[prefix].removed += log['removed'];
80
- return { seed: stats, value: null };
81
- }
82
- else {
83
- const value = { ...stats[prefix], ...log };
84
- delete stats[prefix];
85
- return value;
86
- }
87
- }, {}))
88
- : stats$);
89
- return cookedStats$.pipe(filter((stats) => stats !== null && Boolean(stats['removed'] || stats['added'])), map((stats) => {
90
- const parts = [];
91
- if (stats['added']) {
92
- parts.push(padStep(chalk.green(`+${stats['added'].toString()}`), 4));
93
- }
94
- if (stats['removed']) {
95
- parts.push(padStep(chalk.red(`-${stats['removed'].toString()}`), 4));
96
- }
97
- let msg = zoomOut(opts.currentPrefix, stats.prefix, parts.join(' '));
98
- const rest = Math.max(0, opts.width - 1 - stringLength(msg));
99
- msg += ' ' + printPlusesAndMinuses(rest, roundStats(stats['added'] || 0), roundStats(stats['removed'] || 0));
100
- return Rx.of({ msg });
101
- }));
102
- }
103
- function padStep(s, step) {
104
- const sLength = stringLength(s);
105
- const placeholderLength = Math.ceil(sLength / step) * step;
106
- if (sLength < placeholderLength) {
107
- return repeat(' ', placeholderLength - sLength).join('') + s;
108
- }
109
- return s;
110
- }
111
- function roundStats(stat) {
112
- if (stat === 0)
113
- return 0;
114
- return Math.max(1, Math.round(stat / 10));
115
- }
116
- function printPlusesAndMinuses(maxWidth, added, removed) {
117
- if (maxWidth === 0)
118
- return '';
119
- const changes = added + removed;
120
- let addedChars;
121
- let removedChars;
122
- if (changes > maxWidth) {
123
- if (!added) {
124
- addedChars = 0;
125
- removedChars = maxWidth;
126
- }
127
- else if (!removed) {
128
- addedChars = maxWidth;
129
- removedChars = 0;
130
- }
131
- else {
132
- const p = maxWidth / changes;
133
- addedChars = Math.min(Math.max(Math.floor(added * p), 1), maxWidth - 1);
134
- removedChars = maxWidth - addedChars;
135
- }
136
- }
137
- else {
138
- addedChars = added;
139
- removedChars = removed;
140
- }
141
- return `${repeat(ADDED_CHAR, addedChars).join('')}${repeat(REMOVED_CHAR, removedChars).join('')}`;
142
- }
143
- //# sourceMappingURL=reportStats.js.map
@@ -1,19 +0,0 @@
1
- import type { Config } from '@pnpm/config.reader';
2
- import type { DeprecationLog, PackageManifestLog, RootLog, SummaryLog } from '@pnpm/core-loggers';
3
- import * as Rx from 'rxjs';
4
- import { type PackageDiff } from './pkgsDiff.js';
5
- export declare function reportSummary(log$: {
6
- deprecation: Rx.Observable<DeprecationLog>;
7
- summary: Rx.Observable<SummaryLog>;
8
- root: Rx.Observable<RootLog>;
9
- packageManifest: Rx.Observable<PackageManifestLog>;
10
- }, opts: {
11
- cmd: string;
12
- cwd: string;
13
- env: NodeJS.ProcessEnv;
14
- filterPkgsDiff?: FilterPkgsDiff;
15
- pnpmConfig?: Config;
16
- }): Rx.Observable<Rx.Observable<{
17
- msg: string;
18
- }>>;
19
- export type FilterPkgsDiff = (pkgsDiff: PackageDiff) => boolean;