@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,13 +5,18 @@ const criteria_1 = require("../criteria/criteria");
5
5
  const format_utils_1 = require("../format/format.utils");
6
6
  const project_context_1 = require("../project/project-context");
7
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");
8
+ const actions_1 = require("./actions");
9
+ const boot_single_1 = require("./bundle/boot-single");
10
+ const dupes_1 = require("./bundle/dupes");
11
+ const graph_1 = require("./bundle/graph");
12
+ const own_in_boot_1 = require("./bundle/own-in-boot");
13
+ const requests_1 = require("./bundle/requests");
14
+ const shipped_1 = require("./bundle/shipped");
15
+ const caching_1 = require("./folder/caching");
16
+ const kind_names_1 = require("./kind-names");
17
+ const causes_1 = require("./text/causes");
18
+ const finding_html_1 = require("./text/finding-html");
19
+ const finding_text_1 = require("./text/finding-text");
15
20
  const unitText = (lang, mode) => {
16
21
  if (lang === 'es') {
17
22
  return mode === 'raw' ? 'en crudo' : mode === 'brotli' ? 'comprimidas en brotli' : 'comprimidas en gzip';
@@ -29,7 +34,13 @@ const buildFindings = (analysis, lang, mode, c = criteria_1.RECOMMENDED[mode],
29
34
  * from here — the shape of the hash cascade, whose severity is not a property of the build —
30
35
  * and it defaults to nobody having answered, which is what every caller did before it existed.
31
36
  */
32
- situation = situation_1.EMPTY_SITUATION) => {
37
+ situation = situation_1.EMPTY_SITUATION,
38
+ /**
39
+ * What each package declares as its dependencies, from the lock file or from `node_modules`.
40
+ * It reaches one signal: whether a duplicate is pinned to an exact version by its parent, which
41
+ * turns "force the resolution" from advice into a breaking change.
42
+ */
43
+ declared = null) => {
33
44
  const text = finding_text_1.TEXT[lang];
34
45
  const findings = [];
35
46
  const totalScreens = analysis.screens.length;
@@ -91,6 +102,10 @@ situation = situation_1.EMPTY_SITUATION) => {
91
102
  }),
92
103
  });
93
104
  }
105
+ // 2b · The same package, imported by a single file of yours that everybody runs: a candidate for
106
+ // an `await import()` where it is used. Its own module, like the folder version below.
107
+ const lazyFlagged = new Set(findings.filter(finding => finding.kind === 'bootLazy').map(f => f.target?.key ?? ''));
108
+ findings.push(...(0, boot_single_1.buildBootSingleFindings)(analysis, lang, c, lazyFlagged));
94
109
  // 3 · Own files too large inside the bootstrap: one signal listing all of them, no cut-off.
95
110
  const bigFiles = analysis.ownFilesInBoot.filter(file => file.bytes > c.bigOwnFileBytes);
96
111
  const first = bigFiles[0];
@@ -100,48 +115,24 @@ situation = situation_1.EMPTY_SITUATION) => {
100
115
  target: { tab: 'boot', key: (0, format_utils_1.projectFolderOf)(first.path) },
101
116
  kind: 'bigFile',
102
117
  saving: insights.exclusiveOf(bigFiles.map(file => file.path)),
118
+ size: bigFiles.reduce((sum, file) => sum + file.bytes, 0),
103
119
  sources: bigFiles.map(file => file.path),
120
+ // The files are raw bytes, and so is the limit they are held to: both are said in the
121
+ // report's unit, at the ratio the bootstrap compresses by, as the savings are.
104
122
  ...text.bigFile({
105
123
  count: bigFiles.length,
106
- each: (0, format_utils_1.formatBytes)(c.bigOwnFileBytes),
124
+ each: (0, actions_1.formatSaving)(c.bigOwnFileBytes, (0, actions_1.unitScale)(analysis)),
107
125
  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),
126
+ size: (0, actions_1.formatSaving)(bigFiles.reduce((sum, file) => sum + file.bytes, 0), (0, actions_1.unitScale)(analysis)),
127
+ list: bigFiles
128
+ .map(file => `${(0, finding_html_1.mono)(file.path)} (${(0, actions_1.formatSaving)(file.bytes, (0, actions_1.unitScale)(analysis))})`)
129
+ .join(' · '),
142
130
  }),
143
131
  });
144
132
  }
