@pnpm/cli.default-reporter 1002.0.11

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 (59) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +41 -0
  3. package/lib/constants.d.ts +1 -0
  4. package/lib/constants.js +4 -0
  5. package/lib/index.d.ts +54 -0
  6. package/lib/index.js +230 -0
  7. package/lib/mergeOutputs.d.ts +4 -0
  8. package/lib/mergeOutputs.js +69 -0
  9. package/lib/reportError.d.ts +3 -0
  10. package/lib/reportError.js +425 -0
  11. package/lib/reporterForClient/index.d.ts +52 -0
  12. package/lib/reporterForClient/index.js +94 -0
  13. package/lib/reporterForClient/outputConstants.d.ts +4 -0
  14. package/lib/reporterForClient/outputConstants.js +6 -0
  15. package/lib/reporterForClient/pkgsDiff.d.ts +36 -0
  16. package/lib/reporterForClient/pkgsDiff.js +113 -0
  17. package/lib/reporterForClient/reportBigTarballsProgress.d.ts +8 -0
  18. package/lib/reporterForClient/reportBigTarballsProgress.js +26 -0
  19. package/lib/reporterForClient/reportContext.d.ts +10 -0
  20. package/lib/reporterForClient/reportContext.js +34 -0
  21. package/lib/reporterForClient/reportDeprecations.d.ts +11 -0
  22. package/lib/reporterForClient/reportDeprecations.js +27 -0
  23. package/lib/reporterForClient/reportExecutionTime.d.ts +6 -0
  24. package/lib/reporterForClient/reportExecutionTime.js +13 -0
  25. package/lib/reporterForClient/reportHooks.d.ts +8 -0
  26. package/lib/reporterForClient/reportHooks.js +12 -0
  27. package/lib/reporterForClient/reportIgnoredBuilds.d.ts +11 -0
  28. package/lib/reporterForClient/reportIgnoredBuilds.js +21 -0
  29. package/lib/reporterForClient/reportInstallChecks.d.ts +7 -0
  30. package/lib/reporterForClient/reportInstallChecks.js +19 -0
  31. package/lib/reporterForClient/reportInstallingConfigDeps.d.ts +5 -0
  32. package/lib/reporterForClient/reportInstallingConfigDeps.js +18 -0
  33. package/lib/reporterForClient/reportLifecycleScripts.d.ts +13 -0
  34. package/lib/reporterForClient/reportLifecycleScripts.js +193 -0
  35. package/lib/reporterForClient/reportMisc.d.ts +17 -0
  36. package/lib/reporterForClient/reportMisc.js +69 -0
  37. package/lib/reporterForClient/reportPeerDependencyIssues.d.ts +7 -0
  38. package/lib/reporterForClient/reportPeerDependencyIssues.js +16 -0
  39. package/lib/reporterForClient/reportProgress.d.ts +16 -0
  40. package/lib/reporterForClient/reportProgress.js +123 -0
  41. package/lib/reporterForClient/reportRequestRetry.d.ts +5 -0
  42. package/lib/reporterForClient/reportRequestRetry.js +15 -0
  43. package/lib/reporterForClient/reportScope.d.ts +8 -0
  44. package/lib/reporterForClient/reportScope.js +41 -0
  45. package/lib/reporterForClient/reportSkippedOptionalDependencies.d.ts +7 -0
  46. package/lib/reporterForClient/reportSkippedOptionalDependencies.js +8 -0
  47. package/lib/reporterForClient/reportStats.d.ts +13 -0
  48. package/lib/reporterForClient/reportStats.js +143 -0
  49. package/lib/reporterForClient/reportSummary.d.ts +19 -0
  50. package/lib/reporterForClient/reportSummary.js +79 -0
  51. package/lib/reporterForClient/reportUpdateCheck.d.ts +8 -0
  52. package/lib/reporterForClient/reportUpdateCheck.js +42 -0
  53. package/lib/reporterForClient/utils/formatPrefix.d.ts +2 -0
  54. package/lib/reporterForClient/utils/formatPrefix.js +19 -0
  55. package/lib/reporterForClient/utils/formatWarn.d.ts +1 -0
  56. package/lib/reporterForClient/utils/formatWarn.js +8 -0
  57. package/lib/reporterForClient/utils/zooming.d.ts +4 -0
  58. package/lib/reporterForClient/utils/zooming.js +13 -0
  59. package/package.json +76 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015-2016 Rico Sta. Cruz and other contributors
