@bymaksym/loadline 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +182 -0
  3. package/bin/loadline.js +50 -0
  4. package/dist/cli/cli/args.js +324 -0
  5. package/dist/cli/cli/args.types.js +3 -0
  6. package/dist/cli/cli/gates.js +173 -0
  7. package/dist/cli/cli/gates.types.js +3 -0
  8. package/dist/cli/cli/main.js +156 -0
  9. package/dist/cli/cli/read-build.js +382 -0
  10. package/dist/cli/cli/read-build.types.js +3 -0
  11. package/dist/cli/cli/render-json.js +116 -0
  12. package/dist/cli/cli/render-json.types.js +10 -0
  13. package/dist/cli/cli/render-markdown.js +30 -0
  14. package/dist/cli/cli/render-pr.js +76 -0
  15. package/dist/cli/cli/render-sarif.js +83 -0
  16. package/dist/cli/cli/render-text.js +388 -0
  17. package/dist/cli/cli/report.js +196 -0
  18. package/dist/cli/cli/report.types.js +3 -0
  19. package/dist/cli/cli/self-check.js +85 -0
  20. package/dist/cli/cli/text.js +180 -0
  21. package/dist/cli/cli/text.types.js +10 -0
  22. package/dist/cli/src/app/core/analysis/analysis.js +661 -0
  23. package/dist/cli/src/app/core/analysis/analysis.types.js +6 -0
  24. package/dist/cli/src/app/core/analysis/barrels.js +128 -0
  25. package/dist/cli/src/app/core/analysis/blast.js +172 -0
  26. package/dist/cli/src/app/core/analysis/cycles.js +110 -0
  27. package/dist/cli/src/app/core/analysis/delivery.js +143 -0
  28. package/dist/cli/src/app/core/analysis/entries.js +217 -0
  29. package/dist/cli/src/app/core/analysis/exclusive.js +91 -0
  30. package/dist/cli/src/app/core/analysis/importers.js +38 -0
  31. package/dist/cli/src/app/core/analysis/insights.js +202 -0
  32. package/dist/cli/src/app/core/analysis/insights.types.js +10 -0
  33. package/dist/cli/src/app/core/analysis/invariant.js +69 -0
  34. package/dist/cli/src/app/core/analysis/metafile.types.js +44 -0
  35. package/dist/cli/src/app/core/analysis/module-graph.js +192 -0
  36. package/dist/cli/src/app/core/analysis/sourcemap.js +231 -0
  37. package/dist/cli/src/app/core/analysis/sourcemap.types.js +3 -0
  38. package/dist/cli/src/app/core/analysis/split-drift.js +47 -0
  39. package/dist/cli/src/app/core/assets/assets.js +296 -0
  40. package/dist/cli/src/app/core/assets/assets.types.js +11 -0
  41. package/dist/cli/src/app/core/baseline/baseline.js +0 -0
  42. package/dist/cli/src/app/core/baseline/baseline.types.js +3 -0
  43. package/dist/cli/src/app/core/caching/caching.js +241 -0
  44. package/dist/cli/src/app/core/caching/caching.types.js +10 -0
  45. package/dist/cli/src/app/core/caching/from-analysis.js +73 -0
  46. package/dist/cli/src/app/core/config/loadline-config.js +110 -0
  47. package/dist/cli/src/app/core/config/loadline-config.types.js +12 -0
  48. package/dist/cli/src/app/core/criteria/criteria.js +228 -0
  49. package/dist/cli/src/app/core/criteria/criteria.types.js +3 -0
  50. package/dist/cli/src/app/core/deps/deps.js +225 -0
  51. package/dist/cli/src/app/core/deps/deps.types.js +15 -0
  52. package/dist/cli/src/app/core/export/markdown-table.utils.js +40 -0
  53. package/dist/cli/src/app/core/export/summary.js +72 -0
  54. package/dist/cli/src/app/core/findings/actions.js +59 -0
  55. package/dist/cli/src/app/core/findings/assets.js +130 -0
  56. package/dist/cli/src/app/core/findings/caching.js +165 -0
  57. package/dist/cli/src/app/core/findings/compose.js +41 -0
  58. package/dist/cli/src/app/core/findings/deps.js +66 -0
  59. package/dist/cli/src/app/core/findings/effort.js +117 -0
  60. package/dist/cli/src/app/core/findings/finding-html.js +13 -0
  61. package/dist/cli/src/app/core/findings/finding-plain.js +26 -0
  62. package/dist/cli/src/app/core/findings/finding-text.js +1231 -0
  63. package/dist/cli/src/app/core/findings/finding.types.js +80 -0
  64. package/dist/cli/src/app/core/findings/findings.js +514 -0
  65. package/dist/cli/src/app/core/findings/graph.js +167 -0
  66. package/dist/cli/src/app/core/findings/own-in-boot.js +88 -0
  67. package/dist/cli/src/app/core/findings/page.js +49 -0
  68. package/dist/cli/src/app/core/findings/requests.js +185 -0
  69. package/dist/cli/src/app/core/findings/scan.js +126 -0
  70. package/dist/cli/src/app/core/findings/shipped.js +244 -0
  71. package/dist/cli/src/app/core/findings/situation.js +116 -0
  72. package/dist/cli/src/app/core/format/format.utils.js +204 -0
  73. package/dist/cli/src/app/core/i18n/en.js +819 -0
  74. package/dist/cli/src/app/core/i18n/es.js +822 -0
  75. package/dist/cli/src/app/core/i18n/ui-strings.js +11 -0
  76. package/dist/cli/src/app/core/i18n/ui.js +7 -0
  77. package/dist/cli/src/app/core/intake/bundle-graph.js +346 -0
  78. package/dist/cli/src/app/core/intake/bundle-graph.types.js +3 -0
  79. package/dist/cli/src/app/core/intake/dist-files.js +160 -0
  80. package/dist/cli/src/app/core/intake/index-html.js +292 -0
  81. package/dist/cli/src/app/core/json/json.utils.js +55 -0
  82. package/dist/cli/src/app/core/measurement/measurement.types.js +14 -0
  83. package/dist/cli/src/app/core/project/budget-advice.js +76 -0
  84. package/dist/cli/src/app/core/project/project-context.js +394 -0
  85. package/dist/cli/src/app/core/project/project-context.types.js +3 -0
  86. package/dist/cli/src/app/core/scan/catalog.js +67 -0
  87. package/dist/cli/src/app/core/scan/scan.js +280 -0
  88. package/dist/cli/src/app/core/scan/scan.types.js +10 -0
  89. package/dist/cli/src/app/core/scan/secrets.js +0 -0
  90. package/dist/cli/src/app/core/situation/situation.js +261 -0
  91. package/dist/cli/src/app/core/situation/situation.types.js +19 -0
  92. package/dist/cli/src/app/core/timing/timing.js +87 -0
  93. package/dist/cli/src/app/core/timing/timing.types.js +3 -0
  94. package/dist/cli/src/app/core/whatif/defer.js +68 -0
  95. package/dist/cli/src/app/state/report-messages.utils.js +73 -0
  96. package/docs/HOW-IT-WORKS.md +1087 -0
  97. package/loadline.html +78 -0
  98. package/package.json +154 -0
