@bymaksym/loadline 0.1.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.
Files changed (115) hide show
  1. package/README.md +272 -45
  2. package/dist/cli/cli/args.js +97 -116
  3. package/dist/cli/cli/gates.js +80 -14
  4. package/dist/cli/cli/main.js +275 -31
  5. package/dist/cli/cli/memory.js +114 -0
  6. package/dist/cli/cli/read/declared.js +52 -0
  7. package/dist/cli/cli/read/locate.js +214 -0
  8. package/dist/cli/cli/{read-build.js → read/read-build.js} +156 -87
  9. package/dist/cli/cli/read/read-config.js +120 -0
  10. package/dist/cli/cli/render/html-report.js +111 -0
  11. package/dist/cli/cli/render/render-agent.js +114 -0
  12. package/dist/cli/cli/render/render-asked.js +104 -0
  13. package/dist/cli/cli/render/render-badge.js +140 -0
  14. package/dist/cli/cli/{render-json.js → render/render-json.js} +26 -10
  15. package/dist/cli/cli/{render-markdown.js → render/render-markdown.js} +6 -6
  16. package/dist/cli/cli/{render-pr.js → render/render-pr.js} +37 -15
  17. package/dist/cli/cli/{render-sarif.js → render/render-sarif.js} +11 -6
  18. package/dist/cli/cli/{render-text.js → render/render-text.js} +169 -127
  19. package/dist/cli/cli/render/terminal.js +55 -0
  20. package/dist/cli/cli/report.js +76 -29
  21. package/dist/cli/cli/self-check.js +19 -23
  22. package/dist/cli/cli/since-last.js +45 -0
  23. package/dist/cli/cli/text/text-errors.js +124 -0
  24. package/dist/cli/cli/text/text.js +343 -0
  25. package/dist/cli/cli/text/usage.js +240 -0
  26. package/dist/cli/src/app/core/analysis/analysis.js +68 -24
  27. package/dist/cli/src/app/core/analysis/{barrels.js → graph/barrels.js} +10 -3
  28. package/dist/cli/src/app/core/analysis/{blast.js → graph/blast.js} +56 -17
  29. package/dist/cli/src/app/core/analysis/{cycles.js → graph/cycles.js} +1 -1
  30. package/dist/cli/src/app/core/analysis/{importers.js → graph/importers.js} +1 -1
  31. package/dist/cli/src/app/core/analysis/{insights.js → graph/insights.js} +10 -4
  32. package/dist/cli/src/app/core/analysis/invariant.js +1 -1
  33. package/dist/cli/src/app/core/analysis/metafile.types.js +21 -7
  34. package/dist/cli/src/app/core/analysis/{delivery.js → screens/delivery.js} +1 -1
  35. package/dist/cli/src/app/core/analysis/{entries.js → screens/entries.js} +87 -11
  36. package/dist/cli/src/app/core/analysis/screens/marks.js +32 -0
  37. package/dist/cli/src/app/core/analysis/screens/route-files.js +116 -0
  38. package/dist/cli/src/app/core/analysis/{sourcemap.js → sourcemap/sourcemap.js} +106 -7
  39. package/dist/cli/src/app/core/analysis/{split-drift.js → sourcemap/split-drift.js} +13 -7
  40. package/dist/cli/src/app/core/analysis/tool.js +83 -0
  41. package/dist/cli/src/app/core/assets/assets.js +137 -16
  42. package/dist/cli/src/app/core/baseline/baseline.js +0 -0
  43. package/dist/cli/src/app/core/{intake → build-text}/index-html.js +234 -29
  44. package/dist/cli/src/app/core/build-text/route-table.js +178 -0
  45. package/dist/cli/src/app/core/build-text/tool-marks.js +54 -0
  46. package/dist/cli/src/app/core/caching/caching.js +123 -45
  47. package/dist/cli/src/app/core/caching/from-analysis.js +20 -4
  48. package/dist/cli/src/app/core/config/config-text.js +90 -0
  49. package/dist/cli/src/app/core/config/config-values.js +358 -0
  50. package/dist/cli/src/app/core/config/loadline-config.js +81 -16
  51. package/dist/cli/src/app/core/config/merge-config.js +98 -0
  52. package/dist/cli/src/app/core/deps/deps.js +141 -23
  53. package/dist/cli/src/app/core/deps/pins.js +63 -0
  54. package/dist/cli/src/app/core/export/summary.js +54 -12
  55. package/dist/cli/src/app/core/findings/actions.js +65 -6
  56. package/dist/cli/src/app/core/findings/bundle/boot-single.js +76 -0
  57. package/dist/cli/src/app/core/findings/bundle/dupes.js +68 -0
  58. package/dist/cli/src/app/core/findings/{graph.js → bundle/graph.js} +32 -20
  59. package/dist/cli/src/app/core/findings/{own-in-boot.js → bundle/own-in-boot.js} +9 -5
  60. package/dist/cli/src/app/core/findings/{requests.js → bundle/requests.js} +3 -3
  61. package/dist/cli/src/app/core/findings/{shipped.js → bundle/shipped.js} +30 -18
  62. package/dist/cli/src/app/core/findings/compose.js +6 -1
  63. package/dist/cli/src/app/core/findings/effort.js +4 -0
  64. package/dist/cli/src/app/core/findings/finding.types.js +2 -0
  65. package/dist/cli/src/app/core/findings/findings.js +68 -55
  66. package/dist/cli/src/app/core/findings/{assets.js → folder/assets.js} +65 -16
  67. package/dist/cli/src/app/core/findings/{caching.js → folder/caching.js} +17 -10
  68. package/dist/cli/src/app/core/findings/{page.js → folder/page.js} +6 -2
  69. package/dist/cli/src/app/core/findings/{scan.js → folder/scan.js} +37 -13
  70. package/dist/cli/src/app/core/findings/kind-names.js +163 -0
  71. package/dist/cli/src/app/core/findings/{deps.js → supplied/deps.js} +13 -8
  72. package/dist/cli/src/app/core/findings/supplied/forbidden.js +71 -0
  73. package/dist/cli/src/app/core/findings/{situation.js → supplied/situation.js} +2 -2
  74. package/dist/cli/src/app/core/findings/text/causes.js +39 -0
  75. package/dist/cli/src/app/core/findings/text/finding-html.js +33 -0
  76. package/dist/cli/src/app/core/findings/{finding-text.js → text/finding-text.js} +307 -103
  77. package/dist/cli/src/app/core/findings/text/tool-advice.js +97 -0
  78. package/dist/cli/src/app/core/format/format.utils.js +172 -18
  79. package/dist/cli/src/app/core/format/ownership.js +93 -0
  80. package/dist/cli/src/app/core/i18n/en.js +180 -61
  81. package/dist/cli/src/app/core/i18n/es.js +192 -68
  82. package/dist/cli/src/app/core/intake/bundle-graph.js +285 -46
  83. package/dist/cli/src/app/core/intake/dist-files.js +87 -16
  84. package/dist/cli/src/app/core/intake/embedded.js +56 -0
  85. package/dist/cli/src/app/core/intake/unreached.js +139 -0
  86. package/dist/cli/src/app/core/intake/webpack-modules.js +185 -0
  87. package/dist/cli/src/app/core/intake/webpack-stats.js +298 -0
  88. package/dist/cli/src/app/core/project/budget-advice.js +14 -10
  89. package/dist/cli/src/app/core/project/project-context.js +89 -19
  90. package/dist/cli/src/app/core/project/project-name.js +36 -0
  91. package/dist/cli/src/app/core/scan/scan.js +116 -39
  92. package/dist/cli/src/app/core/scan/secrets.js +0 -0
  93. package/dist/cli/src/app/core/situation/situation-text.js +23 -0
  94. package/dist/cli/src/app/core/situation/situation.js +9 -8
  95. package/dist/cli/src/app/core/timing/timing.js +5 -2
  96. package/dist/cli/src/app/core/whatif/defer.js +29 -4
  97. package/dist/cli/src/app/core/whatif/source-importers.js +58 -0
  98. package/dist/cli/src/app/core/whatif/why.js +102 -0
  99. package/dist/cli/src/app/state/report-messages.utils.js +1 -4
  100. package/docs/CONFIG-REFERENCE.md +230 -0
  101. package/docs/CONFIG.md +511 -0
  102. package/docs/HOW-IT-WORKS.md +286 -25
  103. package/loadline.html +26 -24
  104. package/loadline.schema.json +1209 -0
  105. package/package.json +71 -35
  106. package/dist/cli/cli/text.js +0 -180
  107. package/dist/cli/src/app/core/findings/finding-html.js +0 -13
  108. /package/dist/cli/cli/{read-build.types.js → read/read-build.types.js} +0 -0
  109. /package/dist/cli/cli/{render-json.types.js → render/render-json.types.js} +0 -0
  110. /package/dist/cli/cli/{text.types.js → text/text.types.js} +0 -0
  111. /package/dist/cli/src/app/core/analysis/{exclusive.js → graph/exclusive.js} +0 -0
  112. /package/dist/cli/src/app/core/analysis/{insights.types.js → graph/insights.types.js} +0 -0
  113. /package/dist/cli/src/app/core/analysis/{module-graph.js → graph/module-graph.js} +0 -0
  114. /package/dist/cli/src/app/core/analysis/{sourcemap.types.js → sourcemap/sourcemap.types.js} +0 -0
  115. /package/dist/cli/src/app/core/findings/{finding-plain.js → text/finding-plain.js} +0 -0
