@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
@@ -0,0 +1,298 @@
1
+ "use strict";
2
+ /**
3
+ * webpack's `stats.json`, read as the metafile everything else analyses.
4
+ *
5
+ * It was refused on purpose until 09/10/2026, with "Statoscope does it better". It is also, by far,
6
+ * what the applications written before 2020 can produce: Angular up to 16, Create React App, Vue
7
+ * CLI, Gatsby, Nuxt 2, Rspack. Their folders cannot be read — the chunks load each other by number —
8
+ * and the stats file has the same three things the metafile has, in another shape:
9
+ *
10
+ * | webpack | metafile |
11
+ * | ---------------------------------------- | ---------------------------------------------- |
12
+ * | `modules[]` (and `chunks[].modules[]`) | `inputs`, with the edges taken from `reasons` |
13
+ * | `chunks[].files` and `assets[].size` | `outputs`, one per file the browser downloads |
14
+ * | `entrypoints[].chunks` | static edges: the files an entry starts with |
15
+ * | `chunks[].origins` | lazy edges: who asked for the chunk, and where |
16
+ *
17
+ * ⚠️ **A module's `size` is its source before minification**, not what it takes in the file. A main
18
+ * chunk of Angular 8 is 2.9 MB of modules in a file of 560 kB. The per-file weights are that size
19
+ * shared out in proportion to what the file weighs, so they add up to the file and the bootstrap
20
+ * by package reads in the unit of everything else. It is an estimate — minification does not shrink
21
+ * every file by the same factor — and a source map in the folder replaces it with a measurement,
22
+ * as it does for every other build.
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.metafileOf = exports.fromWebpackStats = void 0;
26
+ const metafile_types_1 = require("../analysis/metafile.types");
27
+ const json_utils_1 = require("../json/json.utils");
28
+ const webpack_modules_1 = require("./webpack-modules");
29
+ /**
30
+ * The compilation that is the browser's. A build of several configurations writes one per child and
31
+ * nothing at the top: the one with chunks is taken, and of several, not the server's — nobody
32
+ * downloads that — and then the one with the most chunks.
33
+ */
34
+ const compilationOf = (data) => {
35
+ if (((0, json_utils_1.asArray)(data['chunks'])?.length ?? 0) > 0) {
36
+ return data;
37
+ }
38
+ const children = ((0, json_utils_1.asArray)(data['children']) ?? [])
39
+ .map(child => (0, json_utils_1.asRecord)(child))
40
+ .filter((child) => ((0, json_utils_1.asArray)(child?.['chunks'])?.length ?? 0) > 0);
41
+ const browser = children.filter(child => !/server|edge|node/i.test((0, json_utils_1.asText)(child['name']) ?? ''));
42
+ const [best] = (browser.length > 0 ? browser : children).toSorted((a, b) => ((0, json_utils_1.asArray)(b['chunks'])?.length ?? 0) - ((0, json_utils_1.asArray)(a['chunks'])?.length ?? 0));
43
+ return best ?? null;
44
+ };
45
+ const chunksOf = (compilation) => ((0, json_utils_1.asArray)(compilation['chunks']) ?? []).flatMap(item => {
46
+ const chunk = (0, json_utils_1.asRecord)(item);
47
+ if (!chunk) {
48
+ return [];
49
+ }
50
+ const origins = ((0, json_utils_1.asArray)(chunk['origins']) ?? []).flatMap(entry => {
51
+ const origin = (0, json_utils_1.asRecord)(entry);
52
+ const from = (0, json_utils_1.asText)(origin?.['moduleName']) ?? '';
53
+ return origin && from
54
+ ? [{ from, loc: (0, json_utils_1.asText)(origin['loc']) ?? '', request: (0, json_utils_1.asText)(origin['request']) ?? '' }]
55
+ : [];
56
+ });
57
+ return [
58
+ {
59
+ id: String(chunk['id']),
60
+ names: (0, webpack_modules_1.textsOf)(chunk['names']),
61
+ files: (0, webpack_modules_1.textsOf)(chunk['files']),
62
+ initial: chunk['initial'] === true,
63
+ parents: (0, webpack_modules_1.idsOf)(chunk['parents']),
64
+ origins,
65
+ },
66
+ ];
67
+ });
68
+ /** What each emitted file weighs. webpack 5 nests them in groups for the terminal, as it does modules. */
69
+ const assetSizes = (list, into = new Map()) => {
70
+ const items = (0, json_utils_1.asArray)(list) ?? [];
71
+ for (const item of items) {
72
+ const asset = (0, json_utils_1.asRecord)(item);
73
+ const name = (0, json_utils_1.asText)(asset?.['name']);
74
+ if (asset && name && typeof asset['size'] === 'number') {
75
+ into.set(name, asset['size']);
76
+ }
77
+ else if (asset) {
78
+ assetSizes(asset['children'], into);
79
+ }
80
+ }
81
+ return into;
82
+ };
83
+ const isScript = (file) => /\.m?js$/.test(file);
84
+ const isStyle = (file) => file.endsWith('.css');
85
+ /**
86
+ * The source weights of a chunk shared out over what its file weighs, so they add up to the file
87
+ * (see the top of this file). Rounded down, with what rounding lost given to the largest, so the
88
+ * sum is exact: the breakdown that does not add up to the file is a signal of its own (§3.23).
89
+ */
90
+ const shareOut = (parts, bytes) => {
91
+ let total = 0;
92
+ for (const size of parts.values()) {
93
+ total += size;
94
+ }
95
+ if (total === 0) {
96
+ return {};
97
+ }
98
+ const shares = [...parts].map(([path, size]) => [path, Math.floor((size * bytes) / total)]);
99
+ const lost = bytes - shares.reduce((sum, [, share]) => sum + share, 0);
100
+ const largest = shares.reduce((best, entry) => (entry[1] > best[1] ? entry : best), shares[0] ?? ['', 0]);
101
+ return Object.fromEntries(shares.map(([path, share]) => [path, { bytesInOutput: path === largest[0] ? share + lost : share }]));
102
+ };
103
+ const isLazy = (kind) => kind.startsWith('import()');
104
+ const isEntry = (kind) => kind.endsWith('entry');
105
+ /** A worker is a second program beside the page, not a part of it that arrives later. */
106
+ const isWorker = (kind) => kind.includes('Worker');
107
+ const importKind = (kind) => {
108
+ if (isLazy(kind)) {
109
+ return 'dynamic-import';
110
+ }
111
+ if (isWorker(kind) || kind.startsWith('new URL')) {
112
+ return 'url-token';
113
+ }
114
+ return /cjs|require/.test(kind) ? 'require-call' : 'import-statement';
115
+ };
116
+ /**
117
+ * A webpack `stats.json` as a metafile, or `null` when it has no chunk with a script in it — a
118
+ * stats file written with `chunks: false` has nothing to analyse.
119
+ */
120
+ const fromWebpackStats = (value) => {
121
+ const data = (0, json_utils_1.asRecord)(value);
122
+ const compilation = data ? compilationOf(data) : null;
123
+ if (!compilation) {
124
+ return null;
125
+ }
126
+ const chunks = chunksOf(compilation);
127
+ const byId = new Map(chunks.map(chunk => [chunk.id, chunk]));
128
+ const read = { rows: new Map(), concatenated: new Map() };
129
+ (0, webpack_modules_1.collect)({ children: compilation['modules'] }, [], read);
130
+ const rawChunks = (0, json_utils_1.asArray)(compilation['chunks']) ?? [];
131
+ for (const item of rawChunks) {
132
+ const chunk = (0, json_utils_1.asRecord)(item);
133
+ (0, webpack_modules_1.collect)({ children: chunk?.['modules'] }, chunk ? [String(chunk['id'])] : [], read);
134
+ }
135
+ const { rows } = read;
136
+ const sizes = assetSizes(compilation['assets']);
137
+ // --- inputs: every file, and who imports it -------------------------------------------------
138
+ const inputs = {};
139
+ for (const row of rows.values()) {
140
+ const input = (inputs[row.path] ??= { bytes: 0, imports: [] });
141
+ input.bytes += row.size;
142
+ if (row.cjs) {
143
+ input.format = 'cjs';
144
+ }
145
+ }
146
+ const seen = new Set();
147
+ for (const row of rows.values()) {
148
+ for (const reason of row.reasons) {
149
+ if (isEntry(reason.kind)) {
150
+ continue;
151
+ }
152
+ const kind = importKind(reason.kind);
153
+ for (const from of (0, webpack_modules_1.importersOf)(reason, row, read)) {
154
+ const key = `${from}>${row.path}>${kind}`;
155
+ if (from === row.path || seen.has(key)) {
156
+ continue;
157
+ }
158
+ seen.add(key);
159
+ inputs[from]?.imports?.push({ path: row.path, kind });
160
+ }
161
+ }
162
+ }
163
+ // --- outputs: one per file a chunk writes ---------------------------------------------------
164
+ const outputs = {};
165
+ const rowsIn = new Map();
166
+ for (const row of rows.values()) {
167
+ for (const chunk of row.chunks) {
168
+ rowsIn.set(chunk, [...(rowsIn.get(chunk) ?? []), row]);
169
+ }
170
+ }
171
+ const weights = (chunk, style) => {
172
+ const parts = new Map();
173
+ const inChunk = rowsIn.get(chunk) ?? [];
174
+ for (const row of inChunk) {
175
+ if (row.style === style) {
176
+ parts.set(row.path, (parts.get(row.path) ?? 0) + row.size);
177
+ }
178
+ }
179
+ return parts;
180
+ };
181
+ for (const chunk of chunks) {
182
+ const scripts = chunk.files.filter(file => isScript(file));
183
+ const styles = chunk.files.filter(file => isStyle(file));
184
+ for (const [index, file] of [...scripts, ...styles].entries()) {
185
+ const bytes = sizes.get(file) ?? 0;
186
+ const output = { bytes, imports: [] };
187
+ // One script per chunk is the rule; were there two, the modules would be counted twice.
188
+ if (index === 0 || isStyle(file)) {
189
+ output.inputs = shareOut(weights(chunk.id, isStyle(file)), bytes);
190
+ }
191
+ outputs[file] = output;
192
+ }
193
+ }
194
+ const scriptsOf = (chunk) => byId.get(chunk)?.files.filter(file => isScript(file)) ?? [];
195
+ const link = (from, to, kind) => {
196
+ const imports = outputs[from]?.imports;
197
+ if (from !== to && imports?.every(imp => !(imp.path === to && imp.kind === kind))) {
198
+ imports.push({ path: to, kind });
199
+ }
200
+ };
201
+ // --- where the application starts -----------------------------------------------------------
202
+ const entrypoints = Object.entries((0, json_utils_1.asRecord)(compilation['entrypoints']) ?? {});
203
+ for (const [name, raw] of entrypoints) {
204
+ const entry = (0, json_utils_1.asRecord)(raw);
205
+ const named = new Set(((0, json_utils_1.asArray)(entry?.['assets']) ?? []).map(asset => (0, json_utils_1.asText)(asset) ?? (0, json_utils_1.asText)((0, json_utils_1.asRecord)(asset)?.['name']) ?? ''));
206
+ const listed = (0, webpack_modules_1.idsOf)(entry?.['chunks']);
207
+ const ids = listed.length > 0
208
+ ? listed
209
+ : chunks.filter(chunk => chunk.files.some(file => named.has(file))).map(chunk => chunk.id);
210
+ // The chunk named after the entry holds its module; webpack lists it last, after the runtime
211
+ // and the vendors it needs.
212
+ const home = ids.find(id => byId.get(id)?.names.includes(name)) ?? ids.at(-1);
213
+ const [start] = home ? scriptsOf(home) : [];
214
+ const output = start ? outputs[start] : undefined;
215
+ if (!home || !start || !output) {
216
+ continue;
217
+ }
218
+ const module = (rowsIn.get(home) ?? []).find(row => row.reasons.some(reason => isEntry(reason.kind)));
219
+ output.entryPoint = module?.path ?? name;
220
+ for (const id of ids) {
221
+ for (const file of scriptsOf(id)) {
222
+ link(start, file, 'import-statement');
223
+ }
224
+ }
225
+ }
226
+ // --- what arrives later, and who asks for it --------------------------------------------------
227
+ // A lazy chunk group is every chunk sharing one origin: the `import()` at one place in one file.
228
+ // One of them holds the module asked for and is what gets imported; the others — the vendors
229
+ // `splitChunks` moved out, a chunk two routes share — travel with it.
230
+ const groups = new Map();
231
+ for (const chunk of chunks) {
232
+ if (chunk.initial) {
233
+ continue;
234
+ }
235
+ for (const origin of chunk.origins) {
236
+ const key = `${origin.from}|${origin.loc}`;
237
+ const group = groups.get(key) ?? { ...origin, members: [] };
238
+ group.members.push(chunk.id);
239
+ groups.set(key, group);
240
+ }
241
+ }
242
+ const groupsOf = (id) => [...groups.values()].filter(group => group.members.includes(id)).length;
243
+ for (const group of groups.values()) {
244
+ const from = (0, webpack_modules_1.modulePath)(group.from);
245
+ const here = (reason) => (0, webpack_modules_1.modulePath)(reason.from) === from && reason.loc === group.loc;
246
+ const target = group.members
247
+ .flatMap(id => (rowsIn.get(id) ?? [])
248
+ .filter(row => row.reasons.some(reason => here(reason)))
249
+ .map(row => ({ id, row })))
250
+ .at(0);
251
+ if (target?.row.reasons.some(reason => here(reason) && isWorker(reason.kind))) {
252
+ continue;
253
+ }
254
+ const primary = target?.id ??
255
+ group.members.toSorted((a, b) => groupsOf(a) - groupsOf(b) ||
256
+ (sizes.get(scriptsOf(b)[0] ?? '') ?? 0) - (sizes.get(scriptsOf(a)[0] ?? '') ?? 0))[0];
257
+ const [lazy] = primary ? scriptsOf(primary) : [];
258
+ const output = lazy ? outputs[lazy] : undefined;
259
+ if (!primary || !lazy || !output) {
260
+ continue;
261
+ }
262
+ output.entryPoint ??= target?.row.path ?? (from ? (0, webpack_modules_1.requested)(from, group.request) : lazy);
263
+ for (const id of group.members) {
264
+ for (const file of scriptsOf(id)) {
265
+ link(lazy, file, 'import-statement');
266
+ if (file !== lazy && !output.fetchedWith?.includes(file)) {
267
+ output.fetchedWith = [...(output.fetchedWith ?? []), file];
268
+ }
269
+ }
270
+ }
271
+ const holders = new Set([...rows.values()].filter(row => row.path === from).flatMap(row => [...row.chunks]));
272
+ const importers = holders.size > 0 ? holders : new Set(group.members.flatMap(id => byId.get(id)?.parents ?? []));
273
+ for (const id of importers) {
274
+ if (group.members.includes(id)) {
275
+ continue;
276
+ }
277
+ for (const file of scriptsOf(id)) {
278
+ link(file, lazy, 'dynamic-import');
279
+ }
280
+ }
281
+ }
282
+ return Object.keys(outputs).some(file => isScript(file))
283
+ ? { inputs, outputs, builtBy: { bundler: 'webpack' }, readFrom: 'webpack' }
284
+ : null;
285
+ };
286
+ exports.fromWebpackStats = fromWebpackStats;
287
+ /**
288
+ * What a parsed file is as a metafile: itself when it is one, translated when it is webpack's, and
289
+ * `null` otherwise. Every door a stats file comes in by goes through here, so the two formats are
290
+ * read the same way by the page, the command, a baseline and a comparison.
291
+ */
292
+ const metafileOf = (value) => {
293
+ if ((0, metafile_types_1.isMetafile)(value)) {
294
+ return value;
295
+ }
296
+ return (0, metafile_types_1.foreignFormat)(value) === 'webpack' ? (0, exports.fromWebpackStats)(value) : null;
297
+ };
298
+ exports.metafileOf = metafileOf;
@@ -51,19 +51,23 @@ const budgetAdvice = (initialRawBytes, headroom = 0.15) => {
51
51
  };