@@ -0,0 +1,167 @@
1
+ "use strict";
2
+ /**
3
+ * The signals that read `analysis.insights()`: the figures that were inside the metafile all along.
4
+ *
5
+ * They are in their own file for the reason the other groups of signals are — `requests.ts` holds
6
+ * the two counted in round trips, `shipped.ts` what travels without being screen code — so that
7
+ * `findings.ts` stays the list of what the report has always said.
8
+ *
9
+ * Every one of them names everything it found. A list of seven cycles with four of them printed is
10
+ * a list that has to be checked somewhere else, which is the thing this tool exists not to do.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.buildGraphFindings = void 0;
14
+ const format_utils_1 = require("../format/format.utils");
15
+ const finding_html_1 = require("./finding-html");
16
+ const finding_text_1 = require("./finding-text");
17
+ const named = (items) => items.map(item => (0, finding_html_1.mono)(item)).join(', ');
18
+ /** A cycle as the circle somebody would draw: `checkout › shared › analytics › checkout`. */
19
+ const loop = (cycle) => cycle.steps.map(step => (0, finding_html_1.mono)(step)).join(' › ');
20
+ const buildGraphFindings = (analysis, lang, c) => {
21
+ const text = finding_text_1.TEXT[lang];
22
+ const insights = analysis.insights();
23
+ const findings = [];
24
+ // 1 · The `import()` that defers nothing. The classic silent failure of code splitting, and it
25
+ // lives on the edges of the graph, which is why no tool looking at chunks shows it.
26
+ const mixed = insights.mixedImports;
27
+ const worstMixed = mixed[0];
28
+ if (worstMixed) {
29
+ const eager = mixed.filter(entry => entry.inBoot).map(entry => entry.path);
30
+ findings.push({
31
+ severity: mixed.some(entry => entry.inBoot) ? 'high' : 'mid',
32
+ target: { tab: 'search', key: worstMixed.label },
33
+ kind: 'mixedImport',
34
+ // Only the ones in the bootstrap have a first-load saving: a mixed import inside a lazy
35
+ // chunk is still a mistake and still costs nothing before the first paint.
36
+ saving: eager.length > 0 ? insights.exclusiveOf(eager) : 0,
37
+ sources: eager,
38
+ ...text.mixedImport({
39
+ count: mixed.length,
40
+ name: worstMixed.label,
41
+ size: (0, format_utils_1.formatBytes)(mixed.reduce((sum, entry) => sum + entry.bytes, 0)),
42
+ inBoot: mixed.some(entry => entry.inBoot),
43
+ list: mixed
44
+ .map(entry => `${(0, finding_html_1.mono)(entry.label)} (${(0, format_utils_1.formatBytes)(entry.bytes)}${entry.inBoot ? ', bootstrap' : ''}) — ${named(entry.staticImporters.map(file => (0, format_utils_1.baseName)(file)))}`)
45
+ .join(' · '),
46
+ }),
47
+ });
48
+ }
49
+ // 2 · A barrel of the project's own. Only the ones whose exclusive weight clears the threshold:
50
+ // a barrel in front of code that arrives five other ways costs nothing and is not a finding.
51
+ const barrels = insights.ownBarrels.filter(barrel => barrel.inBoot && barrel.exclusive >= c.barrelMinBytes);
52
+ const worstBarrel = barrels[0];
53
+ if (worstBarrel) {
54
+ findings.push({
55
+ severity: 'mid',
56
+ target: { tab: 'boot', key: worstBarrel.path },
57
+ kind: 'ownBarrel',
58
+ saving: insights.exclusiveOf(barrels.map(barrel => barrel.path)),
59
+ sources: barrels.map(barrel => barrel.path),
60
+ ...text.ownBarrel({
61
+ count: barrels.length,
62
+ name: worstBarrel.path,
63
+ pulls: worstBarrel.pulls,
64
+ size: (0, format_utils_1.formatBytes)(worstBarrel.exclusive),
65
+ importers: named(worstBarrel.importers.map(file => (0, format_utils_1.baseName)(file))),
66
+ list: barrels
67
+ .map(barrel => `${(0, finding_html_1.mono)(barrel.path)} — ${barrel.reexports} re-exports, ${barrel.pulls} files, ${(0, format_utils_1.formatBytes)(barrel.exclusive)}`)
68
+ .join(' · '),
69
+ }),
70
+ });
71
+ }
72
+ // 3 · The same shape one level up: a package whose files arrive by the hundred through one door.
73
+ const packages = insights.packageBarrels.filter(pkg => pkg.bytes >= c.bootPackageMinBytes);
74
+ const worstPackage = packages[0];
75
+ if (worstPackage) {
76
+ findings.push({
77
+ severity: worstPackage.inBoot ? 'mid' : 'info',
78
+ target: { tab: worstPackage.inBoot ? 'boot' : 'search', key: worstPackage.name },
79
+ kind: 'packageBarrel',
80
+ ...text.packageBarrel({
81
+ count: packages.length,
82
+ name: worstPackage.name,
83
+ files: worstPackage.files,
84
+ entryPoints: worstPackage.entryPoints,
85
+ size: (0, format_utils_1.formatBytes)(worstPackage.bytes),
86
+ importers: named(worstPackage.importers.map(file => (0, format_utils_1.baseName)(file))),
87
+ list: packages
88
+ .map(pkg => `${(0, finding_html_1.mono)(pkg.name)} — ${pkg.files} files in, ${pkg.entryPoints} imported from outside, ${(0, format_utils_1.formatBytes)(pkg.bytes)}${pkg.inBoot ? ' (bootstrap)' : ''}`)
89
+ .join(' · '),
90
+ }),
91
+ });
92
+ }
93
+ // 4 · Cycles. Architecture, measured rather than argued about, and ending in bytes: a cycle
94
+ // lengthens import chains and stops a bundler from tree-shaking either half of the loop.
95
+ const cycles = insights.cycles;
96
+ const folders = insights.folderCycles;
97
+ const firstCycle = folders[0] ?? cycles[0];
98
+ if (firstCycle) {
99
+ findings.push({
100
+ severity: cycles.some(cycle => cycle.inBoot) ? 'mid' : 'info',
101
+ kind: 'cycles',
102
+ ...text.cycles({
103
+ files: cycles.length,
104
+ folders: folders.length,
105
+ worst: loop(firstCycle),
106
+ inBoot: cycles.some(cycle => cycle.inBoot),
107
+ folderList: folders.map(cycle => loop(cycle)).join(' · '),
108
+ fileList: cycles.map(cycle => `${loop(cycle)} (${(0, format_utils_1.formatBytes)(cycle.bytes)})`).join(' · '),
109
+ }),
110
+ });
111
+ }
112
+ // 5 · The same module in two chunks. Different from a package shipped in two versions, which
113
+ // the report already names: here both copies are the same code, twice.
114
+ const twice = insights.paidTwice.filter(entry => entry.wasted > 0);
115
+ const twiceBytes = insights.paidTwiceBytes;
116
+ if (twice.length > 0 && twiceBytes >= c.paidTwiceMinBytes) {
117
+ findings.push({
118
+ severity: 'mid',
119
+ target: { tab: 'search', key: twice[0]?.label ?? '' },
120
+ kind: 'paidTwice',
121
+ ...text.paidTwice({
122
+ count: twice.length,
123
+ size: (0, format_utils_1.formatBytes)(twiceBytes),
124
+ list: twice
125
+ .map(entry => `${(0, finding_html_1.mono)(entry.label)} ×${entry.copies} (${(0, format_utils_1.formatBytes)(entry.wasted)}) — ${named(entry.chunks)}`)
126
+ .join(' · '),
127
+ }),
128
+ });
129
+ }
130
+ // 6 · Two screens that are the same screen. Either a shared chunk is missing or one of them is.
131
+ const twins = insights.twins;
132
+ const firstTwin = twins[0];
133
+ if (firstTwin) {
134
+ findings.push({
135
+ severity: 'info',
136
+ target: { tab: 'screens', key: firstTwin.a },
137
+ kind: 'twinScreens',
138
+ ...text.twinScreens({
139
+ count: twins.length,
140
+ a: firstTwin.labelA,
141
+ b: firstTwin.labelB,
142
+ pct: Math.round(firstTwin.overlap * 100),
143
+ apart: (0, format_utils_1.formatBytes)(firstTwin.apartBytes),
144
+ list: twins
145
+ .map(twin => `${(0, finding_html_1.mono)(twin.labelA)} / ${(0, finding_html_1.mono)(twin.labelB)} (${Math.round(twin.overlap * 100)} %, ${(0, format_utils_1.formatBytes)(twin.apartBytes)})`)
146
+ .join(' · '),
147
+ }),
148
+ });
149
+ }
150
+ // 7 · Whose code the first load is. Context, never a fault: a framework is somebody else's code.
151
+ const { ownership } = insights;
152
+ if (ownership.theirsRatio >= c.theirsRatio && ownership.theirs > 0) {
153
+ findings.push({
154
+ severity: 'info',
155
+ target: { tab: 'boot', key: '' },
156
+ kind: 'theirs',
157
+ ...text.theirs({
158
+ pct: Math.round(ownership.theirsRatio * 100),
159
+ theirs: (0, format_utils_1.formatBytes)(ownership.theirs),
160
+ yours: (0, format_utils_1.formatBytes)(ownership.yours),
161
+ list: ownership.topPackages.map(pkg => `${(0, finding_html_1.mono)(pkg.name)} (${(0, format_utils_1.formatBytes)(pkg.bytes)})`).join(' · '),
162
+ }),
163
+ });
164
+ }
165
+ return findings;
166
+ };
167
+ exports.buildGraphFindings = buildGraphFindings;
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ /**
3
+ * A project folder in the bootstrap whose consumers are lazy screens.
4
+ *
5
+ * The report already asks this of npm packages — a library everybody downloads because one lazy
6
+ * screen registers it — and the same thing happens with project code, where no signal covered it.
7
+ *
8
+ * **Why by folder and not by file.** Tried against a real build first: the business layer was in the
9
+ * bootstrap across thirty files of one to three kilobytes each. Every one of them is far below any
10
+ * size worth naming, and together they are a layer that should not be there. A per-file rule finds
11
+ * nothing; the folder is the unit the problem has.
12
+ *
13
+ * The fix is also different from the package one. A package moves by changing where it is
14
+ * registered. A project folder is usually one layer depending on another at build time, and what
15
+ * matters is the list of files keeping it in the bootstrap: moving the first and leaving the other
16
+ * two changes nothing, which is the mistake this signal exists to prevent.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.buildOwnInBootFindings = void 0;
20
+ const format_utils_1 = require("../format/format.utils");
21
+ const finding_html_1 = require("./finding-html");
22
+ const finding_text_1 = require("./finding-text");
23
+ const inBoot = (module) => module.places.some(place => place.zone === 'boot');
24
+ const candidatesOf = (analysis, c) => {
25
+ const screens = new Set(analysis.screens.map(screen => screen.source));
26
+ const bytesOf = new Map(analysis.bootBuckets.filter(bucket => bucket.isProjectCode).map(bucket => [bucket.name, bucket.bytes]));
27
+ const byFolder = new Map();
28
+ for (const module of analysis.modules) {
29
+ if (module.pkg || !inBoot(module)) {
30
+ continue;
31
+ }
32
+ const folder = (0, format_utils_1.projectFolderOf)(module.path);
33
+ byFolder.set(folder, [...(byFolder.get(folder) ?? []), module]);
34
+ }
35
+ return ([...byFolder]
36
+ .map(([folder, modules]) => {
37
+ // Files of the folder import each other constantly: that says nothing about who wants it.
38
+ const importers = [
39
+ ...new Set(modules.flatMap(module => [...(analysis.ownImporters.get(module.path) ?? [])])),
40
+ ].filter(file => (0, format_utils_1.projectFolderOf)(file) !== folder);
41
+ return {
42
+ folder,
43
+ bytes: bytesOf.get(folder) ?? 0,
44
+ lazy: importers.filter(file => screens.has(file)),
45
+ keeping: importers.filter(file => !screens.has(file)),
46
+ };
47
+ })
48
+ // The structural condition is per folder; the size floor is not. Tried against a real
49
+ // build: the business layer was there as six folders of one to eight kilobytes each, so a
50
+ // floor applied folder by folder finds nothing and the layer stays invisible.
51
+ .filter(entry => entry.lazy.length > 0 &&
52
+ entry.keeping.length > 0 &&
53
+ entry.keeping.length <= c.bootPackageMaxImporters)
54
+ .toSorted((a, b) => b.bytes - a.bytes));
55
+ };
56
+ const buildOwnInBootFindings = (analysis, lang, c) => {
57
+ const text = finding_text_1.TEXT[lang];
58
+ const candidates = candidatesOf(analysis, c);
59
+ const bytes = candidates.reduce((sum, entry) => sum + entry.bytes, 0);
60
+ const first = candidates[0];
61
+ // One folder of two kilobytes is not worth naming. The same layer across six of them is. The
62
+ // floor is a criterion of its own rather than a fraction of the package one: a folder of yours
63
+ // in the bootstrap is a coupling problem before it is a weight problem, and whoever wants to
64
+ // move one line should not have to move the other.
65
+ if (!first || bytes < c.ownFolderMinBytes) {
66
+ return [];
67
+ }
68
+ const insights = analysis.insights();
69
+ const files = candidates.flatMap(entry => insights.filesByBucket.get(entry.folder) ?? []);
70
+ return [
71
+ {
72
+ severity: 'mid',
73
+ target: { tab: 'boot', key: first.folder },
74
+ kind: 'ownInBoot',
75
+ saving: insights.exclusiveOf(files),
76
+ sources: files,
77
+ ...text.ownInBoot({
78
+ count: candidates.length,
79
+ name: first.folder,
80
+ size: (0, format_utils_1.formatBytes)(bytes),
81
+ list: candidates
82
+ .map(entry => `${(0, finding_html_1.mono)(entry.folder)} (${(0, format_utils_1.formatBytes)(entry.bytes)}) — ${text.ownInBootKept(entry.keeping.map(file => (0, finding_html_1.mono)(file)).join(', '), entry.lazy.length)}`)
83
+ .join(' · '),
84
+ }),
85
+ },
86
+ ];
87
+ };
88
+ exports.buildOwnInBootFindings = buildOwnInBootFindings;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ /**
3
+ * What `index.html` says about **where** the first load comes from, as opposed to what is in it.
4
+ *
5
+ * Every other figure of the report is about bytes and edges. This one is about hosts, and it is
6
+ * the only fact of the first load that moves the arithmetic at the root: a chunk on another origin
7
+ * is not one request later than the page, it is a DNS lookup, a TCP connection and a TLS handshake
8
+ * before the first byte of the first chunk. Under HTTP/1.1 it cuts the other way as well — a
9
+ * second origin is a second pool of six connections — which is why this is context and not a fault.
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.buildPageFindings = void 0;
13
+ const finding_text_1 = require("./finding-text");
14
+ /**
15
+ * A page fetching from somewhere else, when it does.
16
+ *
17
+ * Only origins carrying JavaScript raise it above context. An analytics tag on a third host is a
18
+ * fact about the page and not about the split, and this report is about the split — the third
19
+ * parties are counted where they are actually observed, in the browser measurement, because a page
20
+ * that injects them at run time names none of them in its markup.
21
+ */
22
+ const buildPageFindings = (page, lang) => {
23
+ if (!page) {
24
+ return [];
25
+ }
26
+ const carrying = page.origins.filter(row => row.scripts > 0);
27
+ if (carrying.length === 0 && !page.base) {
28
+ return [];
29
+ }
30
+ const hinted = new Set(page.hinted);
31
+ const cold = carrying.filter(row => !hinted.has(row.origin));
32
+ return [
33
+ {
34
+ // Never a fault: serving assets from a CDN is a decision with two sides, and the tool's
35
+ // job here is to put the handshake on the bill, not to ask for it back.
36
+ severity: cold.length > 0 ? 'mid' : 'info',
37
+ kind: 'assetOrigin',
38
+ ...finding_text_1.TEXT[lang].assetOrigin({
39
+ origins: carrying.map(row => row.origin),
40
+ scripts: carrying.reduce((sum, row) => sum + row.scripts, 0),
41
+ files: page.origins.reduce((sum, row) => sum + row.files, 0),
42
+ cold: cold.map(row => row.origin),
43
+ warmed: carrying.filter(row => hinted.has(row.origin)).map(row => row.origin),
44
+ base: page.base,
45
+ }),
46
+ },
47
+ ];
48
+ };
49
+ exports.buildPageFindings = buildPageFindings;
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+ /**
3
+ * The two signals measured in requests instead of bytes.
4
+ *
5
+ * Every other figure in the report answers "how much comes down". These answer "in how many
6
+ * pieces" and "in how many goes", which are different questions and the ones left when the bytes
7
+ * are fine.
8
+ *
9
+ * **What the second one is NOT.** "Chunks under 30 kB are bad" is a bad rule. A 5 kB chunk for an admin screen
10
+ * nobody opens is doing exactly its job: those 5 kB never download. Small is only a problem for
11
+ * code that comes down **together**, so this counts what one screen loads at once — the bootstrap
12
+ * plus what that screen pulls in — and never the build's chunk list.
13
+ *
14
+ * And it is deliberately conservative about the fix. The split is not a decision anybody took: the
15
+ * bundler makes one chunk per distinct set of screens that reach a module, so many chunks means
16
+ * many combinations of "these screens and not those use this". Merging them by hand is possible and
17
+ * sometimes wrong — a big chunk mixing what changes with what does not is invalidated whole on
18
+ * every deploy.
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.buildRequestFindings = void 0;
22
+ const format_utils_1 = require("../format/format.utils");
23
+ const finding_html_1 = require("./finding-html");
24
+ const finding_text_1 = require("./finding-text");
25
+ /** The middle screen, which is what "the typical screen" means everywhere else in the report. */
26
+ const median = (list) => list[Math.floor(list.length / 2)];
27
+ /**
28
+ * Screens that arrive in several goes.
29
+ *
30
+ * The count itself has been a column of the screens table since the round trips were added; what
31
+ * was missing was anything pointing at it. It is deliberately about the **deepest** screen rather
32
+ * than an average: a chain is a property of one screen's imports, and averaging chains across a
33
+ * report describes no screen that exists.
34
+ *
35
+ * Separate from the signal below on purpose. That one is about how many pieces come down, this one
36
+ * about how many of them had to wait, and a build can easily have either without the other: two
37
+ * files fetched together cost one trip, and two files where the second is only discovered by
38
+ * parsing the first cost two.
39
+ */
40
+ const slowScreenFindings = (analysis, lang, c) => {
41
+ const slow = analysis.screens.filter(screen => screen.waves >= c.screenWavesMax);
42
+ const worst = slow.toSorted((a, b) => b.waves - a.waves || b.total - a.total)[0];
43
+ if (!worst) {
44
+ return [];
45
+ }
46
+ const named = (screen) => `${(0, finding_html_1.mono)(screen.label)} (${screen.waves})`;
47
+ return [
48
+ {
49
+ // Nothing here is downloaded that would not be downloaded anyway: the bytes are right
50
+ // and the wait is not, which is worth a look and never worth stopping a build for.
51
+ severity: 'mid',
52
+ target: { tab: 'screens', key: worst.source },
53
+ kind: 'slowScreens',
54
+ ...finding_text_1.TEXT[lang].slowScreens({
55
+ count: slow.length,
56
+ max: c.screenWavesMax,
57
+ worstLabel: worst.label,
58
+ worstWaves: worst.waves,
59
+ // Depth on its own reads a chain and a fan-out as the same problem, and their
60
+ // fixes are opposite: a chain shortens by flattening imports, a fan-out does not
61
+ // shorten at all. The width is what tells the reader which of the two this is.
62
+ worstWidth: worst.width,
63
+ // The threshold as a formula rather than a number. A round trip is at least one
64
+ // latency, whatever the protocol and whatever the compression, which is what makes
65
+ // this the one figure here with a first principle behind it — so the finding shows
66
+ // the arithmetic instead of asking anybody to take `3` on faith.
67
+ latencyMs: c.latencyMs,
68
+ worstMs: worst.waves * c.latencyMs,
69
+ list: slow
70
+ .toSorted((a, b) => b.waves - a.waves)
71
+ .map(screen => named(screen))
72
+ .join(', '),
73
+ }),
74
+ },
75
+ ];
76
+ };
77
+ /**
78
+ * The size Rollup's own example uses for `experimentalMinChunkSize`, in raw bytes.
79
+ *
80
+ * It is quoted in the unit Rollup measures in — bytes before minification — and not converted,
81
+ * because converting it would be the mistake this constant exists to avoid. Loadline's own crumb
82
+ * line is 5 kB **gzip**, which is roughly 15 to 20 kB raw, so the two lines land in about the same
83
+ * place; written side by side without saying which unit each is in, they read as a contradiction.
84
+ */
85
+ const ROLLUP_MIN_CHUNK = 20 * 1024;
86
+ const manyFileFindings = (analysis, lang, c) => {
87
+ const typical = median(analysis.screens.toSorted((a, b) => a.files - b.files));
88
+ if (!typical || typical.files <= c.screenFilesMax) {
89
+ return [];
90
+ }
91
+ // Only what this screen downloads together. A tiny chunk somewhere else in the build is not
92
+ // this signal's business: not downloading it is the reason it is lazy.
93
+ const chunks = [...analysis.bootChunks, ...typical.ownChunks, ...typical.sharedChunks];
94
+ const tiny = chunks.filter(file => (analysis.chunkOf(file)?.bytes ?? 0) < c.tinyChunkBytes);
95
+ if (tiny.length < c.minTinyChunks) {
96
+ return [];
97
+ }
98
+ const worst = analysis.screens.toSorted((a, b) => b.files - a.files)[0];
99
+ // Raw bytes, because that is the unit the bundler option is written in. The tree carries the
100
+ // size on disk per chunk; the report's own figure is compressed when a folder was loaded, and
101
+ // comparing that against a raw threshold is how the two numbers came to disagree.
102
+ const rawOf = new Map(analysis.tree.filter(node => node.kind === 'chunk').map(node => [node.id, node.rawBytes ?? node.bytes]));
103
+ const small = chunks.filter(file => (rawOf.get(file) ?? 0) < ROLLUP_MIN_CHUNK).length;
104
+ return [
105
+ {
106
+ // Context, not a gate. Under HTTP/2 and HTTP/3 sixty well-sized files are fine and
107
+ // sixty crumbs are not, and a count cannot tell the two apart — the granularity below
108
+ // can, which is why that half is the headline and this one is the frame around it.
109
+ // What raises this to a problem is evidence: `poolExhausted` fires when a measurement
110
+ // shows the connection pool actually running out.
111
+ severity: 'info',
112
+ target: worst ? { tab: 'screens', key: worst.source } : undefined,
113
+ kind: 'manyRequests',
114
+ ...finding_text_1.TEXT[lang].manyRequests({
115
+ files: typical.files,
116
+ tiny: tiny.length,
117
+ tinySize: (0, format_utils_1.formatBytes)(c.tinyChunkBytes),
118
+ max: c.screenFilesMax,
119
+ worstLabel: worst?.label ?? '',
120
+ worstFiles: worst?.files ?? 0,
121
+ small,
122
+ smallSize: (0, format_utils_1.formatBytes)(ROLLUP_MIN_CHUNK),
123
+ }),
124
+ },
125
+ ];
126
+ };
127
+ /**
128
+ * The first load in more than one go.
129
+ *
130
+ * The report has said this in the bootstrap panel for a while and it was never a signal, which is
131
+ * the asymmetry worth fixing: a screen that arrives in three round trips gets a line telling you
132
+ * so, and the first load — the one moment every visitor pays and the one nobody can skip — got a
133
+ * sentence in a panel and nothing to act on. It is also the cheapest thing on this list to fix.
134
+ *
135
+ * There is no threshold on purpose. Every other signal here weighs something against a criterion,
136
+ * because "how many files is too many" is a judgement; this one is structural. Either the page
137
+ * names every chunk of the bootstrap or the browser has to parse one to discover another, and the
138
+ * second is a round trip that buys nothing.
139
+ *
140
+ * **What it must not say.** This used to end in "add a `modulepreload` for each one", which is
141
+ * advice that has made first paint worse in real projects: every tag competes for bandwidth with
142
+ * the stylesheet that blocks rendering, and a page carrying dozens of them can paint later than
143
+ * the same page carrying none. So the finding reports the two shapes separately — how many trips
144
+ * deep the bootstrap is, and how many chunks share the next trip — and prices the tags instead of
145
+ * prescribing them. The count of tags is part of the cost, not part of the fix.
146
+ */
147
+ const bootWaveFindings = (analysis, lang) => {
148
+ const startup = analysis.startup;
149
+ if (!startup || startup.waves <= 1 || startup.discovered.length === 0) {
150
+ return [];
151
+ }
152
+ return [
153
+ {
154
+ // The bytes are right and the wait is not: worth a line, never worth failing a build.
155
+ severity: 'mid',
156
+ target: { tab: 'boot', key: '' },
157
+ kind: 'bootWaves',
158
+ ...finding_text_1.TEXT[lang].bootWaves({
159
+ waves: startup.waves,
160
+ count: startup.discovered.length,
161
+ // How many are found on the very next trip. This is the number the advice is
162
+ // allowed to ask for tags for: naming fewer than all of them shortens nothing,
163
+ // and naming more than the bootstrap needs is the failure mode above.
164
+ next: startup.byWave[0]?.length ?? startup.discovered.length,
165
+ // Every chunk that arrives late, named — a list missing four of them is a change
166
+ // somebody half applies and then measures as having done nothing.
167
+ list: startup.discovered.map(chunk => (0, finding_html_1.mono)((0, format_utils_1.baseName)(chunk))).join(', '),
168
+ // The critical preload set, and its opposite. Naming a chunk that shares a trip
169
+ // already being paid removes no wait and still competes for bandwidth with the
170
+ // stylesheet, so saying which chunks NOT to name is half the advice.
171
+ critical: startup.critical.map(chunk => (0, finding_html_1.mono)((0, format_utils_1.baseName)(chunk))).join(' → '),
172
+ criticalBytes: (0, format_utils_1.formatBytes)(startup.critical.reduce((sum, chunk) => sum + (analysis.chunkOf(chunk)?.bytes ?? 0), 0)),
173
+ // How many late chunks are not on that chain: a tag for each of these buys nothing.
174
+ offPath: startup.discovered.filter(chunk => !startup.critical.includes(chunk)).length,
175
+ width: startup.width,
176
+ }),
177
+ },
178
+ ];
179
+ };
180
+ const buildRequestFindings = (analysis, lang, c) => [
181
+ ...bootWaveFindings(analysis, lang),
182
+ ...slowScreenFindings(analysis, lang, c),
183
+ ...manyFileFindings(analysis, lang, c),
184
+ ];
185
+ exports.buildRequestFindings = buildRequestFindings;
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ /**
3
+ * The signals that come from reading the text of the build: what it gives away, what it should
4
+ * never have shipped, whose code it is, and under what licence.
5
+ *
6
+ * All of it offline. The one thing this area normally needs — a registry, a CVE database, a
7
+ * telemetry endpoint — is the one thing this tool will not do, and it turns out most of the answer
8
+ * was inside the files that were already open.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
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");
15
+ const named = (items) => items.map(item => (0, finding_html_1.mono)(item)).join(', ');
16
+ /** The ones that are a problem whatever else is true, as opposed to a build pointed at the wrong place. */
17
+ const ALWAYS_SERIOUS = new Set(['privateKey', 'awsKey', 'githubToken', 'slackToken', 'googleKey']);
18
+ const buildScanFindings = (scan, lang, c) => {
19
+ const text = finding_text_1.TEXT[lang];
20
+ const findings = [];
21
+ // 1 · Credentials and internal addresses. The cheapest finding here and the most expensive to
22
+ // have. Every pattern identifies a specific format by its own prefix: there is deliberately
23
+ // no rule for "a long string near the word key", which is what makes a security signal noisy
24
+ // and then switched off.
25
+ const secrets = scan.secrets;
26
+ const serious = secrets.filter(match => ALWAYS_SERIOUS.has(match.kind));
27
+ const first = secrets[0];
28
+ if (first) {
29
+ findings.push({
30
+ severity: serious.length > 0 ? 'high' : 'mid',
31
+ kind: 'secrets',
32
+ ...text.secrets({
33
+ count: secrets.length,
34
+ serious: serious.length,
35
+ kinds: [...new Set(secrets.map(match => match.kind))].join(', '),
36
+ 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}` : ''})`)
38
+ .join(' · '),
39
+ }),
40
+ });
41
+ }
42
+ // 2 · What a development build leaves behind. It is a fault in itself and it also invalidates
43
+ // the rest of the report, which is why the card says so before giving any figure.
44
+ const leftovers = scan.leftovers;
45
+ const breaking = leftovers.filter(item => item.kind === 'reactDev' || item.kind === 'devServer');
46
+ const worst = leftovers[0];
47
+ if (worst) {
48
+ // Nothing here could be traced to a file of the project's: the occurrences are real and
49
+ // whose they are is not known. That is context, not a fault to fix, and it stops the card
50
+ // that fires on every Angular build from sitting in the "what to fix first" table.
51
+ const unattributed = leftovers.every(item => !item.attributed);
52
+ findings.push({
53
+ severity: breaking.length > 0 ? 'high' : unattributed ? 'info' : 'mid',
54
+ kind: 'devLeftovers',
55
+ ...text.devLeftovers({
56
+ count: leftovers.length,
57
+ broken: breaking.length > 0,
58
+ unattributed,
59
+ list: leftovers.map(item => `${(0, finding_html_1.mono)(item.kind)} ×${item.count} (${named(item.where)})`).join(' · '),
60
+ }),
61
+ });
62
+ }
63
+ // 3 · What the maps published with the build give away. The report has said "there are source
64
+ // maps here" for a while and that sentence gets ignored; this one says what is in them.
65
+ const exposure = scan.exposure;
66
+ if (exposure && exposure.hasContent && exposure.ownFiles > 0) {
67
+ findings.push({
68
+ // Context, like the `sourceMaps` card it stands next to, and for its reason: this tool
69
+ // cannot tell the folder somebody deploys from the one they just built locally. What
70
+ // this card adds is what is inside the maps, not a stronger claim about them.
71
+ severity: 'info',
72
+ kind: 'sourceExposed',
73
+ ...text.sourceExposed({
74
+ files: exposure.ownFiles,
75
+ maps: exposure.maps,
76
+ env: exposure.envReferences,
77
+ list: exposure.paths.map(path => (0, finding_html_1.mono)(path)).join(' · '),
78
+ }),
79
+ });
80
+ }
81
+ // 4 · Whose code the first load is, by what it is for. The list somebody takes to the meeting
82
+ // where it is decided whether the session recorder stays.
83
+ const groups = scan.thirdParty;
84
+ const bootBytes = groups.reduce((sum, group) => sum + group.bootBytes, 0);
85
+ if (groups.length > 0 && bootBytes >= c.shippedMinBytes) {
86
+ findings.push({
87
+ severity: 'info',
88
+ kind: 'thirdParty',
89
+ ...text.thirdParty({
90
+ 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)),
93
+ 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' : ''})`)
96
+ .join(', ')}`)
97
+ .join(' · '),
98
+ }),
99
+ });
100
+ }
101
+ // 5 · Licences, from the legal comments the bundler kept on purpose. Partial by construction,
102
+ // and the card says so: without `node_modules` there is no way to see the ones with no header.
103
+ const licences = scan.licences;
104
+ const conditional = licences.filter(entry => entry.class !== 'permissive');
105
+ if (conditional.length > 0) {
106
+ findings.push({
107
+ severity: conditional.some(entry => entry.class === 'strongCopyleft' || entry.class === 'nonCommercial')
108
+ ? 'mid'
109
+ : 'info',
110
+ kind: 'licences',
111
+ ...text.licences({
112
+ count: conditional.length,
113
+ worst: conditional[0]?.id ?? '',
114
+ list: conditional
115
+ .map(entry => `${(0, finding_html_1.mono)(entry.id)}${entry.packages.length > 0 ? ` (${named(entry.packages)})` : ''}`)
116
+ .join(' · '),
117
+ permissive: licences
118
+ .filter(entry => entry.class === 'permissive')
119
+ .map(entry => entry.id)
120
+ .join(', '),
121
+ }),
122
+ });
123
+ }
124
+ return findings;
125
+ };
126
+ exports.buildScanFindings = buildScanFindings;