@@ -5,11 +5,12 @@
5
5
  * that it does not need one.
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.USAGE = exports.parseArgs = void 0;
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,12 +41,14 @@ 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',
43
48
  '--max-growth',
44
49
  '--max-growth-pct',
45
50
  '--fail-on',
51
+ '--html',
46
52
  ]);
47
53
  const EMPTY = {
48
54
  target: '',
@@ -56,33 +62,64 @@ const EMPTY = {
56
62
  lock: null,
57
63
  audit: null,
58
64
  whatIf: [],
65
+ why: [],
66
+ entries: [],
59
67
  lang: 'en',
60
68
  format: 'text',
61
69
  gates: {
62
70
  maxBoot: null,
63
71
  maxScreen: null,
72
+ screenLimits: {},
64
73
  maxOwn: null,
65
74
  maxGrowth: null,
66
75
  maxGrowthRatio: null,
67
76
  failOn: 'none',
68
77
  failOnNewPackage: false,
78
+ failOnSignals: [],
69
79
  },
70
80
  color: true,
71
81
  help: false,
72
82
  version: false,
73
83
  selfCheck: false,
84
+ printConfig: false,
85
+ html: null,
86
+ open: false,
87
+ cache: true,
74
88
  };
75
89
  /** A percentage as it is written on the command line (`10`) into the fraction the code compares. */
76
90
  const parsePercent = (value) => {
77
91
  const number = Number(value.replace('%', ''));
78
92
  return Number.isFinite(number) && number >= 0 ? number / 100 : null;
79
93
  };
80
- const sizeError = (flag, value) => `${flag} takes a size like 350kB, 1.5MB or a number of bytes, not "${value}".`;
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
+ };
81
118
  /**
82
119
  * Applies one flag to the options. Returns the message when the value cannot be used, so every
83
120
  * rejection names the flag it was about instead of saying "invalid arguments".
84
121
  */
