@bymaksym/loadline 0.1.0

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 (98) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +182 -0
  3. package/bin/loadline.js +50 -0
  4. package/dist/cli/cli/args.js +324 -0
  5. package/dist/cli/cli/args.types.js +3 -0
  6. package/dist/cli/cli/gates.js +173 -0
  7. package/dist/cli/cli/gates.types.js +3 -0
  8. package/dist/cli/cli/main.js +156 -0
  9. package/dist/cli/cli/read-build.js +382 -0
  10. package/dist/cli/cli/read-build.types.js +3 -0
  11. package/dist/cli/cli/render-json.js +116 -0
  12. package/dist/cli/cli/render-json.types.js +10 -0
  13. package/dist/cli/cli/render-markdown.js +30 -0
  14. package/dist/cli/cli/render-pr.js +76 -0
  15. package/dist/cli/cli/render-sarif.js +83 -0
  16. package/dist/cli/cli/render-text.js +388 -0
  17. package/dist/cli/cli/report.js +196 -0
  18. package/dist/cli/cli/report.types.js +3 -0
  19. package/dist/cli/cli/self-check.js +85 -0
  20. package/dist/cli/cli/text.js +180 -0
  21. package/dist/cli/cli/text.types.js +10 -0
  22. package/dist/cli/src/app/core/analysis/analysis.js +661 -0
  23. package/dist/cli/src/app/core/analysis/analysis.types.js +6 -0
  24. package/dist/cli/src/app/core/analysis/barrels.js +128 -0
  25. package/dist/cli/src/app/core/analysis/blast.js +172 -0
  26. package/dist/cli/src/app/core/analysis/cycles.js +110 -0
  27. package/dist/cli/src/app/core/analysis/delivery.js +143 -0
  28. package/dist/cli/src/app/core/analysis/entries.js +217 -0
  29. package/dist/cli/src/app/core/analysis/exclusive.js +91 -0
  30. package/dist/cli/src/app/core/analysis/importers.js +38 -0
  31. package/dist/cli/src/app/core/analysis/insights.js +202 -0
  32. package/dist/cli/src/app/core/analysis/insights.types.js +10 -0
  33. package/dist/cli/src/app/core/analysis/invariant.js +69 -0
  34. package/dist/cli/src/app/core/analysis/metafile.types.js +44 -0
  35. package/dist/cli/src/app/core/analysis/module-graph.js +192 -0
  36. package/dist/cli/src/app/core/analysis/sourcemap.js +231 -0
  37. package/dist/cli/src/app/core/analysis/sourcemap.types.js +3 -0
  38. package/dist/cli/src/app/core/analysis/split-drift.js +47 -0
  39. package/dist/cli/src/app/core/assets/assets.js +296 -0
  40. package/dist/cli/src/app/core/assets/assets.types.js +11 -0
  41. package/dist/cli/src/app/core/baseline/baseline.js +0 -0
  42. package/dist/cli/src/app/core/baseline/baseline.types.js +3 -0
  43. package/dist/cli/src/app/core/caching/caching.js +241 -0
  44. package/dist/cli/src/app/core/caching/caching.types.js +10 -0
  45. package/dist/cli/src/app/core/caching/from-analysis.js +73 -0
  46. package/dist/cli/src/app/core/config/loadline-config.js +110 -0
  47. package/dist/cli/src/app/core/config/loadline-config.types.js +12 -0
  48. package/dist/cli/src/app/core/criteria/criteria.js +228 -0
  49. package/dist/cli/src/app/core/criteria/criteria.types.js +3 -0
  50. package/dist/cli/src/app/core/deps/deps.js +225 -0
  51. package/dist/cli/src/app/core/deps/deps.types.js +15 -0
  52. package/dist/cli/src/app/core/export/markdown-table.utils.js +40 -0
  53. package/dist/cli/src/app/core/export/summary.js +72 -0
  54. package/dist/cli/src/app/core/findings/actions.js +59 -0
  55. package/dist/cli/src/app/core/findings/assets.js +130 -0
  56. package/dist/cli/src/app/core/findings/caching.js +165 -0
  57. package/dist/cli/src/app/core/findings/compose.js +41 -0
  58. package/dist/cli/src/app/core/findings/deps.js +66 -0
  59. package/dist/cli/src/app/core/findings/effort.js +117 -0
  60. package/dist/cli/src/app/core/findings/finding-html.js +13 -0
  61. package/dist/cli/src/app/core/findings/finding-plain.js +26 -0
  62. package/dist/cli/src/app/core/findings/finding-text.js +1231 -0
  63. package/dist/cli/src/app/core/findings/finding.types.js +80 -0
  64. package/dist/cli/src/app/core/findings/findings.js +514 -0
  65. package/dist/cli/src/app/core/findings/graph.js +167 -0
  66. package/dist/cli/src/app/core/findings/own-in-boot.js +88 -0
  67. package/dist/cli/src/app/core/findings/page.js +49 -0
  68. package/dist/cli/src/app/core/findings/requests.js +185 -0
  69. package/dist/cli/src/app/core/findings/scan.js +126 -0
  70. package/dist/cli/src/app/core/findings/shipped.js +244 -0
  71. package/dist/cli/src/app/core/findings/situation.js +116 -0
  72. package/dist/cli/src/app/core/format/format.utils.js +204 -0
  73. package/dist/cli/src/app/core/i18n/en.js +819 -0
  74. package/dist/cli/src/app/core/i18n/es.js +822 -0
  75. package/dist/cli/src/app/core/i18n/ui-strings.js +11 -0
  76. package/dist/cli/src/app/core/i18n/ui.js +7 -0
  77. package/dist/cli/src/app/core/intake/bundle-graph.js +346 -0
  78. package/dist/cli/src/app/core/intake/bundle-graph.types.js +3 -0
  79. package/dist/cli/src/app/core/intake/dist-files.js +160 -0
  80. package/dist/cli/src/app/core/intake/index-html.js +292 -0
  81. package/dist/cli/src/app/core/json/json.utils.js +55 -0
  82. package/dist/cli/src/app/core/measurement/measurement.types.js +14 -0
  83. package/dist/cli/src/app/core/project/budget-advice.js +76 -0
  84. package/dist/cli/src/app/core/project/project-context.js +394 -0
  85. package/dist/cli/src/app/core/project/project-context.types.js +3 -0
  86. package/dist/cli/src/app/core/scan/catalog.js +67 -0
  87. package/dist/cli/src/app/core/scan/scan.js +280 -0
  88. package/dist/cli/src/app/core/scan/scan.types.js +10 -0
  89. package/dist/cli/src/app/core/scan/secrets.js +0 -0
  90. package/dist/cli/src/app/core/situation/situation.js +261 -0
  91. package/dist/cli/src/app/core/situation/situation.types.js +19 -0
  92. package/dist/cli/src/app/core/timing/timing.js +87 -0
  93. package/dist/cli/src/app/core/timing/timing.types.js +3 -0
  94. package/dist/cli/src/app/core/whatif/defer.js +68 -0
  95. package/dist/cli/src/app/state/report-messages.utils.js +73 -0
  96. package/docs/HOW-IT-WORKS.md +1087 -0
  97. package/loadline.html +78 -0
  98. package/package.json +154 -0
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ /**
3
+ * The report as SARIF 2.1.0, so GitHub shows each signal where the developer already looks.
4
+ *
5
+ * The point is not the format, it is the anchoring. "You have 47 vulnerabilities" in a log nobody
6
+ * opens does nothing; the same finding attached to the file it is about, in the diff view, gets
7
+ * read. Every signal that names a source file gets a location; the ones about the build as a whole
8
+ * are anchored to the page or the stats file the report was made from, because a SARIF result with
9
+ * no location at all is dropped silently by some viewers.
10
+ *
11
+ * Reference: https://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.renderSarif = void 0;
15
+ const finding_types_1 = require("../src/app/core/findings/finding.types");
16
+ const finding_plain_1 = require("../src/app/core/findings/finding-plain");
17
+ /** SARIF has three levels that matter to a code-scanning view; the report has four. */
18
+ const LEVEL = {
19
+ high: 'error',
20
+ mid: 'warning',
21
+ ok: 'note',
22
+ info: 'note',
23
+ };
24
+ /**
25
+ * Which file a signal points at.
26
+ *
27
+ * A signal about a package or a chunk has no source file of its own, and inventing one would put a
28
+ * warning on a line somebody did not write. Those are anchored to what the report was read from,
29
+ * which is true and checkable.
30
+ */
31
+ const locationOf = (finding, fallback) => {
32
+ const key = finding.target?.key ?? '';
33
+ return /\.[a-z]+$/i.test(key) && !key.includes('node_modules') ? key : fallback;
34
+ };
35
+ const renderSarif = (report) => {
36
+ const fallback = report.statsName;
37
+ // Only the signals this run actually raised. Declaring all of them would mean rules with no
38
+ // help text — a rule somebody has to look up elsewhere, which is the thing this tool spends
39
+ // most of its words avoiding — and a code-scanning view listing signals nobody saw.
40
+ const raised = finding_types_1.FINDING_KINDS.filter(kind => report.findings.some(finding => finding.kind === kind));
41
+ const rules = raised.map(kind => {
42
+ const example = report.findings.find(finding => finding.kind === kind);
43
+ return {
44
+ id: kind,
45
+ name: kind,
46
+ shortDescription: { text: example?.chip ?? kind },
47
+ fullDescription: { text: example?.title ?? kind },
48
+ help: { text: example ? (0, finding_plain_1.plainText)(example.fix) : '' },
49
+ };
50
+ });
51
+ const results = report.findings.map(finding => ({
52
+ ruleId: finding.kind,
53
+ level: LEVEL[finding.severity],
54
+ message: { text: `${finding.title} — ${(0, finding_plain_1.plainText)(finding.body)}` },
55
+ locations: [
56
+ {
57
+ physicalLocation: {
58
+ artifactLocation: { uri: locationOf(finding, fallback) },
59
+ region: { startLine: 1 },
60
+ },
61
+ },
62
+ ],
63
+ ...(finding.saving !== undefined && { properties: { savingBytes: finding.saving } }),
64
+ }));
65
+ const log = {
66
+ $schema: 'https://json.schemastore.org/sarif-2.1.0.json',
67
+ version: '2.1.0',
68
+ runs: [
69
+ {
70
+ tool: {
71
+ driver: {
72
+ name: 'Loadline',
73
+ informationUri: 'https://github.com/loadline',
74
+ rules,
75
+ },
76
+ },
77
+ results,
78
+ },
79
+ ],
80
+ };
81
+ return `${JSON.stringify(log, null, 2)}\n`;
82
+ };
83
+ exports.renderSarif = renderSarif;
@@ -0,0 +1,388 @@
1
+ "use strict";
2
+ /**
3
+ * The report as a person reads it in a terminal. Same message as the page, in the order the page
4
+ * puts it: the headline first, then one row per screen on the same three segments, then the
5
+ * signals with what to do about each one.
6
+ *
7
+ * Colour is an extra, never the message: every line says what it means in words too, because half
8
+ * the places this runs strip the escape codes.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.renderText = void 0;
12
+ const criteria_1 = require("../src/app/core/criteria/criteria");
13
+ const actions_1 = require("../src/app/core/findings/actions");
14
+ const finding_plain_1 = require("../src/app/core/findings/finding-plain");
15
+ const format_utils_1 = require("../src/app/core/format/format.utils");
16
+ const ui_1 = require("../src/app/core/i18n/ui");
17
+ const budget_advice_1 = require("../src/app/core/project/budget-advice");
18
+ const timing_1 = require("../src/app/core/timing/timing");
19
+ const gates_1 = require("./gates");
20
+ const text_1 = require("./text");
21
+ const WIDTH = 96;
22
+ const ESC = String.fromCodePoint(27);
23
+ const ANSI = new RegExp(String.raw `${ESC}\[\d+m`, 'g');
24
+ const code = (open) => value => `${ESC}[${open}m${value}${ESC}[0m`;
25
+ const plain = value => value;
26
+ const paletteOf = (color) => color
27
+ ? { bold: code(1), dim: code(90), good: code(32), warn: code(33), bad: code(31) }
28
+ : { bold: plain, dim: plain, good: plain, warn: plain, bad: plain };
29
+ /** Length as the terminal shows it: padding a coloured string by its raw length breaks the column. */
30
+ const visible = (value) => value.replaceAll(ANSI, '').length;
31
+ const pad = (value, width, right) => {
32
+ const filler = ' '.repeat(Math.max(0, width - visible(value)));
33
+ return right ? `${filler}${value}` : `${value}${filler}`;
34
+ };
35
+ const verdictPaint = (palette, verdict) => verdict === 'good' ? palette.good : verdict === 'ok' ? palette.warn : palette.bad;
36
+ const severityPaint = (palette, severity) => severity === 'high' ? palette.bad : severity === 'mid' ? palette.warn : palette.dim;
37
+ /** Wraps at word boundaries. A signal is a sentence, and a sentence cut mid-word is harder to read. */
38
+ const wrap = (value, width) => {
39
+ const lines = [];
40
+ const words = value.split(/\s+/).filter(Boolean);
41
+ let current = '';
42
+ for (const word of words) {
43
+ if (current && current.length + word.length + 1 > width) {
44
+ lines.push(current);
45
+ current = word;
46
+ }
47
+ else {
48
+ current = current ? `${current} ${word}` : word;
49
+ }
50
+ }
51
+ if (current) {
52
+ lines.push(current);
53
+ }
54
+ return lines;
55
+ };
56
+ /** A table sized to its own content: nothing truncated, nothing padded to a guess. */
57
+ const table = (columns, rows, palette) => {
58
+ const widths = columns.map((column, index) => Math.max(column.head.length, ...rows.map(row => visible(row[index] ?? ''))));
59
+ const line = (cells) => cells.map((value, index) => pad(value, widths[index] ?? 0, columns[index]?.right ?? false)).join(' ');
60
+ return [
61
+ palette.dim(line(columns.map(column => column.head))),
62
+ palette.dim(widths.map(width => '-'.repeat(width)).join(' ')),
63
+ ...rows.map(row => line(row)),
64
+ ];
65
+ };
66
+ /**
67
+ * What the first load costs in round trips, under the bootstrap figure. Empty without `--dist`:
68
+ * `index.html` is the only file that tells a preloaded chunk from one the browser has to discover
69
+ * by parsing, and the page's "drop the folder" wording is not what a terminal should say.
70
+ */
71
+ const startupLines = (report, palette) => {
72
+ const startup = report.analysis.startup;
73
+ if (!startup) {
74
+ return [];
75
+ }
76
+ const note = ui_1.UI[report.lang].startupNote({
77
+ waves: startup.waves,
78
+ late: startup.discovered.length,
79
+ chunks: report.analysis.bootFiles,
80
+ });
81
+ return [palette.dim(note)];
82
+ };
83
+ /**
84
+ * Everything the page asks for before anything appears, or — without a folder to read — just the
85
+ * stylesheets, which is as much of it as a page alone can say.
86
+ */
87
+ const firstTripLines = (report, palette) => {
88
+ const text = text_1.CLI_TEXT[report.lang];
89
+ const trip = report.assets?.firstTrip;
90
+ if (trip && trip.total > 0) {
91
+ const parts = [
92
+ `${(0, format_utils_1.formatBytes)(trip.scripts)} JS`,
93
+ `${(0, format_utils_1.formatBytes)(trip.styles)} CSS`,
94
+ `${(0, format_utils_1.formatBytes)(trip.fonts)} fonts`,
95
+ `${(0, format_utils_1.formatBytes)(trip.images)} images`,
96
+ ].join(' + ');
97
+ return [palette.warn(text.firstTrip((0, format_utils_1.formatBytes)(trip.total), trip.files, parts))];
98
+ }
99
+ if (report.pageCssBytes === null) {
100
+ return [];
101
+ }
102
+ return [
103
+ palette.warn(text.pageCss((0, format_utils_1.formatBytes)(report.pageCssBytes), report.pageCssFiles, (0, format_utils_1.formatBytes)(report.analysis.bootBytes + report.pageCssBytes))),
104
+ ];
105
+ };
106
+ const screensTable = (report, palette) => {
107
+ const strings = ui_1.UI[report.lang];
108
+ const { analysis, comparison, criteria } = report;
109
+ const columns = [
110
+ { head: strings.colScreen, right: false },
111
+ { head: strings.tabBoot, right: true },
112
+ { head: strings.colShared, right: true },
113
+ { head: strings.colOwn, right: true },
114
+ { head: strings.colTotal, right: true },
115
+ { head: strings.colWaves, right: true },
116
+ ];
117
+ if (comparison) {
118
+ columns.push({ head: `${strings.colDelta} ${comparison.baselineName}`, right: true });
119
+ }
120
+ const rows = analysis.screens.map(screen => {
121
+ const verdict = (0, criteria_1.rate)(screen.total, criteria.screenOk, criteria.screenBad);
122
+ const cells = [
123
+ screen.label,
124
+ (0, format_utils_1.formatBytes)(screen.boot),
125
+ (0, format_utils_1.formatBytes)(screen.shared),
126
+ (0, format_utils_1.formatBytes)(screen.own),
127
+ verdictPaint(palette, verdict)((0, format_utils_1.formatBytes)(screen.total)),
128
+ String(screen.waves),
129
+ ];
130
+ if (comparison) {
131
+ const delta = comparison.screens.get(screen.source);
132
+ cells.push(delta ? (0, format_utils_1.formatDelta)(delta.total.diff) : strings.compareNew);
133
+ }
134
+ return cells;
135
+ });
136
+ return table(columns, rows, palette);
137
+ };
138
+ const signalBlock = (finding, palette, fixLabel) => {
139
+ const head = severityPaint(palette, finding.severity)(`${finding.severity.padEnd(4)} · ${finding.chip}`);
140
+ const indent = (line) => ` ${line}`;
141
+ const body = wrap((0, finding_plain_1.plainText)(finding.body), WIDTH - 6).map(element => indent(element));
142
+ const fix = finding.fix ? wrap(`${fixLabel}: ${(0, finding_plain_1.plainText)(finding.fix)}`, WIDTH - 6).map(l => indent(l)) : [];
143
+ return ['', ` ${head}`, ` ${palette.bold(finding.title)}`, ...body, ...(fix.length > 0 ? ['', ...fix] : [])];
144
+ };
145
+ /**
146
+ * What to fix first: the signals ranked by bytes per unit of effort, then what doing all of it is
147
+ * worth. It is an **order**, and the note says so: every signal is printed again below, in full.
148
+ */
149
+ const actionsBlock = (report, palette) => {
150
+ const text = text_1.CLI_TEXT[report.lang];
151
+ const actions = (0, actions_1.rankActions)(report.findings);
152
+ if (actions.length === 0) {
153
+ return [];
154
+ }
155
+ // Painted by severity, like the signal it points at. Without it this table reads as four
156
+ // equal jobs, and the eye has to go down to Signals to learn that the fourth is an `info`
157
+ // and the first is not. The saving cell stays plain on purpose: one colour per row, or the
158
+ // colour stops meaning anything.
159
+ const rows = actions.map((action, index) => [
160
+ `${index + 1}.`,
161
+ severityPaint(palette, action.finding.severity)(action.finding.title),
162
+ text.savingCell(action.saving > 0 ? (0, format_utils_1.formatBytes)(action.saving) : ''),
163
+ text.effortLabel[action.effort],
164
+ ]);
165
+ const total = (0, actions_1.totalSaving)(report.analysis, report.findings);
166
+ const summary = total.counted > 0
167
+ ? text.totalSaving((0, format_utils_1.formatBytes)(total.bytes), (0, format_utils_1.formatBytes)(total.after), total.counted)
168
+ : text.nothingToSave;
169
+ return [
170
+ '',
171
+ palette.bold(text.headActions),
172
+ palette.dim(text.actionsNote),
173
+ ...table([
174
+ { head: '#', right: true },
175
+ { head: text.colAction, right: false },
176
+ { head: text.colSaving, right: true },
177
+ { head: text.colEffort, right: false },
178
+ ], rows, palette),
179
+ '',
180
+ ...wrap(summary, WIDTH).map(line => palette.dim(line)),
181
+ ];
182
+ };
183
+ /**
184
+ * Bytes as seconds, on three connections. Every line of this block is labelled an estimate, and the
185
+ * note is printed before the table rather than after it: a figure read first and qualified second
186
+ * is a figure somebody quotes without the qualification.
187
+ */
188
+ const timeBlock = (report, palette) => {
189
+ const text = text_1.CLI_TEXT[report.lang];
190
+ const { analysis } = report;
191
+ const waves = analysis.startup?.waves ?? 1;
192
+ // The transfer half goes by what travels; the parse half by raw bytes, plus the stylesheets the
193
+ // page asks for, because the first load is what the first load is.
194
+ const bytes = analysis.bootBytes + (report.pageCssBytes ?? 0);
195
+ const timings = (0, timing_1.timingsOf)(bytes, analysis.bootRawBytes, waves, report.criteria.latencyMs);
196
+ const columns = text.timeColumns;
197
+ const rows = timings.map(timing => [
198
+ text.profileName[timing.profile],
199
+ (0, timing_1.formatMs)(timing.transferMs, report.lang),
200
+ (0, timing_1.formatMs)(timing.latencyMs, report.lang),
201
+ (0, timing_1.formatMs)(timing.scriptMs, report.lang),
202
+ palette.bold((0, timing_1.formatMs)(timing.totalMs, report.lang)),
203
+ ]);
204
+ return [
205
+ '',
206
+ palette.bold(text.headTime),
207
+ ...wrap(text.timeNote, WIDTH).map(line => palette.dim(line)),
208
+ ...table([
209
+ { head: columns.profile, right: false },
210
+ { head: columns.transfer, right: true },
211
+ { head: columns.latency, right: true },
212
+ { head: columns.script, right: true },
213
+ { head: columns.total, right: true },
214
+ ], rows, palette),
215
+ ];
216
+ };
217
+ /**
218
+ * The budget that should be in `angular.json`. Only with `--project`, because without it there is
219
+ * nothing to say a budget is missing from, and the figure is raw bytes: that is what Angular counts.
220
+ */
221
+ const budgetBlock = (report, palette) => {
222
+ const text = text_1.CLI_TEXT[report.lang];
223
+ // Only when the report already said the budget is missing, unreachable or a warning: without
224
+ // `--project` there is nothing to say a budget is missing from.
225
+ const asking = new Set(['budgetNone', 'budgetTooHigh', 'budgetWarnOnly']);
226
+ const wanted = report.findings.some(finding => asking.has(finding.kind));
227
+ const advice = wanted ? (0, budget_advice_1.budgetAdvice)(report.analysis.bootRawBytes + (report.pageCssRawBytes ?? 0)) : null;
228
+ if (!advice) {
229
+ return [];
230
+ }
231
+ // The second budget, for a build that has screens: `anyScript` applies to every emitted file,
232
+ // which is what makes it useful when the names carry hashes and `bundle` budgets cannot.
233
+ const heaviest = Math.max(0, ...report.analysis.screens.map(screen => screen.own));
234
+ const perScreen = (0, budget_advice_1.screenBudgetAdvice)(heaviest);
235
+ return [
236
+ '',
237
+ palette.bold(text.headBudget),
238
+ ...wrap(text.budgetNote(`${advice.warningKb}kB`, `${advice.errorKb}kB`, (0, format_utils_1.formatBytes)(advice.currentBytes)), WIDTH).map(line => palette.dim(line)),
239
+ '',
240
+ ...advice.snippet.split('\n').map(line => ` ${line}`),
241
+ ...(perScreen
242
+ ? [
243
+ '',
244
+ ...wrap(text.screenBudgetNote(`${perScreen.warningKb}kB`), WIDTH).map(line => palette.dim(line)),
245
+ ...perScreen.snippet.split('\n').map(line => ` ${line}`),
246
+ ]
247
+ : []),
248
+ ];
249
+ };
250
+ /**
251
+ * What the team decided to live with, and what happened to each of those decisions.
252
+ *
253
+ * It is printed rather than silent for the reason acceptances exist at all: a signal that
254
+ * disappears without a trace is a suppression, and the next person cannot tell the difference
255
+ * between "we looked at this" and "nobody ever saw it". An acceptance that ran out or that no
256
+ * longer covers the figure is said out loud here, and the signal itself is back in the list above.
257
+ */
258
+ const acceptedBlock = (report, palette) => {
259
+ if (report.accepted.length === 0) {
260
+ return [];
261
+ }
262
+ const text = text_1.CLI_TEXT[report.lang];
263
+ const lines = report.accepted.map(item => {
264
+ const { entry, lapse } = item;
265
+ if (lapse === 'expired') {
266
+ return palette.warn(` ! ${text.acceptedExpired(entry.kind, entry.until ?? '')}`);
267
+ }
268
+ if (lapse === 'grew') {
269
+ return palette.warn(` ! ${text.acceptedGrew(entry.kind, (0, format_utils_1.formatBytes)(entry.bytes ?? 0), (0, format_utils_1.formatBytes)(item.finding.saving ?? 0))}`);
270
+ }
271
+ return palette.dim(` · ${text.accepted(entry.kind, entry.why, entry.who ?? null, entry.until ?? null)}`);
272
+ });
273
+ return ['', palette.bold(text.headAccepted), ...lines];
274
+ };
275
+ /**
276
+ * "What would the first load weigh without this?", for each name asked about.
277
+ *
278
+ * The saving is exact — the graph walked without those files — and the note under it says what is
279
+ * deliberately not recomputed, because a simulated re-chunking would produce round trips that look
280
+ * exactly like the measured ones and are not.
281
+ */
282
+ const whatIfBlock = (report, palette) => {
283
+ if (report.whatIf.length === 0) {
284
+ return [];
285
+ }
286
+ const text = text_1.CLI_TEXT[report.lang];
287
+ const rows = report.whatIf.map(result => [
288
+ result.target,
289
+ (0, format_utils_1.formatBytes)(result.weight),
290
+ palette.bold((0, format_utils_1.formatBytes)(result.saved)),
291
+ (0, format_utils_1.formatBytes)(result.after),
292
+ result.screens.length > 0 ? result.screens.join(', ') : text.whatIfNobody,
293
+ ]);
294
+ return [
295
+ '',
296
+ palette.bold(text.headWhatIf),
297
+ ...wrap(text.whatIfNote, WIDTH).map(line => palette.dim(line)),
298
+ ...table([
299
+ { head: text.colWhatIf, right: false },
300
+ { head: text.colSize, right: true },
301
+ { head: text.colSaving, right: true },
302
+ { head: text.colAfter, right: true },
303
+ { head: text.colWhoPays, right: false },
304
+ ], rows, palette),
305
+ ];
306
+ };
307
+ const gateBlock = (violations, anyAsked, report, palette) => {
308
+ const text = text_1.CLI_TEXT[report.lang];
309
+ if (!anyAsked) {
310
+ return ['', palette.dim(text.noGates)];
311
+ }
312
+ const head = ['', palette.bold(text.headGates)];
313
+ if (violations.length === 0) {
314
+ return [...head, ` ${palette.good(text.passed)}`];
315
+ }
316
+ return [
317
+ ...head,
318
+ ...(0, gates_1.violationLines)(violations).map(line => ` ${palette.bad('x')} ${line}`),
319
+ '',
320
+ palette.bad(text.failed(violations.length)),
321
+ ];
322
+ };
323
+ /** The lead: what was analysed, in which unit, against what, and how the weights were measured. */
324
+ const header = (report, palette) => {
325
+ const text = text_1.CLI_TEXT[report.lang];
326
+ const lines = [
327
+ palette.bold(report.projectName ? `Loadline · ${report.projectName}` : 'Loadline'),
328
+ palette.dim(text.lead(report.statsName, report.unit)),
329
+ ];
330
+ if (report.comparison) {
331
+ lines.push(palette.dim(text.against(report.comparison.baselineName, report.comparison.baselineDate.slice(0, 10))));
332
+ }
333
+ if (report.comparisonBlocked) {
334
+ lines.push(palette.warn(text.blocked));
335
+ }
336
+ if (report.analysis.splitSource === 'sourcemap') {
337
+ lines.push(palette.dim(text.exactSplit));
338
+ }
339
+ // Which file the thresholds came from. A run judged by a committed file and one judged by the
340
+ // recommended values are different runs, and the log should not leave that to be guessed.
341
+ if (report.configName) {
342
+ lines.push(palette.dim(text.configRead(report.configName)));
343
+ }
344
+ // Dropping half a build in silence is the one thing this line stops. An SSR build writes both
345
+ // sides into one stats file, and the page has said which half it is reading since it could.
346
+ if (report.analysis.serverOutputs > 0) {
347
+ lines.push(palette.dim(text.serverLeftOut(report.analysis.serverOutputs)));
348
+ }
349
+ return lines;
350
+ };
351
+ const renderText = (report, violations, anyAsked, color) => {
352
+ const palette = paletteOf(color);
353
+ const text = text_1.CLI_TEXT[report.lang];
354
+ const strings = ui_1.UI[report.lang];
355
+ const { analysis, criteria } = report;
356
+ const verdict = (0, criteria_1.rate)(analysis.bootBytes, criteria.bootOk, criteria.bootBad);
357
+ const word = { good: strings.verdictGood, ok: strings.verdictOk, bad: strings.verdictBad }[verdict];
358
+ const headline = verdictPaint(palette, verdict)(`${(0, format_utils_1.formatBytes)(analysis.bootBytes)} ${word}`);
359
+ return [
360
+ ...header(report, palette),
361
+ '',
362
+ `${palette.bold(text.headBoot)} ${headline}`,
363
+ palette.dim(text.bootSummary(analysis.bootFiles, analysis.screens.length)),
364
+ // What the first load really costs. The headline above stays the JavaScript, deliberately:
365
+ // it is the one figure the whole tool is named after and it is the one it can break down.
366
+ // This line is the honest total next to it, with the parts spelled out so nobody has to
367
+ // take the number on trust. The stylesheet alone is the fallback for a report that read a
368
+ // page but no folder, and it is worth saying on its own: a render-blocking stylesheet is
369
+ // the strictest "before anything appears" there is.
370
+ ...firstTripLines(report, palette),
371
+ ...startupLines(report, palette),
372
+ '',
373
+ palette.bold(text.headScreens),
374
+ ...(analysis.screens.length > 0 ? screensTable(report, palette) : [palette.dim(text.noScreens)]),
375
+ '',
376
+ ...actionsBlock(report, palette),
377
+ ...timeBlock(report, palette),
378
+ ...budgetBlock(report, palette),
379
+ '',
380
+ palette.bold(text.headSignals),
381
+ ...report.findings.flatMap(finding => signalBlock(finding, palette, text.fix)),
382
+ ...whatIfBlock(report, palette),
383
+ ...acceptedBlock(report, palette),
384
+ ...gateBlock(violations, anyAsked, report, palette),
385
+ '',
386
+ ].join('\n');
387
+ };
388
+ exports.renderText = renderText;
@@ -0,0 +1,196 @@
1
+ "use strict";
2
+ /**
3
+ * What `ReportStore` does for the page, done once and returned: pick the unit, analyse, compare
4
+ * against the baseline and put the signals in order. It calls the same functions in the same order,
5
+ * so the terminal and the page cannot disagree about a build.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.buildReport = void 0;
9
+ const analysis_1 = require("../src/app/core/analysis/analysis");
10
+ const sourcemap_1 = require("../src/app/core/analysis/sourcemap");
11
+ const baseline_1 = require("../src/app/core/baseline/baseline");
12
+ const from_analysis_1 = require("../src/app/core/caching/from-analysis");
13
+ const loadline_config_1 = require("../src/app/core/config/loadline-config");
14
+ const criteria_1 = require("../src/app/core/criteria/criteria");
15
+ const deps_1 = require("../src/app/core/deps/deps");
16
+ const assets_1 = require("../src/app/core/findings/assets");
17
+ const caching_1 = require("../src/app/core/findings/caching");
18
+ const compose_1 = require("../src/app/core/findings/compose");
19
+ const deps_2 = require("../src/app/core/findings/deps");
20
+ const findings_1 = require("../src/app/core/findings/findings");
21
+ const page_1 = require("../src/app/core/findings/page");
22
+ const scan_1 = require("../src/app/core/findings/scan");
23
+ const shipped_1 = require("../src/app/core/findings/shipped");
24
+ const situation_1 = require("../src/app/core/findings/situation");
25
+ const format_utils_1 = require("../src/app/core/format/format.utils");
26
+ const ui_1 = require("../src/app/core/i18n/ui");
27
+ const scan_2 = require("../src/app/core/scan/scan");
28
+ const situation_2 = require("../src/app/core/situation/situation");
29
+ const defer_1 = require("../src/app/core/whatif/defer");
30
+ const read_build_1 = require("./read-build");
31
+ /**
32
+ * Which figure the report is in. Brotli when the folder brought the `.br` files, gzip when it
33
+ * brought the assets, raw otherwise. Asking for a unit the folder cannot give is an error rather
34
+ * than a silent downgrade: a gate written for gzip and checked against raw bytes passes for a
35
+ * reason that has nothing to do with the build.
36
+ */
37
+ const resolveMode = (input, asked) => {
38
+ const best = input.brotli ? 'brotli' : input.gzip ? 'gzip' : 'raw';
39
+ if (!asked) {
40
+ return best;
41
+ }
42
+ if (asked === 'brotli' && !input.brotli) {
43
+ throw new read_build_1.InputError('--mode brotli needs the .js.br files of the build in --dist.');
44
+ }
45
+ if (asked === 'gzip' && !input.gzip) {
46
+ throw new read_build_1.InputError('--mode gzip needs the build folder in --dist.');
47
+ }
48
+ return asked;
49
+ };
50
+ /**
51
+ * The thresholds: the recommended ones for the unit, then `loadline.json`, then `--criteria`.
52
+ *
53
+ * That order is the one people expect and the one that makes the file useful: the committed file
54
+ * is what the team agreed to, and a flag typed on a command line is somebody overriding it for one
55
+ * run on purpose. The file's own `mode` is not checked against the report's, because a threshold
56
+ * written in gzip and applied to raw bytes is a real mismatch and the report already has a signal
57
+ * for that shape of mistake elsewhere; here it would only be a second place to look.
58
+ */
59
+ const resolveCriteria = (mode, config, overrides) => ({
60
+ ...criteria_1.RECOMMENDED[mode],
61
+ ...config?.criteria,
62
+ ...overrides,
63
+ });
64
+ /**
65
+ * Raw compares against a raw analysis; a compressed baseline only against the same compression,
66
+ * because gzip against brotli would read as a saving that never happened.
67
+ */
68
+ const comparisonOf = (input, shown, raw, mode, findings) => {
69
+ const baseline = input.baseline;
70
+ if (!baseline) {
71
+ return { comparison: null, blocked: false };
72
+ }
73
+ if (baseline.mode !== 'raw' && baseline.mode !== mode) {
74
+ return { comparison: null, blocked: true };
75
+ }
76
+ const against = baseline.mode === 'raw' ? raw : shown;
77
+ // The signals go into the snapshot so the comparison can say which of them are new and which
78
+ // went away. They are the ones from this build alone: the comparison's own signals do not exist
79
+ // yet, and a signal about a comparison is not a property of the build being compared.
80
+ const current = (0, baseline_1.snapshotOf)(against, baseline.mode, input.statsName, new Date(), findings);
81
+ return { comparison: (0, baseline_1.compare)(current, baseline), blocked: false };
82
+ };
83
+ const buildReport = (input, options) => {
84
+ const mode = resolveMode(input, options.mode);
85
+ const sizes = mode === 'brotli' ? input.brotli : mode === 'gzip' ? input.gzip : null;
86
+ const exact = (0, sourcemap_1.resolveSplits)(input.splits, Object.keys(input.meta.inputs ?? {}));
87
+ const lang = options.lang;
88
+ const criteria = resolveCriteria(mode, input.config, input.criteria);
89
+ // The language only decides the decimal separator, and it is set before anything is formatted.
90
+ (0, format_utils_1.setNumberLang)(lang);
91
+ const analysis = (0, analysis_1.analyze)(input.meta, sizes, exact, input.announced, null, criteria, input.parallel);
92
+ // The same build in raw bytes, for comparing against a raw baseline while showing compressed
93
+ // figures. It is the shown analysis itself when nothing is compressed, so it costs nothing then.
94
+ const raw = sizes ? (0, analysis_1.analyze)(input.meta, null, exact, input.announced, null, criteria, input.parallel) : analysis;
95
+ // What the team answered about itself, out of the committed file. Unlike a measurement, this
96
+ // half of the context does reach the terminal: it is the same for everybody who runs the
97
+ // command, which is exactly why it lives in `loadline.json` rather than in a browser.
98
+ const situation = input.config?.situation ?? situation_2.EMPTY_SITUATION;
99
+ const strings = ui_1.UI[lang];
100
+ const units = {
101
+ raw: strings.unitRaw,
102
+ gzip: strings.unitGzip,
103
+ brotli: strings.unitBrotli,
104
+ };
105
+ const pageCss = input.pageCss;
106
+ const cssBytes = pageCss ? (mode === 'brotli' ? (pageCss.brotli ?? pageCss.gzip) : pageCss[mode]) : null;
107
+ // What an update costs. It needs the baseline's file names, which only a snapshot carrying them
108
+ // has; without one the delta is absent and the other two caching figures still come out.
109
+ const caching = (0, from_analysis_1.cachingOf)(analysis, input.baseline, input.assets ?? null, new Set(input.announced), input.hrefs);
110
+ // What the text of the build says, and what the two dependency files say about what ships. Both
111
+ // are empty rather than absent when nothing was given: `null` inside them says which.
112
+ const scan = (input.texts?.size ?? 0) > 0
113
+ ? (0, scan_2.scanBuild)({
114
+ texts: input.texts ?? new Map(),
115
+ modules: analysis.modules,
116
+ boot: new Set(analysis.bootChunks),
117
+ maps: input.maps ?? [],
118
+ })
119
+ : null;
120
+ const deps = (0, deps_1.readDeps)({
121
+ lock: input.lock ?? null,
122
+ advisories: input.advisories ?? null,
123
+ modules: analysis.modules,
124
+ boot: new Set(analysis.bootChunks),
125
+ direct: new Set(input.context.pkg?.dependencies),
126
+ });
127
+ // The signals of this build alone, built once. They are what the comparison needs to say which
128
+ // of them are new, what the snapshot carries so the *next* run can ask the same question, and
129
+ // what composing puts in order. Built once because they were built twice and the two lists had
130
+ // drifted: the one the snapshot kept was missing caching, scan and deps, so a `devLeftovers`
131
+ // somebody had actually fixed could never show as gone, and a page export — which does carry
132
+ // them — read as three signals fixed the moment the terminal compared against it.
133
+ const base = (0, findings_1.buildFindings)(analysis, lang, mode, criteria, situation);
134
+ const fromContext = (0, findings_1.buildContextFindings)(input.context, analysis, lang, criteria);
135
+ const fromBuild = [
136
+ ...(0, shipped_1.buildFolderFindings)({
137
+ sourceMaps: input.splits?.size ?? 0,
138
+ derived: !!input.graph,
139
+ screens: analysis.screens.map(s => s.label),
140
+ drift: analysis.splitDrift,
141
+ }, lang),
142
+ ...(input.assets ? (0, assets_1.buildAssetFindings)(input.assets, lang, criteria) : []),
143
+ ...(0, page_1.buildPageFindings)(input.pageOrigins ?? null, lang),
144
+ ...(0, caching_1.buildCachingFindings)(caching, lang, criteria, situation),
145
+ ...(scan ? (0, scan_1.buildScanFindings)(scan, lang, criteria) : []),
146
+ ...(0, deps_2.buildDepsFindings)(deps, lang, criteria),
147
+ ];
148
+ const own = [...base, ...fromContext, ...fromBuild];
149
+ const { comparison, blocked } = comparisonOf(input, analysis, raw, mode, own);
150
+ // This build as the next run's baseline. Written whether or not `--export` was asked for: it
151
+ // costs a walk over lists that are already in memory, and having it here is what keeps the
152
+ // exported file and the compared-against file the same shape by construction.
153
+ const snapshot = (0, baseline_1.snapshotOf)(analysis, mode, input.statsName, new Date(), own);
154
+ const composed = (0, compose_1.composeFindings)({
155
+ base,
156
+ fromComparison: comparison ? (0, findings_1.buildComparisonFindings)(comparison, lang, criteria) : [],
157
+ fromContext,
158
+ // Nothing measures a browser in a pipeline: that half of the report is the page's.
159
+ fromMeasurement: [],
160
+ fromBuild,
161
+ });
162
+ // Read after everything else and appended rather than composed in, because they are about the
163
+ // list itself: which question is worth asking is decided by which signals came out, and the
164
+ // card that names the unanswered ones would be boilerplate on every report if it were not.
165
+ // They are all context, so the end of the list is where composing would have put them anyway.
166
+ const withSituation = [...composed, ...(0, situation_1.buildSituationFindings)(situation, composed, lang, criteria)];
167
+ // What the team decided to live with is set aside here, once, so the gates, the ranking and
168
+ // every renderer see the same list. An acceptance that ran out stays in it.
169
+ const { kept, accepted } = (0, loadline_config_1.applyAcceptances)(withSituation, input.config ?? null);
170
+ return {
171
+ statsName: input.statsName,
172
+ snapshot,
173
+ pageCssBytes: cssBytes,
174
+ pageCssRawBytes: pageCss?.raw ?? null,
175
+ pageCssFiles: pageCss?.files.length ?? 0,
176
+ assets: input.assets ?? null,
177
+ caching,
178
+ scan,
179
+ deps,
180
+ whatIf: options.whatIf.map(name => (0, defer_1.simulateDefer)(analysis, name)),
181
+ projectName: input.context.pkg?.name ?? input.context.angular?.project ?? null,
182
+ mode,
183
+ unit: units[mode],
184
+ lang,
185
+ criteria,
186
+ analysis,
187
+ comparison,
188
+ comparisonBlocked: blocked,
189
+ findings: kept,
190
+ accepted,
191
+ config: input.config ?? null,
192
+ configName: input.configName ?? null,
193
+ configProblems: input.configProblems ?? [],
194
+ };
195
+ };
196
+ exports.buildReport = buildReport;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ /** The finished analysis, in the shape the three renderers read it from. */
3
+ Object.defineProperty(exports, "__esModule", { value: true });