133
+ // 4 · Two versions of the same package, each copy followed to whatever brings it in — and, when
134
+ // the ranges are known, whether a parent pins its copy so it cannot be moved at all.
135
+ findings.push(...(0, dupes_1.buildDupesFindings)(analysis, lang, declared));
145
136
  // 5 · A screen much more expensive than the rest.
146
137
  if (analysis.screens.length >= c.heavyScreenMinScreens) {
147
138
  const owns = analysis.screens.map(screen => screen.own).toSorted((a, b) => a - b);
@@ -158,6 +149,7 @@ situation = situation_1.EMPTY_SITUATION) => {
158
149
  severity: 'mid',
159
150
  target: { tab: 'screens', key: worstScreen.source },
160
151
  kind: 'heavy',
152
+ size: worstScreen.own,
161
153
  ...text.heavy({
162
154
  count: byOwn.length,
163
155
  label: worstScreen.label,
@@ -175,6 +167,10 @@ situation = situation_1.EMPTY_SITUATION) => {
175
167
  const unreachable = analysis.unreachable;
176
168
  if (unreachable.length > 0) {
177
169
  const unreachableBytes = unreachable.reduce((sum, chunk) => sum + chunk.bytes, 0);
170
+ const namesakes = new Map();
171
+ for (const chunk of unreachable) {
172
+ namesakes.set((0, format_utils_1.baseName)(chunk.file), (namesakes.get((0, format_utils_1.baseName)(chunk.file)) ?? 0) + 1);
173
+ }
178
174
  // `allChunks` is every chunk of the build, these among them, so the share is over that.
179
175
  const allBytes = analysis.allChunks.reduce((sum, file) => sum + (analysis.chunkOf(file)?.bytes ?? 0), 0);
180
176
  // Two service workers are a footnote; most of the build is not. The share is what decides,
@@ -185,6 +181,7 @@ situation = situation_1.EMPTY_SITUATION) => {
185
181
  severity: most ? 'mid' : 'info',
186
182
  kind: 'unreachable',
187
183
  ...text.unreachable({
184
+ folder: analysis.readFrom === 'folder',
188
185
  count: unreachable.length,
189
186
  total: analysis.allChunks.length,
190
187
  size: (0, format_utils_1.formatBytes)(unreachableBytes),
@@ -192,9 +189,11 @@ situation = situation_1.EMPTY_SITUATION) => {
192
189
  // All of them, heaviest first. This signal exists because a report described 12
193
190
  // chunks of 244 without saying so; naming four of the 232 would be the same
194
191
  // mistake one level down.
192
+ // By path where two share a name: TinyMCE ships 25 `plugin.min.js`, and the list
193
+ // read "plugin.min.js" 25 times, which identifies none of them.
195
194
  list: unreachable
196
195
  .toSorted((a, b) => b.bytes - a.bytes)
197
- .map(chunk => (0, finding_html_1.mono)((0, format_utils_1.baseName)(chunk.file)))
196
+ .map(chunk => (0, finding_html_1.mono)((namesakes.get((0, format_utils_1.baseName)(chunk.file)) ?? 0) > 1 ? chunk.file : (0, format_utils_1.baseName)(chunk.file)))
198
197
  .join(', '),
199
198
  }),
200
199
  });
@@ -280,6 +279,9 @@ const buildComparisonFindings = (comparison, lang, c) => {
280
279
  before: (0, format_utils_1.formatBytes)(comparison.boot.before),
281
280
  after: (0, format_utils_1.formatBytes)(comparison.boot.after),
282
281
  baseline: comparison.baselineName,
282
+ causes: (0, causes_1.bootCausesText)(comparison, lang),
283
+ estimated: comparison.causesEstimated,
284
+ ownKnown: comparison.causesOwnKnown,
283
285
  }),
284
286
  });
285
287
  }
