@atlaspack/reporter-cli 2.15.1-canary.35 → 2.15.1-canary.350
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 +375 -0
- package/dist/CLIReporter.js +304 -0
- package/dist/bundleReport.js +117 -0
- package/dist/emoji.js +25 -0
- package/dist/logLevels.js +12 -0
- package/dist/phaseReport.js +32 -0
- package/dist/render.js +166 -0
- package/dist/utils.js +39 -0
- package/lib/CLIReporter.js +302 -7745
- 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 +16 -12
- package/src/{CLIReporter.js → CLIReporter.ts} +105 -19
- 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 +21 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/lib/CLIReporter.js.map +0 -1
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type {
|
|
2
|
+
ReporterEvent,
|
|
3
|
+
PluginOptions,
|
|
4
|
+
PluginLogger,
|
|
5
|
+
} from '@atlaspack/types';
|
|
3
6
|
import type {Diagnostic} from '@atlaspack/diagnostic';
|
|
4
|
-
import type {Color} from 'chalk';
|
|
5
7
|
|
|
8
|
+
import {getFeatureFlag} from '@atlaspack/feature-flags';
|
|
6
9
|
import {Reporter} from '@atlaspack/plugin';
|
|
7
10
|
import {
|
|
8
11
|
getProgressMessage,
|
|
12
|
+
getPackageProgressMessage,
|
|
9
13
|
prettifyTime,
|
|
10
14
|
prettyDiagnostic,
|
|
11
15
|
throttle,
|
|
16
|
+
debugTools,
|
|
12
17
|
} from '@atlaspack/utils';
|
|
13
18
|
import chalk from 'chalk';
|
|
14
19
|
|
|
@@ -23,8 +28,10 @@ import {
|
|
|
23
28
|
isTTY,
|
|
24
29
|
resetWindow,
|
|
25
30
|
persistMessage,
|
|
31
|
+
table,
|
|
26
32
|
} from './render';
|
|
27
33
|
import * as emoji from './emoji';
|
|
34
|
+
// @ts-expect-error TS7016
|
|
28
35
|
import wrapAnsi from 'wrap-ansi';
|
|
29
36
|
|
|
30
37
|
const THROTTLE_DELAY = 100;
|
|
@@ -32,23 +39,77 @@ const seenWarnings = new Set();
|
|
|
32
39
|
const seenPhases = new Set();
|
|
33
40
|
const seenPhasesGen = new Set();
|
|
34
41
|
|
|
35
|
-
let phaseStartTimes = {};
|
|
42
|
+
let phaseStartTimes: Record<string, any> = {};
|
|
36
43
|
let pendingIncrementalBuild = false;
|
|
44
|
+
let packagingProgress = 0;
|
|
45
|
+
|
|
46
|
+
let updatePackageProgress = (completeBundles: number, totalBundles: number) => {
|
|
47
|
+
let updateThreshold = 0;
|
|
48
|
+
if (totalBundles > 5000) {
|
|
49
|
+
// If more than 5000 bundles, update every 5%
|
|
50
|
+
updateThreshold = 5;
|
|
51
|
+
} else if (totalBundles > 1000) {
|
|
52
|
+
// If more than 1000 bundles, update every 10%
|
|
53
|
+
updateThreshold = 10;
|
|
54
|
+
} else {
|
|
55
|
+
// othewise update every 25%
|
|
56
|
+
updateThreshold = 25;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let percent = Math.floor((completeBundles / totalBundles) * 100);
|
|
60
|
+
if (percent - packagingProgress >= updateThreshold) {
|
|
61
|
+
packagingProgress = percent;
|
|
62
|
+
updateSpinner(getPackageProgressMessage(completeBundles, totalBundles));
|
|
63
|
+
}
|
|
64
|
+
};
|
|
37
65
|
|
|
38
66
|
let statusThrottle = throttle((message: string) => {
|
|
39
67
|
updateSpinner(message);
|
|
40
68
|
}, THROTTLE_DELAY);
|
|
41
69
|
|
|
42
|
-
const cacheWriteState: {
|
|
43
|
-
startTime: number | null
|
|
44
|
-
|
|
70
|
+
const cacheWriteState: {
|
|
71
|
+
startTime: number | null;
|
|
72
|
+
} = {
|
|
45
73
|
startTime: null,
|
|
46
74
|
};
|
|
47
75
|
|
|
76
|
+
function calculateWrappingStats(
|
|
77
|
+
scopeHoistingStats:
|
|
78
|
+
| {
|
|
79
|
+
totalAssets: number;
|
|
80
|
+
wrappedAssets: number;
|
|
81
|
+
}
|
|
82
|
+
| undefined,
|
|
83
|
+
logger: PluginLogger,
|
|
84
|
+
) {
|
|
85
|
+
if (!scopeHoistingStats) {
|
|
86
|
+
logger.info({
|
|
87
|
+
message: 'No scope hoisting data collected.',
|
|
88
|
+
origin: '@atlaspack/reporter-cli',
|
|
89
|
+
});
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
let {totalAssets, wrappedAssets} = scopeHoistingStats;
|
|
94
|
+
let hoistedAssets = totalAssets - wrappedAssets;
|
|
95
|
+
let percentage = totalAssets > 0 ? (hoistedAssets / totalAssets) * 100 : 0;
|
|
96
|
+
|
|
97
|
+
table(
|
|
98
|
+
[{align: 'left'}, {align: 'right'}],
|
|
99
|
+
[
|
|
100
|
+
['Wrapped Assets', wrappedAssets.toString()],
|
|
101
|
+
['Total Assets', totalAssets.toString()],
|
|
102
|
+
['Hoisted Assets', hoistedAssets.toString()],
|
|
103
|
+
['Percentage Hoisted', `${percentage.toFixed(3)}%`],
|
|
104
|
+
],
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
48
108
|
// Exported only for test
|
|
49
109
|
export async function _report(
|
|
50
110
|
event: ReporterEvent,
|
|
51
111
|
options: PluginOptions,
|
|
112
|
+
logger: PluginLogger,
|
|
52
113
|
): Promise<void> {
|
|
53
114
|
let logLevelFilter = logLevels[options.logLevel || 'info'];
|
|
54
115
|
|
|
@@ -94,11 +155,23 @@ export async function _report(
|
|
|
94
155
|
seenPhasesGen.add(event.phase);
|
|
95
156
|
}
|
|
96
157
|
|
|
158
|
+
if (
|
|
159
|
+
getFeatureFlag('cliProgressReportingImprovements') &&
|
|
160
|
+
(event.phase === 'packaging' || event.phase === 'optimizing')
|
|
161
|
+
) {
|
|
162
|
+
// If the flag is turned on, we ignore the old `packaging` and
|
|
163
|
+
// `optimizing` event types, and only consider `packagingAndOptimizing`
|
|
164
|
+
// events
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
|
|
97
168
|
if (!isTTY && logLevelFilter != logLevels.verbose) {
|
|
98
169
|
if (event.phase == 'transforming' && !seenPhases.has('transforming')) {
|
|
99
170
|
updateSpinner('Building...');
|
|
100
171
|
} else if (event.phase == 'bundling' && !seenPhases.has('bundling')) {
|
|
101
172
|
updateSpinner('Bundling...');
|
|
173
|
+
} else if (event.phase === 'packagingAndOptimizing') {
|
|
174
|
+
updatePackageProgress(event.completeBundles, event.totalBundles);
|
|
102
175
|
} else if (
|
|
103
176
|
(event.phase == 'packaging' || event.phase == 'optimizing') &&
|
|
104
177
|
!seenPhases.has('packaging') &&
|
|
@@ -134,12 +207,21 @@ export async function _report(
|
|
|
134
207
|
);
|
|
135
208
|
|
|
136
209
|
if (options.mode === 'production') {
|
|
137
|
-
|
|
138
|
-
event.
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
210
|
+
if (debugTools['scope-hoisting-stats']) {
|
|
211
|
+
calculateWrappingStats(event.scopeHoistingStats, logger);
|
|
212
|
+
}
|
|
213
|
+
if (debugTools['simple-cli-reporter']) {
|
|
214
|
+
writeOut(
|
|
215
|
+
`🛠️ Built ${event.bundleGraph.getBundles().length} bundles.`,
|
|
216
|
+
);
|
|
217
|
+
} else {
|
|
218
|
+
await bundleReport(
|
|
219
|
+
event.bundleGraph,
|
|
220
|
+
options.outputFS,
|
|
221
|
+
options.projectRoot,
|
|
222
|
+
options.detailedReport?.assetsPerBundle,
|
|
223
|
+
);
|
|
224
|
+
}
|
|
143
225
|
} else {
|
|
144
226
|
pendingIncrementalBuild = true;
|
|
145
227
|
}
|
|
@@ -214,6 +296,7 @@ export async function _report(
|
|
|
214
296
|
await writeDiagnostic(options, event.diagnostics, 'red', true);
|
|
215
297
|
break;
|
|
216
298
|
default:
|
|
299
|
+
// @ts-expect-error TS2339
|
|
217
300
|
throw new Error('Unknown log level ' + event.level);
|
|
218
301
|
}
|
|
219
302
|
}
|
|
@@ -223,6 +306,7 @@ export async function _report(
|
|
|
223
306
|
async function writeDiagnostic(
|
|
224
307
|
options: PluginOptions,
|
|
225
308
|
diagnostics: Array<Diagnostic>,
|
|
309
|
+
// @ts-expect-error TS2749
|
|
226
310
|
color: Color,
|
|
227
311
|
isError: boolean = false,
|
|
228
312
|
) {
|
|
@@ -232,7 +316,7 @@ async function writeDiagnostic(
|
|
|
232
316
|
for (let diagnostic of diagnostics) {
|
|
233
317
|
let {message, stack, codeframe, hints, documentation} =
|
|
234
318
|
await prettyDiagnostic(diagnostic, options, columns - indent);
|
|
235
|
-
//
|
|
319
|
+
// @ts-expect-error TS7053
|
|
236
320
|
message = chalk[color](message);
|
|
237
321
|
|
|
238
322
|
if (spaceAfter) {
|
|
@@ -281,6 +365,7 @@ async function writeDiagnostic(
|
|
|
281
365
|
);
|
|
282
366
|
}
|
|
283
367
|
|
|
368
|
+
// @ts-expect-error TS2322
|
|
284
369
|
spaceAfter = stack || codeframe || hints.length > 0 || documentation;
|
|
285
370
|
}
|
|
286
371
|
|
|
@@ -289,7 +374,7 @@ async function writeDiagnostic(
|
|
|
289
374
|
}
|
|
290
375
|
}
|
|
291
376
|
|
|
292
|
-
function wrapWithIndent(string, indent = 0, initialIndent = indent) {
|
|
377
|
+
function wrapWithIndent(string: string, indent = 0, initialIndent = indent) {
|
|
293
378
|
let width = getTerminalWidth().columns;
|
|
294
379
|
return indentString(
|
|
295
380
|
wrapAnsi(string.trimEnd(), width - indent, {trim: false}),
|
|
@@ -298,14 +383,15 @@ function wrapWithIndent(string, indent = 0, initialIndent = indent) {
|
|
|
298
383
|
);
|
|
299
384
|
}
|
|
300
385
|
|
|
386
|
+
// @ts-expect-error TS7006
|
|
301
387
|
function indentString(string, indent = 0, initialIndent = indent) {
|
|
302
388
|
return (
|
|
303
389
|
' '.repeat(initialIndent) + string.replace(/\n/g, '\n' + ' '.repeat(indent))
|
|
304
390
|
);
|
|
305
391
|
}
|
|
306
392
|
|
|
307
|
-
export default
|
|
308
|
-
report({event, options}) {
|
|
309
|
-
return _report(event, options);
|
|
393
|
+
export default new Reporter({
|
|
394
|
+
report({event, options, logger}) {
|
|
395
|
+
return _report(event, options, logger);
|
|
310
396
|
},
|
|
311
|
-
})
|
|
397
|
+
}) 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
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../tsconfig.base.json",
|
|
3
|
+
"include": ["src"],
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"composite": true
|
|
6
|
+
},
|
|
7
|
+
"references": [
|
|
8
|
+
{
|
|
9
|
+
"path": "../../core/feature-flags/tsconfig.json"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"path": "../../core/plugin/tsconfig.json"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"path": "../../core/types/tsconfig.json"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"path": "../../core/utils/tsconfig.json"
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
}
|