@bymaksym/loadline 0.1.0 → 1.0.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.
- package/README.md +66 -7
- package/dist/cli/cli/args.js +33 -3
- package/dist/cli/cli/declared.js +52 -0
- package/dist/cli/cli/html-report.js +107 -0
- package/dist/cli/cli/locate.js +60 -0
- package/dist/cli/cli/main.js +118 -5
- package/dist/cli/cli/memory.js +78 -0
- package/dist/cli/cli/read-build.js +8 -4
- package/dist/cli/cli/render-json.js +8 -5
- package/dist/cli/cli/render-markdown.js +1 -1
- package/dist/cli/cli/render-pr.js +5 -3
- package/dist/cli/cli/render-sarif.js +3 -3
- package/dist/cli/cli/render-text.js +63 -28
- package/dist/cli/cli/report.js +9 -3
- package/dist/cli/cli/since-last.js +45 -0
- package/dist/cli/cli/text.js +54 -19
- package/dist/cli/src/app/core/analysis/analysis.js +8 -4
- package/dist/cli/src/app/core/analysis/barrels.js +9 -2
- package/dist/cli/src/app/core/analysis/entries.js +41 -6
- package/dist/cli/src/app/core/analysis/metafile.types.js +14 -6
- package/dist/cli/src/app/core/analysis/split-drift.js +12 -6
- package/dist/cli/src/app/core/assets/assets.js +4 -2
- package/dist/cli/src/app/core/caching/caching.js +3 -3
- package/dist/cli/src/app/core/deps/deps.js +37 -7
- package/dist/cli/src/app/core/deps/pins.js +63 -0
- package/dist/cli/src/app/core/export/summary.js +27 -9
- package/dist/cli/src/app/core/findings/actions.js +63 -6
- package/dist/cli/src/app/core/findings/assets.js +30 -5
- package/dist/cli/src/app/core/findings/boot-single.js +76 -0
- package/dist/cli/src/app/core/findings/caching.js +1 -1
- package/dist/cli/src/app/core/findings/dupes.js +65 -0
- package/dist/cli/src/app/core/findings/effort.js +2 -0
- package/dist/cli/src/app/core/findings/finding-html.js +14 -1
- package/dist/cli/src/app/core/findings/finding-text.js +104 -31
- package/dist/cli/src/app/core/findings/finding.types.js +1 -0
- package/dist/cli/src/app/core/findings/findings.js +22 -38
- package/dist/cli/src/app/core/findings/graph.js +4 -4
- package/dist/cli/src/app/core/findings/scan.js +13 -3
- package/dist/cli/src/app/core/findings/shipped.js +3 -5
- package/dist/cli/src/app/core/format/format.utils.js +16 -9
- package/dist/cli/src/app/core/i18n/en.js +108 -48
- package/dist/cli/src/app/core/i18n/es.js +114 -50
- package/dist/cli/src/app/core/intake/bundle-graph.js +6 -5
- package/dist/cli/src/app/core/intake/dist-files.js +5 -2
- package/dist/cli/src/app/core/intake/embedded.js +46 -0
- package/dist/cli/src/app/core/intake/index-html.js +66 -16
- package/dist/cli/src/app/core/project/budget-advice.js +14 -10
- package/dist/cli/src/app/core/project/project-context.js +74 -16
- package/dist/cli/src/app/core/scan/scan.js +59 -21
- package/dist/cli/src/app/core/scan/secrets.js +0 -0
- package/dist/cli/src/app/core/situation/situation.js +3 -4
- package/dist/cli/src/app/state/report-messages.utils.js +1 -4
- package/loadline.html +22 -24
- package/package.json +60 -30
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The previous run, remembered without being asked to.
|
|
4
|
+
*
|
|
5
|
+
* `--baseline` is the right tool for a pipeline and the wrong one for a person who has just changed
|
|
6
|
+
* one import and wants to know whether the bootstrap went down: they had to export yesterday's
|
|
7
|
+
* build on purpose, or compare two outputs by hand. So every run leaves its snapshot in
|
|
8
|
+
* `node_modules/.cache/loadline` — where build tools keep what they can always rebuild, already
|
|
9
|
+
* ignored by every repository — and the next run of the same build says what moved.
|
|
10
|
+
*
|
|
11
|
+
* It is a convenience, never a gate: nothing here changes the exit code, and an explicit
|
|
12
|
+
* `--baseline` replaces it entirely. A machine without a `node_modules` above it simply has no
|
|
13
|
+
* memory, and every failure to read or write is silent: losing the comparison is not worth an error.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.writeLastRun = exports.readLastRun = void 0;
|
|
17
|
+
const node_crypto_1 = require("node:crypto");
|
|
18
|
+
const promises_1 = require("node:fs/promises");
|
|
19
|
+
const node_path_1 = require("node:path");
|
|
20
|
+
const baseline_1 = require("../src/app/core/baseline/baseline");
|
|
21
|
+
/** The nearest `node_modules` at or above the folder, which is where the cache belongs. */
|
|
22
|
+
const nodeModulesAbove = async (from) => {
|
|
23
|
+
let folder = (0, node_path_1.resolve)(from);
|
|
24
|
+
for (;;) {
|
|
25
|
+
const candidate = (0, node_path_1.join)(folder, 'node_modules');
|
|
26
|
+
try {
|
|
27
|
+
const info = await (0, promises_1.stat)(candidate);
|
|
28
|
+
if (info.isDirectory()) {
|
|
29
|
+
return candidate;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
// Not here; one level up.
|
|
34
|
+
}
|
|
35
|
+
const parent = (0, node_path_1.dirname)(folder);
|
|
36
|
+
if (parent === folder) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
folder = parent;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
/** One file per build, keyed by where it is: two apps of one workspace do not overwrite each other. */
|
|
43
|
+
const fileFor = async (cwd, target) => {
|
|
44
|
+
const modules = await nodeModulesAbove(cwd);
|
|
45
|
+
if (!modules) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
const key = (0, node_crypto_1.createHash)('sha1').update((0, node_path_1.resolve)(target)).digest('hex').slice(0, 12);
|
|
49
|
+
return (0, node_path_1.join)(modules, '.cache', 'loadline', `last-${key}.json`);
|
|
50
|
+
};
|
|
51
|
+
const readLastRun = async (cwd, target) => {
|
|
52
|
+
const file = await fileFor(cwd, target);
|
|
53
|
+
if (!file) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
const parsed = JSON.parse(await (0, promises_1.readFile)(file, 'utf8'));
|
|
58
|
+
return (0, baseline_1.isSnapshot)(parsed) ? parsed : null;
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
exports.readLastRun = readLastRun;
|
|
65
|
+
const writeLastRun = async (cwd, target, snapshot) => {
|
|
66
|
+
const file = await fileFor(cwd, target);
|
|
67
|
+
if (!file) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
await (0, promises_1.mkdir)((0, node_path_1.dirname)(file), { recursive: true });
|
|
72
|
+
await (0, promises_1.writeFile)(file, JSON.stringify(snapshot), 'utf8');
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
// A read-only checkout or a full disk: the report is still right, it just will not remember.
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
exports.writeLastRun = writeLastRun;
|
|
@@ -207,7 +207,9 @@ const readDist = async (folder, derive = false) => {
|
|
|
207
207
|
.update(await (0, promises_1.readFile)(path))
|
|
208
208
|
.digest('hex'));
|
|
209
209
|
}
|
|
210
|
-
const named = html
|
|
210
|
+
const named = html
|
|
211
|
+
? (0, index_html_1.assetsIn)(html)
|
|
212
|
+
: { referenced: [], preloaded: [], prefetched: [], hrefs: [], icons: [], alternates: [] };
|
|
211
213
|
const assets = (0, assets_1.readAssets)({
|
|
212
214
|
files: assetFiles,
|
|
213
215
|
html,
|
|
@@ -216,6 +218,7 @@ const readDist = async (folder, derive = false) => {
|
|
|
216
218
|
inPage: new Set([...named.referenced, ...(html ? (0, index_html_1.announcedIn)(html) : []), ...(html ? (0, index_html_1.stylesIn)(html) : [])]),
|
|
217
219
|
preloaded: new Set(named.preloaded),
|
|
218
220
|
prefetched: new Set(named.prefetched),
|
|
221
|
+
icons: new Set(named.icons),
|
|
219
222
|
bootChunks: new Set(),
|
|
220
223
|
// The same figures the rest of the report is in, so the first trip and the headline are
|
|
221
224
|
// not the same bytes quoted in two units.
|
|
@@ -328,10 +331,11 @@ const pipelinePaths = async (folder) => {
|
|
|
328
331
|
}
|
|
329
332
|
for (const segments of PIPELINE_FOLDERS) {
|
|
330
333
|
const directory = (0, node_path_1.join)(folder, ...segments);
|
|
331
|
-
if (await exists(directory)) {
|
|
332
|
-
|
|
333
|
-
found.push(...paths.filter(path => /\.ya?ml$/i.test(path)));
|
|
334
|
+
if (!(await exists(directory))) {
|
|
335
|
+
continue;
|
|
334
336
|
}
|
|
337
|
+
const paths = await filesUnder(directory);
|
|
338
|
+
found.push(...paths.filter(path => /\.ya?ml$/i.test(path)));
|
|
335
339
|
}
|
|
336
340
|
return found;
|
|
337
341
|
};
|
|
@@ -42,7 +42,7 @@ const renderJson = (report, violations, anyAsked) => {
|
|
|
42
42
|
const { analysis, criteria } = report;
|
|
43
43
|
const asking = new Set(['budgetNone', 'budgetTooHigh', 'budgetWarnOnly']);
|
|
44
44
|
const advice = report.findings.some(finding => asking.has(finding.kind))
|
|
45
|
-
? (0, budget_advice_1.budgetAdvice)(analysis.
|
|
45
|
+
? (0, budget_advice_1.budgetAdvice)(analysis.initialRawBytes)
|
|
46
46
|
: null;
|
|
47
47
|
const payload = {
|
|
48
48
|
tool: 'loadline',
|
|
@@ -87,8 +87,8 @@ const renderJson = (report, violations, anyAsked) => {
|
|
|
87
87
|
findings: report.findings.map(finding => ({
|
|
88
88
|
kind: finding.kind,
|
|
89
89
|
severity: finding.severity,
|
|
90
|
-
chip: finding.chip,
|
|
91
|
-
title: finding.title,
|
|
90
|
+
chip: (0, finding_plain_1.plainText)(finding.chip),
|
|
91
|
+
title: (0, finding_plain_1.plainText)(finding.title),
|
|
92
92
|
body: (0, finding_plain_1.plainText)(finding.body),
|
|
93
93
|
fix: (0, finding_plain_1.plainText)(finding.fix),
|
|
94
94
|
...(finding.saving !== undefined && { saving: finding.saving }),
|
|
@@ -96,16 +96,19 @@ const renderJson = (report, violations, anyAsked) => {
|
|
|
96
96
|
})),
|
|
97
97
|
actions: (0, actions_1.rankActions)(report.findings).map(action => ({
|
|
98
98
|
kind: action.finding.kind,
|
|
99
|
-
title: action.finding.title,
|
|
99
|
+
title: (0, finding_plain_1.plainText)(action.finding.title),
|
|
100
100
|
saving: action.saving,
|
|
101
101
|
effort: action.effort,
|
|
102
102
|
})),
|
|
103
103
|
saving: (0, actions_1.totalSaving)(analysis, report.findings),
|
|
104
|
+
savingInUnit: (0, actions_1.savingInUnit)(analysis, (0, actions_1.totalSaving)(analysis, report.findings)),
|
|
105
|
+
whatIf: report.whatIf,
|
|
104
106
|
timing: (0, timing_1.timingsOf)(analysis.bootBytes + (report.pageCssBytes ?? 0), analysis.bootRawBytes, analysis.startup?.waves ?? 1, criteria.latencyMs),
|
|
105
107
|
budget: advice,
|
|
106
108
|
caching: report.caching,
|
|
107
109
|
scan: report.scan,
|
|
108
|
-
|
|
110
|
+
// Without the declared ranges: they are an input the signals already read, not a finding.
|
|
111
|
+
deps: (({ declared: _declared, ...rest }) => rest)(report.deps),
|
|
109
112
|
comparison: comparisonOf(report),
|
|
110
113
|
comparable: !report.comparisonBlocked,
|
|
111
114
|
gates: { asked: anyAsked, violations },
|
|
@@ -17,7 +17,7 @@ const renderMarkdown = (report, violations, anyAsked) => {
|
|
|
17
17
|
const blocks = [(0, markdown_table_utils_1.markdownTable)(report.analysis, report.comparison, strings, report.unit)];
|
|
18
18
|
if (report.findings.length > 0) {
|
|
19
19
|
blocks.push(`### ${text.headSignals}`, report.findings
|
|
20
|
-
.map(finding => `- **${finding.title}** — ${(0, finding_plain_1.plainText)(finding.body)}\n ${text.fix}: ${(0, finding_plain_1.plainText)(finding.fix)}`)
|
|
20
|
+
.map(finding => `- **${(0, finding_plain_1.plainText)(finding.title)}** — ${(0, finding_plain_1.plainText)(finding.body)}\n ${text.fix}: ${(0, finding_plain_1.plainText)(finding.fix)}`)
|
|
21
21
|
.join('\n'));
|
|
22
22
|
}
|
|
23
23
|
if (anyAsked) {
|
|
@@ -52,10 +52,12 @@ const renderPrComment = (report, violations, anyAsked) => {
|
|
|
52
52
|
const actions = (0, actions_1.rankActions)(report.findings);
|
|
53
53
|
if (actions.length > 0) {
|
|
54
54
|
const total = (0, actions_1.totalSaving)(analysis, report.findings);
|
|
55
|
-
const
|
|
55
|
+
const scale = (0, actions_1.unitScale)(analysis);
|
|
56
|
+
const rows = actions.map((action, index) => `| ${index + 1} | ${(0, finding_plain_1.plainText)(action.finding.title)} | ${action.saving > 0 ? (0, actions_1.formatSaving)(action.saving, scale) : '—'} | ${text.effortLabel[action.effort]} |`);
|
|
56
57
|
lines.push('', `#### ${text.headActions}`, `| # | ${text.colAction} | ${text.colSaving} | ${text.colEffort} |`, '| --: | --- | --: | --- |', ...rows);
|
|
57
58
|
if (total.counted > 0) {
|
|
58
|
-
|
|
59
|
+
const words = (0, actions_1.savingWords)(analysis, total);
|
|
60
|
+
lines.push('', `_${text.totalSaving(words.saving, words.after, total.counted, words.estimated)}_`);
|
|
59
61
|
}
|
|
60
62
|
}
|
|
61
63
|
if (anyAsked) {
|
|
@@ -68,7 +70,7 @@ const renderPrComment = (report, violations, anyAsked) => {
|
|
|
68
70
|
(0, markdown_table_utils_1.markdownTable)(analysis, comparison, strings, report.unit),
|
|
69
71
|
'',
|
|
70
72
|
`#### ${text.headSignals}`,
|
|
71
|
-
...report.findings.map(finding => `- **${finding.title}** — ${(0, finding_plain_1.plainText)(finding.body)}\n ${text.fix}: ${(0, finding_plain_1.plainText)(finding.fix)}`),
|
|
73
|
+
...report.findings.map(finding => `- **${(0, finding_plain_1.plainText)(finding.title)}** — ${(0, finding_plain_1.plainText)(finding.body)}\n ${text.fix}: ${(0, finding_plain_1.plainText)(finding.fix)}`),
|
|
72
74
|
].join('\n');
|
|
73
75
|
lines.push('', details(text.prDetails, rest));
|
|
74
76
|
return `${lines.join('\n')}\n`;
|
|
@@ -43,15 +43,15 @@ const renderSarif = (report) => {
|
|
|
43
43
|
return {
|
|
44
44
|
id: kind,
|
|
45
45
|
name: kind,
|
|
46
|
-
shortDescription: { text: example
|
|
47
|
-
fullDescription: { text: example
|
|
46
|
+
shortDescription: { text: example ? (0, finding_plain_1.plainText)(example.chip) : kind },
|
|
47
|
+
fullDescription: { text: example ? (0, finding_plain_1.plainText)(example.title) : kind },
|
|
48
48
|
help: { text: example ? (0, finding_plain_1.plainText)(example.fix) : '' },
|
|
49
49
|
};
|
|
50
50
|
});
|
|
51
51
|
const results = report.findings.map(finding => ({
|
|
52
52
|
ruleId: finding.kind,
|
|
53
53
|
level: LEVEL[finding.severity],
|
|
54
|
-
message: { text: `${finding.title} — ${(0, finding_plain_1.plainText)(finding.body)}` },
|
|
54
|
+
message: { text: `${(0, finding_plain_1.plainText)(finding.title)} — ${(0, finding_plain_1.plainText)(finding.body)}` },
|
|
55
55
|
locations: [
|
|
56
56
|
{
|
|
57
57
|
physicalLocation: {
|
|
@@ -17,6 +17,7 @@ const ui_1 = require("../src/app/core/i18n/ui");
|
|
|
17
17
|
const budget_advice_1 = require("../src/app/core/project/budget-advice");
|
|
18
18
|
const timing_1 = require("../src/app/core/timing/timing");
|
|
19
19
|
const gates_1 = require("./gates");
|
|
20
|
+
const since_last_1 = require("./since-last");
|
|
20
21
|
const text_1 = require("./text");
|
|
21
22
|
const WIDTH = 96;
|
|
22
23
|
const ESC = String.fromCodePoint(27);
|
|
@@ -88,12 +89,16 @@ const firstTripLines = (report, palette) => {
|
|
|
88
89
|
const text = text_1.CLI_TEXT[report.lang];
|
|
89
90
|
const trip = report.assets?.firstTrip;
|
|
90
91
|
if (trip && trip.total > 0) {
|
|
92
|
+
// The parts that are there: "0 B fonts" is a part of nothing.
|
|
91
93
|
const parts = [
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
]
|
|
94
|
+
[trip.scripts, 'JS'],
|
|
95
|
+
[trip.styles, 'CSS'],
|
|
96
|
+
[trip.fonts, text.tripFonts],
|
|
97
|
+
[trip.images, text.tripImages],
|
|
98
|
+
]
|
|
99
|
+
.filter(([bytes]) => bytes > 0)
|
|
100
|
+
.map(([bytes, label]) => `${(0, format_utils_1.formatBytes)(bytes)} ${label}`)
|
|
101
|
+
.join(' + ');
|
|
97
102
|
return [palette.warn(text.firstTrip((0, format_utils_1.formatBytes)(trip.total), trip.files, parts))];
|
|
98
103
|
}
|
|
99
104
|
if (report.pageCssBytes === null) {
|
|
@@ -114,8 +119,14 @@ const screensTable = (report, palette) => {
|
|
|
114
119
|
{ head: strings.colTotal, right: true },
|
|
115
120
|
{ head: strings.colWaves, right: true },
|
|
116
121
|
];
|
|
117
|
-
|
|
118
|
-
|
|
122
|
+
// Against the explicit baseline when there is one; otherwise against the last run, so the table
|
|
123
|
+
// says which screen moved without anybody having asked for a comparison.
|
|
124
|
+
const against = comparison ?? report.sinceLast;
|
|
125
|
+
if (against) {
|
|
126
|
+
columns.push({
|
|
127
|
+
head: comparison ? `${strings.colDelta} ${comparison.baselineName}` : strings.colDelta,
|
|
128
|
+
right: true,
|
|
129
|
+
});
|
|
119
130
|
}
|
|
120
131
|
const rows = analysis.screens.map(screen => {
|
|
121
132
|
const verdict = (0, criteria_1.rate)(screen.total, criteria.screenOk, criteria.screenBad);
|
|
@@ -127,8 +138,8 @@ const screensTable = (report, palette) => {
|
|
|
127
138
|
verdictPaint(palette, verdict)((0, format_utils_1.formatBytes)(screen.total)),
|
|
128
139
|
String(screen.waves),
|
|
129
140
|
];
|
|
130
|
-
if (
|
|
131
|
-
const delta =
|
|
141
|
+
if (against) {
|
|
142
|
+
const delta = against.screens.get(screen.source);
|
|
132
143
|
cells.push(delta ? (0, format_utils_1.formatDelta)(delta.total.diff) : strings.compareNew);
|
|
133
144
|
}
|
|
134
145
|
return cells;
|
|
@@ -136,11 +147,17 @@ const screensTable = (report, palette) => {
|
|
|
136
147
|
return table(columns, rows, palette);
|
|
137
148
|
};
|
|
138
149
|
const signalBlock = (finding, palette, fixLabel) => {
|
|
139
|
-
const head = severityPaint(palette, finding.severity)(`${finding.severity.padEnd(4)} · ${finding.chip}`);
|
|
150
|
+
const head = severityPaint(palette, finding.severity)(`${finding.severity.padEnd(4)} · ${(0, finding_plain_1.plainText)(finding.chip)}`);
|
|
140
151
|
const indent = (line) => ` ${line}`;
|
|
141
152
|
const body = wrap((0, finding_plain_1.plainText)(finding.body), WIDTH - 6).map(element => indent(element));
|
|
142
153
|
const fix = finding.fix ? wrap(`${fixLabel}: ${(0, finding_plain_1.plainText)(finding.fix)}`, WIDTH - 6).map(l => indent(l)) : [];
|
|
143
|
-
return [
|
|
154
|
+
return [
|
|
155
|
+
'',
|
|
156
|
+
` ${head}`,
|
|
157
|
+
` ${palette.bold((0, finding_plain_1.plainText)(finding.title))}`,
|
|
158
|
+
...body,
|
|
159
|
+
...(fix.length > 0 ? ['', ...fix] : []),
|
|
160
|
+
];
|
|
144
161
|
};
|
|
145
162
|
/**
|
|
146
163
|
* What to fix first: the signals ranked by bytes per unit of effort, then what doing all of it is
|
|
@@ -156,16 +173,20 @@ const actionsBlock = (report, palette) => {
|
|
|
156
173
|
// equal jobs, and the eye has to go down to Signals to learn that the fourth is an `info`
|
|
157
174
|
// and the first is not. The saving cell stays plain on purpose: one colour per row, or the
|
|
158
175
|
// colour stops meaning anything.
|
|
176
|
+
const scale = (0, actions_1.unitScale)(report.analysis);
|
|
159
177
|
const rows = actions.map((action, index) => [
|
|
160
178
|
`${index + 1}.`,
|
|
161
|
-
severityPaint(palette, action.finding.severity)(action.finding.title),
|
|
162
|
-
text.savingCell(action.saving > 0 ? (0,
|
|
179
|
+
severityPaint(palette, action.finding.severity)((0, finding_plain_1.plainText)(action.finding.title)),
|
|
180
|
+
text.savingCell(action.saving > 0 ? (0, actions_1.formatSaving)(action.saving, scale) : ''),
|
|
163
181
|
text.effortLabel[action.effort],
|
|
164
182
|
]);
|
|
165
183
|
const total = (0, actions_1.totalSaving)(report.analysis, report.findings);
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
184
|
+
// Said only when there is a figure. "No signal here names a saving that can be measured" under
|
|
185
|
+
// a table whose saving column is all dashes repeated what the column had already said.
|
|
186
|
+
const words = (0, actions_1.savingWords)(report.analysis, total);
|
|
187
|
+
const summary = total.counted > 0 && total.bytes > 0
|
|
188
|
+
? text.totalSaving(words.saving, words.after, total.counted, words.estimated)
|
|
189
|
+
: null;
|
|
169
190
|
return [
|
|
170
191
|
'',
|
|
171
192
|
palette.bold(text.headActions),
|
|
@@ -176,8 +197,7 @@ const actionsBlock = (report, palette) => {
|
|
|
176
197
|
{ head: text.colSaving, right: true },
|
|
177
198
|
{ head: text.colEffort, right: false },
|
|
178
199
|
], rows, palette),
|
|
179
|
-
'',
|
|
180
|
-
...wrap(summary, WIDTH).map(line => palette.dim(line)),
|
|
200
|
+
...(summary ? ['', ...wrap(summary, WIDTH).map(line => palette.dim(line))] : []),
|
|
181
201
|
];
|
|
182
202
|
};
|
|
183
203
|
/**
|
|
@@ -224,14 +244,15 @@ const budgetBlock = (report, palette) => {
|
|
|
224
244
|
// `--project` there is nothing to say a budget is missing from.
|
|
225
245
|
const asking = new Set(['budgetNone', 'budgetTooHigh', 'budgetWarnOnly']);
|
|
226
246
|
const wanted = report.findings.some(finding => asking.has(finding.kind));
|
|
227
|
-
const advice = wanted ? (0, budget_advice_1.budgetAdvice)(report.analysis.
|
|
247
|
+
const advice = wanted ? (0, budget_advice_1.budgetAdvice)(report.analysis.initialRawBytes) : null;
|
|
228
248
|
if (!advice) {
|
|
229
249
|
return [];
|
|
230
250
|
}
|
|
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`
|
|
233
|
-
|
|
234
|
-
const
|
|
251
|
+
// The second budget, for a build that has screens: `anyScript` applies to every emitted file —
|
|
252
|
+
// the bootstrap's too — which is what makes it useful when the names carry hashes and `bundle`
|
|
253
|
+
// budgets cannot, and why it is set above the largest script and not above a screen.
|
|
254
|
+
const largest = report.analysis.largestScript;
|
|
255
|
+
const perScreen = report.analysis.screens.length > 0 && largest ? (0, budget_advice_1.screenBudgetAdvice)(largest.bytes) : null;
|
|
235
256
|
return [
|
|
236
257
|
'',
|
|
237
258
|
palette.bold(text.headBudget),
|
|
@@ -241,7 +262,7 @@ const budgetBlock = (report, palette) => {
|
|
|
241
262
|
...(perScreen
|
|
242
263
|
? [
|
|
243
264
|
'',
|
|
244
|
-
...wrap(text.screenBudgetNote(`${perScreen.warningKb}kB
|
|
265
|
+
...wrap(text.screenBudgetNote(`${perScreen.warningKb}kB`, largest?.name ?? '', (0, format_utils_1.formatBytes)(perScreen.currentBytes)), WIDTH).map(line => palette.dim(line)),
|
|
245
266
|
...perScreen.snippet.split('\n').map(line => ` ${line}`),
|
|
246
267
|
]
|
|
247
268
|
: []),
|
|
@@ -284,17 +305,19 @@ const whatIfBlock = (report, palette) => {
|
|
|
284
305
|
return [];
|
|
285
306
|
}
|
|
286
307
|
const text = text_1.CLI_TEXT[report.lang];
|
|
308
|
+
// In the report's unit, like the headline above it: see `unitScale`.
|
|
309
|
+
const scale = (0, actions_1.unitScale)(report.analysis);
|
|
287
310
|
const rows = report.whatIf.map(result => [
|
|
288
311
|
result.target,
|
|
289
|
-
(0,
|
|
290
|
-
palette.bold((0,
|
|
291
|
-
(0,
|
|
312
|
+
(0, actions_1.formatSaving)(result.weight, scale),
|
|
313
|
+
palette.bold((0, actions_1.formatSaving)(result.saved, scale)),
|
|
314
|
+
(0, actions_1.formatRemaining)(report.analysis, result.saved, result.after),
|
|
292
315
|
result.screens.length > 0 ? result.screens.join(', ') : text.whatIfNobody,
|
|
293
316
|
]);
|
|
294
317
|
return [
|
|
295
318
|
'',
|
|
296
319
|
palette.bold(text.headWhatIf),
|
|
297
|
-
...wrap(text.whatIfNote, WIDTH).map(line => palette.dim(line)),
|
|
320
|
+
...wrap(scale.estimated ? `${text.whatIfNote} ${text.whatIfEstimated}` : text.whatIfNote, WIDTH).map(line => palette.dim(line)),
|
|
298
321
|
...table([
|
|
299
322
|
{ head: text.colWhatIf, right: false },
|
|
300
323
|
{ head: text.colSize, right: true },
|
|
@@ -333,6 +356,13 @@ const header = (report, palette) => {
|
|
|
333
356
|
if (report.comparisonBlocked) {
|
|
334
357
|
lines.push(palette.warn(text.blocked));
|
|
335
358
|
}
|
|
359
|
+
if (report.located.length > 0) {
|
|
360
|
+
lines.push(palette.dim(text.located(report.located.join(' + '))));
|
|
361
|
+
}
|
|
362
|
+
const since = (0, since_last_1.sinceLastLine)(report);
|
|
363
|
+
if (since) {
|
|
364
|
+
lines.push(palette.bold(since));
|
|
365
|
+
}
|
|
336
366
|
if (report.analysis.splitSource === 'sourcemap') {
|
|
337
367
|
lines.push(palette.dim(text.exactSplit));
|
|
338
368
|
}
|
|
@@ -346,6 +376,11 @@ const header = (report, palette) => {
|
|
|
346
376
|
if (report.analysis.serverOutputs > 0) {
|
|
347
377
|
lines.push(palette.dim(text.serverLeftOut(report.analysis.serverOutputs)));
|
|
348
378
|
}
|
|
379
|
+
// And the other reason the metafile names files the folder does not hold. Said once, so the
|
|
380
|
+
// difference between the two is explained rather than left for somebody to count by hand.
|
|
381
|
+
if (report.analysis.componentStyles > 0) {
|
|
382
|
+
lines.push(palette.dim(text.componentStyles(report.analysis.componentStyles)));
|
|
383
|
+
}
|
|
349
384
|
return lines;
|
|
350
385
|
};
|
|
351
386
|
const renderText = (report, violations, anyAsked, color) => {
|
package/dist/cli/cli/report.js
CHANGED
|
@@ -83,7 +83,7 @@ const comparisonOf = (input, shown, raw, mode, findings) => {
|
|
|
83
83
|
const buildReport = (input, options) => {
|
|
84
84
|
const mode = resolveMode(input, options.mode);
|
|
85
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
|
|
86
|
+
const exact = (0, sourcemap_1.resolveSplits)(input.splits, Object.keys(input.meta.inputs));
|
|
87
87
|
const lang = options.lang;
|
|
88
88
|
const criteria = resolveCriteria(mode, input.config, input.criteria);
|
|
89
89
|
// The language only decides the decimal separator, and it is set before anything is formatted.
|
|
@@ -130,7 +130,7 @@ const buildReport = (input, options) => {
|
|
|
130
130
|
// drifted: the one the snapshot kept was missing caching, scan and deps, so a `devLeftovers`
|
|
131
131
|
// somebody had actually fixed could never show as gone, and a page export — which does carry
|
|
132
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);
|
|
133
|
+
const base = (0, findings_1.buildFindings)(analysis, lang, mode, criteria, situation, input.declared ?? null);
|
|
134
134
|
const fromContext = (0, findings_1.buildContextFindings)(input.context, analysis, lang, criteria);
|
|
135
135
|
const fromBuild = [
|
|
136
136
|
...(0, shipped_1.buildFolderFindings)({
|
|
@@ -139,7 +139,7 @@ const buildReport = (input, options) => {
|
|
|
139
139
|
screens: analysis.screens.map(s => s.label),
|
|
140
140
|
drift: analysis.splitDrift,
|
|
141
141
|
}, lang),
|
|
142
|
-
...(input.assets ? (0, assets_1.buildAssetFindings)(input.assets, lang, criteria) : []),
|
|
142
|
+
...(input.assets ? (0, assets_1.buildAssetFindings)(input.assets, lang, criteria, input.assetSources ?? null, true) : []),
|
|
143
143
|
...(0, page_1.buildPageFindings)(input.pageOrigins ?? null, lang),
|
|
144
144
|
...(0, caching_1.buildCachingFindings)(caching, lang, criteria, situation),
|
|
145
145
|
...(scan ? (0, scan_1.buildScanFindings)(scan, lang, criteria) : []),
|
|
@@ -151,6 +151,10 @@ const buildReport = (input, options) => {
|
|
|
151
151
|
// costs a walk over lists that are already in memory, and having it here is what keeps the
|
|
152
152
|
// exported file and the compared-against file the same shape by construction.
|
|
153
153
|
const snapshot = (0, baseline_1.snapshotOf)(analysis, mode, input.statsName, new Date(), own);
|
|
154
|
+
// The last run, when it was in the same unit: a gzip figure against a raw one would read as a
|
|
155
|
+
// saving that never happened, which is the rule the explicit baseline follows too.
|
|
156
|
+
const last = input.lastRun ?? null;
|
|
157
|
+
const sinceLast = last?.mode === mode ? (0, baseline_1.compare)(snapshot, last) : null;
|
|
154
158
|
const composed = (0, compose_1.composeFindings)({
|
|
155
159
|
base,
|
|
156
160
|
fromComparison: comparison ? (0, findings_1.buildComparisonFindings)(comparison, lang, criteria) : [],
|
|
@@ -186,6 +190,8 @@ const buildReport = (input, options) => {
|
|
|
186
190
|
analysis,
|
|
187
191
|
comparison,
|
|
188
192
|
comparisonBlocked: blocked,
|
|
193
|
+
sinceLast,
|
|
194
|
+
located: [],
|
|
189
195
|
findings: kept,
|
|
190
196
|
accepted,
|
|
191
197
|
config: input.config ?? null,
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The line that answers "did that change help?": what moved since the last run of the same build,
|
|
4
|
+
* remembered in `node_modules/.cache/loadline` without anybody passing a `--baseline`.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.sinceLastLine = void 0;
|
|
8
|
+
const format_utils_1 = require("../src/app/core/format/format.utils");
|
|
9
|
+
const ui_1 = require("../src/app/core/i18n/ui");
|
|
10
|
+
const text_1 = require("./text");
|
|
11
|
+
/**
|
|
12
|
+
* What moved since the last run of this build, in one line: "bootstrap 156 kB → 129 kB (−27 kB)",
|
|
13
|
+
* then the screens that changed. `null` when there is nothing to compare against.
|
|
14
|
+
*/
|
|
15
|
+
const sinceLastLine = (report) => {
|
|
16
|
+
const since = report.sinceLast;
|
|
17
|
+
if (!since) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const text = text_1.CLI_TEXT[report.lang];
|
|
21
|
+
const strings = ui_1.UI[report.lang];
|
|
22
|
+
// What each screen adds on top of the bootstrap: a bootstrap that shrank moves every screen's
|
|
23
|
+
// total by the same amount, and listing that once per screen repeats the first figure.
|
|
24
|
+
const moved = [...since.screens.values()].filter(screen => screen.lazy.diff !== 0);
|
|
25
|
+
const parts = [
|
|
26
|
+
...(since.boot.diff === 0
|
|
27
|
+
? []
|
|
28
|
+
: [
|
|
29
|
+
`${strings.tabBoot.toLowerCase()} ${(0, format_utils_1.formatBytes)(since.boot.before)} → ${(0, format_utils_1.formatBytes)(since.boot.after)} (${(0, format_utils_1.formatDelta)(since.boot.diff)})`,
|
|
30
|
+
]),
|
|
31
|
+
...moved
|
|
32
|
+
.toSorted((a, b) => Math.abs(b.lazy.diff) - Math.abs(a.lazy.diff))
|
|
33
|
+
.slice(0, 3)
|
|
34
|
+
.map(screen => `${screen.label} ${(0, format_utils_1.formatDelta)(screen.lazy.diff)}`),
|
|
35
|
+
...(moved.length > 3 ? [`+${moved.length - 3}`] : []),
|
|
36
|
+
];
|
|
37
|
+
// Local time: it is the person's own last run, on their own machine.
|
|
38
|
+
const when = new Date(since.baselineDate);
|
|
39
|
+
const two = (value) => String(value).padStart(2, '0');
|
|
40
|
+
const date = Number.isNaN(when.getTime())
|
|
41
|
+
? since.baselineDate
|
|
42
|
+
: `${when.getFullYear()}-${two(when.getMonth() + 1)}-${two(when.getDate())} ${two(when.getHours())}:${two(when.getMinutes())}`;
|
|
43
|
+
return text.sinceLast(date, parts.length > 0 ? parts.join(' · ') : text.lastRunUnchanged);
|
|
44
|
+
};
|
|
45
|
+
exports.sinceLastLine = sinceLastLine;
|