@atlaspack/reporter-cli 2.15.1-canary.19 → 2.15.1-canary.190
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/CHANGELOG.md +216 -0
- package/lib/CLIReporter.js +273 -7746
- package/lib/bundleReport.js +112 -0
- package/lib/emoji.js +29 -0
- package/lib/logLevels.js +16 -0
- package/lib/phaseReport.js +46 -0
- package/lib/render.js +157 -0
- package/lib/types/CLIReporter.d.ts +5 -0
- package/lib/types/bundleReport.d.ts +3 -0
- package/lib/types/emoji.d.ts +7 -0
- package/lib/types/logLevels.d.ts +10 -0
- package/lib/types/phaseReport.d.ts +3 -0
- package/lib/types/render.d.ts +14 -0
- package/lib/types/utils.d.ts +5 -0
- package/lib/utils.js +71 -0
- package/package.json +17 -12
- package/src/{CLIReporter.js → CLIReporter.ts} +52 -15
- package/src/{bundleReport.js → bundleReport.ts} +4 -3
- package/src/{emoji.js → emoji.ts} +0 -2
- package/src/{logLevels.js → logLevels.ts} +1 -3
- package/src/{phaseReport.js → phaseReport.ts} +2 -3
- package/src/{render.js → render.ts} +7 -7
- package/src/{utils.js → utils.ts} +0 -1
- package/test/{CLIReporter.test.js → CLIReporter.test.ts} +15 -14
- package/tsconfig.json +4 -0
- package/lib/CLIReporter.js.map +0 -1
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import type {ReporterEvent, PluginOptions} from '@atlaspack/types';
|
|
3
2
|
import type {Diagnostic} from '@atlaspack/diagnostic';
|
|
4
3
|
import type {Color} from 'chalk';
|
|
5
4
|
|
|
5
|
+
import {getFeatureFlag} from '@atlaspack/feature-flags';
|
|
6
6
|
import {Reporter} from '@atlaspack/plugin';
|
|
7
7
|
import {
|
|
8
8
|
getProgressMessage,
|
|
9
|
+
getPackageProgressMessage,
|
|
9
10
|
prettifyTime,
|
|
10
11
|
prettyDiagnostic,
|
|
11
12
|
throttle,
|
|
13
|
+
debugTools,
|
|
12
14
|
} from '@atlaspack/utils';
|
|
13
15
|
import chalk from 'chalk';
|
|
14
16
|
|
|
@@ -25,6 +27,7 @@ import {
|
|
|
25
27
|
persistMessage,
|
|
26
28
|
} from './render';
|
|
27
29
|
import * as emoji from './emoji';
|
|
30
|
+
// @ts-expect-error TS7016
|
|
28
31
|
import wrapAnsi from 'wrap-ansi';
|
|
29
32
|
|
|
30
33
|
const THROTTLE_DELAY = 100;
|
|
@@ -32,16 +35,37 @@ const seenWarnings = new Set();
|
|
|
32
35
|
const seenPhases = new Set();
|
|
33
36
|
const seenPhasesGen = new Set();
|
|
34
37
|
|
|
35
|
-
let phaseStartTimes = {};
|
|
38
|
+
let phaseStartTimes: Record<string, any> = {};
|
|
36
39
|
let pendingIncrementalBuild = false;
|
|
40
|
+
let packagingProgress = 0;
|
|
41
|
+
|
|
42
|
+
let updatePackageProgress = (completeBundles: number, totalBundles: number) => {
|
|
43
|
+
let updateThreshold = 0;
|
|
44
|
+
if (totalBundles > 5000) {
|
|
45
|
+
// If more than 5000 bundles, update every 5%
|
|
46
|
+
updateThreshold = 5;
|
|
47
|
+
} else if (totalBundles > 1000) {
|
|
48
|
+
// If more than 1000 bundles, update every 10%
|
|
49
|
+
updateThreshold = 10;
|
|
50
|
+
} else {
|
|
51
|
+
// othewise update every 25%
|
|
52
|
+
updateThreshold = 25;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
let percent = Math.floor((completeBundles / totalBundles) * 100);
|
|
56
|
+
if (percent - packagingProgress >= updateThreshold) {
|
|
57
|
+
packagingProgress = percent;
|
|
58
|
+
updateSpinner(getPackageProgressMessage(completeBundles, totalBundles));
|
|
59
|
+
}
|
|
60
|
+
};
|
|
37
61
|
|
|
38
62
|
let statusThrottle = throttle((message: string) => {
|
|
39
63
|
updateSpinner(message);
|
|
40
64
|
}, THROTTLE_DELAY);
|
|
41
65
|
|
|
42
|
-
const cacheWriteState: {
|
|
43
|
-
startTime: number | null
|
|
44
|
-
|
|
66
|
+
const cacheWriteState: {
|
|
67
|
+
startTime: number | null;
|
|
68
|
+
} = {
|
|
45
69
|
startTime: null,
|
|
46
70
|
};
|
|
47
71
|
|
|
@@ -99,7 +123,10 @@ export async function _report(
|
|
|
99
123
|
updateSpinner('Building...');
|
|
100
124
|
} else if (event.phase == 'bundling' && !seenPhases.has('bundling')) {
|
|
101
125
|
updateSpinner('Bundling...');
|
|
126
|
+
} else if (event.phase === 'packagingAndOptimizing') {
|
|
127
|
+
updatePackageProgress(event.completeBundles, event.totalBundles);
|
|
102
128
|
} else if (
|
|
129
|
+
!getFeatureFlag('cliProgressReportingImprovements') &&
|
|
103
130
|
(event.phase == 'packaging' || event.phase == 'optimizing') &&
|
|
104
131
|
!seenPhases.has('packaging') &&
|
|
105
132
|
!seenPhases.has('optimizing')
|
|
@@ -134,12 +161,18 @@ export async function _report(
|
|
|
134
161
|
);
|
|
135
162
|
|
|
136
163
|
if (options.mode === 'production') {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
164
|
+
if (debugTools['simple-cli-reporter']) {
|
|
165
|
+
writeOut(
|
|
166
|
+
`🛠️ Built ${event.bundleGraph.getBundles().length} bundles.`,
|
|
167
|
+
);
|
|
168
|
+
} else {
|
|
169
|
+
await bundleReport(
|
|
170
|
+
event.bundleGraph,
|
|
171
|
+
options.outputFS,
|
|
172
|
+
options.projectRoot,
|
|
173
|
+
options.detailedReport?.assetsPerBundle,
|
|
174
|
+
);
|
|
175
|
+
}
|
|
143
176
|
} else {
|
|
144
177
|
pendingIncrementalBuild = true;
|
|
145
178
|
}
|
|
@@ -214,6 +247,7 @@ export async function _report(
|
|
|
214
247
|
await writeDiagnostic(options, event.diagnostics, 'red', true);
|
|
215
248
|
break;
|
|
216
249
|
default:
|
|
250
|
+
// @ts-expect-error TS2339
|
|
217
251
|
throw new Error('Unknown log level ' + event.level);
|
|
218
252
|
}
|
|
219
253
|
}
|
|
@@ -223,6 +257,7 @@ export async function _report(
|
|
|
223
257
|
async function writeDiagnostic(
|
|
224
258
|
options: PluginOptions,
|
|
225
259
|
diagnostics: Array<Diagnostic>,
|
|
260
|
+
// @ts-expect-error TS2749
|
|
226
261
|
color: Color,
|
|
227
262
|
isError: boolean = false,
|
|
228
263
|
) {
|
|
@@ -232,7 +267,7 @@ async function writeDiagnostic(
|
|
|
232
267
|
for (let diagnostic of diagnostics) {
|
|
233
268
|
let {message, stack, codeframe, hints, documentation} =
|
|
234
269
|
await prettyDiagnostic(diagnostic, options, columns - indent);
|
|
235
|
-
//
|
|
270
|
+
// @ts-expect-error TS7053
|
|
236
271
|
message = chalk[color](message);
|
|
237
272
|
|
|
238
273
|
if (spaceAfter) {
|
|
@@ -281,6 +316,7 @@ async function writeDiagnostic(
|
|
|
281
316
|
);
|
|
282
317
|
}
|
|
283
318
|
|
|
319
|
+
// @ts-expect-error TS2322
|
|
284
320
|
spaceAfter = stack || codeframe || hints.length > 0 || documentation;
|
|
285
321
|
}
|
|
286
322
|
|
|
@@ -289,7 +325,7 @@ async function writeDiagnostic(
|
|
|
289
325
|
}
|
|
290
326
|
}
|
|
291
327
|
|
|
292
|
-
function wrapWithIndent(string, indent = 0, initialIndent = indent) {
|
|
328
|
+
function wrapWithIndent(string: string, indent = 0, initialIndent = indent) {
|
|
293
329
|
let width = getTerminalWidth().columns;
|
|
294
330
|
return indentString(
|
|
295
331
|
wrapAnsi(string.trimEnd(), width - indent, {trim: false}),
|
|
@@ -298,14 +334,15 @@ function wrapWithIndent(string, indent = 0, initialIndent = indent) {
|
|
|
298
334
|
);
|
|
299
335
|
}
|
|
300
336
|
|
|
337
|
+
// @ts-expect-error TS7006
|
|
301
338
|
function indentString(string, indent = 0, initialIndent = indent) {
|
|
302
339
|
return (
|
|
303
340
|
' '.repeat(initialIndent) + string.replace(/\n/g, '\n' + ' '.repeat(indent))
|
|
304
341
|
);
|
|
305
342
|
}
|
|
306
343
|
|
|
307
|
-
export default
|
|
344
|
+
export default new Reporter({
|
|
308
345
|
report({event, options}) {
|
|
309
346
|
return _report(event, options);
|
|
310
347
|
},
|
|
311
|
-
})
|
|
348
|
+
}) as Reporter;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import type {BundleGraph, FilePath, PackagedBundle} from '@atlaspack/types';
|
|
3
2
|
import type {FileSystem} from '@atlaspack/fs';
|
|
4
3
|
|
|
@@ -40,7 +39,7 @@ export default async function bundleReport(
|
|
|
40
39
|
};
|
|
41
40
|
}),
|
|
42
41
|
};
|
|
43
|
-
let rows = [];
|
|
42
|
+
let rows: Array<Array<string>> = [];
|
|
44
43
|
|
|
45
44
|
for (let bundle of bundles) {
|
|
46
45
|
// Add a row for the bundle
|
|
@@ -55,6 +54,7 @@ export default async function bundleReport(
|
|
|
55
54
|
for (let asset of largestAssets) {
|
|
56
55
|
let columns: Array<string> = [
|
|
57
56
|
asset == largestAssets[largestAssets.length - 1] ? '└── ' : '├── ',
|
|
57
|
+
// @ts-expect-error TS2554
|
|
58
58
|
chalk.dim(prettifySize(asset.size)),
|
|
59
59
|
chalk.dim(chalk.green(prettifyTime(asset.time))),
|
|
60
60
|
];
|
|
@@ -87,10 +87,11 @@ export default async function bundleReport(
|
|
|
87
87
|
|
|
88
88
|
// Render table
|
|
89
89
|
writeOut('');
|
|
90
|
+
// @ts-expect-error TS2345
|
|
90
91
|
table(COLUMNS, rows);
|
|
91
92
|
}
|
|
92
93
|
|
|
93
|
-
function prettifySize(size, isLarge) {
|
|
94
|
+
function prettifySize(size: number, isLarge: undefined | boolean) {
|
|
94
95
|
let res = filesize(size);
|
|
95
96
|
if (isLarge) {
|
|
96
97
|
return chalk.yellow(emoji.warning + ' ' + res);
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import {prettifyTime} from '@atlaspack/utils';
|
|
3
2
|
import chalk from 'chalk';
|
|
4
3
|
import {writeOut} from './render';
|
|
5
4
|
import invariant from 'assert';
|
|
6
5
|
|
|
7
|
-
export default function phaseReport(phaseStartTimes: {[string]: number}) {
|
|
8
|
-
let phaseTimes = {};
|
|
6
|
+
export default function phaseReport(phaseStartTimes: {[key: string]: number}) {
|
|
7
|
+
let phaseTimes: Record<string, any> = {};
|
|
9
8
|
if (phaseStartTimes['transforming'] && phaseStartTimes['bundling']) {
|
|
10
9
|
phaseTimes['Transforming'] =
|
|
11
10
|
phaseStartTimes['bundling'] - phaseStartTimes['transforming'];
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import type {Writable} from 'stream';
|
|
3
2
|
|
|
4
3
|
import readline from 'readline';
|
|
@@ -9,12 +8,11 @@ import type {PadAlign} from './utils';
|
|
|
9
8
|
import {pad, countLines} from './utils';
|
|
10
9
|
import * as emoji from './emoji';
|
|
11
10
|
|
|
12
|
-
type ColumnType = {
|
|
13
|
-
align: PadAlign
|
|
14
|
-
|
|
11
|
+
type ColumnType = {
|
|
12
|
+
align: PadAlign;
|
|
13
|
+
};
|
|
15
14
|
|
|
16
15
|
export const isTTY: any | boolean | true =
|
|
17
|
-
// $FlowFixMe
|
|
18
16
|
process.env.NODE_ENV !== 'test' && process.stdout.isTTY;
|
|
19
17
|
|
|
20
18
|
let stdout = process.stdout;
|
|
@@ -33,7 +31,9 @@ let errorLineCount = 0;
|
|
|
33
31
|
let statusPersisted = false;
|
|
34
32
|
|
|
35
33
|
export function _setStdio(stdoutLike: Writable, stderrLike: Writable) {
|
|
34
|
+
// @ts-expect-error TS2322
|
|
36
35
|
stdout = stdoutLike;
|
|
36
|
+
// @ts-expect-error TS2322
|
|
37
37
|
stderr = stderrLike;
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -42,7 +42,7 @@ let spinner = ora({
|
|
|
42
42
|
stream: stdout,
|
|
43
43
|
discardStdin: false,
|
|
44
44
|
});
|
|
45
|
-
let persistedMessages = [];
|
|
45
|
+
let persistedMessages: Array<string> = [];
|
|
46
46
|
|
|
47
47
|
export function writeOut(message: string, isError: boolean = false) {
|
|
48
48
|
let processedMessage = message + '\n';
|
|
@@ -132,7 +132,7 @@ export function resetWindow() {
|
|
|
132
132
|
|
|
133
133
|
export function table(columns: Array<ColumnType>, table: Array<Array<string>>) {
|
|
134
134
|
// Measure column widths
|
|
135
|
-
let colWidths = [];
|
|
135
|
+
let colWidths: Array<number> = [];
|
|
136
136
|
for (let row of table) {
|
|
137
137
|
let i = 0;
|
|
138
138
|
for (let item of row) {
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
1
|
import assert from 'assert';
|
|
4
2
|
import sinon from 'sinon';
|
|
5
3
|
import {PassThrough} from 'stream';
|
|
@@ -39,13 +37,13 @@ const EMPTY_OPTIONS = {
|
|
|
39
37
|
assetsPerBundle: 10,
|
|
40
38
|
},
|
|
41
39
|
featureFlags: DEFAULT_FEATURE_FLAGS,
|
|
42
|
-
};
|
|
40
|
+
} as const;
|
|
43
41
|
|
|
44
42
|
describe('CLIReporter', () => {
|
|
45
|
-
let originalStdout;
|
|
46
|
-
let originalStderr;
|
|
47
|
-
let stdoutOutput;
|
|
48
|
-
let stderrOutput;
|
|
43
|
+
let originalStdout: any;
|
|
44
|
+
let originalStderr: any;
|
|
45
|
+
let stdoutOutput: any;
|
|
46
|
+
let stderrOutput: any;
|
|
49
47
|
|
|
50
48
|
beforeEach(async () => {
|
|
51
49
|
// Stub these out to avoid writing noise to real stdio and to read from these
|
|
@@ -57,9 +55,15 @@ describe('CLIReporter', () => {
|
|
|
57
55
|
stderrOutput = '';
|
|
58
56
|
|
|
59
57
|
let mockStdout = new PassThrough();
|
|
60
|
-
mockStdout.on(
|
|
58
|
+
mockStdout.on(
|
|
59
|
+
'data',
|
|
60
|
+
(d: any) => (stdoutOutput += stripAnsi(d.toString())),
|
|
61
|
+
);
|
|
61
62
|
let mockStderr = new PassThrough();
|
|
62
|
-
mockStderr.on(
|
|
63
|
+
mockStderr.on(
|
|
64
|
+
'data',
|
|
65
|
+
(d: any) => (stderrOutput += stripAnsi(d.toString())),
|
|
66
|
+
);
|
|
63
67
|
_setStdio(mockStdout, mockStderr);
|
|
64
68
|
|
|
65
69
|
await _report(
|
|
@@ -200,7 +204,6 @@ describe('CLIReporter', () => {
|
|
|
200
204
|
// emit a buildSuccess event to reset the timings and seen phases
|
|
201
205
|
// from the previous test
|
|
202
206
|
process.env['ATLASPACK_SHOW_PHASE_TIMES'] = undefined;
|
|
203
|
-
// $FlowFixMe
|
|
204
207
|
await _report({type: 'buildSuccess'}, EMPTY_OPTIONS);
|
|
205
208
|
|
|
206
209
|
process.env['ATLASPACK_SHOW_PHASE_TIMES'] = 'true';
|
|
@@ -210,17 +213,16 @@ describe('CLIReporter', () => {
|
|
|
210
213
|
);
|
|
211
214
|
await _report({type: 'buildProgress', phase: 'bundling'}, EMPTY_OPTIONS);
|
|
212
215
|
await _report(
|
|
213
|
-
// $FlowFixMe
|
|
214
216
|
{
|
|
215
217
|
type: 'buildProgress',
|
|
216
218
|
phase: 'packaging',
|
|
219
|
+
|
|
217
220
|
bundle: {
|
|
218
221
|
displayName: 'test',
|
|
219
222
|
},
|
|
220
223
|
},
|
|
221
224
|
EMPTY_OPTIONS,
|
|
222
225
|
);
|
|
223
|
-
// $FlowFixMe
|
|
224
226
|
await _report({type: 'buildSuccess'}, EMPTY_OPTIONS);
|
|
225
227
|
const expected =
|
|
226
228
|
/Building...\nBundling...\nPackaging & Optimizing...\nTransforming finished in [0-9]ms\nBundling finished in [0-9]ms\nPackaging & Optimizing finished in [0-9]ms/;
|
|
@@ -235,17 +237,16 @@ describe('CLIReporter', () => {
|
|
|
235
237
|
);
|
|
236
238
|
await _report({type: 'buildProgress', phase: 'bundling'}, EMPTY_OPTIONS);
|
|
237
239
|
await _report(
|
|
238
|
-
// $FlowFixMe
|
|
239
240
|
{
|
|
240
241
|
type: 'buildProgress',
|
|
241
242
|
phase: 'packaging',
|
|
243
|
+
|
|
242
244
|
bundle: {
|
|
243
245
|
displayName: 'test',
|
|
244
246
|
},
|
|
245
247
|
},
|
|
246
248
|
EMPTY_OPTIONS,
|
|
247
249
|
);
|
|
248
|
-
// $FlowFixMe
|
|
249
250
|
await _report({type: 'buildSuccess'}, EMPTY_OPTIONS);
|
|
250
251
|
|
|
251
252
|
assert.equal(
|
package/tsconfig.json
ADDED