52
52
  exports.budgetAdvice = budgetAdvice;
53
53
  /**
54
- * The same for one screen: the budget on what a lazy chunk may weigh.
54
+ * The budget on what any one script may weigh.
55
55
  *
56
- * Angular's `anyComponentStyle` and `bundle` budgets are per named bundle, which hashed chunk names
57
- * make useless. What is worth writing is `anyScript`, applied to every emitted script: the figure
58
- * to base it on is the heaviest screen's own code, not the average, or the budget fires on the
59
- * screen that was already the largest the day it was written.
56
+ * Angular's `bundle` budgets are per named bundle, which hashed chunk names make useless. What is
57
+ * worth writing is `anyScript`, and **it applies to every script the build emits, the bootstrap's
58
+ * included**. It used to be suggested over the heaviest screen's own code — 20/30 kB on a build
59
+ * whose bootstrap chunks were 137 and 284 kB — which is a budget that fails the very next build on
60
+ * files nobody touched. It is suggested above the largest script instead, so that it starts green
61
+ * and fires when any file grows past what the biggest one is today.
62
+ *
63
+ * @param largestScriptRawBytes the heaviest script of the build, raw, wherever it lands.
60
64
  */
61
- const screenBudgetAdvice = (heaviestOwnRawBytes, headroom = 0.25) => {
62
- if (heaviestOwnRawBytes <= 0) {
65
+ const screenBudgetAdvice = (largestScriptRawBytes, headroom = 0.15) => {
66
+ if (largestScriptRawBytes <= 0) {
63
67
  return null;
64
68
  }
65
- const warningKb = roundKb(heaviestOwnRawBytes * (1 + headroom));
66
- const errorKb = roundKb(heaviestOwnRawBytes * (1 + headroom) * 1.5);
69
+ const warningKb = roundKb(largestScriptRawBytes * (1 + headroom));
70
+ const errorKb = roundKb(largestScriptRawBytes * (1 + headroom) * 1.3);
67
71
  const snippet = [
68
72
  '{',
69
73
  ' "type": "anyScript",',
@@ -71,6 +75,6 @@ const screenBudgetAdvice = (heaviestOwnRawBytes, headroom = 0.25) => {
71
75
  ` "maximumError": "${errorKb}kB"`,
72
76
  '}',
73
77
  ].join('\n');
74
- return { warningKb, errorKb, currentBytes: heaviestOwnRawBytes, snippet };
78
+ return { warningKb, errorKb, currentBytes: largestScriptRawBytes, snippet };
75
79
  };
76
80
  exports.screenBudgetAdvice = screenBudgetAdvice;
@@ -11,7 +11,7 @@
11
11
  * tolerant, and every guess is reported with the command it came from so it can be checked.
12
12
  */
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.pipelineKnown = exports.configurationBudgets = exports.readPipeline = exports.resolveBuildCommand = exports.isZoneless = exports.readPackageJson = exports.readAngularJson = exports.isInitialBudget = exports.parseSize = exports.EMPTY_CONTEXT = void 0;
14
+ exports.pipelineKnown = exports.configurationBudgets = exports.readPipeline = exports.resolveBuildCommand = exports.isZoneless = exports.readPackageJson = exports.repoPathOf = exports.repoPathsOf = exports.readAngularJson = exports.isInitialBudget = exports.parseSize = exports.EMPTY_CONTEXT = void 0;
15
15
  exports.EMPTY_CONTEXT = { angular: null, pkg: null, pipelines: [] };
16
16
  const KB = 1024;
17
17
  const UNITS = { b: 1, kb: KB, mb: KB * KB, gb: KB * KB * KB };
@@ -26,7 +26,7 @@ const parseSize = (value) => {
26
26
  if (typeof value !== 'string') {
27
27
  return null;
28
28
  }
29
- const match = /^\s*(\d+(?:\.\d+)?)\s*(b|kb|mb|gb)?\s*$/i.exec(value);
29
+ const match = /^\s*(\d+(?:\.\d+)?)\s*(?:(b|kb|mb|gb)\s*)?$/i.exec(value);
30
30
  if (!match?.[1]) {
31
31
  return null;
32
32
  }
@@ -49,14 +49,38 @@ const readBudgets = (value) => {
49
49
  /** The budgets that bound the initial download. `initial` is the one Angular CLI writes by default. */
50
50
  const isInitialBudget = (budget) => budget.type === 'initial' || budget.type === 'all';
51
51
  exports.isInitialBudget = isInitialBudget;
52
+ const trimSlashes = (path) => path.replaceAll('\\', '/').replaceAll(/^\.?\/+|\/+$/g, '');
53
+ /**
54
+ * `build.options.assets`, in both spellings Angular accepts: a path, copied to the same path under
55
+ * the output (`src/assets` → `assets/`, the old default), or `{ glob, input, output }`, copied from
56
+ * `input` to `output` (a `glob` over `public`, landing at the root, the default since v17).
57
+ */
58
+ const assetFoldersOf = (assets) => {
59
+ if (!Array.isArray(assets)) {
60
+ return [];
61
+ }
62
+ return assets.flatMap((entry) => {
63
+ if (typeof entry === 'string') {
64
+ const input = trimSlashes(entry);
65
+ // `src/assets` lands as `assets`: Angular drops the source root from a plain path.
66
+ return input ? [{ input, output: input.replace(/^src\//, '') }] : [];
67
+ }
68
+ if (entry && typeof entry === 'object') {
69
+ const { input, output } = entry;
70
+ return typeof input === 'string'
71
+ ? [{ input: trimSlashes(input), output: typeof output === 'string' ? trimSlashes(output) : '' }]
72
+ : [];
73
+ }
74
+ return [];
75
+ });
76
+ };
52
77
  const polyfillsHaveZone = (polyfills) => {
53
78
  if (typeof polyfills === 'string') {
54
79
  return polyfills.includes('zone.js');
55
80
  }
56
- if (Array.isArray(polyfills)) {
57
- return polyfills.some(entry => typeof entry === 'string' && entry.includes('zone.js'));
58
- }
59
- return null;
81
+ return Array.isArray(polyfills)
82
+ ? polyfills.some(entry => typeof entry === 'string' && entry.includes('zone.js'))
83
+ : null;
60
84
  };
61
85
  /**
62
86
  * Reads one application of an `angular.json`, and lists the rest.
@@ -100,9 +124,44 @@ const readAngularJson = (json, pick = null) => {
100
124
  configurations,
101
125
  defaultConfiguration: typeof build.defaultConfiguration === 'string' ? build.defaultConfiguration : null,
102
126
  zonePolyfill: polyfillsHaveZone(build.options?.polyfills),
127
+ assetFolders: assetFoldersOf(build.options?.assets),
103
128
  };
104
129
  };
105
130
  exports.readAngularJson = readAngularJson;
131
+ /**
132
+ * Where in the repository a file of the build folder comes from, when an `assets` entry of
133
+ * `angular.json` copies it there. Unverified on its own: the page has `angular.json` and not the
134
+ * repository, so it says "comes from"; the command can look on disk and drop what is not there.
135
+ *
136
+ * @param path the file's path inside the build folder, `/`-separated.
137
+ */
138
+ const repoPathsOf = (files, folders) => {
139
+ if (folders.length === 0) {
140
+ return null;
141
+ }
142
+ const found = new Map();
143
+ for (const { path } of files) {
144
+ const repo = (0, exports.repoPathOf)(path, folders);
145
+ if (repo) {
146
+ found.set(path, repo);
147
+ }
148
+ }
149
+ return found;
150
+ };
151
+ exports.repoPathsOf = repoPathsOf;
152
+ const repoPathOf = (path, folders) => {
153
+ const clean = trimSlashes(path);
154
+ // The most specific folder first: `assets/icons` before the root.
155
+ const match = folders
156
+ .filter(folder => folder.output === '' || clean === folder.output || clean.startsWith(`${folder.output}/`))
157
+ .toSorted((a, b) => b.output.length - a.output.length)[0];
158
+ if (!match) {
159
+ return null;
160
+ }
161
+ const rest = match.output === '' ? clean : clean.slice(match.output.length).replace(/^\//, '');
162
+ return `${match.input}/${rest}`;
163
+ };
164
+ exports.repoPathOf = repoPathOf;
106
165
  const buildTargetOf = (project) => project.architect?.['build'] ?? project.targets?.['build'];
107
166
  const readPackageJson = (json) => {
108
167
  if (!json || typeof json !== 'object') {
@@ -122,8 +181,11 @@ const readPackageJson = (json) => {
122
181
  name: typeof pkg.name === 'string' && pkg.name.trim() ? pkg.name.trim() : null,
123
182
  scripts,
124
183
  // What the project asks for by name. It is what tells a dependency you chose from one that
125
- // came along with something else, which changes the fix and not the weight.
126
- dependencies: Object.keys({ ...pkg.dependencies }),
184
+ // came along with something else, which changes the fix and not the weight. Both lists:
185
+ // a bundled application keeps what it ships in `devDependencies` as often as not — Vite
186
+ // and Nuxt scaffold it that way — and reading `dependencies` alone called `nuxt` itself
187
+ // "a package you never asked for".
188
+ dependencies: Object.keys(deps),
127
189
  zoneDependency: 'zone.js' in deps,
128
190
  angularVersion: typeof angularVersion === 'string' ? angularVersion.replace(/^[\^~>=<\s]+/, '') : null,
129
191
  };
@@ -131,16 +193,15 @@ const readPackageJson = (json) => {
131
193
  exports.readPackageJson = readPackageJson;
132
194
  /**
133
195
  * Is the project zoneless? `angular.json` decides when it lists the polyfills; otherwise the
134
- * absence of `zone.js` in `package.json` does. `null` when neither file is loaded.
196
+ * absence of `zone.js` in `package.json` does — of an Angular project. `null` when neither file is
197
+ * loaded, and for a `package.json` with no `@angular/core`: a Svelte, React or Nuxt app has no
198
+ * zone.js either, and was told its change detection runs on signals.
135
199
  */
136
200
  const isZoneless = (context) => {
137
201
  if (context.angular?.zonePolyfill !== null && context.angular?.zonePolyfill !== undefined) {
138
202
  return !context.angular.zonePolyfill;
139
203
  }
140
- if (context.pkg) {
141
- return !context.pkg.zoneDependency;
142
- }
143
- return null;
204
+ return context.pkg?.angularVersion ? !context.pkg.zoneDependency : null;
144
205
  };
145
206
  exports.isZoneless = isZoneless;
146
207
  // --- Pipeline ---------------------------------------------------------------------------------
@@ -163,7 +224,9 @@ const BUILD_COMMANDS = [
163
224
  /\brsbuild\s+build\b([^&|;]*)/,
164
225
  // esbuild has no `build` subcommand, so it is only recognised when it is being invoked with
165
226
  // flags. Matching the bare word would turn `pnpm add esbuild` into a build of the application.
166
- /\besbuild\s+([^&|;]*--[\w-][^&|;]*)/,
227
+ // Both conditions are lookaheads so the whitespace after the word is read once: written as
228
+ // `\s+` followed by the flags, the two could trade spaces and a long run of them backtracked.
229
+ /\besbuild(?=\s)(?=[^&|;]+--[\w-])([^&|;]+)/,
167
230
  ];
168
231
  /** The flags of a build command, when one of them is a build command. `null` when none is. */
169
232
  const buildFlagsIn = (command) => {
@@ -230,22 +293,22 @@ exports.resolveBuildCommand = resolveBuildCommand;
230
293
  * a file nobody recognises is still read line by line rather than skipped.
231
294
  */
232
295
  const kindOf = (fileName, text) => {
233
- if (/gitlab-ci/.test(fileName)) {
296
+ if (fileName.includes('gitlab-ci')) {
234
297
  return 'gitlab';
235
298
  }
236
- if (/azure-pipelines/.test(fileName) || /^\s*vmImage:/m.test(text)) {
299
+ if (fileName.includes('azure-pipelines') || /^\s*vmImage:/m.test(text)) {
237
300
  return 'azure';
238
301
  }
239
- if (/bitbucket-pipelines/.test(fileName) || /^pipelines:/m.test(text)) {
302
+ if (fileName.includes('bitbucket-pipelines') || /^pipelines:/m.test(text)) {
240
303
  return 'bitbucket';
241
304
  }
242
- if (/circleci/.test(fileName) || /^workflows:/m.test(text)) {
305
+ if (fileName.includes('circleci') || /^workflows:/m.test(text)) {
243
306
  return 'circleci';
244
307
  }
245
308
  if (/jenkinsfile/i.test(fileName)) {
246
309
  return 'jenkins';
247
310
  }
248
- if (/^jobs:/m.test(text) && /runs-on:/.test(text)) {
311
+ if (/^jobs:/m.test(text) && text.includes('runs-on:')) {
249
312
  return 'github';
250
313
  }
251
314
  return /^stages:/m.test(text) ? 'gitlab' : 'unknown';
@@ -313,6 +376,12 @@ const jobOf = (lines, index) => {
313
376
  }
314
377
  return null;
315
378
  };
379
+ /**
380
+ * What an `echo` or a `printf` prints: text, never a command. This project's own pipeline tells
381
+ * whoever broke it to "Run `pnpm build`" from an `echo`, and that message was read as a step
382
+ * building the default configuration.
383
+ */
384
+ const PRINTED = /\b(?:echo|printf)\s+(?:"[^"]*"|'[^']*'|[^&|;]*)/g;
316
385
  /**
317
386
  * Every build command found in a pipeline file, with the configuration it resolves to.
318
387
  * Comments are dropped first: a commented-out `ng build` is not a build.
@@ -332,6 +401,7 @@ const readPipeline = (fileName, text, scripts = {}) => {
332
401
  const command = line
333
402
  .replace(/^\s*-\s*/, '')
334
403
  .replace(/^\s*(?:run|script|before_script|after_script|commands?|steps?|bash|pwsh):\s*/, '')
404
+ .replaceAll(PRINTED, '')
335
405
  .trim();
336
406
  if (!command || /^[\w-]+:$/.test(command)) {
337
407
  continue;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ /**
3
+ * What the project being analysed is called, from whatever says it.
4
+ *
5
+ * A report has to name what it is about at a glance, and the name used to come only from a
6
+ * `package.json` or an `angular.json` loaded as context — which almost nobody loads — so almost
7
+ * every report was about nothing in particular. The build itself says it too: the page has a
8
+ * `<title>`, and the folder is usually named after the app.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.projectNameOf = void 0;
12
+ /** Folder names that are the build tool's, not the project's: `dist/browser` says nothing. */
13
+ const GENERIC_FOLDERS = new Set([
14
+ 'dist',
15
+ 'build',
16
+ 'browser',
17
+ 'public',
18
+ 'out',
19
+ 'output',
20
+ '.output',
21
+ 'www',
22
+ 'static',
23
+ 'assets',
24
+ 'client',
25
+ 'server',
26
+ ]);
27
+ /** A folder path's most specific segment that is not one of the build tool's own names. */
28
+ const folderName = (folder) => folder
29
+ .replaceAll('\\', '/')
30
+ .split('/')
31
+ .filter(part => part !== '' && part !== '.' && part !== '..')
32
+ .findLast(part => !GENERIC_FOLDERS.has(part.toLowerCase()) && !/\.json$/i.test(part)) ?? null;
33
+ const projectNameOf = (sources) => [sources.packageName, sources.angularProject, sources.pageTitle, sources.folder ? folderName(sources.folder) : null]
34
+ .map(name => name?.trim())
35
+ .find(name => !!name) ?? null;
36
+ exports.projectNameOf = projectNameOf;