@bymaksym/loadline 1.0.0 → 1.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/README.md +211 -43
- package/dist/cli/cli/args.js +79 -128
- package/dist/cli/cli/gates.js +80 -14
- package/dist/cli/cli/main.js +164 -33
- package/dist/cli/cli/memory.js +40 -4
- package/dist/cli/cli/{declared.js → read/declared.js} +1 -1
- package/dist/cli/cli/read/locate.js +214 -0
- package/dist/cli/cli/{read-build.js → read/read-build.js} +149 -84
- package/dist/cli/cli/read/read-config.js +120 -0
- package/dist/cli/cli/{html-report.js → render/html-report.js} +14 -10
- package/dist/cli/cli/render/render-agent.js +114 -0
- package/dist/cli/cli/render/render-asked.js +104 -0
- package/dist/cli/cli/render/render-badge.js +140 -0
- package/dist/cli/cli/{render-json.js → render/render-json.js} +18 -5
- package/dist/cli/cli/{render-markdown.js → render/render-markdown.js} +5 -5
- package/dist/cli/cli/{render-pr.js → render/render-pr.js} +33 -13
- package/dist/cli/cli/{render-sarif.js → render/render-sarif.js} +8 -3
- package/dist/cli/cli/{render-text.js → render/render-text.js} +118 -111
- package/dist/cli/cli/render/terminal.js +55 -0
- package/dist/cli/cli/report.js +68 -27
- package/dist/cli/cli/self-check.js +19 -23
- package/dist/cli/cli/since-last.js +2 -2
- package/dist/cli/cli/text/text-errors.js +124 -0
- package/dist/cli/cli/text/text.js +343 -0
- package/dist/cli/cli/text/usage.js +240 -0
- package/dist/cli/src/app/core/analysis/analysis.js +63 -23
- package/dist/cli/src/app/core/analysis/{barrels.js → graph/barrels.js} +1 -1
- package/dist/cli/src/app/core/analysis/{blast.js → graph/blast.js} +56 -17
- package/dist/cli/src/app/core/analysis/{cycles.js → graph/cycles.js} +1 -1
- package/dist/cli/src/app/core/analysis/{importers.js → graph/importers.js} +1 -1
- package/dist/cli/src/app/core/analysis/{insights.js → graph/insights.js} +10 -4
- package/dist/cli/src/app/core/analysis/invariant.js +1 -1
- package/dist/cli/src/app/core/analysis/metafile.types.js +7 -1
- package/dist/cli/src/app/core/analysis/{delivery.js → screens/delivery.js} +1 -1
- package/dist/cli/src/app/core/analysis/{entries.js → screens/entries.js} +50 -9
- package/dist/cli/src/app/core/analysis/screens/marks.js +32 -0
- package/dist/cli/src/app/core/analysis/screens/route-files.js +116 -0
- package/dist/cli/src/app/core/analysis/{sourcemap.js → sourcemap/sourcemap.js} +106 -7
- package/dist/cli/src/app/core/analysis/{split-drift.js → sourcemap/split-drift.js} +1 -1
- package/dist/cli/src/app/core/analysis/tool.js +83 -0
- package/dist/cli/src/app/core/assets/assets.js +134 -15
- package/dist/cli/src/app/core/baseline/baseline.js +0 -0
- package/dist/cli/src/app/core/{intake → build-text}/index-html.js +168 -13
- package/dist/cli/src/app/core/build-text/route-table.js +178 -0
- package/dist/cli/src/app/core/build-text/tool-marks.js +54 -0
- package/dist/cli/src/app/core/caching/caching.js +121 -43
- package/dist/cli/src/app/core/caching/from-analysis.js +20 -4
- package/dist/cli/src/app/core/config/config-text.js +90 -0
- package/dist/cli/src/app/core/config/config-values.js +358 -0
- package/dist/cli/src/app/core/config/loadline-config.js +81 -16
- package/dist/cli/src/app/core/config/merge-config.js +98 -0
- package/dist/cli/src/app/core/deps/deps.js +104 -16
- package/dist/cli/src/app/core/export/summary.js +29 -5
- package/dist/cli/src/app/core/findings/actions.js +3 -1
- package/dist/cli/src/app/core/findings/{boot-single.js → bundle/boot-single.js} +3 -3
- package/dist/cli/src/app/core/findings/{dupes.js → bundle/dupes.js} +8 -5
- package/dist/cli/src/app/core/findings/{graph.js → bundle/graph.js} +30 -18
- package/dist/cli/src/app/core/findings/{own-in-boot.js → bundle/own-in-boot.js} +9 -5
- package/dist/cli/src/app/core/findings/{requests.js → bundle/requests.js} +3 -3
- package/dist/cli/src/app/core/findings/{shipped.js → bundle/shipped.js} +28 -14
- package/dist/cli/src/app/core/findings/compose.js +6 -1
- package/dist/cli/src/app/core/findings/effort.js +2 -0
- package/dist/cli/src/app/core/findings/finding.types.js +1 -0
- package/dist/cli/src/app/core/findings/findings.js +48 -19
- package/dist/cli/src/app/core/findings/{assets.js → folder/assets.js} +38 -14
- package/dist/cli/src/app/core/findings/{caching.js → folder/caching.js} +16 -9
- package/dist/cli/src/app/core/findings/{page.js → folder/page.js} +6 -2
- package/dist/cli/src/app/core/findings/{scan.js → folder/scan.js} +25 -11
- package/dist/cli/src/app/core/findings/kind-names.js +163 -0
- package/dist/cli/src/app/core/findings/{deps.js → supplied/deps.js} +13 -8
- package/dist/cli/src/app/core/findings/supplied/forbidden.js +71 -0
- package/dist/cli/src/app/core/findings/{situation.js → supplied/situation.js} +2 -2
- package/dist/cli/src/app/core/findings/text/causes.js +39 -0
- package/dist/cli/src/app/core/findings/{finding-html.js → text/finding-html.js} +8 -1
- package/dist/cli/src/app/core/findings/{finding-text.js → text/finding-text.js} +208 -77
- package/dist/cli/src/app/core/findings/text/tool-advice.js +97 -0
- package/dist/cli/src/app/core/format/format.utils.js +158 -11
- package/dist/cli/src/app/core/format/ownership.js +93 -0
- package/dist/cli/src/app/core/i18n/en.js +76 -17
- package/dist/cli/src/app/core/i18n/es.js +82 -22
- package/dist/cli/src/app/core/intake/bundle-graph.js +281 -43
- package/dist/cli/src/app/core/intake/dist-files.js +82 -14
- package/dist/cli/src/app/core/intake/embedded.js +11 -1
- package/dist/cli/src/app/core/intake/unreached.js +139 -0
- package/dist/cli/src/app/core/intake/webpack-modules.js +185 -0
- package/dist/cli/src/app/core/intake/webpack-stats.js +298 -0
- package/dist/cli/src/app/core/project/project-context.js +16 -4
- package/dist/cli/src/app/core/project/project-name.js +36 -0
- package/dist/cli/src/app/core/scan/scan.js +58 -19
- package/dist/cli/src/app/core/scan/secrets.js +23 -3
- package/dist/cli/src/app/core/situation/situation-text.js +23 -0
- package/dist/cli/src/app/core/situation/situation.js +6 -4
- package/dist/cli/src/app/core/timing/timing.js +5 -2
- package/dist/cli/src/app/core/whatif/defer.js +29 -4
- package/dist/cli/src/app/core/whatif/source-importers.js +58 -0
- package/dist/cli/src/app/core/whatif/why.js +102 -0
- package/docs/CONFIG-REFERENCE.md +230 -0
- package/docs/CONFIG.md +511 -0
- package/docs/HOW-IT-WORKS.md +286 -25
- package/loadline.html +24 -20
- package/loadline.schema.json +1209 -0
- package/package.json +35 -29
- package/dist/cli/cli/locate.js +0 -60
- package/dist/cli/cli/text.js +0 -215
- /package/dist/cli/cli/{read-build.types.js → read/read-build.types.js} +0 -0
- /package/dist/cli/cli/{render-json.types.js → render/render-json.types.js} +0 -0
- /package/dist/cli/cli/{text.types.js → text/text.types.js} +0 -0
- /package/dist/cli/src/app/core/analysis/{exclusive.js → graph/exclusive.js} +0 -0
- /package/dist/cli/src/app/core/analysis/{insights.types.js → graph/insights.types.js} +0 -0
- /package/dist/cli/src/app/core/analysis/{module-graph.js → graph/module-graph.js} +0 -0
- /package/dist/cli/src/app/core/analysis/{sourcemap.types.js → sourcemap/sourcemap.types.js} +0 -0
- /package/dist/cli/src/app/core/findings/{finding-plain.js → text/finding-plain.js} +0 -0
package/dist/cli/cli/args.js
CHANGED
|
@@ -5,11 +5,12 @@
|
|
|
5
5
|
* that it does not need one.
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.
|
|
8
|
+
exports.parseArgs = void 0;
|
|
9
9
|
const criteria_1 = require("../src/app/core/criteria/criteria");
|
|
10
10
|
const ui_strings_1 = require("../src/app/core/i18n/ui-strings");
|
|
11
11
|
const json_utils_1 = require("../src/app/core/json/json.utils");
|
|
12
12
|
const project_context_1 = require("../src/app/core/project/project-context");
|
|
13
|
+
const text_errors_1 = require("./text/text-errors");
|
|
13
14
|
// The two lists the page also uses. Written out again here, they drifted: adding a language would
|
|
14
15
|
// have been accepted by the page and rejected by the command.
|
|
15
16
|
const MODES = new Set(criteria_1.MODES);
|
|
@@ -21,11 +22,14 @@ const FORMATS = new Set([
|
|
|
21
22
|
'pr-comment',
|
|
22
23
|
'sarif',
|
|
23
24
|
'summary',
|
|
25
|
+
'agent',
|
|
26
|
+
'badge',
|
|
24
27
|
]);
|
|
25
28
|
const SEVERITIES = new Set(['high', 'mid', 'none']);
|
|
26
29
|
/** Flags that take a value. Everything else is a switch, which is how a missing value gets caught. */
|
|
27
30
|
const WITH_VALUE = new Set([
|
|
28
31
|
'--dist',
|
|
32
|
+
'--entry',
|
|
29
33
|
'--baseline',
|
|
30
34
|
'--export',
|
|
31
35
|
'--project',
|
|
@@ -37,6 +41,7 @@ const WITH_VALUE = new Set([
|
|
|
37
41
|
'--lock',
|
|
38
42
|
'--audit',
|
|
39
43
|
'--what-if',
|
|
44
|
+
'--why',
|
|
40
45
|
'--max-boot',
|
|
41
46
|
'--max-screen',
|
|
42
47
|
'--max-own',
|
|
@@ -57,21 +62,26 @@ const EMPTY = {
|
|
|
57
62
|
lock: null,
|
|
58
63
|
audit: null,
|
|
59
64
|
whatIf: [],
|
|
65
|
+
why: [],
|
|
66
|
+
entries: [],
|
|
60
67
|
lang: 'en',
|
|
61
68
|
format: 'text',
|
|
62
69
|
gates: {
|
|
63
70
|
maxBoot: null,
|
|
64
71
|
maxScreen: null,
|
|
72
|
+
screenLimits: {},
|
|
65
73
|
maxOwn: null,
|
|
66
74
|
maxGrowth: null,
|
|
67
75
|
maxGrowthRatio: null,
|
|
68
76
|
failOn: 'none',
|
|
69
77
|
failOnNewPackage: false,
|
|
78
|
+
failOnSignals: [],
|
|
70
79
|
},
|
|
71
80
|
color: true,
|
|
72
81
|
help: false,
|
|
73
82
|
version: false,
|
|
74
83
|
selfCheck: false,
|
|
84
|
+
printConfig: false,
|
|
75
85
|
html: null,
|
|
76
86
|
open: false,
|
|
77
87
|
cache: true,
|
|
@@ -81,12 +91,35 @@ const parsePercent = (value) => {
|
|
|
81
91
|
const number = Number(value.replace('%', ''));
|
|
82
92
|
return Number.isFinite(number) && number >= 0 ? number / 100 : null;
|
|
83
93
|
};
|
|
84
|
-
|
|
94
|
+
/** The flags that take a size, and the gate each one sets. */
|
|
95
|
+
const SIZE_GATES = {
|
|
96
|
+
'--max-boot': 'maxBoot',
|
|
97
|
+
'--max-screen': 'maxScreen',
|
|
98
|
+
'--max-own': 'maxOwn',
|
|
99
|
+
'--max-growth': 'maxGrowth',
|
|
100
|
+
};
|
|
101
|
+
/** Below this a bare number is a size somebody meant in kilobytes: no bootstrap is that small. */
|
|
102
|
+
const BARE_FLOOR = 1000;
|
|
103
|
+
/**
|
|
104
|
+
* A size for a gate, or the message saying why not. A number with no unit is bytes, as Angular
|
|
105
|
+
* reads it — and `--max-boot 350` then failed every build with "over the 350 B allowed", which
|
|
106
|
+
* looks like a broken tool rather than a typo. Small enough to be that typo, it is refused with
|
|
107
|
+
* both spellings it could have meant.
|
|
108
|
+
*/
|
|
109
|
+
const gateSize = (flag, value, t) => {
|
|
110
|
+
const bytes = (0, project_context_1.parseSize)(value);
|
|
111
|
+
if (bytes === null) {
|
|
112
|
+
return t.badSize(flag, value);
|
|
113
|
+
}
|
|
114
|
+
const typed = value.trim();
|
|
115
|
+
const typo = bytes < BARE_FLOOR && /^\d+(?:\.\d+)?$/.test(typed);
|
|
116
|
+
return typo ? t.bareSize(flag, typed) : bytes;
|
|
117
|
+
};
|
|
85
118
|
/**
|
|
86
119
|
* Applies one flag to the options. Returns the message when the value cannot be used, so every
|
|
87
120
|
* rejection names the flag it was about instead of saying "invalid arguments".
|
|
88
121
|
*/
|
|
89
|
-
const apply = (options, flag, value, positional) => {
|
|
122
|
+
const apply = (options, flag, value, positional, t) => {
|
|
90
123
|
switch (flag) {
|
|
91
124
|
case '-h':
|
|
92
125
|
case '--help': {
|
|
@@ -106,6 +139,10 @@ const apply = (options, flag, value, positional) => {
|
|
|
106
139
|
options.selfCheck = true;
|
|
107
140
|
return null;
|
|
108
141
|
}
|
|
142
|
+
case '--print-config': {
|
|
143
|
+
options.printConfig = true;
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
109
146
|
case '--html': {
|
|
110
147
|
options.html = value;
|
|
111
148
|
return null;
|
|
@@ -154,6 +191,14 @@ const apply = (options, flag, value, positional) => {
|
|
|
154
191
|
options.whatIf.push(value);
|
|
155
192
|
return null;
|
|
156
193
|
}
|
|
194
|
+
case '--why': {
|
|
195
|
+
options.why.push(value);
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
case '--entry': {
|
|
199
|
+
options.entries.push(value);
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
157
202
|
case '--fail-on-new-package': {
|
|
158
203
|
options.gates.failOnNewPackage = true;
|
|
159
204
|
return null;
|
|
@@ -161,7 +206,7 @@ const apply = (options, flag, value, positional) => {
|
|
|
161
206
|
case '--mode': {
|
|
162
207
|
const mode = (0, json_utils_1.asMember)(value, MODES);
|
|
163
208
|
if (mode === null) {
|
|
164
|
-
return
|
|
209
|
+
return t.badMode(value);
|
|
165
210
|
}
|
|
166
211
|
options.mode = mode;
|
|
167
212
|
return null;
|
|
@@ -169,7 +214,7 @@ const apply = (options, flag, value, positional) => {
|
|
|
169
214
|
case '--lang': {
|
|
170
215
|
const lang = (0, json_utils_1.asMember)(value, LANGS);
|
|
171
216
|
if (lang === null) {
|
|
172
|
-
return
|
|
217
|
+
return t.badLang(value);
|
|
173
218
|
}
|
|
174
219
|
options.lang = lang;
|
|
175
220
|
return null;
|
|
@@ -177,7 +222,7 @@ const apply = (options, flag, value, positional) => {
|
|
|
177
222
|
case '--format': {
|
|
178
223
|
const format = (0, json_utils_1.asMember)(value, FORMATS);
|
|
179
224
|
if (format === null) {
|
|
180
|
-
return
|
|
225
|
+
return t.badFormat(value);
|
|
181
226
|
}
|
|
182
227
|
options.format = format;
|
|
183
228
|
return null;
|
|
@@ -185,34 +230,30 @@ const apply = (options, flag, value, positional) => {
|
|
|
185
230
|
case '--fail-on': {
|
|
186
231
|
const failOn = (0, json_utils_1.asMember)(value, SEVERITIES);
|
|
187
232
|
if (failOn === null) {
|
|
188
|
-
return
|
|
233
|
+
return t.badFailOn(value);
|
|
189
234
|
}
|
|
190
235
|
options.gates.failOn = failOn;
|
|
236
|
+
options.gates.failOnTyped = true;
|
|
191
237
|
return null;
|
|
192
238
|
}
|
|
193
|
-
case '--max-boot':
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
case '--max-screen': {
|
|
198
|
-
options.gates.maxScreen = (0, project_context_1.parseSize)(value);
|
|
199
|
-
return options.gates.maxScreen === null ? sizeError(flag, value) : null;
|
|
200
|
-
}
|
|
201
|
-
case '--max-own': {
|
|
202
|
-
options.gates.maxOwn = (0, project_context_1.parseSize)(value);
|
|
203
|
-
return options.gates.maxOwn === null ? sizeError(flag, value) : null;
|
|
204
|
-
}
|
|
239
|
+
case '--max-boot':
|
|
240
|
+
case '--max-screen':
|
|
241
|
+
case '--max-own':
|
|
205
242
|
case '--max-growth': {
|
|
206
|
-
|
|
207
|
-
|
|
243
|
+
const size = gateSize(flag, value, t);
|
|
244
|
+
if (typeof size === 'string') {
|
|
245
|
+
return size;
|
|
246
|
+
}
|
|
247
|
+
options.gates[SIZE_GATES[flag]] = size;
|
|
248
|
+
return null;
|
|
208
249
|
}
|
|
209
250
|
case '--max-growth-pct': {
|
|
210
251
|
options.gates.maxGrowthRatio = parsePercent(value);
|
|
211
|
-
return options.gates.maxGrowthRatio === null ?
|
|
252
|
+
return options.gates.maxGrowthRatio === null ? t.badPct(value) : null;
|
|
212
253
|
}
|
|
213
254
|
default: {
|
|
214
255
|
if (flag.startsWith('-')) {
|
|
215
|
-
return
|
|
256
|
+
return t.unknownFlag(flag);
|
|
216
257
|
}
|
|
217
258
|
positional.push(flag);
|
|
218
259
|
return null;
|
|
@@ -225,130 +266,40 @@ const expand = (argv) => argv.flatMap(argument => {
|
|
|
225
266
|
return equals > 0 ? [argument.slice(0, equals), argument.slice(equals + 1)] : [argument];
|
|
226
267
|
});
|
|
227
268
|
const parseArgs = (argv) => {
|
|
228
|
-
|
|
269
|
+
// The lists are fresh too: spread, they would be EMPTY's own arrays, and every parse after the
|
|
270
|
+
// first would push onto what the previous one asked.
|
|
271
|
+
const options = { ...EMPTY, whatIf: [], why: [], entries: [], gates: { ...EMPTY.gates } };
|
|
229
272
|
const args = expand(argv);
|
|
230
273
|
const positional = [];
|
|
274
|
+
// Looked for before anything else, so a mistake in the flags that come before it is already
|
|
275
|
+
// said in the language asked for. One it cannot read is the first mistake, said in English.
|
|
276
|
+
const asked = (0, json_utils_1.asMember)(args[args.indexOf('--lang') + 1] ?? '', LANGS);
|
|
277
|
+
const lang = args.includes('--lang') && asked ? asked : 'en';
|
|
278
|
+
const t = text_errors_1.ERROR_TEXT[lang];
|
|
231
279
|
for (let index = 0; index < args.length; index++) {
|
|
232
280
|
const flag = args[index] ?? '';
|
|
233
281
|
const takesValue = WITH_VALUE.has(flag);
|
|
234
282
|
const value = takesValue ? args[++index] : undefined;
|
|
235
283
|
if (takesValue && value === undefined) {
|
|
236
|
-
return { ok: false, message:
|
|
284
|
+
return { ok: false, lang, message: t.needsValue(flag) };
|
|
237
285
|
}
|
|
238
|
-
const failed = apply(options, flag, value ?? '', positional);
|
|
286
|
+
const failed = apply(options, flag, value ?? '', positional, t);
|
|
239
287
|
if (failed) {
|
|
240
|
-
return { ok: false, message: failed };
|
|
288
|
+
return { ok: false, lang, message: failed };
|
|
241
289
|
}
|
|
242
290
|
}
|
|
243
|
-
if (options.help || options.version) {
|
|
291
|
+
if (options.help || options.version || options.printConfig) {
|
|
244
292
|
return { ok: true, options };
|
|
245
293
|
}
|
|
246
294
|
const target = positional[0];
|
|
247
295
|
if (!target) {
|
|
248
|
-
return { ok: false, message:
|
|
296
|
+
return { ok: false, lang, message: t.missingTarget };
|
|
249
297
|
}
|
|
250
298
|
if (positional.length > 1) {
|
|
251
|
-
return { ok: false, message:
|
|
299
|
+
return { ok: false, lang, message: t.unexpected(positional[1] ?? '') };
|
|
252
300
|
}
|
|
253
301
|
return options.open && !options.html
|
|
254
|
-
? { ok: false, message:
|
|
302
|
+
? { ok: false, lang, message: t.openNeedsHtml }
|
|
255
303
|
: { ok: true, options: { ...options, target } };
|
|
256
304
|
};
|
|
257
305
|
exports.parseArgs = parseArgs;
|
|
258
|
-
exports.USAGE = `Loadline — weight per screen, from the terminal.
|
|
259
|
-
|
|
260
|
-
Usage
|
|
261
|
-
loadline <build root|stats.json|browser folder> [options]
|
|
262
|
-
|
|
263
|
-
The root of an Angular build — dist/<app> — is enough: browser-stats.json (Angular 22.2+) or
|
|
264
|
-
stats.json, and the browser/ folder next to it, are found on their own.
|
|
265
|
-
|
|
266
|
-
A build folder works on its own too: its chunks carry the import graph, so anything that emits ES
|
|
267
|
-
modules — Vite, Rollup, Rolldown, esbuild — is read without a stats file. It has to hold the
|
|
268
|
-
index.html of the build, which is what names the chunk the application starts at.
|
|
269
|
-
|
|
270
|
-
Reading the build
|
|
271
|
-
--dist <folder> The build output (the "browser" folder). Gives gzip figures, brotli when
|
|
272
|
-
it carries .br files, and exact per-file weights when it carries .js.map.
|
|
273
|
-
Not needed when the folder is what is being analysed.
|
|
274
|
-
--baseline <file> A previous stats.json or a Loadline export, to compare against.
|
|
275
|
-
--export <file> Write this build's snapshot there, to be the --baseline of a later run.
|
|
276
|
-
The other half of --baseline, and the only one a build that writes no
|
|
277
|
-
stats.json has: a folder read as a graph could be compared against a
|
|
278
|
-
baseline and never produce one.
|
|
279
|
-
--lock <file> pnpm-lock.yaml, package-lock.json or yarn.lock. Says which packages you
|
|
280
|
-
did not ask for directly and what pulls each one in.
|
|
281
|
-
--audit <file.json> The output of "pnpm audit --json" or "npm audit --json". Crossed with
|
|
282
|
-
what actually ships: "3 of your 47 are in the first load" instead of
|
|
283
|
-
"you have 47". Nothing is fetched — both files are ones you already have.
|
|
284
|
-
--project <folder> Where angular.json, package.json and the pipeline file live. Adds the
|
|
285
|
-
budget checks. Not read unless asked for.
|
|
286
|
-
--mode raw|gzip|brotli Which figure the report is in. Default: the best --dist allows.
|
|
287
|
-
--criteria <file.json> Thresholds replacing the recommended ones. The Criteria tab of the page
|
|
288
|
-
writes this file with its "Download criteria" button.
|
|
289
|
-
--config <file.json> loadline.json: the thresholds, the gates and the signals the team has
|
|
290
|
-
decided to live with, kept next to the code. Without the flag, a
|
|
291
|
-
loadline.json in the working directory is read if there is one. Flags on
|
|
292
|
-
the command line win over the file.
|
|
293
|
-
|
|
294
|
-
Output
|
|
295
|
-
--format <format> text (default), summary, json, markdown, pr-comment or sarif.
|
|
296
|
-
summary is the whole report in a dozen lines — the figures, what to
|
|
297
|
-
fix first and nothing else — for a pipeline step that runs next to
|
|
298
|
-
twenty others and should not bury them.
|
|
299
|
-
pr-comment writes the comment a bot leaves on a merge request, with
|
|
300
|
-
an HTML marker so the next run edits it instead of adding a
|
|
301
|
-
sixteenth one. sarif anchors each signal to a file, which is what
|
|
302
|
-
GitHub's code scanning reads.
|
|
303
|
-
--html <file> Also write the page — treemap, search, every chunk — with this build
|
|
304
|
-
already loaded into it. One self-contained file: nothing to drag in,
|
|
305
|
-
nothing fetched, opens offline.
|
|
306
|
-
--open Open what --html wrote.
|
|
307
|
-
--lang en|es Default: en.
|
|
308
|
-
--no-color Never emit colour. It is off already when stdout is not a terminal.
|
|
309
|
-
--no-cache Do not remember this run. By default each run is kept in
|
|
310
|
-
node_modules/.cache/loadline and the next one says what moved —
|
|
311
|
-
"bootstrap 156 kB → 129 kB" — without a --baseline.
|
|
312
|
-
|
|
313
|
-
Failing the build
|
|
314
|
-
--max-boot <size> Fail when the bootstrap is over it.
|
|
315
|
-
--max-screen <size> Fail when the total download of a screen is over it.
|
|
316
|
-
--max-own <size> Fail when the own code of a screen is over it.
|
|
317
|
-
--max-growth <size> With --baseline: fail when the bootstrap or a screen grows by more.
|
|
318
|
-
--max-growth-pct <n> The same, as a percentage.
|
|
319
|
-
--fail-on high|mid|none Fail when a signal of that severity is raised. Default: none.
|
|
320
|
-
--fail-on-new-package Fail when a package enters the bootstrap that was not in the baseline,
|
|
321
|
-
or that the "packages" list of loadline.json does not name.
|
|
322
|
-
|
|
323
|
-
Asking what if
|
|
324
|
-
--what-if <name> What the first load would weigh without that package, folder or file —
|
|
325
|
-
the figure to have BEFORE spending the afternoon. Exact: the graph is
|
|
326
|
-
walked without those files, and what stops being reachable is what stops
|
|
327
|
-
being downloaded. It does not re-chunk the build, so the round trips and
|
|
328
|
-
the per-screen totals are not recomputed and the output says so.
|
|
329
|
-
Repeatable.
|
|
330
|
-
|
|
331
|
-
Checking the tool itself
|
|
332
|
-
--self-check Work the bootstrap out twice — once by walking the import graph, once
|
|
333
|
-
by closing what index.html announces — and fail when the two disagree.
|
|
334
|
-
It says nothing about the bundle: it catches the build changing shape
|
|
335
|
-
under Loadline, which is how the figures go wrong without an error.
|
|
336
|
-
Needs the index.html, so pass the build folder or add --dist. Prints
|
|
337
|
-
the check and nothing else.
|
|
338
|
-
|
|
339
|
-
Exit codes
|
|
340
|
-
0 ran, nothing broke a gate.
|
|
341
|
-
1 a gate broke.
|
|
342
|
-
2 the arguments or the files could not be used.
|
|
343
|
-
|
|
344
|
-
Examples
|
|
345
|
-
loadline dist/app
|
|
346
|
-
loadline dist/app --html loadline.html --open
|
|
347
|
-
loadline dist/app/browser
|
|
348
|
-
loadline dist/app/stats.json --dist dist/app/browser
|
|
349
|
-
loadline dist/app/stats.json --dist dist/app/browser --max-boot 350kB --fail-on high
|
|
350
|
-
loadline dist/app/stats.json --baseline prev/stats.json --max-growth 20kB --format json
|
|
351
|
-
loadline dist --export loadline-baseline.json
|
|
352
|
-
loadline dist --baseline loadline-baseline.json --max-growth 20kB
|
|
353
|
-
loadline dist/app/stats.json --dist dist/app/browser --self-check
|
|
354
|
-
`;
|
package/dist/cli/cli/gates.js
CHANGED
|
@@ -9,10 +9,9 @@
|
|
|
9
9
|
* every screen at once and send someone to twenty places to fix one thing.
|
|
10
10
|
*/
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.violationLines = exports.anyGate = exports.checkGates = exports.mergeGates = void 0;
|
|
12
|
+
exports.violationLines = exports.anyGate = exports.uncheckedGates = exports.unmatchedScreenLimits = exports.checkGates = exports.mergeGates = void 0;
|
|
13
13
|
const format_utils_1 = require("../src/app/core/format/format.utils");
|
|
14
|
-
const
|
|
15
|
-
const text_1 = require("./text");
|
|
14
|
+
const text_1 = require("./text/text");
|
|
16
15
|
const percent = (ratio) => (ratio * 100).toFixed(1);
|
|
17
16
|
/** Which severities the `--fail-on` level covers. `high` alone, or `high` and `mid`. */
|
|
18
17
|
const covered = (level) => level === 'mid' ? new Set(['high', 'mid']) : new Set(['high']);
|
|
@@ -29,15 +28,18 @@ const mergeGates = (gates, config) => {
|
|
|
29
28
|
if (!wanted) {
|
|
30
29
|
return gates;
|
|
31
30
|
}
|
|
32
|
-
|
|
31
|
+
// The file's sizes arrive as bytes: `readConfig` parsed them and named the ones it could not.
|
|
33
32
|
return {
|
|
34
|
-
maxBoot: gates.maxBoot ??
|
|
35
|
-
maxScreen: gates.maxScreen ??
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
maxBoot: gates.maxBoot ?? wanted.maxBoot ?? null,
|
|
34
|
+
maxScreen: gates.maxScreen ?? wanted.maxScreen ?? null,
|
|
35
|
+
screenLimits: { ...wanted.screens, ...gates.screenLimits },
|
|
36
|
+
maxOwn: gates.maxOwn ?? wanted.maxOwn ?? null,
|
|
37
|
+
maxGrowth: gates.maxGrowth ?? wanted.maxGrowth ?? null,
|
|
38
38
|
maxGrowthRatio: gates.maxGrowthRatio ?? (wanted.maxGrowthPct === undefined ? null : wanted.maxGrowthPct / 100),
|
|
39
|
-
failOn: gates.
|
|
39
|
+
failOn: gates.failOnTyped ? gates.failOn : (wanted.failOn ?? gates.failOn),
|
|
40
|
+
failOnTyped: gates.failOnTyped ?? false,
|
|
40
41
|
failOnNewPackage: gates.failOnNewPackage || wanted.failOnNewPackage === true,
|
|
42
|
+
failOnSignals: wanted.failOnSignals ?? gates.failOnSignals,
|
|
41
43
|
};
|
|
42
44
|
};
|
|
43
45
|
exports.mergeGates = mergeGates;
|
|
@@ -51,17 +53,20 @@ const checkGates = (report, gates) => {
|
|
|
51
53
|
subject: null,
|
|
52
54
|
limit: gates.maxBoot,
|
|
53
55
|
actual: analysis.bootBytes,
|
|
54
|
-
message: text.overBoot((0, format_utils_1.
|
|
56
|
+
message: text.overBoot(...(0, format_utils_1.formatBytesApart)(analysis.bootBytes, gates.maxBoot)),
|
|
55
57
|
});
|
|
56
58
|
}
|
|
57
59
|
for (const screen of analysis.screens) {
|
|
58
|
-
|
|
60
|
+
// Its own limit first, by the name the report gives it or by its source file; the general
|
|
61
|
+
// one otherwise. A map screen allowed 900 kB does not loosen the limit of every other one.
|
|
62
|
+
const limit = gates.screenLimits[screen.label] ?? gates.screenLimits[screen.source] ?? gates.maxScreen;
|
|
63
|
+
if (limit !== null && screen.total > limit) {
|
|
59
64
|
violations.push({
|
|
60
65
|
gate: 'screen',
|
|
61
66
|
subject: screen.label,
|
|
62
|
-
limit
|
|
67
|
+
limit,
|
|
63
68
|
actual: screen.total,
|
|
64
|
-
message: text.overScreen(screen.label, (0, format_utils_1.
|
|
69
|
+
message: text.overScreen(screen.label, ...(0, format_utils_1.formatBytesApart)(screen.total, limit)),
|
|
65
70
|
});
|
|
66
71
|
}
|
|
67
72
|
if (gates.maxOwn !== null && screen.own > gates.maxOwn) {
|
|
@@ -70,7 +75,7 @@ const checkGates = (report, gates) => {
|
|
|
70
75
|
subject: screen.label,
|
|
71
76
|
limit: gates.maxOwn,
|
|
72
77
|
actual: screen.own,
|
|
73
|
-
message: text.overOwn(screen.label, (0, format_utils_1.
|
|
78
|
+
message: text.overOwn(screen.label, ...(0, format_utils_1.formatBytesApart)(screen.own, gates.maxOwn)),
|
|
74
79
|
});
|
|
75
80
|
}
|
|
76
81
|
}
|
|
@@ -146,12 +151,73 @@ const checkGates = (report, gates) => {
|
|
|
146
151
|
});
|
|
147
152
|
}
|
|
148
153
|
}
|
|
154
|
+
// The signals named one by one: one gate per signal, so the log says which of them stopped the
|
|
155
|
+
// run. Accepted ones are not in `findings` by now, and so do not count here either.
|
|
156
|
+
const named = new Set(gates.failOnSignals);
|
|
157
|
+
for (const kind of named) {
|
|
158
|
+
const raised = report.findings.filter(finding => finding.kind === kind);
|
|
159
|
+
if (raised.length > 0) {
|
|
160
|
+
violations.push({
|
|
161
|
+
gate: 'signal',
|
|
162
|
+
subject: kind,
|
|
163
|
+
limit: 0,
|
|
164
|
+
actual: raised.length,
|
|
165
|
+
message: text.signalRaised(kind, raised.length),
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
149
169
|
return violations;
|
|
150
170
|
};
|
|
151
171
|
exports.checkGates = checkGates;
|
|
172
|
+
/**
|
|
173
|
+
* The screen limits that name no screen of this build. A renamed route or a typo would otherwise
|
|
174
|
+
* be a gate that silently guards nothing, so each one is said, with the names that do exist.
|
|
175
|
+
*/
|
|
176
|
+
const unmatchedScreenLimits = (report, gates) => {
|
|
177
|
+
const names = new Set(report.analysis.screens.flatMap(screen => [screen.label, screen.source]));
|
|
178
|
+
return Object.keys(gates.screenLimits)
|
|
179
|
+
.filter(name => !names.has(name))
|
|
180
|
+
.map(name => text_1.CLI_TEXT[report.lang].screenLimitUnmatched(name, report.analysis.screens.map(s => s.label)));
|
|
181
|
+
};
|
|
182
|
+
exports.unmatchedScreenLimits = unmatchedScreenLimits;
|
|
183
|
+
/**
|
|
184
|
+
* The gates that were asked for and have nothing to be checked against on this run.
|
|
185
|
+
*
|
|
186
|
+
* A gate that cannot run passes, and a pipeline guarded by one passes every build. So one typed on
|
|
187
|
+
* the command line stops the run, as `--max-growth` without `--baseline` always has; one written in
|
|
188
|
+
* `loadline.json` is said and skipped, because the file is read on every machine and the baseline
|
|
189
|
+
* usually exists only in the pipeline. A baseline in another unit stops the run either way: it was
|
|
190
|
+
* given precisely so that something would be compared.
|
|
191
|
+
*/
|
|
192
|
+
const uncheckedGates = (report, gates, typed) => {
|
|
193
|
+
const text = text_1.CLI_TEXT[report.lang];
|
|
194
|
+
const hasBaseline = report.comparison !== null || report.comparisonBlocked;
|
|
195
|
+
const growth = gates.maxGrowth !== null || gates.maxGrowthRatio !== null;
|
|
196
|
+
if (growth && report.comparisonBlocked) {
|
|
197
|
+
return {
|
|
198
|
+
refuse: `${text.blocked(report.baselineMode ?? 'raw', report.mode)} ${text.growthUnchecked}`,
|
|
199
|
+
skipped: [],
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
const listed = !!report.config?.packages;
|
|
203
|
+
if (typed.failOnNewPackage && !hasBaseline && !listed) {
|
|
204
|
+
return { refuse: text.newPackageUnchecked, skipped: [] };
|
|
205
|
+
}
|
|
206
|
+
const skipped = [];
|
|
207
|
+
if (growth && !hasBaseline) {
|
|
208
|
+
skipped.push(text.configGrowthSkipped);
|
|
209
|
+
}
|
|
210
|
+
if (gates.failOnNewPackage && !typed.failOnNewPackage && !hasBaseline && !listed) {
|
|
211
|
+
skipped.push(text.configNewPackageSkipped);
|
|
212
|
+
}
|
|
213
|
+
return { refuse: null, skipped };
|
|
214
|
+
};
|
|
215
|
+
exports.uncheckedGates = uncheckedGates;
|
|
152
216
|
/** Whether any gate was asked for at all, which is what tells "passed" from "nothing was checked". */
|
|
153
217
|
const anyGate = (gates) => gates.failOn !== 'none' ||
|
|
154
218
|
gates.failOnNewPackage ||
|
|
219
|
+
gates.failOnSignals.length > 0 ||
|
|
220
|
+
Object.keys(gates.screenLimits).length > 0 ||
|
|
155
221
|
[gates.maxBoot, gates.maxScreen, gates.maxOwn, gates.maxGrowth, gates.maxGrowthRatio].some(limit => limit !== null);
|
|
156
222
|
exports.anyGate = anyGate;
|
|
157
223
|
/**
|