@@ -291,8 +293,10 @@ const buildComparisonFindings = (comparison, lang, c) => {
291
293
  kind: 'bootNewPackages',
292
294
  ...text.bootNewPackages({
293
295
  count: comparison.newBootPackages.length,
296
+ // Raw, as everything inside a chunk is: at the ratio the bootstrap compresses by,
297
+ // or "marked (40 kB)" sat next to "marked ≈+15 kB" for the same package.
294
298
  list: comparison.newBootPackages
295
- .map(pkg => `${(0, finding_html_1.mono)(pkg.name)} (${(0, format_utils_1.formatBytes)(pkg.bytes)})`)
299
+ .map(pkg => `${(0, finding_html_1.mono)(pkg.name)} (${comparison.causesEstimated ? '≈' : ''}${(0, format_utils_1.formatBytes)(pkg.bytes * comparison.causesRatio)})`)
296
300
  .join(' · '),
297
301
  baseline: comparison.baselineName,
298
302
  }),
@@ -301,15 +305,14 @@ const buildComparisonFindings = (comparison, lang, c) => {
301
305
  // What the person actually wants to see on a merge request: not the delta of bytes, but which
302
306
  // signals went away and which came in. It is the only thing that makes fixing something visible.
303
307
  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
308
  findings.push({
306
309
  severity: comparison.newFindings.length > 0 ? 'mid' : 'ok',
307
310
  kind: 'signalsChanged',
308
311
  ...text.signalsChanged({
309
312
  fixed: comparison.goneFindings.length,
310
313
  added: comparison.newFindings.length,
311
- fixedList: chips(comparison.goneFindings),
312
- addedList: chips(comparison.newFindings),
314
+ fixedList: (0, kind_names_1.signalList)(lang, comparison.goneFindings),
315
+ addedList: (0, kind_names_1.signalList)(lang, comparison.newFindings),
313
316
  baseline: comparison.baselineName,
314
317
  }),
315
318
  });
@@ -335,6 +338,10 @@ const buildComparisonFindings = (comparison, lang, c) => {
335
338
  const individual = sharedGrowth ? grown.filter(screen => !alike.includes(screen)) : grown;
336
339
  const top = individual[0];
337
340
  if (top) {
341
+ // Each screen with what grew in it, when both snapshots broke it down: "+120 kB" sends the
342
+ // person to open two reports side by side; "`xlsx` ≈+118 kB (new)" is the answer itself.
343
+ const rows = individual.map(screen => ({ screen, causes: (0, causes_1.screenCausesText)(screen, lang) }));
344
+ const explained = rows.filter(row => row.causes.length > 0);
338
345
  findings.push({
339
346
  severity: 'mid',
340
347
  target: { tab: 'screens', key: top.source },
@@ -344,9 +351,14 @@ const buildComparisonFindings = (comparison, lang, c) => {
344
351
  top: top.label,
345
352
  diff: signed(top.lazy.diff),
346
353
  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)} %)`)
354
+ list: rows
355
+ .map(({ screen, causes }) => {
356
+ const figure = `${(0, finding_html_1.mono)(screen.label)} ${signed(screen.lazy.diff)} (${pctOf(screen.lazy.ratio)} %)`;
357
+ return causes.length > 0 ? `${figure} — ${causes.join(', ')}` : figure;
358
+ })
349
359
  .join(' · '),
360
+ explained: explained.length > 0,
361
+ estimated: explained.some(row => row.screen.causesEstimated),
350
362
  }),
351
363
  });
352
364
  }
@@ -355,7 +367,8 @@ const buildComparisonFindings = (comparison, lang, c) => {
355
367
  exports.buildComparisonFindings = buildComparisonFindings;
356
368
  /**
357
369
  * 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.
370
+ * the raw initial load — JavaScript and the global stylesheet — because that is what Angular's
371
+ * `initial` budget adds up, whatever the report shows, and it is the figure the suggestion uses.
359
372
  */
360
373
  const buildContextFindings = (context, analysis, lang, c) => {
361
374
  const text = finding_text_1.TEXT[lang];
@@ -382,7 +395,7 @@ const buildContextFindings = (context, analysis, lang, c) => {
382
395
  ...text.budgetNone({ configs: names(rows) }),
383
396
  });
384
397
  }
385
- else if (known && built.length > 0 && strictest && strictest.builtBy.length === 0) {
398
+ else if (known && built.length > 0 && strictest?.builtBy.length === 0) {
386
399
  findings.push({
387
400
  severity: 'high',
388
401
  target: { tab: 'project', key: strictest.name },
@@ -418,8 +431,8 @@ const buildContextFindings = (context, analysis, lang, c) => {
418
431
  });
419
432
  }
420
433
  const tooHigh = examined.filter(row => row.error !== null &&
421
- analysis.bootRawBytes > 0 &&
422
- row.error >= analysis.bootRawBytes * c.budgetSlackFactor);
434
+ analysis.initialRawBytes > 0 &&
435
+ row.error >= analysis.initialRawBytes * c.budgetSlackFactor);
423
436
  const byError = groupBy(tooHigh, row => row.error ?? 0);
424
437
  for (const [error, group] of byError) {
425
438
  findings.push({
@@ -430,7 +443,7 @@ const buildContextFindings = (context, analysis, lang, c) => {
430
443
  configs: plainNames(group),
431
444
  count: group.length,
432
445
  error: (0, format_utils_1.formatBytes)(error),
433
- boot: (0, format_utils_1.formatBytes)(analysis.bootRawBytes),
446
+ boot: (0, format_utils_1.formatBytes)(analysis.initialRawBytes),
434
447
  factor: c.budgetSlackFactor,
435
448
  }),
436
449
  });
@@ -12,11 +12,19 @@
12
12
  */
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.buildAssetFindings = void 0;
15
- const format_utils_1 = require("../format/format.utils");
16
- const finding_html_1 = require("./finding-html");
17
- const finding_text_1 = require("./finding-text");
15
+ const format_utils_1 = require("../../format/format.utils");
16
+ const finding_html_1 = require("../text/finding-html");
17
+ const finding_text_1 = require("../text/finding-text");
18
18
  const named = (items) => items.map(item => (0, finding_html_1.mono)(item)).join(', ');
19
- const buildAssetFindings = (assets, lang, c) => {
19
+ /**
20
+ * @param repoPaths where in the repository each unreferenced file comes from, when `angular.json`
21
+ * copies it from an assets folder: build-folder path → repository path. Those are
22
+ * not leftovers of an old deploy — Angular empties the output before every build
23
+ * — and "clean the folder before building" is advice that changes nothing for them.
24
+ * @param verified whether those paths were checked on disk (the command) or only read off
25
+ * `angular.json` (the page).
26
+ */
27
+ const buildAssetFindings = (assets, lang, c, repoPaths = null, verified = false) => {
20
28
  const text = finding_text_1.TEXT[lang];
21
29
  const findings = [];
22
30
  // 1 · Fonts. The one place where "you are shipping the same face twice" is a fact rather than
@@ -24,19 +32,33 @@ const buildAssetFindings = (assets, lang, c) => {
24
32
  const fonts = assets.fonts;
25
33
  const fontBytes = fonts.reduce((sum, family) => sum + family.bytes, 0);
26
34
  const superseded = fonts.flatMap(family => family.superseded);
27
- const manyWeights = fonts.filter(family => family.files.length > 2);
35
+ // Weights, not files: regular and bold in woff2 and ttf are two weights, and counting the
36
+ // second format here would raise the card for the very files the title says nobody downloads.
37
+ const manyWeights = fonts.filter(family => family.files.filter(file => !family.superseded.includes(file.name)).length > 2);
38
+ // What the superseded formats weigh. They are on the server and nobody downloads them — a
39
+ // browser takes the first format of the list it understands — so they are said apart from
40
+ // the total, which is a figure of the folder and not of a visit.
41
+ const spare = new Set(superseded);
42
+ const spareBytes = fonts
43
+ .flatMap(family => family.files)
44
+ .filter(file => spare.has(file.name))
45
+ .reduce((sum, file) => sum + file.bytes, 0);
28
46
  if (fonts.length > 0 && (fontBytes >= c.shippedMinBytes || superseded.length > 0)) {
29
47
  findings.push({
30
- severity: superseded.length > 0 || manyWeights.length > 0 ? 'mid' : 'info',
48
+ // A second format is clutter on the server, not bytes on the wire: on its own it is
49
+ // context. Weights nobody uses are downloaded the moment a style asks for them.
50
+ severity: manyWeights.length > 0 ? 'mid' : 'info',
31
51
  kind: 'fonts',
52
+ size: fontBytes,
32
53
  ...text.fonts({
33
54
  families: fonts.length,
34
55
  files: fonts.reduce((sum, family) => sum + family.files.length, 0),
35
56
  size: (0, format_utils_1.formatBytes)(fontBytes),
57
+ spare: (0, format_utils_1.formatBytes)(spareBytes),
36
58
  superseded: named(superseded),
37
59
  preloaded: named(fonts.flatMap(family => family.preloaded)),
38
60
  list: fonts
39
- .map(family => `${(0, finding_html_1.mono)(family.name)} — ${family.files.length} files, ${(0, format_utils_1.formatBytes)(family.bytes)}, ${family.formats.join('/')}`)
61
+ .map(family => `${(0, finding_html_1.mono)(family.name)} — ${text.fileCount(family.files.length)}, ${(0, format_utils_1.formatBytes)(family.bytes)}, ${family.formats.join('/')}`)
40
62
  .join(' · '),
41
63
  }),
42
64
  });
@@ -56,23 +78,35 @@ const buildAssetFindings = (assets, lang, c) => {
56
78
  outdated: outdated.length,
57
79
  outdatedList: named(outdated.map(file => `${file.name} → .${file.modernNeighbour}`)),
58
80
  list: media
59
- .map(file => `${(0, finding_html_1.mono)(file.name)} (${(0, format_utils_1.formatBytes)(file.bytes)}${file.inPage ? ', in the page' : ''})`)
81
+ .map(file => `${(0, finding_html_1.mono)(file.name)} (${(0, format_utils_1.formatBytes)(file.bytes)}${file.inPage ? `, ${text.inPage}` : ''})`)
60
82
  .join(' · '),
61
83
  }),
62
84
  });
63
85
  }
64
86
  // 3 · The same file under two names. Only when the contents were compared: a list built from
65
87
  // sizes alone would be a guess dressed as a finding.
66
- const duplicates = assets.duplicates;
67
- const first = duplicates[0];
68
- if (first) {
88
+ // And what travels twice apart from what is only stored twice: a copy nothing names is never
89
+ // downloaded, and two copies with one of them named cost the deploy, not the visit.
90
+ const listOf = (entries) => entries.map(entry => `${named(entry.names)} (${(0, format_utils_1.formatBytes)(entry.bytes)} ${text.each})`).join(' · ');
91
+ const wastedBy = (entries) => entries.reduce((sum, entry) => sum + entry.wasted, 0);
92
+ const travels = assets.duplicates.filter(entry => entry.named === null || entry.named > 1);
93
+ const stored = assets.duplicates.filter(entry => entry.named !== null && entry.named <= 1);
94
+ const wasted = wastedBy(travels);
95
+ if (assets.duplicates.length > 0) {
69
96
  findings.push({
70
- severity: 'mid',
97
+ // A copy smaller than what moves between two builds is said, and is no work to plan.
98
+ severity: wasted >= c.growthMinBytes ? 'mid' : 'info',
71
99
  kind: 'duplicateAssets',
72
100
  ...text.duplicateAssets({
73
- count: duplicates.length,
74
- size: (0, format_utils_1.formatBytes)(duplicates.reduce((sum, entry) => sum + entry.wasted, 0)),
75
- list: duplicates.map(entry => `${named(entry.names)} (${(0, format_utils_1.formatBytes)(entry.bytes)} each)`).join(' · '),
101
+ count: travels.length,
102
+ size: (0, format_utils_1.formatBytes)(wasted),
103
+ list: listOf(travels),
104
+ stored: {
105
+ count: stored.length,
106
+ size: (0, format_utils_1.formatBytes)(wastedBy(stored)),
107
+ list: listOf(stored),
108
+ none: stored.every(entry => entry.named === 0),
109
+ },
76
110
  }),
77
111
  });
78
112
  }
@@ -106,7 +140,22 @@ const buildAssetFindings = (assets, lang, c) => {
106
140
  ...text.unreferencedAssets({
107
141
  count: orphans.length,
108
142
  size: (0, format_utils_1.formatBytes)(orphanBytes),
109
- list: orphans.map(file => `${(0, finding_html_1.mono)(file.path)} (${(0, format_utils_1.formatBytes)(file.bytes)})`).join(' · '),
143
+ list: orphans
144
+ .map(file => {
145
+ const repo = repoPaths?.get(file.path);
146
+ return `${(0, finding_html_1.mono)(file.path)} (${(0, format_utils_1.formatBytes)(file.bytes)}${repo ? ` ← ${(0, finding_html_1.mono)(repo)}` : ''})`;
147
+ })
148
+ .join(' · '),
149
+ fromRepo: orphans.filter(file => repoPaths?.has(file.path)).length,
150
+ folders: [
151
+ ...new Set(orphans
152
+ .map(file => repoPaths?.get(file.path)?.split('/').slice(0, -1).join('/') ?? null)
153
+ .filter((folder) => !!folder)),
154
+ ]
155
+ .slice(0, 3)
156
+ .map(folder => (0, finding_html_1.mono)(`${folder}/`))
157
+ .join(', '),
158
+ verified,
110
159
  }),
111
160
  });
112
161
  }
@@ -8,11 +8,11 @@
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.buildCachingFindings = exports.buildCascadeShapeFindings = void 0;
11
- const blast_1 = require("../analysis/blast");
12
- const format_utils_1 = require("../format/format.utils");
13
- const situation_1 = require("../situation/situation");
14
- const finding_html_1 = require("./finding-html");
15
- const finding_text_1 = require("./finding-text");
11
+ const blast_1 = require("../../analysis/graph/blast");
12
+ const format_utils_1 = require("../../format/format.utils");
13
+ const situation_1 = require("../../situation/situation");
14
+ const finding_html_1 = require("../text/finding-html");
15
+ const finding_text_1 = require("../text/finding-text");
16
16
  /**
17
17
  * How exposed this build is to the hash cascade, from its own topology.
18
18
  *
@@ -31,7 +31,7 @@ const finding_text_1 = require("./finding-text");
31
31
  const buildCascadeShapeFindings = (analysis, lang, situation = situation_1.EMPTY_SITUATION) => {
32
32
  const shape = (0, blast_1.cascadeShapeOf)(analysis);
33
33
  // Nothing to say about a build with no chunk that names several others: there is no shape yet.
34
- if (!shape.hub || shape.names < 2) {
34
+ if (!shape.hub || (shape.via === 'names' && shape.names < 2)) {
35
35
  return [];
36
36
  }
37
37
  const exposure = (0, situation_1.cascadeExposure)(situation);
@@ -54,6 +54,9 @@ const buildCascadeShapeFindings = (analysis, lang, situation = situation_1.EMPTY
54
54
  hub: shape.hub,
55
55
  names: shape.names,
56
56
  named: shape.named,
57
+ concentrated: shape.concentrated,
58
+ hubInBoot: shape.hubInBoot,
59
+ imported: shape.via === 'imports',
57
60
  size: (0, format_utils_1.formatBytes)(shape.bytes),
58
61
  chunks: analysis.allChunks.length,
59
62
  exposure,
@@ -63,7 +66,9 @@ const buildCascadeShapeFindings = (analysis, lang, situation = situation_1.EMPTY
63
66
  ];
64
67
  };
65
68
  exports.buildCascadeShapeFindings = buildCascadeShapeFindings;
66
- const buildCachingFindings = (caching, lang, c, situation = situation_1.EMPTY_SITUATION) => {
69
+ const buildCachingFindings = (caching, lang, c, situation = situation_1.EMPTY_SITUATION,
70
+ /** What wrote the build, for which setting the advice on splitting names. */
71
+ tool) => {
67
72
  const text = finding_text_1.TEXT[lang];
68
73
  const findings = [];
69
74
  // 1 · What the update costs. The figure that does not exist anywhere else, and the one this
@@ -124,14 +129,16 @@ const buildCachingFindings = (caching, lang, c, situation = situation_1.EMPTY_SI
124
129
  findings.push({
125
130
  severity: worst.inBoot ? 'mid' : 'info',
126
131
  kind: 'unstableChunk',
132
+ size: wasted,
127
133
  ...text.unstableChunk({
128
134
  count: unstable.length,
129
135
  name: worst.name,
130
136
  pct: Math.round(worst.vendorRatio * 100),
131
- size: (0, format_utils_1.formatBytes)(wasted),
137
+ size: `${worst.estimated ? '≈' : ''}${(0, format_utils_1.formatBytes)(wasted)}`,
132
138
  inBoot: worst.inBoot,
139
+ tool,
133
140
  list: unstable
134
- .map(chunk => `${(0, finding_html_1.mono)(chunk.name)} — ${Math.round(chunk.vendorRatio * 100)} % ${(0, format_utils_1.formatBytes)(chunk.vendorBytes)}${chunk.inBoot ? ' (bootstrap)' : ''}`)
141
+ .map(chunk => `${(0, finding_html_1.mono)(chunk.name)} — ${Math.round(chunk.vendorRatio * 100)} % ${chunk.estimated ? '≈' : ''}${(0, format_utils_1.formatBytes)(chunk.vendorBytes)}${chunk.inBoot ? ' (bootstrap)' : ''}`)
135
142
  .join(' · '),
136
143
  }),
137
144
  });
@@ -155,7 +162,7 @@ const buildCachingFindings = (caching, lang, c, situation = situation_1.EMPTY_SI
155
162
  .map(file => (0, finding_html_1.mono)(file.path))
156
163
  .join(', '),
157
164
  list: unhashable
158
- .map(file => `${(0, finding_html_1.mono)(file.path)} (${(0, format_utils_1.formatBytes)(file.bytes)}${file.inPage ? ', in the page' : ''})`)
165
+ .map(file => `${(0, finding_html_1.mono)(file.path)} (${(0, format_utils_1.formatBytes)(file.bytes)}${file.inPage ? `, ${text.inPage}` : ''})`)
159
166
  .join(' · '),
160
167
  }),
161
168
  });
@@ -10,7 +10,7 @@
10
10
  */
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.buildPageFindings = void 0;
13
- const finding_text_1 = require("./finding-text");
13
+ const finding_text_1 = require("../text/finding-text");
14
14
  /**
15
15
  * A page fetching from somewhere else, when it does.
16
16
  *
@@ -23,7 +23,10 @@ const buildPageFindings = (page, lang) => {
23
23
  if (!page) {
24
24
  return [];
25
25
  }
26
- const carrying = page.origins.filter(row => row.scripts > 0);
26
+ // And the stylesheets that block the paint: an icon font or a web font's CSS from another host
27
+ // is the strictest "before anything appears" there is, and three real builds had one that no
28
+ // figure and no signal mentioned.
29
+ const carrying = page.origins.filter(row => row.scripts > 0 || (row.styles ?? 0) > 0);
27
30
  if (carrying.length === 0 && !page.base) {
28
31
  return [];
29
32
  }
@@ -38,6 +41,7 @@ const buildPageFindings = (page, lang) => {
38
41
  ...finding_text_1.TEXT[lang].assetOrigin({
39
42
  origins: carrying.map(row => row.origin),
40
43
  scripts: carrying.reduce((sum, row) => sum + row.scripts, 0),
44
+ styles: carrying.reduce((sum, row) => sum + (row.styles ?? 0), 0),
41
45
  files: page.origins.reduce((sum, row) => sum + row.files, 0),
42
46
  cold: cold.map(row => row.origin),
43
47
  warmed: carrying.filter(row => hinted.has(row.origin)).map(row => row.origin),
@@ -9,13 +9,20 @@
9
9
  */
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.buildScanFindings = void 0;
12
- const format_utils_1 = require("../format/format.utils");
13
- const finding_html_1 = require("./finding-html");
14
- const finding_text_1 = require("./finding-text");
12
+ const actions_1 = require("../actions");
13
+ const finding_html_1 = require("../text/finding-html");
14
+ const finding_text_1 = require("../text/finding-text");
15
15
  const named = (items) => items.map(item => (0, finding_html_1.mono)(item)).join(', ');
16
16
  /** The ones that are a problem whatever else is true, as opposed to a build pointed at the wrong place. */
17
17
  const ALWAYS_SERIOUS = new Set(['privateKey', 'awsKey', 'githubToken', 'slackToken', 'googleKey']);
18
- const buildScanFindings = (scan, lang, c) => {
18
+ /**
19
+ * @param scale how the raw weights of packages are said in the report's unit: `unitScale` of the
20
+ * analysis. Raw by default, which is what a raw report needs and nothing more.
21
+ */
22
+ const buildScanFindings = (scan, lang, c, scale = actions_1.RAW_SCALE,
23
+ /** What wrote the build: which setting the advice on source maps names, and whose console it may be. */
24
+ tool) => {
25
+ const sized = (bytes) => (0, actions_1.formatSaving)(bytes, scale);
19
26
  const text = finding_text_1.TEXT[lang];
20
27
  const findings = [];
21
28
  // 1 · Credentials and internal addresses. The cheapest finding here and the most expensive to
@@ -23,18 +30,31 @@ const buildScanFindings = (scan, lang, c) => {
23
30
  // no rule for "a long string near the word key", which is what makes a security signal noisy
24
31
  // and then switched off.
25
32
  const secrets = scan.secrets;
26
- const serious = secrets.filter(match => ALWAYS_SERIOUS.has(match.kind));
33
+ // A Firebase web `apiKey` is public by design, and a `process.env.X` inside a package is that
34
+ // package reading its own switch. Both are said, with the reason, and neither raises the card:
35
+ // a security signal that cries wolf on every Firebase app is one somebody switches off.
36
+ const explained = (match) => !!match.benign || !!match.owner;
37
+ const serious = secrets.filter(match => ALWAYS_SERIOUS.has(match.kind) && !explained(match));
38
+ const open = secrets.filter(match => !explained(match));
27
39
  const first = secrets[0];
28
40
  if (first) {
41
+ const publicKeys = secrets.filter(match => match.benign === 'firebaseConfig');
42
+ const theirs = secrets.filter(match => !!match.owner);
29
43
  findings.push({
30
- severity: serious.length > 0 ? 'high' : 'mid',
44
+ severity: serious.length > 0 ? 'high' : open.length > 0 ? 'mid' : 'info',
31
45
  kind: 'secrets',
32
46
  ...text.secrets({
33
47
  count: secrets.length,
34
48
  serious: serious.length,
35
- kinds: [...new Set(secrets.map(match => match.kind))].join(', '),
49
+ open: open.length,
50
+ publicKeys: publicKeys.length,
51
+ theirs: [...new Set(theirs.map(match => match.owner ?? ''))].map(pkg => (0, finding_html_1.mono)(pkg)).join(', '),
52
+ kinds: [...new Set(secrets.map(match => text.secretNames[match.kind]))].join(', '),
53
+ // What raises the card, named in its title. A public Firebase key is said in the same
54
+ // card, so "medium" next to "public by design" read as the key being the problem.
55
+ openKinds: [...new Set(open.map(match => text.secretNames[match.kind]))].join(', '),
36
56
  list: secrets
37
- .map(match => `${(0, finding_html_1.mono)(match.kind)} ${match.redacted} (${(0, finding_html_1.mono)(match.chunk)}${match.count > 1 ? `, ×${match.count}` : ''})`)
57
+ .map(match => `${text.secretNames[match.kind]} ${(0, finding_html_1.mono)(match.redacted)} (${(0, finding_html_1.mono)(match.chunk)}${match.count > 1 ? `, ×${match.count}` : ''}${match.benign ? `, ${text.secretBenign[match.benign]}` : ''}${match.owner ? `, ${text.secretOwner((0, finding_html_1.mono)(match.owner))}` : ''})`)
38
58
  .join(' · '),
39
59
  }),
40
60
  });
@@ -56,7 +76,10 @@ const buildScanFindings = (scan, lang, c) => {
56
76
  count: leftovers.length,
57
77
  broken: breaking.length > 0,
58
78
  unattributed,
59
- list: leftovers.map(item => `${(0, finding_html_1.mono)(item.kind)} ×${item.count} (${named(item.where)})`).join(' · '),
79
+ tool,
80
+ list: leftovers
81
+ .map(item => `${text.leftoverNames[item.kind]} ×${item.count} (${named(item.where)})`)
82
+ .join(' · '),
60
83
  }),
61
84
  });
62
85
  }
@@ -74,6 +97,7 @@ const buildScanFindings = (scan, lang, c) => {
74
97
  files: exposure.ownFiles,
75
98
  maps: exposure.maps,
76
99
  env: exposure.envReferences,
100
+ tool,
77
101
  list: exposure.paths.map(path => (0, finding_html_1.mono)(path)).join(' · '),
78
102
  }),
79
103
  });
@@ -88,11 +112,11 @@ const buildScanFindings = (scan, lang, c) => {
88
112
  kind: 'thirdParty',
89
113
  ...text.thirdParty({
90
114
  count: groups.reduce((sum, group) => sum + group.packages.length, 0),
91
- size: (0, format_utils_1.formatBytes)(bootBytes),
92
- total: (0, format_utils_1.formatBytes)(groups.reduce((sum, group) => sum + group.bytes, 0)),
115
+ size: sized(bootBytes),
116
+ total: sized(groups.reduce((sum, group) => sum + group.bytes, 0)),
93
117
  list: groups
94
- .map(group => `${(0, finding_html_1.mono)(group.category)} — ${(0, format_utils_1.formatBytes)(group.bytes)}: ${group.packages
95
- .map(pkg => `${pkg.name} (${(0, format_utils_1.formatBytes)(pkg.bytes)}${pkg.inBoot ? ', bootstrap' : ''})`)
118
+ .map(group => `${(0, finding_html_1.mono)(group.category)} — ${sized(group.bytes)}: ${group.packages
119
+ .map(pkg => `${pkg.name} (${sized(pkg.bytes)}${pkg.inBoot ? ', bootstrap' : ''})`)
96
120
  .join(', ')}`)
97
121
  .join(' · '),
98
122
  }),