@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,192 @@
1
+ "use strict";
2
+ /**
3
+ * The source graph as something to walk quickly, and the three walks every insight is built on.
4
+ *
5
+ * `analysis.ts` walks `meta.inputs` directly, which is fine when it is done twice. The figures in
6
+ * `insights.ts` walk it once per package, so the graph is turned into arrays of integers first:
7
+ * the same breadth-first search over string keys of a `Record` is several times slower, and on a
8
+ * two-megabyte metafile that is the difference between a report and a frozen tab.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.shortestLoop = exports.stronglyConnected = exports.reachIds = exports.buildModuleGraph = void 0;
12
+ /** Whether an edge keeps two files in the same chunk. A lazy boundary and an external do not. */
13
+ const travelsTogether = (kind, external) => !external && kind !== 'dynamic-import';
14
+ const buildModuleGraph = (inputs) => {
15
+ const nodes = Object.keys(inputs);
16
+ const index = new Map(nodes.map((path, id) => [path, id]));
17
+ const statics = nodes.map(() => []);
18
+ const dynamics = nodes.map(() => []);
19
+ const importedBy = nodes.map(() => []);
20
+ /** One edge of one file. An external import names something outside the bundle: no node for it. */
21
+ const link = (from, edge) => {
22
+ const to = index.get(edge.path);
23
+ if (to === undefined || edge.external) {
24
+ return;
25
+ }
26
+ (travelsTogether(edge.kind, edge.external) ? statics : dynamics)[from]?.push(to);
27
+ importedBy[to]?.push(from);
28
+ };
29
+ const entries = [...nodes.entries()];
30
+ for (const [from, path] of entries) {
31
+ const imports = inputs[path]?.imports ?? [];
32
+ for (const edge of imports) {
33
+ link(from, edge);
34
+ }
35
+ }
36
+ return { nodes, index, statics, dynamics, importedBy };
37
+ };
38
+ exports.buildModuleGraph = buildModuleGraph;
39
+ /**
40
+ * What is reachable from a set of roots, following one kind of edge.
41
+ *
42
+ * `skip` is what makes the exclusive weight computable: walking the graph with a package taken out
43
+ * and seeing what no longer arrives is the same question as "what does only this package bring
44
+ * in", asked in the direction that has an answer.
45
+ */
46
+ const reachIds = (graph, roots, edges, skip) => {
47
+ const seen = new Uint8Array(graph.nodes.length);
48
+ const stack = roots.filter(root => !skip?.has(root));
49
+ while (stack.length > 0) {
50
+ const node = stack.pop();
51
+ if (node === undefined || seen[node] === 1) {
52
+ continue;
53
+ }
54
+ seen[node] = 1;
55
+ const next = edges[node] ?? [];
56
+ const wanted = next.filter(other => seen[other] === 0 && !skip?.has(other));
57
+ stack.push(...wanted);
58
+ }
59
+ return seen;
60
+ };
61
+ exports.reachIds = reachIds;
62
+ /**
63
+ * Pops one component off the open stack, up to and including `root`.
64
+ *
65
+ * A component of a single node is only a cycle when the node imports itself, which is rare and
66
+ * real: a file re-exporting from its own path through an alias.
67
+ */
68
+ const closeComponent = (state, root, edges) => {
69
+ const found = [];
70
+ let member = state.open.pop();
71
+ while (member !== undefined) {
72
+ state.onStack[member] = 0;
73
+ found.push(member);
74
+ if (member === root) {
75
+ break;
76
+ }
77
+ member = state.open.pop();
78
+ }
79
+ const selfEdge = found.length === 1 && (edges[root] ?? []).includes(root);
80
+ if (found.length > 1 || selfEdge) {
81
+ state.components.push(found);
82
+ }
83
+ };
84
+ /** The walk out of one root, with an explicit stack of "node, and how far through its edges". */
85
+ const walkFrom = (state, root, edges) => {
86
+ const frames = [{ node: root, edge: 0 }];
87
+ state.order[root] = state.low[root] = state.next++;
88
+ state.open.push(root);
89
+ state.onStack[root] = 1;
90
+ while (frames.length > 0) {
91
+ const frame = frames.at(-1);
92
+ if (!frame) {
93
+ return;
94
+ }
95
+ const outgoing = edges[frame.node] ?? [];
96
+ if (frame.edge < outgoing.length) {
97
+ const child = outgoing[frame.edge++] ?? 0;
98
+ if (state.order[child] === -1) {
99
+ state.order[child] = state.low[child] = state.next++;
100
+ state.open.push(child);
101
+ state.onStack[child] = 1;
102
+ frames.push({ node: child, edge: 0 });
103
+ }
104
+ else if (state.onStack[child] === 1) {
105
+ state.low[frame.node] = Math.min(state.low[frame.node] ?? 0, state.order[child] ?? 0);
106
+ }
107
+ continue;
108
+ }
109
+ frames.pop();
110
+ const parent = frames.at(-1);
111
+ if (parent) {
112
+ state.low[parent.node] = Math.min(state.low[parent.node] ?? 0, state.low[frame.node] ?? 0);
113
+ }
114
+ // A node whose lowest reachable order is its own closes a component.
115
+ if (state.low[frame.node] === state.order[frame.node]) {
116
+ closeComponent(state, frame.node, edges);
117
+ }
118
+ }
119
+ };
120
+ /**
121
+ * The strongly connected components of a graph, iteratively.
122
+ *
123
+ * Tarjan's algorithm, written with an explicit stack rather than recursion: a bundle can nest
124
+ * imports thousands deep — a barrel importing a barrel importing a barrel — and the recursive
125
+ * version blows the JavaScript stack on exactly the projects this figure is about.
126
+ *
127
+ * @returns one array of node ids per component, in no particular order. Single nodes without a
128
+ * self-edge are left out: they are not cycles.
129
+ */
130
+ const stronglyConnected = (edges, count) => {
131
+ const state = {
132
+ order: new Int32Array(count).fill(-1),
133
+ low: new Int32Array(count),
134
+ onStack: new Uint8Array(count),
135
+ open: [],
136
+ components: [],
137
+ next: 0,
138
+ };
139
+ for (let root = 0; root < count; root++) {
140
+ if (state.order[root] === -1) {
141
+ walkFrom(state, root, edges);
142
+ }
143
+ }
144
+ return state.components;
145
+ };
146
+ exports.stronglyConnected = stronglyConnected;
147
+ /**
148
+ * The shortest loop through a node inside its component: a breadth-first walk out of it that stops
149
+ * the first time it comes back.
150
+ *
151
+ * A component of forty files is not something anybody can act on. The loop that closes through the
152
+ * heaviest of them is, and it is what a person would draw on a whiteboard: `checkout → shared →
153
+ * analytics → checkout`.
154
+ */
155
+ const shortestLoop = (edges, start, inside) => {
156
+ const previous = new Map();
157
+ const queue = [start];
158
+ const seen = new Set([start]);
159
+ /** The loop as it reads: from the start round to the node that closes it, and back to the start. */
160
+ const loopThrough = (last) => {
161
+ const back = [];
162
+ for (let step = last; step !== undefined; step = previous.get(step)) {
163
+ back.push(step);
164
+ }
165
+ return [...back.toReversed(), start];
166
+ };
167
+ /** One step of the walk: the loop when this node closes it, `null` while it is still open. */
168
+ const stepFrom = (node) => {
169
+ const outgoing = edges[node] ?? [];
170
+ for (const next of outgoing) {
171
+ if (next === start) {
172
+ return loopThrough(node);
173
+ }
174
+ if (!inside.has(next) || seen.has(next)) {
175
+ continue;
176
+ }
177
+ seen.add(next);
178
+ previous.set(next, node);
179
+ queue.push(next);
180
+ }
181
+ return null;
182
+ };
183
+ let head = 0;
184
+ while (head < queue.length) {
185
+ const loop = stepFrom(queue[head++] ?? start);
186
+ if (loop) {
187
+ return loop;
188
+ }
189
+ }
190
+ return [start];
191
+ };
192
+ exports.shortestLoop = shortestLoop;
@@ -0,0 +1,231 @@
1
+ "use strict";
2
+ /**
3
+ * Weight per file read from the source maps of the build folder: a second, independent measurement
4
+ * of what the metafile already says.
5
+ *
6
+ * This was written expecting to *correct* the metafile, on the assumption — true of webpack stats,
7
+ * which is what source-map-explorer and Sonda were built around — that it measures each file
8
+ * before minification. Measured on a real esbuild build of this very tool, it does not:
9
+ * `bytesInOutput` adds up to 99.9 % of the generated file, while the raw source bytes of the same
10
+ * files add up to 6.2 times it. File by file, the two measurements agree within 1 %.
11
+ *
12
+ * So the maps are kept for what they turned out to be worth: checking the figure rather than
13
+ * replacing a bad one. They are an extra, never a requirement — without them everything works the
14
+ * same, on a figure now known to be sound.
15
+ *
16
+ * Caveat kept on purpose: the columns of a source map count UTF-16 units, not bytes. Minified
17
+ * JavaScript is almost entirely ASCII, so the two coincide except for the odd literal with
18
+ * accents or emoji.
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.resolveSplits = exports.readSourceMaps = exports.resolveSources = exports.sourcePathOf = exports.bytesBySource = exports.sourceAt = exports.segmentsOf = exports.isSourceMap = void 0;
22
+ const VLQ_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
23
+ const isSourceMap = (value) => {
24
+ if (!value || typeof value !== 'object') {
25
+ return false;
26
+ }
27
+ const candidate = value;
28
+ return Array.isArray(candidate.sources) && typeof candidate.mappings === 'string';
29
+ };
30
+ exports.isSourceMap = isSourceMap;
31
+ /**
32
+ * Decodes one segment of the `mappings` field: base64 VLQ, little-endian, five bits per digit,
33
+ * the sixth marking "there is more", and the lowest bit of the value carrying the sign.
34
+ */
35
+ const decodeSegment = (segment) => {
36
+ const values = [];
37
+ let value = 0;
38
+ let shift = 0;
39
+ for (const char of segment) {
40
+ const digit = VLQ_CHARS.indexOf(char);
41
+ if (digit === -1) {
42
+ return values;
43
+ }
44
+ // The sixth bit is the "more digits follow" flag, so a digit of 32 or more carries it.
45
+ value += (digit % 32) * 2 ** shift;
46
+ if (digit >= 32) {
47
+ shift += 5;
48
+ continue;
49
+ }
50
+ const negative = value % 2 === 1;
51
+ const magnitude = Math.floor(value / 2);
52
+ values.push(negative ? -magnitude : magnitude);
53
+ value = 0;
54
+ shift = 0;
55
+ }
56
+ return values;
57
+ };
58
+ /**
59
+ * The mappings decoded, one array of segments per generated line. Empty lines keep their place, so
60
+ * the index of the outer array is the line number.
61
+ */
62
+ const segmentsOf = (map) => {
63
+ const decoded = [];
64
+ // The generated column restarts on every line; the source index does not.
65
+ let sourceIndex = 0;
66
+ for (const line of map.mappings.split(';')) {
67
+ const segments = [];
68
+ const fieldsOf = line ? line.split(',') : [];
69
+ let column = 0;
70
+ for (const segment of fieldsOf) {
71
+ const fields = decodeSegment(segment);
72
+ column += fields[0] ?? 0;
73
+ // Fewer than four fields means "this stretch maps to nothing".
74
+ if (fields.length >= 4) {
75
+ sourceIndex += fields[1] ?? 0;
76
+ segments.push({ column, source: map.sources[sourceIndex] ?? null });
77
+ }
78
+ else {
79
+ segments.push({ column, source: null });
80
+ }
81
+ }
82
+ decoded.push(segments);
83
+ }
84
+ return decoded;
85
+ };
86
+ exports.segmentsOf = segmentsOf;
87
+ /**
88
+ * Which source a position of the generated file came from: the last segment that starts at or
89
+ * before it. `null` when no segment claims that stretch, which is the honest answer — the position
90
+ * is inside the bundler's own runtime, not inside anybody's file.
91
+ */
92
+ const sourceAt = (segments, line, column) => {
93
+ const row = segments[line] ?? [];
94
+ let found = null;
95
+ for (const segment of row) {
96
+ if (segment.column > column) {
97
+ break;
98
+ }
99
+ found = segment.source;
100
+ }
101
+ return found;
102
+ };
103
+ exports.sourceAt = sourceAt;
104
+ /**
105
+ * Bytes of the generated file attributed to each of its sources.
106
+ *
107
+ * Every segment of a line owns the output from its column to the next segment's, and the last one
108
+ * to the end of the line. What no segment claims — the bundler's own runtime, banners — is left
109
+ * out rather than shared around: making it up would be worse than not having it.
110
+ */
111
+ const bytesBySource = (map, code) => {
112
+ const lines = code.split('\n');
113
+ const bytes = new Map();
114
+ const decoded = (0, exports.segmentsOf)(map).entries();
115
+ for (const [lineNumber, segments] of decoded) {
116
+ // The newline is a byte of the file too.
117
+ const lineLength = (lines[lineNumber]?.length ?? 0) + 1;
118
+ for (const [index, segment] of segments.entries()) {
119
+ const end = segments[index + 1]?.column ?? lineLength;
120
+ const size = end - segment.column;
121
+ if (segment.source && size > 0) {
122
+ bytes.set(segment.source, (bytes.get(segment.source) ?? 0) + size);
123
+ }
124
+ }
125
+ }
126
+ return bytes;
127
+ };
128
+ exports.bytesBySource = bytesBySource;
129
+ /**
130
+ * A source as the rest of the tool names it: the `./` and `../` a map uses to climb out of the
131
+ * output folder dropped, which leaves the path the metafile would have written.
132
+ */
133
+ const sourcePathOf = (source) => source.replace(/^(?:\.\.?\/)+/, '');
134
+ exports.sourcePathOf = sourcePathOf;
135
+ /**
136
+ * Angular compiles a component's template into the component, so the map has a stretch coming from
137
+ * `x.component.html` while the metafile only knows `x.component.ts`. Without folding one into the
138
+ * other a component with a big template looks far lighter than it is: measured against this build,
139
+ * the screens panel came out at 58 % of its real weight.
140
+ */
141
+ const CODE_EXTENSIONS = ['.ts', '.tsx', '.mts', '.js', '.mjs'];
142
+ /**
143
+ * Matches the paths of a source map against the metafile's file names.
144
+ *
145
+ * A map writes its sources relative to the output folder (`../../src/app/x.ts`) and the metafile
146
+ * relative to the project root (`src/app/x.ts`), so most of them line up once the `../` are gone.
147
+ * What is left over is matched by file name, and only when there is exactly one candidate: a wrong
148
+ * guess would move weight onto an unrelated file, which is worse than leaving it out.
149
+ */
150
+ const resolveSources = (sources, inputs) => {
151
+ const known = new Set(inputs);
152
+ const byFileName = new Map();
153
+ for (const input of inputs) {
154
+ const name = input.split('/').pop() ?? input;
155
+ byFileName.set(name, [...(byFileName.get(name) ?? []), input]);
156
+ }
157
+ return sources.map(source => {
158
+ const path = (0, exports.sourcePathOf)(source);
159
+ if (known.has(path)) {
160
+ return path;
161
+ }
162
+ const base = path.replace(/\.[^./]+$/, '');
163
+ const sibling = CODE_EXTENSIONS.map(extension => base + extension).find(candidate => known.has(candidate));
164
+ if (sibling) {
165
+ return sibling;
166
+ }
167
+ const candidates = (byFileName.get(path.split('/').pop() ?? path) ?? []).filter(input => input.endsWith(path) || path.endsWith(input));
168
+ return candidates.length === 1 ? (candidates[0] ?? null) : null;
169
+ });
170
+ };
171
+ exports.resolveSources = resolveSources;
172
+ /**
173
+ * Reads the source maps of a build folder. The key is the name of the generated file, the same one
174
+ * the compressed sizes are keyed by. Takes anything with a name and its text, so the page feeds it
175
+ * dropped files and the command feeds it files on disk.
176
+ */
177
+ const readSourceMaps = async (files) => {
178
+ const splits = new Map();
179
+ const codeByName = new Map(files.filter(file => /\.m?js$/.test(file.name)).map(file => [file.name, file]));
180
+ for (const file of files) {
181
+ if (!/\.m?js\.map$/.test(file.name)) {
182
+ continue;
183
+ }
184
+ const generated = file.name.slice(0, -4);
185
+ const code = codeByName.get(generated);
186
+ if (!code) {
187
+ continue;
188
+ }
189
+ try {
190
+ const parsed = JSON.parse(await file.text());
191
+ if (!(0, exports.isSourceMap)(parsed)) {
192
+ continue;
193
+ }
194
+ const split = (0, exports.bytesBySource)(parsed, await code.text());
195
+ if (split.size > 0) {
196
+ splits.set(generated, split);
197
+ }
198
+ }
199
+ catch {
200
+ // A truncated or unreadable map is simply not used: the approximation still works.
201
+ }
202
+ }
203
+ return splits;
204
+ };
205
+ exports.readSourceMaps = readSourceMaps;
206
+ /**
207
+ * Turns the raw splits into what the analysis takes: bytes keyed by metafile file name. Kept apart
208
+ * from reading, so a folder can be read before the `stats.json` arrives and matched afterwards.
209
+ */
210
+ const resolveSplits = (splits, inputs) => {
211
+ if (!splits || splits.size === 0) {
212
+ return null;
213
+ }
214
+ const resolved = new Map();
215
+ for (const [chunk, split] of splits) {
216
+ const sources = [...split.keys()];
217
+ const mapped = (0, exports.resolveSources)(sources, inputs);
218
+ const byInput = new Map();
219
+ for (const [index, source] of sources.entries()) {
220
+ const input = mapped[index];
221
+ if (input) {
222
+ byInput.set(input, (byInput.get(input) ?? 0) + (split.get(source) ?? 0));
223
+ }
224
+ }
225
+ if (byInput.size > 0) {
226
+ resolved.set(chunk, byInput);
227
+ }
228
+ }
229
+ return resolved.size > 0 ? resolved : null;
230
+ };
231
+ exports.resolveSplits = resolveSplits;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ /** The part of a source map Loadline reads, and what it gets reduced to. */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ /**
3
+ * The report's own margin of error, measured rather than assumed.
4
+ *
5
+ * Every figure this report takes from *inside* a chunk — the bootstrap broken down by package, the
6
+ * exclusive weight of a row, what a `--what-if` would save — is a sum of per-file weights. Those
7
+ * come from the metafile, unless a source map measured the generated file itself. So there are two
8
+ * measurements of the same chunk and they are supposed to agree: `bytes` is what the file weighs,
9
+ * and the per-file weights are what it is made of.
10
+ *
11
+ * On Angular 17 they agree to within 1 %. On Angular 22 they do not: measured on three builds, the
12
+ * per-file weights add up to **125 %** of the file, because the metafile is written before a later
13
+ * pass shrinks the output. Nothing said so, and the consequence is that every one of those figures
14
+ * read a quarter high while the headline weight printed next to it was exact.
15
+ *
16
+ * Both numbers were already in the file. Nobody had subtracted them.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.splitDriftOf = void 0;
20
+ const format_utils_1 = require("../format/format.utils");
21
+ /** `.mjs` is what esbuild writes with `--out-extension:.js=.mjs`, and what several setups ship. */
22
+ const isJs = (file) => /\.m?js$/.test(file);
23
+ /**
24
+ * @param outputs the browser side of the build, already separated from the server one.
25
+ * @param exact chunk name → the per-file weights a source map measured. Those chunks are left
26
+ * out: they were measured on the generated file, so there is nothing to drift.
27
+ */
28
+ const splitDriftOf = (outputs, exact) => {
29
+ let file = 0;
30
+ let measured = 0;
31
+ let chunks = 0;
32
+ for (const [chunk, output] of Object.entries(outputs)) {
33
+ if (!isJs(chunk) || exact?.has((0, format_utils_1.baseName)(chunk))) {
34
+ continue;
35
+ }
36
+ const sum = Object.values(output.inputs ?? {}).reduce((total, one) => total + (one.bytesInOutput ?? 0), 0);
37
+ // A chunk the metafile does not break down says nothing either way, and counting its
38
+ // `bytes` against a sum of zero would invent a drift of 100 % on every folder read.
39
+ if (sum > 0 && output.bytes > 0) {
40
+ file += output.bytes;
41
+ measured += sum;
42
+ chunks += 1;
43
+ }
44
+ }
45
+ return chunks > 0 ? { file, measured, ratio: measured / file, chunks } : null;
46
+ };
47
+ exports.splitDriftOf = splitDriftOf;