4
+ Copyright (c) 2016-2026 Zoltan Kochan and other contributors
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # @pnpm/default-reporter
2
+
3
+ > The default reporter of pnpm
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ pnpm add @pnpm/default-reporter
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { streamParser } from '@pnpm/logger'
15
+ import { initDefaultReporter } from '@pnpm/default-reporter'
16
+
17
+ const stopReporting = initDefaultReporter({
18
+ context: {
19
+ argv: [],
20
+ },
21
+ streamParser,
22
+ })
23
+
24
+ try {
25
+ // calling some pnpm APIs
26
+ } finally {
27
+ stopReporting()
28
+ }
29
+ ```
30
+
31
+ ## Style Guide
32
+
33
+ 1. Never use blue or grey as font color as they are hard to read in many consoles.
34
+ 1. Use dim instead of grey
35
+ 1. Use cyan bright instead of blue
36
+ 1. Don't hide the CLI cursor. (It is easier to never hide but it is really needed only when scripts are running.)
37
+ 1. Don't use green and yellow to distinct something.
38
+
39
+ ## License
40
+
41
+ [MIT](LICENSE)
@@ -0,0 +1 @@
1
+ export declare const EOL = "\n";
@@ -0,0 +1,4 @@
1
+ // In terminals, always Unix line endings are used
2
+ // even on Windows
3
+ export const EOL = '\n';
4
+ //# sourceMappingURL=constants.js.map
package/lib/index.d.ts ADDED
@@ -0,0 +1,54 @@
1
+ import type { Config } from '@pnpm/config.reader';
2
+ import type * as logs from '@pnpm/core-loggers';
3
+ import type { LogLevel, StreamParser } from '@pnpm/logger';
4
+ import * as Rx from 'rxjs';
5
+ import type { FilterPkgsDiff } from './reporterForClient/reportSummary.js';
6
+ import { formatWarn } from './reporterForClient/utils/formatWarn.js';
7
+ export { formatWarn };
8
+ export declare function initDefaultReporter(opts: {
9
+ useStderr?: boolean;
10
+ streamParser: StreamParser<logs.Log>;
11
+ reportingOptions?: {
12
+ appendOnly?: boolean;
13
+ logLevel?: LogLevel;
14
+ streamLifecycleOutput?: boolean;
15
+ aggregateOutput?: boolean;
16
+ throttleProgress?: number;
17
+ outputMaxWidth?: number;
18
+ hideAddedPkgsProgress?: boolean;
19
+ hideProgressPrefix?: boolean;
20
+ hideLifecycleOutput?: boolean;
21
+ hideLifecyclePrefix?: boolean;
22
+ approveBuildsInstructionText?: string;
23
+ };
24
+ context: {
25
+ argv: string[];
26
+ config?: Config;
27
+ env?: NodeJS.ProcessEnv;
28
+ process?: NodeJS.Process;
29
+ };
30
+ filterPkgsDiff?: FilterPkgsDiff;
31
+ }): () => void;
32
+ export declare function toOutput$(opts: {
33
+ streamParser: StreamParser<logs.Log>;
34
+ reportingOptions?: {
35
+ appendOnly?: boolean;
36
+ logLevel?: LogLevel;
37
+ outputMaxWidth?: number;
38
+ streamLifecycleOutput?: boolean;
39
+ aggregateOutput?: boolean;
40
+ throttleProgress?: number;
41
+ hideAddedPkgsProgress?: boolean;
42
+ hideProgressPrefix?: boolean;
43
+ hideLifecycleOutput?: boolean;
44
+ hideLifecyclePrefix?: boolean;
45
+ approveBuildsInstructionText?: string;
46
+ };
47
+ context: {
48
+ argv: string[];
49
+ config?: Config;
50
+ env?: NodeJS.ProcessEnv;
51
+ process?: NodeJS.Process;
52
+ };
53
+ filterPkgsDiff?: FilterPkgsDiff;
54
+ }): Rx.Observable<string>;
package/lib/index.js ADDED
@@ -0,0 +1,230 @@
1
+ import createDiffer from 'ansi-diff';
2
+ import * as Rx from 'rxjs';
3
+ import { filter, map, mergeAll } from 'rxjs/operators';
4
+ import { EOL } from './constants.js';
5
+ import { mergeOutputs } from './mergeOutputs.js';
6
+ import { reporterForClient } from './reporterForClient/index.js';
7
+ import { formatWarn } from './reporterForClient/utils/formatWarn.js';
8
+ export { formatWarn };
9
+ export function initDefaultReporter(opts) {
10
+ const proc = opts.context.process ?? process;
11
+ const outputMaxWidth = opts.reportingOptions?.outputMaxWidth ?? (proc.stdout.columns && proc.stdout.columns - 2) ?? 80;
12
+ const output$ = toOutput$({
13
+ ...opts,
14
+ reportingOptions: {
15
+ ...opts.reportingOptions,
16
+ outputMaxWidth,
17
+ },
18
+ });
19
+ if (opts.reportingOptions?.appendOnly) {
20
+ const writeNext = opts.useStderr
21
+ ? console.error.bind(console)
22
+ : console.log.bind(console);
23
+ const subscription = output$
24
+ .subscribe({
25
+ complete() { }, // eslint-disable-line:no-empty
26
+ error: (err) => {
27
+ console.error(err.message);
28
+ },
29
+ next: writeNext,
30
+ });
31
+ return () => {
32
+ subscription.unsubscribe();
33
+ };
34
+ }
35
+ const diff = createDiffer({
36
+ height: proc.stdout.rows,
37
+ outputMaxWidth,
38
+ });
39
+ const subscription = output$
40
+ .subscribe({
41
+ complete() { }, // eslint-disable-line:no-empty
42
+ error: (err) => {
43
+ logUpdate(err.message);
44
+ },
45
+ next: logUpdate,
46
+ });
47
+ const write = opts.useStderr
48
+ ? proc.stderr.write.bind(proc.stderr)
49
+ : proc.stdout.write.bind(proc.stdout);
50
+ function logUpdate(view) {
51
+ // A new line should always be appended in case a prompt needs to appear.
52
+ // Without a new line the prompt will be joined with the previous output.
53
+ // An example of such prompt may be seen by running: pnpm update --interactive
54
+ if (!view.endsWith(EOL))
55
+ view += EOL;
56
+ write(diff.update(view));
57
+ }
58
+ return () => {
59
+ subscription.unsubscribe();
60
+ };
61
+ }
62
+ export function toOutput$(opts) {
63
+ opts = opts || {};
64
+ const contextPushStream = new Rx.Subject();
65
+ const fetchingProgressPushStream = new Rx.Subject();
66
+ const executionTimePushStream = new Rx.Subject();
67
+ const progressPushStream = new Rx.Subject();
68
+ const stagePushStream = new Rx.Subject();
69
+ const deprecationPushStream = new Rx.Subject();
70
+ const summaryPushStream = new Rx.Subject();
71
+ const lifecyclePushStream = new Rx.Subject();
72
+ const statsPushStream = new Rx.Subject();
73
+ const packageImportMethodPushStream = new Rx.Subject();
74
+ const installCheckPushStream = new Rx.Subject();
75
+ const installingConfigDepsStream = new Rx.Subject();
76
+ const ignoredScriptsPushStream = new Rx.Subject();
77
+ const registryPushStream = new Rx.Subject();
78
+ const rootPushStream = new Rx.Subject();
79
+ const packageManifestPushStream = new Rx.Subject();
80
+ const peerDependencyIssuesPushStream = new Rx.Subject();
81
+ const linkPushStream = new Rx.Subject();
82
+ const otherPushStream = new Rx.Subject();
83
+ const hookPushStream = new Rx.Subject();
84
+ const skippedOptionalDependencyPushStream = new Rx.Subject();
85
+ const scopePushStream = new Rx.Subject();
86
+ const requestRetryPushStream = new Rx.Subject();
87
+ const updateCheckPushStream = new Rx.Subject();
88
+ setTimeout(() => {
89
+ opts.streamParser.on('data', (log) => {
90
+ switch (log.name) {
91
+ case 'pnpm:context':
92
+ contextPushStream.next(log);
93
+ break;
94
+ case 'pnpm:execution-time':
95
+ executionTimePushStream.next(log);
96
+ break;
97
+ case 'pnpm:fetching-progress':
98
+ fetchingProgressPushStream.next(log);
99
+ break;
100
+ case 'pnpm:progress':
101
+ progressPushStream.next(log);
102
+ break;
103
+ case 'pnpm:stage':
104
+ stagePushStream.next(log);
105
+ break;
106
+ case 'pnpm:deprecation':
107
+ deprecationPushStream.next(log);
108
+ break;
109
+ case 'pnpm:summary':
110
+ summaryPushStream.next(log);
111
+ break;
112
+ case 'pnpm:lifecycle':
113
+ lifecyclePushStream.next(log);
114
+ break;
115
+ case 'pnpm:stats':
116
+ statsPushStream.next(log);
117
+ break;
118
+ case 'pnpm:package-import-method':
119
+ packageImportMethodPushStream.next(log);
120
+ break;
121
+ case 'pnpm:peer-dependency-issues':
122
+ peerDependencyIssuesPushStream.next(log);
123
+ break;
124
+ case 'pnpm:install-check':
125
+ installCheckPushStream.next(log);
126
+ break;
127
+ case 'pnpm:installing-config-deps':
128
+ installingConfigDepsStream.next(log);
129
+ break;
130
+ case 'pnpm:ignored-scripts':
131
+ ignoredScriptsPushStream.next(log);
132
+ break;
133
+ case 'pnpm:registry':
134
+ registryPushStream.next(log);
135
+ break;
136
+ case 'pnpm:root':
137
+ rootPushStream.next(log);
138
+ break;
139
+ case 'pnpm:package-manifest':
140
+ packageManifestPushStream.next(log);
141
+ break;
142
+ case 'pnpm:link':
143
+ linkPushStream.next(log);
144
+ break;
145
+ case 'pnpm:hook':
146
+ hookPushStream.next(log);
147
+ break;
148
+ case 'pnpm:skipped-optional-dependency':
149
+ skippedOptionalDependencyPushStream.next(log);
150
+ break;
151
+ case 'pnpm:scope':
152
+ scopePushStream.next(log);
153
+ break;
154
+ case 'pnpm:request-retry':
155
+ requestRetryPushStream.next(log);
156
+ break;
157
+ case 'pnpm:update-check':
158
+ updateCheckPushStream.next(log);
159
+ break;
160
+ case 'pnpm': // eslint-disable-line
161
+ case 'pnpm:global': // eslint-disable-line
162
+ case 'pnpm:store': // eslint-disable-line
163
+ case 'pnpm:lockfile': // eslint-disable-line
164
+ otherPushStream.next(log);
165
+ break;
166
+ }
167
+ });
168
+ }, 0);
169
+ let other = Rx.from(otherPushStream);
170
+ if (opts.context.config?.hooks?.filterLog != null) {
171
+ const filterLogs = opts.context.config.hooks.filterLog;
172
+ const filterFn = filterLogs.length === 1
173
+ ? filterLogs[0]
174
+ : (log) => filterLogs.every((filterLog) => filterLog(log));
175
+ other = other.pipe(filter(filterFn));
176
+ }
177
+ const log$ = {
178
+ context: Rx.from(contextPushStream),
179
+ deprecation: Rx.from(deprecationPushStream),
180
+ fetchingProgress: Rx.from(fetchingProgressPushStream),
181
+ executionTime: Rx.from(executionTimePushStream),
182
+ hook: Rx.from(hookPushStream),
183
+ installCheck: Rx.from(installCheckPushStream),
184
+ installingConfigDeps: Rx.from(installingConfigDepsStream),
185
+ ignoredScripts: Rx.from(ignoredScriptsPushStream),
186
+ lifecycle: Rx.from(lifecyclePushStream),
187
+ link: Rx.from(linkPushStream),
188
+ other,
189
+ packageImportMethod: Rx.from(packageImportMethodPushStream),
190
+ packageManifest: Rx.from(packageManifestPushStream),
191
+ peerDependencyIssues: Rx.from(peerDependencyIssuesPushStream),
192
+ progress: Rx.from(progressPushStream),
193
+ registry: Rx.from(registryPushStream),
194
+ requestRetry: Rx.from(requestRetryPushStream),
195
+ root: Rx.from(rootPushStream),
196
+ scope: Rx.from(scopePushStream),
197
+ skippedOptionalDependency: Rx.from(skippedOptionalDependencyPushStream),
198
+ stage: Rx.from(stagePushStream),
199
+ stats: Rx.from(statsPushStream),
200
+ summary: Rx.from(summaryPushStream),
201
+ updateCheck: Rx.from(updateCheckPushStream),
202
+ };
203
+ const cmd = opts.context.argv[0];
204
+ const outputs = reporterForClient(log$, {
205
+ appendOnly: opts.reportingOptions?.appendOnly,
206
+ cmd,
207
+ config: opts.context.config,
208
+ env: opts.context.env ?? process.env,
209
+ filterPkgsDiff: opts.filterPkgsDiff,
210
+ process: opts.context.process ?? process,
211
+ isRecursive: opts.context.config?.['recursive'] === true,
212
+ logLevel: opts.reportingOptions?.logLevel,
213
+ pnpmConfig: opts.context.config,
214
+ streamLifecycleOutput: opts.reportingOptions?.streamLifecycleOutput,
215
+ aggregateOutput: opts.reportingOptions?.aggregateOutput,
216
+ throttleProgress: opts.reportingOptions?.throttleProgress,
217
+ width: opts.reportingOptions?.outputMaxWidth,
218
+ hideAddedPkgsProgress: opts.reportingOptions?.hideAddedPkgsProgress,
219
+ hideProgressPrefix: opts.reportingOptions?.hideProgressPrefix ?? (cmd === 'dlx' || opts.context.config?.global === true),
220
+ hideLifecycleOutput: opts.reportingOptions?.hideLifecycleOutput,
221
+ hideLifecyclePrefix: opts.reportingOptions?.hideLifecyclePrefix,
222
+ approveBuildsInstructionText: opts.reportingOptions?.approveBuildsInstructionText,
223
+ });
224
+ if (opts.reportingOptions?.appendOnly) {
225
+ return Rx.merge(...outputs)
226
+ .pipe(map((log) => log.pipe(map((msg) => msg.msg))), mergeAll());
227
+ }
228
+ return mergeOutputs(outputs);
229
+ }
230
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,4 @@
1
+ import * as Rx from 'rxjs';
2
+ export declare function mergeOutputs(outputs: Array<Rx.Observable<Rx.Observable<{
3
+ msg: string;
4
+ }>>>): Rx.Observable<string>;
@@ -0,0 +1,69 @@
1
+ import * as Rx from 'rxjs';
2
+ import { filter, map, mergeAll, scan } from 'rxjs/operators';
3
+ import { EOL } from './constants.js';
4
+ export function mergeOutputs(outputs) {
5
+ let blockNo = 0;
6
+ let fixedBlockNo = 0;
7
+ let started = false;
8
+ let previousOutput = null;
9
+ return Rx.merge(...outputs).pipe(map((log) => {
10
+ let currentBlockNo = -1;
11
+ let currentFixedBlockNo = -1;
12
+ return log.pipe(map((msg) => {
13
+ if (msg.fixed) {
14
+ if (currentFixedBlockNo === -1) {
15
+ currentFixedBlockNo = fixedBlockNo++;
16
+ }
17
+ return {
18
+ blockNo: currentFixedBlockNo,
19
+ fixed: true,
20
+ msg: msg.msg,
21
+ };
22
+ }
23
+ if (currentBlockNo === -1) {
24
+ currentBlockNo = blockNo++;
25
+ }
26
+ return {
27
+ blockNo: currentBlockNo,
28
+ fixed: false,
29
+ msg: typeof msg === 'string' ? msg : msg.msg, // eslint-disable-line
30
+ prevFixedBlockNo: currentFixedBlockNo,
31
+ };
32
+ }));
33
+ }), mergeAll(), scan((acc, log) => {
34
+ if (log.fixed) {
35
+ acc.fixedBlocks[log.blockNo] = log.msg;
36
+ }
37
+ else {
38
+ delete acc.fixedBlocks[log.prevFixedBlockNo];
39
+ acc.blocks[log.blockNo] = log.msg;
40
+ }
41
+ return acc;
42
+ }, { fixedBlocks: [], blocks: [] }), map((sections) => {
43
+ const fixedBlocks = sections.fixedBlocks.filter(Boolean);
44
+ const nonFixedPart = sections.blocks.filter(Boolean).join(EOL);
45
+ if (fixedBlocks.length === 0) {
46
+ return nonFixedPart;
47
+ }
48
+ const fixedPart = fixedBlocks.join(EOL);
49
+ if (!nonFixedPart) {
50
+ return fixedPart;
51
+ }
52
+ return `${nonFixedPart}${EOL}${fixedPart}`;
53
+ }), filter((msg) => {
54
+ if (started) {
55
+ return true;
56
+ }
57
+ if (msg === '')
58
+ return false;
59
+ started = true;
60
+ return true;
61
+ }), filter((msg) => {
62
+ if (msg !== previousOutput) {
63
+ previousOutput = msg;
64
+ return true;
65
+ }
66
+ return false;
67
+ }));
68
+ }
69
+ //# sourceMappingURL=mergeOutputs.js.map
@@ -0,0 +1,3 @@
1
+ import type { Config } from '@pnpm/config.reader';
2
+ import type { Log } from '@pnpm/core-loggers';
3
+ export declare function reportError(logObj: Log, config?: Config): string | null;