@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.
- package/LICENSE +21 -0
- package/README.md +182 -0
- package/bin/loadline.js +50 -0
- package/dist/cli/cli/args.js +324 -0
- package/dist/cli/cli/args.types.js +3 -0
- package/dist/cli/cli/gates.js +173 -0
- package/dist/cli/cli/gates.types.js +3 -0
- package/dist/cli/cli/main.js +156 -0
- package/dist/cli/cli/read-build.js +382 -0
- package/dist/cli/cli/read-build.types.js +3 -0
- package/dist/cli/cli/render-json.js +116 -0
- package/dist/cli/cli/render-json.types.js +10 -0
- package/dist/cli/cli/render-markdown.js +30 -0
- package/dist/cli/cli/render-pr.js +76 -0
- package/dist/cli/cli/render-sarif.js +83 -0
- package/dist/cli/cli/render-text.js +388 -0
- package/dist/cli/cli/report.js +196 -0
- package/dist/cli/cli/report.types.js +3 -0
- package/dist/cli/cli/self-check.js +85 -0
- package/dist/cli/cli/text.js +180 -0
- package/dist/cli/cli/text.types.js +10 -0
- package/dist/cli/src/app/core/analysis/analysis.js +661 -0
- package/dist/cli/src/app/core/analysis/analysis.types.js +6 -0
- package/dist/cli/src/app/core/analysis/barrels.js +128 -0
- package/dist/cli/src/app/core/analysis/blast.js +172 -0
- package/dist/cli/src/app/core/analysis/cycles.js +110 -0
- package/dist/cli/src/app/core/analysis/delivery.js +143 -0
- package/dist/cli/src/app/core/analysis/entries.js +217 -0
- package/dist/cli/src/app/core/analysis/exclusive.js +91 -0
- package/dist/cli/src/app/core/analysis/importers.js +38 -0
- package/dist/cli/src/app/core/analysis/insights.js +202 -0
- package/dist/cli/src/app/core/analysis/insights.types.js +10 -0
- package/dist/cli/src/app/core/analysis/invariant.js +69 -0
- package/dist/cli/src/app/core/analysis/metafile.types.js +44 -0
- package/dist/cli/src/app/core/analysis/module-graph.js +192 -0
- package/dist/cli/src/app/core/analysis/sourcemap.js +231 -0
- package/dist/cli/src/app/core/analysis/sourcemap.types.js +3 -0
- package/dist/cli/src/app/core/analysis/split-drift.js +47 -0
- package/dist/cli/src/app/core/assets/assets.js +296 -0
- package/dist/cli/src/app/core/assets/assets.types.js +11 -0
- package/dist/cli/src/app/core/baseline/baseline.js +0 -0
- package/dist/cli/src/app/core/baseline/baseline.types.js +3 -0
- package/dist/cli/src/app/core/caching/caching.js +241 -0
- package/dist/cli/src/app/core/caching/caching.types.js +10 -0
- package/dist/cli/src/app/core/caching/from-analysis.js +73 -0
- package/dist/cli/src/app/core/config/loadline-config.js +110 -0
- package/dist/cli/src/app/core/config/loadline-config.types.js +12 -0
- package/dist/cli/src/app/core/criteria/criteria.js +228 -0
- package/dist/cli/src/app/core/criteria/criteria.types.js +3 -0
- package/dist/cli/src/app/core/deps/deps.js +225 -0
- package/dist/cli/src/app/core/deps/deps.types.js +15 -0
- package/dist/cli/src/app/core/export/markdown-table.utils.js +40 -0
- package/dist/cli/src/app/core/export/summary.js +72 -0
- package/dist/cli/src/app/core/findings/actions.js +59 -0
- package/dist/cli/src/app/core/findings/assets.js +130 -0
- package/dist/cli/src/app/core/findings/caching.js +165 -0
- package/dist/cli/src/app/core/findings/compose.js +41 -0
- package/dist/cli/src/app/core/findings/deps.js +66 -0
- package/dist/cli/src/app/core/findings/effort.js +117 -0
- package/dist/cli/src/app/core/findings/finding-html.js +13 -0
- package/dist/cli/src/app/core/findings/finding-plain.js +26 -0
- package/dist/cli/src/app/core/findings/finding-text.js +1231 -0
- package/dist/cli/src/app/core/findings/finding.types.js +80 -0
- package/dist/cli/src/app/core/findings/findings.js +514 -0
- package/dist/cli/src/app/core/findings/graph.js +167 -0
- package/dist/cli/src/app/core/findings/own-in-boot.js +88 -0
- package/dist/cli/src/app/core/findings/page.js +49 -0
- package/dist/cli/src/app/core/findings/requests.js +185 -0
- package/dist/cli/src/app/core/findings/scan.js +126 -0
- package/dist/cli/src/app/core/findings/shipped.js +244 -0
- package/dist/cli/src/app/core/findings/situation.js +116 -0
- package/dist/cli/src/app/core/format/format.utils.js +204 -0
- package/dist/cli/src/app/core/i18n/en.js +819 -0
- package/dist/cli/src/app/core/i18n/es.js +822 -0
- package/dist/cli/src/app/core/i18n/ui-strings.js +11 -0
- package/dist/cli/src/app/core/i18n/ui.js +7 -0
- package/dist/cli/src/app/core/intake/bundle-graph.js +346 -0
- package/dist/cli/src/app/core/intake/bundle-graph.types.js +3 -0
- package/dist/cli/src/app/core/intake/dist-files.js +160 -0
- package/dist/cli/src/app/core/intake/index-html.js +292 -0
- package/dist/cli/src/app/core/json/json.utils.js +55 -0
- package/dist/cli/src/app/core/measurement/measurement.types.js +14 -0
- package/dist/cli/src/app/core/project/budget-advice.js +76 -0
- package/dist/cli/src/app/core/project/project-context.js +394 -0
- package/dist/cli/src/app/core/project/project-context.types.js +3 -0
- package/dist/cli/src/app/core/scan/catalog.js +67 -0
- package/dist/cli/src/app/core/scan/scan.js +280 -0
- package/dist/cli/src/app/core/scan/scan.types.js +10 -0
- package/dist/cli/src/app/core/scan/secrets.js +0 -0
- package/dist/cli/src/app/core/situation/situation.js +261 -0
- package/dist/cli/src/app/core/situation/situation.types.js +19 -0
- package/dist/cli/src/app/core/timing/timing.js +87 -0
- package/dist/cli/src/app/core/timing/timing.types.js +3 -0
- package/dist/cli/src/app/core/whatif/defer.js +68 -0
- package/dist/cli/src/app/state/report-messages.utils.js +73 -0
- package/docs/HOW-IT-WORKS.md +1087 -0
- package/loadline.html +78 -0
- package/package.json +154 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FINDING_KINDS = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Which signal a finding is, as a key that does not move when the wording does.
|
|
6
|
+
*
|
|
7
|
+
* The chip and the title are copy: they get reworded, and they exist in two languages. Anything
|
|
8
|
+
* that acts on a signal — a bot on a merge request, the checks that read builds nine frameworks
|
|
9
|
+
* wrote — needs to name it without depending on either, and this is that name. It is also what
|
|
10
|
+
* makes "this build raises this signal" a thing a test can assert.
|
|
11
|
+
*/
|
|
12
|
+
exports.FINDING_KINDS = [
|
|
13
|
+
'shared',
|
|
14
|
+
'bootLazy',
|
|
15
|
+
'bigFile',
|
|
16
|
+
'dupes',
|
|
17
|
+
'heavy',
|
|
18
|
+
'clean',
|
|
19
|
+
'commonJs',
|
|
20
|
+
'ownInBoot',
|
|
21
|
+
'locales',
|
|
22
|
+
'dataAsCode',
|
|
23
|
+
'sourceMaps',
|
|
24
|
+
'noSourceMaps',
|
|
25
|
+
'splitDrift',
|
|
26
|
+
'prefetched',
|
|
27
|
+
'unreachable',
|
|
28
|
+
'mixedImport',
|
|
29
|
+
'ownBarrel',
|
|
30
|
+
'packageBarrel',
|
|
31
|
+
'cycles',
|
|
32
|
+
'paidTwice',
|
|
33
|
+
'twinScreens',
|
|
34
|
+
'theirs',
|
|
35
|
+
'fonts',
|
|
36
|
+
'media',
|
|
37
|
+
'duplicateAssets',
|
|
38
|
+
'unreferencedAssets',
|
|
39
|
+
'inlinedData',
|
|
40
|
+
'updateWeight',
|
|
41
|
+
'unstableChunk',
|
|
42
|
+
'unhashable',
|
|
43
|
+
'secrets',
|
|
44
|
+
'devLeftovers',
|
|
45
|
+
'sourceExposed',
|
|
46
|
+
'thirdParty',
|
|
47
|
+
'licences',
|
|
48
|
+
'vulnerable',
|
|
49
|
+
'transitive',
|
|
50
|
+
'bootWaves',
|
|
51
|
+
'slowScreens',
|
|
52
|
+
'manyRequests',
|
|
53
|
+
'bootGrew',
|
|
54
|
+
'bootNewPackages',
|
|
55
|
+
'sharedGrew',
|
|
56
|
+
'signalsChanged',
|
|
57
|
+
'screensGrew',
|
|
58
|
+
'budgetNone',
|
|
59
|
+
'budgetNotBuilt',
|
|
60
|
+
'budgetWarnOnly',
|
|
61
|
+
'budgetTooHigh',
|
|
62
|
+
'zoneless',
|
|
63
|
+
'assetOrigin',
|
|
64
|
+
'cascadeShape',
|
|
65
|
+
'servedUncompressed',
|
|
66
|
+
'measuredWaves',
|
|
67
|
+
'poolExhausted',
|
|
68
|
+
'thirdPartyLoad',
|
|
69
|
+
'revalidated',
|
|
70
|
+
'swControlling',
|
|
71
|
+
'measuredOrigin',
|
|
72
|
+
'observedChannel',
|
|
73
|
+
'measuredEager',
|
|
74
|
+
'measuredExtra',
|
|
75
|
+
'measuredShort',
|
|
76
|
+
'measuredMatch',
|
|
77
|
+
'situationAsked',
|
|
78
|
+
'situationPriority',
|
|
79
|
+
'situationMissing',
|
|
80
|
+
];
|
|
@@ -0,0 +1,514 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildMeasurementFindings = exports.buildContextFindings = exports.buildComparisonFindings = exports.buildFindings = void 0;
|
|
4
|
+
const criteria_1 = require("../criteria/criteria");
|
|
5
|
+
const format_utils_1 = require("../format/format.utils");
|
|
6
|
+
const project_context_1 = require("../project/project-context");
|
|
7
|
+
const situation_1 = require("../situation/situation");
|
|
8
|
+
const caching_1 = require("./caching");
|
|
9
|
+
const finding_html_1 = require("./finding-html");
|
|
10
|
+
const finding_text_1 = require("./finding-text");
|
|
11
|
+
const graph_1 = require("./graph");
|
|
12
|
+
const own_in_boot_1 = require("./own-in-boot");
|
|
13
|
+
const requests_1 = require("./requests");
|
|
14
|
+
const shipped_1 = require("./shipped");
|
|
15
|
+
const unitText = (lang, mode) => {
|
|
16
|
+
if (lang === 'es') {
|
|
17
|
+
return mode === 'raw' ? 'en crudo' : mode === 'brotli' ? 'comprimidas en brotli' : 'comprimidas en gzip';
|
|
18
|
+
}
|
|
19
|
+
return mode === 'raw' ? 'raw' : mode === 'brotli' ? 'brotli-compressed' : 'gzip-compressed';
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* @param c the thresholds of every signal: the recommended ones (`RECOMMENDED`) or the ones the
|
|
23
|
+
* person has set. They are defined in `criteria.ts`, in one place, so they can be discussed
|
|
24
|
+
* and edited.
|
|
25
|
+
*/
|
|
26
|
+
const buildFindings = (analysis, lang, mode, c = criteria_1.RECOMMENDED[mode],
|
|
27
|
+
/**
|
|
28
|
+
* What the team answered about the world this build ships into. It reaches exactly one signal
|
|
29
|
+
* from here — the shape of the hash cascade, whose severity is not a property of the build —
|
|
30
|
+
* and it defaults to nobody having answered, which is what every caller did before it existed.
|
|
31
|
+
*/
|
|
32
|
+
situation = situation_1.EMPTY_SITUATION) => {
|
|
33
|
+
const text = finding_text_1.TEXT[lang];
|
|
34
|
+
const findings = [];
|
|
35
|
+
const totalScreens = analysis.screens.length;
|
|
36
|
+
// The exclusive weight of every bucket, so the signals that name one can say what removing it
|
|
37
|
+
// is actually worth rather than what it weighs. The two differ whenever anything is shared.
|
|
38
|
+
const insights = analysis.insights();
|
|
39
|
+
const filesOf = (bucket) => insights.filesByBucket.get(bucket) ?? [];
|
|
40
|
+
// 1 · A "lazy" chunk that almost everybody actually pays for.
|
|
41
|
+
const worst = analysis.sharedChunks
|
|
42
|
+
.filter(chunk => totalScreens > 0 && chunk.screens >= totalScreens * c.sharedRatio)
|
|
43
|
+
.toSorted((a, b) => b.bytes - a.bytes)[0];
|
|
44
|
+
if (worst && worst.bytes > c.sharedMinBytes) {
|
|
45
|
+
findings.push({
|
|
46
|
+
severity: 'high',
|
|
47
|
+
target: { tab: 'shared', key: worst.file },
|
|
48
|
+
kind: 'shared',
|
|
49
|
+
...text.shared({
|
|
50
|
+
size: (0, format_utils_1.formatBytes)(worst.bytes),
|
|
51
|
+
screens: worst.screens,
|
|
52
|
+
total: totalScreens,
|
|
53
|
+
chunk: worst.name,
|
|
54
|
+
top: worst.mainContent,
|
|
55
|
+
}),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
// 2 · Bootstrap package whose real consumer is in a lazy screen.
|
|
59
|
+
// Few importers is NOT enough: the visual theme is also imported by a single file and it
|
|
60
|
+
// IS needed before painting. What identifies the candidate is where its consumer is.
|
|
61
|
+
const lazySources = new Set(analysis.screens.map(screen => screen.source));
|
|
62
|
+
const candidates = analysis.bootBuckets.filter(bucket => !bucket.isProjectCode && bucket.bytes >= c.bootPackageMinBytes);
|
|
63
|
+
for (const bucket of candidates) {
|
|
64
|
+
const importers = analysis.packageImporters.get(bucket.name);
|
|
65
|
+
if (!importers || importers.size > c.bootPackageMaxImporters) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const inLazyScreens = [...importers].filter(file => lazySources.has(file));
|
|
69
|
+
if (inLazyScreens.length === 0) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
// The chain says which import puts it in the bootstrap; its last own file is the one to edit.
|
|
73
|
+
const chain = analysis.bootChains.get(bucket.name) ?? null;
|
|
74
|
+
const entry = chain?.toReversed().find(file => !(0, format_utils_1.packageOf)(file)) ?? null;
|
|
75
|
+
// The routes files lazy-loading those screens: where the providers go.
|
|
76
|
+
const routes = [...new Set(inLazyScreens.flatMap(file => analysis.screenLoaders.get(file) ?? []))];
|
|
77
|
+
findings.push({
|
|
78
|
+
severity: 'high',
|
|
79
|
+
target: { tab: 'boot', key: bucket.name },
|
|
80
|
+
kind: 'bootLazy',
|
|
81
|
+
saving: insights.exclusive.get(bucket.name) ?? 0,
|
|
82
|
+
sources: filesOf(bucket.name),
|
|
83
|
+
...text.bootLazy({
|
|
84
|
+
pkg: bucket.name,
|
|
85
|
+
size: (0, format_utils_1.formatBytes)(bucket.bytes),
|
|
86
|
+
files: importers.size,
|
|
87
|
+
screens: inLazyScreens.map(file => (0, finding_html_1.mono)((0, format_utils_1.baseName)(file))).join(', '),
|
|
88
|
+
chain: chain ? (0, finding_html_1.chainHtml)((0, format_utils_1.chainSteps)(chain)) : null,
|
|
89
|
+
entry,
|
|
90
|
+
routes: routes.length > 0 ? routes.map(file => (0, finding_html_1.mono)(file)).join(', ') : null,
|
|
91
|
+
}),
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
// 3 · Own files too large inside the bootstrap: one signal listing all of them, no cut-off.
|
|
95
|
+
const bigFiles = analysis.ownFilesInBoot.filter(file => file.bytes > c.bigOwnFileBytes);
|
|
96
|
+
const first = bigFiles[0];
|
|
97
|
+
if (first) {
|
|
98
|
+
findings.push({
|
|
99
|
+
severity: 'mid',
|
|
100
|
+
target: { tab: 'boot', key: (0, format_utils_1.projectFolderOf)(first.path) },
|
|
101
|
+
kind: 'bigFile',
|
|
102
|
+
saving: insights.exclusiveOf(bigFiles.map(file => file.path)),
|
|
103
|
+
sources: bigFiles.map(file => file.path),
|
|
104
|
+
...text.bigFile({
|
|
105
|
+
count: bigFiles.length,
|
|
106
|
+
each: (0, format_utils_1.formatBytes)(c.bigOwnFileBytes),
|
|
107
|
+
name: (0, format_utils_1.baseName)(first.path),
|
|
108
|
+
size: (0, format_utils_1.formatBytes)(bigFiles.reduce((sum, file) => sum + file.bytes, 0)),
|
|
109
|
+
list: bigFiles.map(file => `${(0, finding_html_1.mono)(file.path)} (${(0, format_utils_1.formatBytes)(file.bytes)})`).join(' · '),
|
|
110
|
+
}),
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
// 4 · Two versions of the same package, each copy followed to whatever brings it in. Knowing
|
|
114
|
+
// there are two says nothing about what to do: the fix depends on where each one comes from.
|
|
115
|
+
const firstDupe = analysis.duplicates[0];
|
|
116
|
+
if (firstDupe) {
|
|
117
|
+
const list = analysis.duplicates
|
|
118
|
+
.map(dupe => {
|
|
119
|
+
const copies = dupe.copies
|
|
120
|
+
.map(copy => text.dupeCopy({
|
|
121
|
+
version: copy.version,
|
|
122
|
+
under: copy.under,
|
|
123
|
+
size: (0, format_utils_1.formatBytes)(copy.bytes),
|
|
124
|
+
zone: text.dupeZone[copy.zone],
|
|
125
|
+
chain: copy.chain ? (0, finding_html_1.chainHtml)((0, format_utils_1.chainSteps)(copy.chain)) : null,
|
|
126
|
+
own: copy.importers.length > 0 ? copy.importers.map(file => (0, finding_html_1.mono)(file)).join(', ') : null,
|
|
127
|
+
via: copy.viaPackages.length > 0 ? copy.viaPackages.map(pkg => (0, finding_html_1.mono)(pkg)).join(', ') : null,
|
|
128
|
+
}))
|
|
129
|
+
.join(' ');
|
|
130
|
+
return `<strong>${dupe.name}</strong> — ${copies}`;
|
|
131
|
+
})
|
|
132
|
+
.join(' ');
|
|
133
|
+
findings.push({
|
|
134
|
+
severity: 'mid',
|
|
135
|
+
target: { tab: 'search', key: firstDupe.name },
|
|
136
|
+
kind: 'dupes',
|
|
137
|
+
...text.dupes({
|
|
138
|
+
count: analysis.duplicates.length,
|
|
139
|
+
list,
|
|
140
|
+
viaDependency: analysis.duplicates.some(dupe => dupe.copies.some(copy => copy.importers.length === 0)),
|
|
141
|
+
inBoot: analysis.duplicates.some(dupe => dupe.inBoot),
|
|
142
|
+
}),
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
// 5 · A screen much more expensive than the rest.
|
|
146
|
+
if (analysis.screens.length >= c.heavyScreenMinScreens) {
|
|
147
|
+
const owns = analysis.screens.map(screen => screen.own).toSorted((a, b) => a - b);
|
|
148
|
+
const median = owns[Math.floor(owns.length / 2)] ?? 0;
|
|
149
|
+
const heavy = analysis.screens.filter(screen => median > 0 && screen.own > median * c.heavyScreenFactor && screen.own > c.heavyScreenMinBytes);
|
|
150
|
+
// One finding, not one per screen: on a real application — immich, 166 screens — a loop
|
|
151
|
+
// meant fifty-eight identical-looking cards in a row, which buries every other signal
|
|
152
|
+
// there is. One card, and **all** of them named inside it: grouping is what makes the list
|
|
153
|
+
// readable, and dropping rows is not the same thing. The worst one leads.
|
|
154
|
+
const byOwn = heavy.toSorted((a, b) => b.own - a.own);
|
|
155
|
+
const worstScreen = byOwn[0];
|
|
156
|
+
if (worstScreen) {
|
|
157
|
+
findings.push({
|
|
158
|
+
severity: 'mid',
|
|
159
|
+
target: { tab: 'screens', key: worstScreen.source },
|
|
160
|
+
kind: 'heavy',
|
|
161
|
+
...text.heavy({
|
|
162
|
+
count: byOwn.length,
|
|
163
|
+
label: worstScreen.label,
|
|
164
|
+
own: (0, format_utils_1.formatBytes)(worstScreen.own),
|
|
165
|
+
median: (0, format_utils_1.formatBytes)(median),
|
|
166
|
+
list: byOwn
|
|
167
|
+
.slice(1)
|
|
168
|
+
.map(screen => `${(0, finding_html_1.mono)(screen.label)} (${(0, format_utils_1.formatBytes)(screen.own)})`)
|
|
169
|
+
.join(', '),
|
|
170
|
+
}),
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
// 6 · What the report cannot reach, which is the one signal about the report itself.
|
|
175
|
+
const unreachable = analysis.unreachable;
|
|
176
|
+
if (unreachable.length > 0) {
|
|
177
|
+
const unreachableBytes = unreachable.reduce((sum, chunk) => sum + chunk.bytes, 0);
|
|
178
|
+
// `allChunks` is every chunk of the build, these among them, so the share is over that.
|
|
179
|
+
const allBytes = analysis.allChunks.reduce((sum, file) => sum + (analysis.chunkOf(file)?.bytes ?? 0), 0);
|
|
180
|
+
// Two service workers are a footnote; most of the build is not. The share is what decides,
|
|
181
|
+
// because "12 chunks described out of 244" is a different statement from "you also ship a
|
|
182
|
+
// service worker", and printing both the same way would bury the first.
|
|
183
|
+
const most = allBytes > 0 && unreachableBytes > allBytes * c.sharedRatio;
|
|
184
|
+
findings.push({
|
|
185
|
+
severity: most ? 'mid' : 'info',
|
|
186
|
+
kind: 'unreachable',
|
|
187
|
+
...text.unreachable({
|
|
188
|
+
count: unreachable.length,
|
|
189
|
+
total: analysis.allChunks.length,
|
|
190
|
+
size: (0, format_utils_1.formatBytes)(unreachableBytes),
|
|
191
|
+
most,
|
|
192
|
+
// All of them, heaviest first. This signal exists because a report described 12
|
|
193
|
+
// chunks of 244 without saying so; naming four of the 232 would be the same
|
|
194
|
+
// mistake one level down.
|
|
195
|
+
list: unreachable
|
|
196
|
+
.toSorted((a, b) => b.bytes - a.bytes)
|
|
197
|
+
.map(chunk => (0, finding_html_1.mono)((0, format_utils_1.baseName)(chunk.file)))
|
|
198
|
+
.join(', '),
|
|
199
|
+
}),
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
// 5a · Project code in the bootstrap whose consumer is a lazy screen: the same question
|
|
203
|
+
// signal 2 asks of npm packages, asked of project files. In `own-in-boot.ts`.
|
|
204
|
+
//
|
|
205
|
+
// 5b · What ships without being code for a screen: every language of a library, data embedded
|
|
206
|
+
// as code. Before the "clean" card on purpose — a bootstrap carrying 130 locales is not a
|
|
207
|
+
// clean breakdown. The rules are in `shipped.ts`.
|
|
208
|
+
//
|
|
209
|
+
// 5c · The one signal in requests instead of bytes: what a screen downloads in how many pieces.
|
|
210
|
+
//
|
|
211
|
+
// 5d · The eight figures that were inside the metafile and were not being read: exclusive
|
|
212
|
+
// weight, barrels, cycles, the `import()` that defers nothing, bytes paid twice, twin
|
|
213
|
+
// screens, whose code the first load is. In `graph.ts`. Its problems go here with the
|
|
214
|
+
// rest; its context — cycles nobody pays for, whose code this is — goes after "clean",
|
|
215
|
+
// because none of those makes a breakdown dirty.
|
|
216
|
+
const graph = (0, graph_1.buildGraphFindings)(analysis, lang, c);
|
|
217
|
+
const isNote = (finding) => finding.severity === 'info' || finding.severity === 'ok';
|
|
218
|
+
findings.push(...(0, own_in_boot_1.buildOwnInBootFindings)(analysis, lang, c), ...(0, shipped_1.buildShippedFindings)(analysis, lang, c), ...(0, requests_1.buildRequestFindings)(analysis, lang, c), ...(0, caching_1.buildCascadeShapeFindings)(analysis, lang, situation), ...graph.filter(finding => !isNote(finding)));
|
|
219
|
+
if (findings.length === 0) {
|
|
220
|
+
findings.push({ severity: 'ok', kind: 'clean', ...text.clean({ unit: unitText(lang, mode) }) });
|
|
221
|
+
}
|
|
222
|
+
// 6 · CommonJS packages, read from esbuild's `format` per file. A problem when everyone pays
|
|
223
|
+
// for them (bootstrap); context when only some screens do. After "clean" on purpose: a
|
|
224
|
+
// CommonJS library in one lazy screen does not make the breakdown dirty.
|
|
225
|
+
const cjs = analysis.commonJs;
|
|
226
|
+
if (cjs.length > 0) {
|
|
227
|
+
const inBoot = cjs.find(pkg => pkg.zone === 'boot');
|
|
228
|
+
findings.push({
|
|
229
|
+
severity: inBoot ? 'mid' : 'info',
|
|
230
|
+
target: inBoot ? { tab: 'boot', key: inBoot.name } : undefined,
|
|
231
|
+
kind: 'commonJs',
|
|
232
|
+
...text.commonJs({
|
|
233
|
+
count: cjs.length,
|
|
234
|
+
size: (0, format_utils_1.formatBytes)(cjs.reduce((sum, pkg) => sum + pkg.bytes, 0)),
|
|
235
|
+
items: cjs.map(pkg => ({
|
|
236
|
+
name: pkg.name,
|
|
237
|
+
size: (0, format_utils_1.formatBytes)(pkg.bytes),
|
|
238
|
+
zone: pkg.zone,
|
|
239
|
+
screens: pkg.screens,
|
|
240
|
+
importers: pkg.importers,
|
|
241
|
+
via: pkg.viaPackages,
|
|
242
|
+
})),
|
|
243
|
+
}),
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
findings.push(...graph.filter(finding => isNote(finding)));
|
|
247
|
+
return findings;
|
|
248
|
+
};
|
|
249
|
+
exports.buildFindings = buildFindings;
|
|
250
|
+
const pctOf = (ratio) => Math.round(ratio * 100);
|
|
251
|
+
/**
|
|
252
|
+
* Rows that share a value, in the order the first of each group appeared. Used where several
|
|
253
|
+
* configurations produce the very same sentence: one card that names them all, not one each.
|
|
254
|
+
*/
|
|
255
|
+
const groupBy = (rows, keyOf) => {
|
|
256
|
+
const groups = new Map();
|
|
257
|
+
for (const row of rows) {
|
|
258
|
+
const key = keyOf(row);
|
|
259
|
+
groups.set(key, [...(groups.get(key) ?? []), row]);
|
|
260
|
+
}
|
|
261
|
+
return groups;
|
|
262
|
+
};
|
|
263
|
+
const signed = format_utils_1.formatDelta;
|
|
264
|
+
/**
|
|
265
|
+
* What changed against the baseline. The bootstrap is compared on its own and the screens on
|
|
266
|
+
* what they add beyond it: otherwise a bigger bootstrap would flag every screen at once.
|
|
267
|
+
*/
|
|
268
|
+
const buildComparisonFindings = (comparison, lang, c) => {
|
|
269
|
+
const text = finding_text_1.TEXT[lang];
|
|
270
|
+
const findings = [];
|
|
271
|
+
const grew = (diff, ratio) => diff >= c.growthMinBytes && ratio >= c.growthRatio;
|
|
272
|
+
if (grew(comparison.boot.diff, comparison.boot.ratio)) {
|
|
273
|
+
findings.push({
|
|
274
|
+
severity: 'high',
|
|
275
|
+
target: { tab: 'boot', key: '' },
|
|
276
|
+
kind: 'bootGrew',
|
|
277
|
+
...text.bootGrew({
|
|
278
|
+
diff: signed(comparison.boot.diff),
|
|
279
|
+
pct: pctOf(comparison.boot.ratio),
|
|
280
|
+
before: (0, format_utils_1.formatBytes)(comparison.boot.before),
|
|
281
|
+
after: (0, format_utils_1.formatBytes)(comparison.boot.after),
|
|
282
|
+
baseline: comparison.baselineName,
|
|
283
|
+
}),
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
const first = comparison.newBootPackages[0];
|
|
287
|
+
if (first) {
|
|
288
|
+
findings.push({
|
|
289
|
+
severity: 'high',
|
|
290
|
+
target: { tab: 'boot', key: first.name },
|
|
291
|
+
kind: 'bootNewPackages',
|
|
292
|
+
...text.bootNewPackages({
|
|
293
|
+
count: comparison.newBootPackages.length,
|
|
294
|
+
list: comparison.newBootPackages
|
|
295
|
+
.map(pkg => `${(0, finding_html_1.mono)(pkg.name)} (${(0, format_utils_1.formatBytes)(pkg.bytes)})`)
|
|
296
|
+
.join(' · '),
|
|
297
|
+
baseline: comparison.baselineName,
|
|
298
|
+
}),
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
// What the person actually wants to see on a merge request: not the delta of bytes, but which
|
|
302
|
+
// signals went away and which came in. It is the only thing that makes fixing something visible.
|
|
303
|
+
if (comparison.findingsComparable && (comparison.newFindings.length > 0 || comparison.goneFindings.length > 0)) {
|
|
304
|
+
const chips = (list) => list.map(item => (0, finding_html_1.mono)(item.kind)).join(', ');
|
|
305
|
+
findings.push({
|
|
306
|
+
severity: comparison.newFindings.length > 0 ? 'mid' : 'ok',
|
|
307
|
+
kind: 'signalsChanged',
|
|
308
|
+
...text.signalsChanged({
|
|
309
|
+
fixed: comparison.goneFindings.length,
|
|
310
|
+
added: comparison.newFindings.length,
|
|
311
|
+
fixedList: chips(comparison.goneFindings),
|
|
312
|
+
addedList: chips(comparison.newFindings),
|
|
313
|
+
baseline: comparison.baselineName,
|
|
314
|
+
}),
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
const grown = [...comparison.screens.values()]
|
|
318
|
+
.filter(screen => grew(screen.lazy.diff, screen.lazy.ratio))
|
|
319
|
+
.toSorted((a, b) => b.lazy.diff - a.lazy.diff);
|
|
320
|
+
// Most screens up by the same amount: a chunk they all load grew, not the screens. Saying
|
|
321
|
+
// "19 screens grew" would send the person to 19 places when the cause is in one.
|
|
322
|
+
const total = comparison.screens.size;
|
|
323
|
+
const diffs = grown.map(screen => screen.lazy.diff).toSorted((a, b) => a - b);
|
|
324
|
+
const median = diffs[Math.floor(diffs.length / 2)] ?? 0;
|
|
325
|
+
const alike = grown.filter(screen => Math.abs(screen.lazy.diff - median) <= median * c.sharedGrowthTolerance);
|
|
326
|
+
const sharedGrowth = alike.length >= c.sharedGrowthMinScreens && alike.length >= total * c.sharedRatio;
|
|
327
|
+
if (sharedGrowth) {
|
|
328
|
+
findings.push({
|
|
329
|
+
severity: 'mid',
|
|
330
|
+
target: { tab: 'shared', key: '' },
|
|
331
|
+
kind: 'sharedGrew',
|
|
332
|
+
...text.sharedGrew({ count: alike.length, total, diff: signed(median) }),
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
const individual = sharedGrowth ? grown.filter(screen => !alike.includes(screen)) : grown;
|
|
336
|
+
const top = individual[0];
|
|
337
|
+
if (top) {
|
|
338
|
+
findings.push({
|
|
339
|
+
severity: 'mid',
|
|
340
|
+
target: { tab: 'screens', key: top.source },
|
|
341
|
+
kind: 'screensGrew',
|
|
342
|
+
...text.screensGrew({
|
|
343
|
+
count: individual.length,
|
|
344
|
+
top: top.label,
|
|
345
|
+
diff: signed(top.lazy.diff),
|
|
346
|
+
pct: pctOf(top.lazy.ratio),
|
|
347
|
+
list: individual
|
|
348
|
+
.map(screen => `${(0, finding_html_1.mono)(screen.label)} ${signed(screen.lazy.diff)} (${pctOf(screen.lazy.ratio)} %)`)
|
|
349
|
+
.join(' · '),
|
|
350
|
+
}),
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
return findings;
|
|
354
|
+
};
|
|
355
|
+
exports.buildComparisonFindings = buildComparisonFindings;
|
|
356
|
+
/**
|
|
357
|
+
* What `angular.json`, `package.json` and the pipeline say. The budget signals compare against
|
|
358
|
+
* the raw bootstrap, because that is what Angular's budgets measure, whatever the report shows.
|
|
359
|
+
*/
|
|
360
|
+
const buildContextFindings = (context, analysis, lang, c) => {
|
|
361
|
+
const text = finding_text_1.TEXT[lang];
|
|
362
|
+
const findings = [];
|
|
363
|
+
const rows = (0, project_context_1.configurationBudgets)(context);
|
|
364
|
+
const known = (0, project_context_1.pipelineKnown)(context);
|
|
365
|
+
const names = (list) => list.map(row => (0, finding_html_1.mono)(row.name)).join(', ');
|
|
366
|
+
// A title is read as text everywhere — the page interpolates it, the terminal prints it — so
|
|
367
|
+
// the two signals that name their configurations in the title get the names without markup.
|
|
368
|
+
// With `names()` they came out as `The <span class="mono">production</span> budget is…`, in the
|
|
369
|
+
// browser as well as in a CI log.
|
|
370
|
+
const plainNames = (list) => list.map(row => row.name).join(', ');
|
|
371
|
+
if (rows.length > 0) {
|
|
372
|
+
const withBudget = rows.filter(row => row.hasBudget);
|
|
373
|
+
const built = rows.filter(row => row.builtBy.length > 0);
|
|
374
|
+
// The budget that would fire first: the lowest error, or the lowest warning without one.
|
|
375
|
+
const bound = (row) => row.error ?? row.warning ?? Infinity;
|
|
376
|
+
const strictest = withBudget.toSorted((a, b) => bound(a) - bound(b))[0];
|
|
377
|
+
if (withBudget.length === 0) {
|
|
378
|
+
findings.push({
|
|
379
|
+
severity: 'mid',
|
|
380
|
+
target: { tab: 'project', key: '' },
|
|
381
|
+
kind: 'budgetNone',
|
|
382
|
+
...text.budgetNone({ configs: names(rows) }),
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
else if (known && built.length > 0 && strictest && strictest.builtBy.length === 0) {
|
|
386
|
+
findings.push({
|
|
387
|
+
severity: 'high',
|
|
388
|
+
target: { tab: 'project', key: strictest.name },
|
|
389
|
+
kind: 'budgetNotBuilt',
|
|
390
|
+
...text.budgetNotBuilt({
|
|
391
|
+
config: strictest.name,
|
|
392
|
+
figure: (0, format_utils_1.formatBytes)(bound(strictest)),
|
|
393
|
+
built: built.map(row => ({
|
|
394
|
+
name: row.name,
|
|
395
|
+
error: row.error === null ? null : (0, format_utils_1.formatBytes)(row.error),
|
|
396
|
+
warning: row.warning === null ? null : (0, format_utils_1.formatBytes)(row.warning),
|
|
397
|
+
})),
|
|
398
|
+
}),
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
// Where the budget does apply, is it a budget at all? Without a pipeline, every one is examined.
|
|
402
|
+
//
|
|
403
|
+
// Grouped by the figure, not listed one configuration at a time: two configurations with the
|
|
404
|
+
// same budget produced two cards that were the same sentence word for word, differing only
|
|
405
|
+
// in a name. One card that names both says the same thing and is read once.
|
|
406
|
+
const examined = known ? built.filter(row => row.hasBudget) : withBudget;
|
|
407
|
+
const warnOnly = groupBy(examined.filter(row => row.error === null && row.warning !== null), row => row.warning ?? 0);
|
|
408
|
+
for (const [warning, group] of warnOnly) {
|
|
409
|
+
findings.push({
|
|
410
|
+
severity: 'mid',
|
|
411
|
+
target: { tab: 'project', key: group[0]?.name ?? '' },
|
|
412
|
+
kind: 'budgetWarnOnly',
|
|
413
|
+
...text.budgetWarnOnly({
|
|
414
|
+
configs: plainNames(group),
|
|
415
|
+
count: group.length,
|
|
416
|
+
warning: (0, format_utils_1.formatBytes)(warning),
|
|
417
|
+
}),
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
const tooHigh = examined.filter(row => row.error !== null &&
|
|
421
|
+
analysis.bootRawBytes > 0 &&
|
|
422
|
+
row.error >= analysis.bootRawBytes * c.budgetSlackFactor);
|
|
423
|
+
const byError = groupBy(tooHigh, row => row.error ?? 0);
|
|
424
|
+
for (const [error, group] of byError) {
|
|
425
|
+
findings.push({
|
|
426
|
+
severity: 'mid',
|
|
427
|
+
target: { tab: 'project', key: group[0]?.name ?? '' },
|
|
428
|
+
kind: 'budgetTooHigh',
|
|
429
|
+
...text.budgetTooHigh({
|
|
430
|
+
configs: plainNames(group),
|
|
431
|
+
count: group.length,
|
|
432
|
+
error: (0, format_utils_1.formatBytes)(error),
|
|
433
|
+
boot: (0, format_utils_1.formatBytes)(analysis.bootRawBytes),
|
|
434
|
+
factor: c.budgetSlackFactor,
|
|
435
|
+
}),
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
if ((0, project_context_1.isZoneless)(context) === true) {
|
|
440
|
+
findings.push({ severity: 'info', target: { tab: 'project', key: '' }, kind: 'zoneless', ...text.zoneless() });
|
|
441
|
+
}
|
|
442
|
+
return findings;
|
|
443
|
+
};
|
|
444
|
+
exports.buildContextFindings = buildContextFindings;
|
|
445
|
+
/**
|
|
446
|
+
* What the browser measured, against what was computed. The set of chunks is what gets compared,
|
|
447
|
+
* not the byte count: a chunk that came down without being predicted is a fact regardless of the
|
|
448
|
+
* unit either side is expressed in.
|
|
449
|
+
*/
|
|
450
|
+
const buildMeasurementFindings = (report, lang, c) => {
|
|
451
|
+
const text = finding_text_1.TEXT[lang];
|
|
452
|
+
const findings = [];
|
|
453
|
+
const label = report.screen?.label ?? text.rootScreen;
|
|
454
|
+
// Every chunk, not the first six. This is the tab where a browser measurement is being
|
|
455
|
+
// reconciled against the calculation, so the chunk that explains the gap is as likely to be
|
|
456
|
+
// the ninth as the first.
|
|
457
|
+
const chunkList = (chunks) => chunks.map(chunk => `${(0, finding_html_1.mono)(chunk.name)} (${(0, format_utils_1.formatBytes)(chunk.bytes)})`).join(' · ');
|
|
458
|
+
const extraBytes = report.extra.reduce((sum, chunk) => sum + chunk.bytes, 0);
|
|
459
|
+
const missingBytes = report.missing.reduce((sum, chunk) => sum + chunk.bytes, 0);
|
|
460
|
+
// The router-before-guard case first: it is the only one of these with a fix attached.
|
|
461
|
+
if (report.eager.length > 0) {
|
|
462
|
+
const bytes = report.eager.reduce((sum, screen) => sum + screen.bytes, 0);
|
|
463
|
+
findings.push({
|
|
464
|
+
severity: bytes >= c.growthMinBytes ? 'high' : 'mid',
|
|
465
|
+
target: { tab: 'measured', key: '' },
|
|
466
|
+
kind: 'measuredEager',
|
|
467
|
+
...text.measuredEager({
|
|
468
|
+
screen: label,
|
|
469
|
+
size: (0, format_utils_1.formatBytes)(bytes),
|
|
470
|
+
list: report.eager.map(screen => (0, finding_html_1.mono)(screen.label)).join(', '),
|
|
471
|
+
}),
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
if (report.extra.length > 0 && extraBytes >= c.growthMinBytes) {
|
|
475
|
+
findings.push({
|
|
476
|
+
severity: report.eager.length > 0 ? 'mid' : 'high',
|
|
477
|
+
target: { tab: 'measured', key: '' },
|
|
478
|
+
kind: 'measuredExtra',
|
|
479
|
+
...text.measuredExtra({
|
|
480
|
+
screen: label,
|
|
481
|
+
diff: (0, format_utils_1.formatBytes)(extraBytes),
|
|
482
|
+
computed: (0, format_utils_1.formatBytes)(report.computed),
|
|
483
|
+
measured: (0, format_utils_1.formatBytes)(report.measured),
|
|
484
|
+
computedFiles: report.computedFiles,
|
|
485
|
+
measuredFiles: report.measuredFiles,
|
|
486
|
+
count: report.extra.length,
|
|
487
|
+
list: chunkList(report.extra),
|
|
488
|
+
}),
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
if (report.missing.length > 0 && missingBytes >= c.growthMinBytes) {
|
|
492
|
+
findings.push({
|
|
493
|
+
severity: 'info',
|
|
494
|
+
target: { tab: 'measured', key: '' },
|
|
495
|
+
kind: 'measuredShort',
|
|
496
|
+
...text.measuredShort({
|
|
497
|
+
screen: label,
|
|
498
|
+
count: report.missing.length,
|
|
499
|
+
size: (0, format_utils_1.formatBytes)(missingBytes),
|
|
500
|
+
list: chunkList(report.missing),
|
|
501
|
+
}),
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
if (findings.length === 0) {
|
|
505
|
+
findings.push({
|
|
506
|
+
severity: 'ok',
|
|
507
|
+
target: { tab: 'measured', key: '' },
|
|
508
|
+
kind: 'measuredMatch',
|
|
509
|
+
...text.measuredMatch({ screen: label, size: (0, format_utils_1.formatBytes)(report.measured) }),
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
return findings;
|
|
513
|
+
};
|
|
514
|
+
exports.buildMeasurementFindings = buildMeasurementFindings;
|