85
- const apply = (options, flag, value, positional) => {
122
+ const apply = (options, flag, value, positional, t) => {
86
123
  switch (flag) {
87
124
  case '-h':
88
125
  case '--help': {
@@ -102,6 +139,22 @@ const apply = (options, flag, value, positional) => {
102
139
  options.selfCheck = true;
103
140
  return null;
104
141
  }
142
+ case '--print-config': {
143
+ options.printConfig = true;
144
+ return null;
145
+ }
146
+ case '--html': {
147
+ options.html = value;
148
+ return null;
149
+ }
150
+ case '--open': {
151
+ options.open = true;
152
+ return null;
153
+ }
154
+ case '--no-cache': {
155
+ options.cache = false;
156
+ return null;
157
+ }
105
158
  case '--dist': {
106
159
  options.dist = value;
107
160
  return null;
@@ -138,6 +191,14 @@ const apply = (options, flag, value, positional) => {
138
191
  options.whatIf.push(value);
139
192
  return null;
140
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
+ }
141
202
  case '--fail-on-new-package': {
142
203
  options.gates.failOnNewPackage = true;
143
204
  return null;
@@ -145,7 +206,7 @@ const apply = (options, flag, value, positional) => {
145
206
  case '--mode': {
146
207
  const mode = (0, json_utils_1.asMember)(value, MODES);
147
208
  if (mode === null) {
148
- return `--mode takes raw, gzip or brotli, not "${value}".`;
209
+ return t.badMode(value);
149
210
  }
150
211
  options.mode = mode;
151
212
  return null;
@@ -153,7 +214,7 @@ const apply = (options, flag, value, positional) => {
153
214
  case '--lang': {
154
215
  const lang = (0, json_utils_1.asMember)(value, LANGS);
155
216
  if (lang === null) {
156
- return `--lang takes en or es, not "${value}".`;
217
+ return t.badLang(value);
157
218
  }
158
219
  options.lang = lang;
159
220
  return null;
@@ -161,7 +222,7 @@ const apply = (options, flag, value, positional) => {
161
222
  case '--format': {
162
223
  const format = (0, json_utils_1.asMember)(value, FORMATS);
163
224
  if (format === null) {
164
- return `--format takes text, json, markdown, pr-comment, sarif or summary, not "${value}".`;
225
+ return t.badFormat(value);
165
226
  }
166
227
  options.format = format;
167
228
  return null;
@@ -169,34 +230,30 @@ const apply = (options, flag, value, positional) => {
169
230
  case '--fail-on': {
170
231
  const failOn = (0, json_utils_1.asMember)(value, SEVERITIES);
171
232
  if (failOn === null) {
172
- return `--fail-on takes high, mid or none, not "${value}".`;
233
+ return t.badFailOn(value);
173
234
  }
174
235
  options.gates.failOn = failOn;
236
+ options.gates.failOnTyped = true;
175
237
  return null;
176
238
  }
177
- case '--max-boot': {
178
- options.gates.maxBoot = (0, project_context_1.parseSize)(value);
179
- return options.gates.maxBoot === null ? sizeError(flag, value) : null;
180
- }
181
- case '--max-screen': {
182
- options.gates.maxScreen = (0, project_context_1.parseSize)(value);
183
- return options.gates.maxScreen === null ? sizeError(flag, value) : null;
184
- }
185
- case '--max-own': {
186
- options.gates.maxOwn = (0, project_context_1.parseSize)(value);
187
- return options.gates.maxOwn === null ? sizeError(flag, value) : null;
188
- }
239
+ case '--max-boot':
240
+ case '--max-screen':
241
+ case '--max-own':
189
242
  case '--max-growth': {
190
- options.gates.maxGrowth = (0, project_context_1.parseSize)(value);
191
- return options.gates.maxGrowth === null ? sizeError(flag, value) : null;
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;
192
249
  }
193
250
  case '--max-growth-pct': {
194
251
  options.gates.maxGrowthRatio = parsePercent(value);
195
- return options.gates.maxGrowthRatio === null ? `--max-growth-pct takes a number, not "${value}".` : null;
252
+ return options.gates.maxGrowthRatio === null ? t.badPct(value) : null;
196
253
  }
197
254
  default: {
198
255
  if (flag.startsWith('-')) {
199
- return `Unknown flag: ${flag}`;
256
+ return t.unknownFlag(flag);
200
257
  }
201
258
  positional.push(flag);
202
259
  return null;
@@ -209,116 +266,40 @@ const expand = (argv) => argv.flatMap(argument => {
209
266
  return equals > 0 ? [argument.slice(0, equals), argument.slice(equals + 1)] : [argument];
210
267
  });
211
268
  const parseArgs = (argv) => {
212
- const options = { ...EMPTY, gates: { ...EMPTY.gates } };
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 } };
213
272
  const args = expand(argv);
214
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];
215
279
  for (let index = 0; index < args.length; index++) {
216
280
  const flag = args[index] ?? '';
217
281
  const takesValue = WITH_VALUE.has(flag);
218
282
  const value = takesValue ? args[++index] : undefined;
219
283
  if (takesValue && value === undefined) {
220
- return { ok: false, message: `${flag} needs a value.` };
284
+ return { ok: false, lang, message: t.needsValue(flag) };
221
285
  }
222
- const failed = apply(options, flag, value ?? '', positional);
286
+ const failed = apply(options, flag, value ?? '', positional, t);
223
287
  if (failed) {
224
- return { ok: false, message: failed };
288
+ return { ok: false, lang, message: failed };
225
289
  }
226
290
  }
227
- if (options.help || options.version) {
291
+ if (options.help || options.version || options.printConfig) {
228
292
  return { ok: true, options };
229
293
  }
230
294
  const target = positional[0];
231
295
  if (!target) {
232
- return { ok: false, message: 'Missing the stats.json or the build folder to analyse.' };
296
+ return { ok: false, lang, message: t.missingTarget };
233
297
  }
234
298
  if (positional.length > 1) {
235
- return { ok: false, message: `Unexpected argument: ${positional[1]}` };
299
+ return { ok: false, lang, message: t.unexpected(positional[1] ?? '') };
236
300
  }
237
- return { ok: true, options: { ...options, target } };
301
+ return options.open && !options.html
302
+ ? { ok: false, lang, message: t.openNeedsHtml }
303
+ : { ok: true, options: { ...options, target } };
238
304
  };
239
305
  exports.parseArgs = parseArgs;
240
- exports.USAGE = `Loadline — weight per screen, from the terminal.
241
-
242
- Usage
243
- loadline <stats.json|build folder> [options]
244
-
245
- A build folder works on its own: its chunks carry the import graph, so anything that emits ES
246
- modules — Vite, Rollup, Rolldown, esbuild — is read without a stats file. It has to hold the
247
- index.html of the build, which is what names the chunk the application starts at.
248
-
249
- Reading the build
250
- --dist <folder> The build output (the "browser" folder). Gives gzip figures, brotli when
251
- it carries .br files, and exact per-file weights when it carries .js.map.
252
- Not needed when the folder is what is being analysed.
253
- --baseline <file> A previous stats.json or a Loadline export, to compare against.
254
- --export <file> Write this build's snapshot there, to be the --baseline of a later run.
255
- The other half of --baseline, and the only one a build that writes no
256
- stats.json has: a folder read as a graph could be compared against a
257
- baseline and never produce one.
258
- --lock <file> pnpm-lock.yaml, package-lock.json or yarn.lock. Says which packages you
259
- did not ask for directly and what pulls each one in.
260
- --audit <file.json> The output of "pnpm audit --json" or "npm audit --json". Crossed with
261
- what actually ships: "3 of your 47 are in the first load" instead of
262
- "you have 47". Nothing is fetched — both files are ones you already have.
263
- --project <folder> Where angular.json, package.json and the pipeline file live. Adds the
264
- budget checks. Not read unless asked for.
265
- --mode raw|gzip|brotli Which figure the report is in. Default: the best --dist allows.
266
- --criteria <file.json> Thresholds replacing the recommended ones. The Criteria tab of the page
267
- writes this file with its "Download criteria" button.
268
- --config <file.json> loadline.json: the thresholds, the gates and the signals the team has
269
- decided to live with, kept next to the code. Without the flag, a
270
- loadline.json in the working directory is read if there is one. Flags on
271
- the command line win over the file.
272
-
273
- Output
274
- --format <format> text (default), summary, json, markdown, pr-comment or sarif.
275
- summary is the whole report in a dozen lines — the figures, what to
276
- fix first and nothing else — for a pipeline step that runs next to
277
- twenty others and should not bury them.
278
- pr-comment writes the comment a bot leaves on a merge request, with
279
- an HTML marker so the next run edits it instead of adding a
280
- sixteenth one. sarif anchors each signal to a file, which is what
281
- GitHub's code scanning reads.
282
- --lang en|es Default: en.
283
- --no-color Never emit colour. It is off already when stdout is not a terminal.
284
-
285
- Failing the build
286
- --max-boot <size> Fail when the bootstrap is over it.
287
- --max-screen <size> Fail when the total download of a screen is over it.
288
- --max-own <size> Fail when the own code of a screen is over it.
289
- --max-growth <size> With --baseline: fail when the bootstrap or a screen grows by more.
290
- --max-growth-pct <n> The same, as a percentage.
291
- --fail-on high|mid|none Fail when a signal of that severity is raised. Default: none.
292
- --fail-on-new-package Fail when a package enters the bootstrap that was not in the baseline,
293
- or that the "packages" list of loadline.json does not name.
294
-
295
- Asking what if
296
- --what-if <name> What the first load would weigh without that package, folder or file —
297
- the figure to have BEFORE spending the afternoon. Exact: the graph is
298
- walked without those files, and what stops being reachable is what stops
299
- being downloaded. It does not re-chunk the build, so the round trips and
300
- the per-screen totals are not recomputed and the output says so.
301
- Repeatable.
302
-
303
- Checking the tool itself
304
- --self-check Work the bootstrap out twice — once by walking the import graph, once
305
- by closing what index.html announces — and fail when the two disagree.
306
- It says nothing about the bundle: it catches the build changing shape
307
- under Loadline, which is how the figures go wrong without an error.
308
- Needs the index.html, so pass the build folder or add --dist. Prints
309
- the check and nothing else.
310
-
311
- Exit codes
312
- 0 ran, nothing broke a gate.
313
- 1 a gate broke.
314
- 2 the arguments or the files could not be used.
315
-
316
- Examples
317
- loadline dist/app/browser
318
- loadline dist/app/stats.json --dist dist/app/browser
319
- loadline dist/app/stats.json --dist dist/app/browser --max-boot 350kB --fail-on high
320
- loadline dist/app/stats.json --baseline prev/stats.json --max-growth 20kB --format json
321
- loadline dist --export loadline-baseline.json
322
- loadline dist --baseline loadline-baseline.json --max-growth 20kB
323
- loadline dist/app/stats.json --dist dist/app/browser --self-check
324
- `;
@@ -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 project_context_1 = require("../src/app/core/project/project-context");
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
- const size = (value) => (value === undefined ? null : (0, project_context_1.parseSize)(value));
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 ?? size(wanted.maxBoot),
35
- maxScreen: gates.maxScreen ?? size(wanted.maxScreen),
36
- maxOwn: gates.maxOwn ?? size(wanted.maxOwn),
37
- maxGrowth: gates.maxGrowth ?? size(wanted.maxGrowth),
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.failOn === 'none' ? (wanted.failOn ?? 'none') : gates.failOn,
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.formatBytes)(analysis.bootBytes), (0, format_utils_1.formatBytes)(gates.maxBoot)),
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
- if (gates.maxScreen !== null && screen.total > gates.maxScreen) {
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: gates.maxScreen,
67
+ limit,
63
68
  actual: screen.total,
64
- message: text.overScreen(screen.label, (0, format_utils_1.formatBytes)(screen.total), (0, format_utils_1.formatBytes)(gates.maxScreen)),
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.formatBytes)(screen.own), (0, format_utils_1.formatBytes)(gates.maxOwn)),
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
  /**