@bymaksym/loadline 0.1.0 → 1.0.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.
- package/README.md +66 -7
- package/dist/cli/cli/args.js +33 -3
- package/dist/cli/cli/declared.js +52 -0
- package/dist/cli/cli/html-report.js +107 -0
- package/dist/cli/cli/locate.js +60 -0
- package/dist/cli/cli/main.js +118 -5
- package/dist/cli/cli/memory.js +78 -0
- package/dist/cli/cli/read-build.js +8 -4
- package/dist/cli/cli/render-json.js +8 -5
- package/dist/cli/cli/render-markdown.js +1 -1
- package/dist/cli/cli/render-pr.js +5 -3
- package/dist/cli/cli/render-sarif.js +3 -3
- package/dist/cli/cli/render-text.js +63 -28
- package/dist/cli/cli/report.js +9 -3
- package/dist/cli/cli/since-last.js +45 -0
- package/dist/cli/cli/text.js +54 -19
- package/dist/cli/src/app/core/analysis/analysis.js +8 -4
- package/dist/cli/src/app/core/analysis/barrels.js +9 -2
- package/dist/cli/src/app/core/analysis/entries.js +41 -6
- package/dist/cli/src/app/core/analysis/metafile.types.js +14 -6
- package/dist/cli/src/app/core/analysis/split-drift.js +12 -6
- package/dist/cli/src/app/core/assets/assets.js +4 -2
- package/dist/cli/src/app/core/caching/caching.js +3 -3
- package/dist/cli/src/app/core/deps/deps.js +37 -7
- package/dist/cli/src/app/core/deps/pins.js +63 -0
- package/dist/cli/src/app/core/export/summary.js +27 -9
- package/dist/cli/src/app/core/findings/actions.js +63 -6
- package/dist/cli/src/app/core/findings/assets.js +30 -5
- package/dist/cli/src/app/core/findings/boot-single.js +76 -0
- package/dist/cli/src/app/core/findings/caching.js +1 -1
- package/dist/cli/src/app/core/findings/dupes.js +65 -0
- package/dist/cli/src/app/core/findings/effort.js +2 -0
- package/dist/cli/src/app/core/findings/finding-html.js +14 -1
- package/dist/cli/src/app/core/findings/finding-text.js +104 -31
- package/dist/cli/src/app/core/findings/finding.types.js +1 -0
- package/dist/cli/src/app/core/findings/findings.js +22 -38
- package/dist/cli/src/app/core/findings/graph.js +4 -4
- package/dist/cli/src/app/core/findings/scan.js +13 -3
- package/dist/cli/src/app/core/findings/shipped.js +3 -5
- package/dist/cli/src/app/core/format/format.utils.js +16 -9
- package/dist/cli/src/app/core/i18n/en.js +108 -48
- package/dist/cli/src/app/core/i18n/es.js +114 -50
- package/dist/cli/src/app/core/intake/bundle-graph.js +6 -5
- package/dist/cli/src/app/core/intake/dist-files.js +5 -2
- package/dist/cli/src/app/core/intake/embedded.js +46 -0
- package/dist/cli/src/app/core/intake/index-html.js +66 -16
- package/dist/cli/src/app/core/project/budget-advice.js +14 -10
- package/dist/cli/src/app/core/project/project-context.js +74 -16
- package/dist/cli/src/app/core/scan/scan.js +59 -21
- package/dist/cli/src/app/core/scan/secrets.js +0 -0
- package/dist/cli/src/app/core/situation/situation.js +3 -4
- package/dist/cli/src/app/state/report-messages.utils.js +1 -4
- package/loadline.html +22 -24
- package/package.json +60 -30
package/dist/cli/cli/text.js
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
/** Both languages of the command's own words. See `text.types.ts` for why they are kept apart. */
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.CLI_TEXT = void 0;
|
|
5
|
+
/** "Fixing both", not "acting on all 2": the line under the ranked signals, as the page words it. */
|
|
6
|
+
const fixingEn = (count) => {
|
|
7
|
+
if (count === 1) {
|
|
8
|
+
return 'Fixing it';
|
|
9
|
+
}
|
|
10
|
+
return count === 2 ? 'Fixing both' : `Fixing all ${count}`;
|
|
11
|
+
};
|
|
12
|
+
const fixingEs = (count) => {
|
|
13
|
+
if (count === 1) {
|
|
14
|
+
return 'Arreglándola';
|
|
15
|
+
}
|
|
16
|
+
return count === 2 ? 'Arreglando las dos' : `Arreglando las ${count}`;
|
|
17
|
+
};
|
|
5
18
|
const EN = {
|
|
6
19
|
lead: (stats, unit) => `${stats} · figures ${unit}`,
|
|
7
20
|
against: (baseline, date) => `compared against ${baseline} (${date})`,
|
|
@@ -11,6 +24,14 @@ const EN = {
|
|
|
11
24
|
firstTrip: (total, files, parts) => `The whole first trip is ${total} across ${files} ${files === 1 ? 'file' : 'files'} — ${parts} — ` +
|
|
12
25
|
'counting everything index.html asks for before anything appears. The figure above is the ' +
|
|
13
26
|
'JavaScript half, which is the half this report can break down.',
|
|
27
|
+
htmlWritten: file => `The page with this build loaded: ${file}`,
|
|
28
|
+
located: files => `found ${files}`,
|
|
29
|
+
lastRunUnchanged: 'nothing moved',
|
|
30
|
+
tripFonts: 'fonts',
|
|
31
|
+
tripImages: 'images',
|
|
32
|
+
componentStyles: count => `${count} component ${count === 1 ? 'stylesheet' : 'stylesheets'} of the metafile ${count === 1 ? 'is' : 'are'} ` +
|
|
33
|
+
'inside the JavaScript: Angular inlines them, so they are not files in the folder and are already in the figures.',
|
|
34
|
+
sinceLast: (date, change) => `since the last run (${date}): ${change}`,
|
|
14
35
|
serverLeftOut: count => `${count} output${count === 1 ? '' : 's'} of this build are not in the browser folder ` +
|
|
15
36
|
'(the server side of a rendered build): left out, because nobody downloads them.',
|
|
16
37
|
blocked: 'The baseline was measured in another unit: nothing is compared. Pass --dist, or --mode raw.',
|
|
@@ -33,11 +54,11 @@ const EN = {
|
|
|
33
54
|
none: '',
|
|
34
55
|
},
|
|
35
56
|
savingCell: saving => saving || '—',
|
|
36
|
-
totalSaving: (bytes, after, count) =>
|
|
37
|
-
'
|
|
38
|
-
|
|
39
|
-
'
|
|
40
|
-
|
|
57
|
+
totalSaving: (bytes, after, count, estimated) => `${fixingEn(count)} would take ${bytes} off the first load, leaving it at about ${after}. ${estimated
|
|
58
|
+
? 'Compressed figures are an estimate: the raw bytes taken out, at the ratio the bootstrap ' +
|
|
59
|
+
'compresses by, since a single module has no compressed size of its own. '
|
|
60
|
+
: 'The figures are raw minified bytes inside the chunk. '}They are not added up: the graph is walked once with every file named above taken out ` +
|
|
61
|
+
'together, so bytes reachable two ways are counted once.',
|
|
41
62
|
profileName: { slow4g: 'slow 4G', fast4g: '4G', cable: 'cable' },
|
|
42
63
|
timeNote: 'An estimate, not a measurement: a model over the bytes, the round trips and three standard ' +
|
|
43
64
|
'connection profiles. Transfer and latency go by what travels; parse and compile go by raw ' +
|
|
@@ -70,10 +91,10 @@ const EN = {
|
|
|
70
91
|
prFixed: count => `${count} fixed`,
|
|
71
92
|
prNew: count => `${count} new`,
|
|
72
93
|
prDetails: 'The whole report',
|
|
73
|
-
screenBudgetNote: warning => 'And one
|
|
74
|
-
'makes it usable when the names carry content hashes and a per-bundle budget cannot
|
|
75
|
-
|
|
76
|
-
`
|
|
94
|
+
screenBudgetNote: (warning, file, size) => 'And one per file. "anyScript" applies to every script the build emits — the bootstrap ones too — ' +
|
|
95
|
+
'which is what makes it usable when the names carry content hashes and a per-bundle budget cannot ' +
|
|
96
|
+
`name anything. So it goes above the largest script there is today, ${file} at ${size}, or it fails ` +
|
|
97
|
+
`the next build on a file nobody touched — ${warning}:`,
|
|
77
98
|
headWhatIf: 'What if it were deferred',
|
|
78
99
|
whatIfNote: 'The saving is exact: the graph is walked without those files, and what stops being ' +
|
|
79
100
|
'reachable is what stops being downloaded. What is NOT recomputed is the split — which ' +
|
|
@@ -81,6 +102,9 @@ const EN = {
|
|
|
81
102
|
'round trips and per-screen totals that look measured and are not. So those are unchanged ' +
|
|
82
103
|
'above, and the last column says who would be paying for it instead.',
|
|
83
104
|
whatIfNobody: 'nothing lazy uses it',
|
|
105
|
+
whatIfEstimated: 'In compressed figures those are the exact raw bytes at the ratio the bootstrap compresses by: ' +
|
|
106
|
+
'the right size, not the exact one, hence the ≈.',
|
|
107
|
+
whatIfNotHere: format => `--what-if is not part of the ${format} format: run it again with --format text, summary or json to see the answer.`,
|
|
84
108
|
colWhatIf: 'Deferred',
|
|
85
109
|
colSize: 'In the bootstrap',
|
|
86
110
|
colAfter: 'Bootstrap after',
|
|
@@ -95,6 +119,14 @@ const ES = {
|
|
|
95
119
|
firstTrip: (total, files, parts) => `El primer viaje entero son ${total} en ${files} ${files === 1 ? 'fichero' : 'ficheros'} — ${parts} — ` +
|
|
96
120
|
'contando todo lo que pide index.html antes de que aparezca nada. La cifra de arriba es la ' +
|
|
97
121
|
'mitad de JavaScript, que es la que este informe sabe desglosar.',
|
|
122
|
+
htmlWritten: file => `La página con este build cargado: ${file}`,
|
|
123
|
+
located: files => `encontrado ${files}`,
|
|
124
|
+
lastRunUnchanged: 'no se ha movido nada',
|
|
125
|
+
tripFonts: 'de tipografías',
|
|
126
|
+
tripImages: 'de imágenes',
|
|
127
|
+
componentStyles: count => `${count} ${count === 1 ? 'hoja de estilos de componente del metafile va' : 'hojas de estilos de componente del metafile van'} ` +
|
|
128
|
+
'dentro del JavaScript: Angular las incrusta, así que no son ficheros de la carpeta y ya están en las cifras.',
|
|
129
|
+
sinceLast: (date, change) => `desde la última ejecución (${date}): ${change}`,
|
|
98
130
|
serverLeftOut: count => `${count} salida${count === 1 ? '' : 's'} de este build no ${count === 1 ? 'está' : 'están'} en la carpeta ` +
|
|
99
131
|
'del navegador (el lado servidor de un build con render): fuera, porque nadie las descarga.',
|
|
100
132
|
blocked: 'La línea base se midió en otra unidad: no se compara nada. Pasa --dist, o bien --mode raw.',
|
|
@@ -117,11 +149,11 @@ const ES = {
|
|
|
117
149
|
none: '',
|
|
118
150
|
},
|
|
119
151
|
savingCell: saving => saving || '—',
|
|
120
|
-
totalSaving: (bytes, after, count) =>
|
|
121
|
-
'Las cifras son bytes
|
|
122
|
-
|
|
123
|
-
'
|
|
124
|
-
|
|
152
|
+
totalSaving: (bytes, after, count, estimated) => `${fixingEs(count)} se quitarían ${bytes} de la primera carga y quedaría en unos ${after}. ${estimated
|
|
153
|
+
? 'Las cifras comprimidas son una estimación: los bytes en crudo que se quitan, a la proporción ' +
|
|
154
|
+
'en que se comprime el bootstrap, porque un módulo suelto no tiene tamaño comprimido propio. '
|
|
155
|
+
: 'Las cifras son bytes minificados en crudo dentro del chunk. '}No se suman: el grafo se recorre una vez quitando de golpe todos los ficheros nombrados arriba, ` +
|
|
156
|
+
'así que lo que se alcanza por dos caminos se cuenta una vez.',
|
|
125
157
|
profileName: { slow4g: '4G lento', fast4g: '4G', cable: 'cable' },
|
|
126
158
|
timeNote: 'Es una estimación, no una medición: un modelo sobre los bytes, las idas y vueltas y tres perfiles ' +
|
|
127
159
|
'de conexión estándar. La transferencia y la latencia van por lo que viaja; el parseo y la ' +
|
|
@@ -137,7 +169,7 @@ const ES = {
|
|
|
137
169
|
budgetNote: (warning, error, current) => `Aquí no se escribe ningún fichero. La primera carga son ${current} en crudo (el JavaScript y el CSS ` +
|
|
138
170
|
'que pide la página, que es lo que cuenta el budget initial de Angular), así que un aviso en ' +
|
|
139
171
|
`${warning} y un error en ${error} deja sitio para una funcionalidad y sigue parando un pipeline.`,
|
|
140
|
-
bootSummary: (files, screens) => `${files} ${files === 1 ? 'fichero' : 'ficheros
|
|
172
|
+
bootSummary: (files, screens) => `${files} ${files === 1 ? 'fichero, descargado' : 'ficheros, descargados'} antes de que aparezca nada · ${screens} ${screens === 1 ? 'pantalla' : 'pantallas'}`,
|
|
141
173
|
noScreens: 'No hay pantallas lazy: todo entra en el bootstrap.',
|
|
142
174
|
fix: 'Qué hacer',
|
|
143
175
|
passed: 'No se ha superado ningún gate.',
|
|
@@ -161,10 +193,10 @@ const ES = {
|
|
|
161
193
|
prFixed: count => `${count} resueltas`,
|
|
162
194
|
prNew: count => `${count} nuevas`,
|
|
163
195
|
prDetails: 'El informe entero',
|
|
164
|
-
screenBudgetNote: warning => 'Y otro
|
|
165
|
-
'que lo hace usable cuando los nombres llevan hash y un budget por bundle no
|
|
166
|
-
|
|
167
|
-
`
|
|
196
|
+
screenBudgetNote: (warning, file, size) => 'Y otro por fichero. «anyScript» aplica a cada script que emite el build —también a los del ' +
|
|
197
|
+
'arranque—, que es lo que lo hace usable cuando los nombres llevan hash y un budget por bundle no ' +
|
|
198
|
+
`puede nombrar nada. Por eso va por encima del script más grande de hoy, ${file} con ${size}, o ` +
|
|
199
|
+
`rompería el siguiente build por un fichero que nadie ha tocado — ${warning}:`,
|
|
168
200
|
headWhatIf: 'Y si se difiriera',
|
|
169
201
|
whatIfNote: 'El ahorro es exacto: se recorre el grafo sin esos ficheros, y lo que deja de alcanzarse es ' +
|
|
170
202
|
'lo que deja de descargarse. Lo que NO se recalcula es el troceado —qué ficheros acaban en ' +
|
|
@@ -172,6 +204,9 @@ const ES = {
|
|
|
172
204
|
'parecen medidos y no lo son—. Así que esos siguen igual arriba, y la última columna dice ' +
|
|
173
205
|
'quién lo pagaría en su lugar.',
|
|
174
206
|
whatIfNobody: 'no lo usa nada diferido',
|
|
207
|
+
whatIfEstimated: 'En cifras comprimidas son los bytes en crudo exactos a la proporción en que se comprime el ' +
|
|
208
|
+
'bootstrap: el tamaño correcto, no el exacto, y por eso el ≈.',
|
|
209
|
+
whatIfNotHere: format => `--what-if no forma parte del formato ${format}: vuelve a lanzarlo con --format text, summary o json para ver la respuesta.`,
|
|
175
210
|
colWhatIf: 'Diferido',
|
|
176
211
|
colSize: 'En el bootstrap',
|
|
177
212
|
colAfter: 'Bootstrap después',
|
|
@@ -78,12 +78,12 @@ const copyOf = (input, pkg) => {
|
|
|
78
78
|
const analyze = (meta, gzip, exact = null, announced = null, marks = null, limits = criteria_1.RECOMMENDED.raw, parallel = null) => {
|
|
79
79
|
// The keys of `gzip` are every asset of the build folder: the measured answer to what a
|
|
80
80
|
// browser can actually download, which is what tells the two sides of an SSR build apart.
|
|
81
|
-
const { outputs, serverOutputs } = (0, entries_1.browserSide)(meta.outputs, gzip ? new Set(gzip.keys()) : null);
|
|
82
|
-
const inputs = meta.inputs
|
|
81
|
+
const { outputs, serverOutputs, componentStyles } = (0, entries_1.browserSide)(meta.outputs, gzip ? new Set(gzip.keys()) : null);
|
|
82
|
+
const inputs = meta.inputs;
|
|
83
83
|
// `.mjs` is what esbuild writes with `--out-extension:.js=.mjs`, and what several setups ship.
|
|
84
84
|
// Filtering on `.js` alone left those builds with no entry at all and threw `NO_ENTRIES`.
|
|
85
85
|
const isJs = (file) => /\.m?js$/.test(file);
|
|
86
|
-
const isOwn = (input) =>
|
|
86
|
+
const isOwn = (input) => !input.includes('node_modules');
|
|
87
87
|
/** Source-graph edges that keep files in the same chunk: anything but a lazy boundary or an external. */
|
|
88
88
|
const travelsTogether = (imp) => !imp.external && imp.kind !== 'dynamic-import';
|
|
89
89
|
/**
|
|
@@ -209,7 +209,7 @@ const analyze = (meta, gzip, exact = null, announced = null, marks = null, limit
|
|
|
209
209
|
.filter(([file]) => reachable.has(file))
|
|
210
210
|
.map(([file, out]) => ({ chunk: file, source: out.entryPoint ?? '', set: reach(file) }))
|
|
211
211
|
// A screen is project code: an `await import('xlsx')` also produces a lazy entry and is not one.
|
|
212
|
-
.filter(entry =>
|
|
212
|
+
.filter(entry => !entry.source.includes('node_modules'));
|
|
213
213
|
// Which of them are screens, which are pieces of one and which only group routes. The three
|
|
214
214
|
// rules and their reasons are in `entries.ts`; a mark, when there is one, overrules them.
|
|
215
215
|
const kinds = (0, entries_1.classifyLazyEntries)(lazyOwnEntries, {
|
|
@@ -243,6 +243,7 @@ const analyze = (meta, gzip, exact = null, announced = null, marks = null, limit
|
|
|
243
243
|
const sumOf = (chunks) => [...chunks].reduce((total, c) => total + sizeOf(c), 0);
|
|
244
244
|
const bootBytes = sumOf(boot);
|
|
245
245
|
const bootRawBytes = [...boot].reduce((total, chunk) => total + (outputs[chunk]?.bytes ?? 0), 0);
|
|
246
|
+
const { initialRawBytes, largestScript } = (0, entries_1.initialFiguresOf)(outputs, boot);
|
|
246
247
|
const screens = kinds.screens
|
|
247
248
|
.map(entry => {
|
|
248
249
|
const lazy = [...entry.set].filter(chunk => !boot.has(chunk));
|
|
@@ -619,6 +620,8 @@ const analyze = (meta, gzip, exact = null, announced = null, marks = null, limit
|
|
|
619
620
|
insights,
|
|
620
621
|
bootBytes,
|
|
621
622
|
bootRawBytes,
|
|
623
|
+
initialRawBytes,
|
|
624
|
+
largestScript,
|
|
622
625
|
bootFiles: boot.size,
|
|
623
626
|
bootChunks: [...boot],
|
|
624
627
|
startup,
|
|
@@ -626,6 +629,7 @@ const analyze = (meta, gzip, exact = null, announced = null, marks = null, limit
|
|
|
626
629
|
bootBuckets: [...buckets.values()].toSorted((a, b) => b.bytes - a.bytes),
|
|
627
630
|
bootBucketTotal,
|
|
628
631
|
serverOutputs,
|
|
632
|
+
componentStyles,
|
|
629
633
|
deferredBlocks: (0, entries_1.labelledByWeight)(kinds.blocks, format_utils_1.screenLabel, sizeOf),
|
|
630
634
|
routeGroupers: (0, entries_1.labelledByWeight)(kinds.groupers, format_utils_1.screenLabel, sizeOf),
|
|
631
635
|
lazyData: (0, entries_1.labelledByWeight)(kinds.data, format_utils_1.screenLabel, sizeOf),
|
|
@@ -71,6 +71,8 @@ const ownBarrels = (input) => {
|
|
|
71
71
|
.toSorted((a, b) => b.exclusive - a.exclusive || b.bytes - a.bytes || b.pulls - a.pulls);
|
|
72
72
|
};
|
|
73
73
|
exports.ownBarrels = ownBarrels;
|
|
74
|
+
/** A file of a package published as flat ES module bundles: `fesm2022/core.mjs`, `fesm2022/_signal-chunk.mjs`. */
|
|
75
|
+
const FLAT_BUNDLE = /\/fesm\d{4}\//;
|
|
74
76
|
/**
|
|
75
77
|
* Packages that ship many more files than anything outside them imports.
|
|
76
78
|
*
|
|
@@ -112,7 +114,12 @@ const packageBarrels = (input) => {
|
|
|
112
114
|
for (const [id, path] of graph.nodes.entries()) {
|
|
113
115
|
count(id, path);
|
|
114
116
|
}
|
|
115
|
-
return [...byPackage]
|
|
117
|
+
return ([...byPackage]
|
|
118
|
+
// A package published as one flat ES module bundle — Angular's `fesm2022/`, and the
|
|
119
|
+
// `_xxx-chunk.mjs` files its build splits out of it — has no submodule to import instead:
|
|
120
|
+
// `@angular/core` came out as "100 files through one door" on every Angular build, with
|
|
121
|
+
// advice nobody could follow. The bundler already tree-shakes inside those files.
|
|
122
|
+
.filter(([, tally]) => [...tally.files].some(path => !FLAT_BUNDLE.test(path)))
|
|
116
123
|
.map(([name, tally]) => ({
|
|
117
124
|
name,
|
|
118
125
|
files: tally.files.size,
|
|
@@ -123,6 +130,6 @@ const packageBarrels = (input) => {
|
|
|
123
130
|
importers: input.importersOf(name),
|
|
124
131
|
}))
|
|
125
132
|
.filter(pkg => pkg.files >= input.minFiles && pkg.entryPoints > 0 && pkg.files >= pkg.entryPoints * input.minRatio)
|
|
126
|
-
.toSorted((a, b) => Number(b.inBoot) - Number(a.inBoot) || b.bytes - a.bytes);
|
|
133
|
+
.toSorted((a, b) => Number(b.inBoot) - Number(a.inBoot) || b.bytes - a.bytes));
|
|
127
134
|
};
|
|
128
135
|
exports.packageBarrels = packageBarrels;
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* every figure in the report, so they are kept here, apart and tested.
|
|
9
9
|
*/
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.labelledByWeight = exports.classifyLazyEntries = exports.isDeferredBlock = exports.isRouteGrouper = exports.lazyLoadersOf = exports.browserSide = exports.ROUTE_FILE = void 0;
|
|
11
|
+
exports.labelledByWeight = exports.classifyLazyEntries = exports.isDeferredBlock = exports.isRouteGrouper = exports.lazyLoadersOf = exports.initialFiguresOf = exports.browserSide = exports.ROUTE_FILE = void 0;
|
|
12
12
|
const format_utils_1 = require("../format/format.utils");
|
|
13
13
|
/**
|
|
14
14
|
* Where a server build lands **when the path says so**. Angular used to write `server/` into the
|
|
@@ -17,7 +17,7 @@ const format_utils_1 = require("../format/format.utils");
|
|
|
17
17
|
* name rule cannot see those without becoming a list of conventions. The other half is
|
|
18
18
|
* `holdsBrowserSide` below, which does not read names at all.
|
|
19
19
|
*/
|
|
20
|
-
const SERVER_OUTPUT = /(
|
|
20
|
+
const SERVER_OUTPUT = /(?:^|\/)server\//;
|
|
21
21
|
/** A file that only groups routes: it owns no code of its own. `.jsx`/`.tsx` for the React case. */
|
|
22
22
|
exports.ROUTE_FILE = new RegExp(String.raw `\.(?:${format_utils_1.ROUTE_SUFFIXES.join('|')})\.${format_utils_1.SOURCE_EXTENSION}$`);
|
|
23
23
|
/**
|
|
@@ -67,7 +67,17 @@ const VIEW_FILE = new RegExp(String.raw `\.(?:${format_utils_1.VIEW_SUFFIXES.joi
|
|
|
67
67
|
* wondering why the figures do not match the folder.
|
|
68
68
|
*/
|
|
69
69
|
const browserSide = (all, inFolder = null) => {
|
|
70
|
-
|
|
70
|
+
/**
|
|
71
|
+
* Component stylesheets first, and on their own: they are not missing from the folder, they are
|
|
72
|
+
* inside the JavaScript. Angular bundles each one apart, merges its output into the metafile and
|
|
73
|
+
* inlines the CSS into the component, so the name is in the metafile and never on disk. Counted
|
|
74
|
+
* by rule 2 they were reported as "the server side of a rendered build" on applications that
|
|
75
|
+
* have no server at all — fourteen of them on one, twenty-six on Loadline's own build.
|
|
76
|
+
*/
|
|
77
|
+
const componentStyles = Object.keys(all).filter(file => all[file]?.['ng-component'] === true);
|
|
78
|
+
const styled = new Set(componentStyles);
|
|
79
|
+
const files = Object.keys(all).filter(file => !styled.has(file));
|
|
80
|
+
const browserOnly = Object.fromEntries(Object.entries(all).filter(([file]) => !styled.has(file)));
|
|
71
81
|
const elsewhere = (file) => SERVER_OUTPUT.test(file) || (inFolder !== null && !inFolder.has((0, format_utils_1.baseName)(file)));
|
|
72
82
|
const server = files.filter(file => elsewhere(file));
|
|
73
83
|
// Leaving everything out is never the answer. It means either a metafile of nothing but server
|
|
@@ -75,12 +85,37 @@ const browserSide = (all, inFolder = null) => {
|
|
|
75
85
|
// build than the stats file, where every name mismatches. Both are better read whole than
|
|
76
86
|
// reported as an empty application.
|
|
77
87
|
if (server.length === 0 || server.length === files.length) {
|
|
78
|
-
return { outputs:
|
|
88
|
+
return { outputs: browserOnly, serverOutputs: 0, componentStyles: componentStyles.length };
|
|
79
89
|
}
|
|
80
|
-
const outputs = Object.fromEntries(
|
|
81
|
-
return { outputs, serverOutputs: server.length };
|
|
90
|
+
const outputs = Object.fromEntries(Object.entries(browserOnly).filter(([file]) => !elsewhere(file)));
|
|
91
|
+
return { outputs, serverOutputs: server.length, componentStyles: componentStyles.length };
|
|
82
92
|
};
|
|
83
93
|
exports.browserSide = browserSide;
|
|
94
|
+
/**
|
|
95
|
+
* The figure Angular's `initial` budget checks, and the file an `anyScript` budget meets first.
|
|
96
|
+
*
|
|
97
|
+
* `initial` sums every initial file, scripts **and** the global stylesheet, raw. A stylesheet is
|
|
98
|
+
* initial when it is an entry of its own — `styles.css` is written with `angular:styles/global` as
|
|
99
|
+
* its entry point — and the component ones are already gone, inlined into the JavaScript. It is
|
|
100
|
+
* kept apart from the bootstrap's own figure because a budget suggested against one and checked
|
|
101
|
+
* against the other contradicted itself: 650/850 kB was proposed over 551 kB of JavaScript and
|
|
102
|
+
* CSS, and then reported as too loose against the 404 kB of JavaScript alone.
|
|
103
|
+
*
|
|
104
|
+
* @param boot the bootstrap chunks, already worked out from the graph.
|
|
105
|
+
*/
|
|
106
|
+
const initialFiguresOf = (outputs, boot) => {
|
|
107
|
+
const entries = Object.entries(outputs);
|
|
108
|
+
const bootRaw = [...boot].reduce((total, chunk) => total + (outputs[chunk]?.bytes ?? 0), 0);
|
|
109
|
+
const css = entries
|
|
110
|
+
.filter(([file, output]) => /\.css$/i.test(file) && !!output.entryPoint)
|
|
111
|
+
.reduce((total, [, output]) => total + output.bytes, 0);
|
|
112
|
+
const largest = entries
|
|
113
|
+
.filter(([file]) => /\.m?js$/.test(file))
|
|
114
|
+
.map(([file, output]) => ({ name: (0, format_utils_1.baseName)(file), bytes: output.bytes, boot: boot.has(file) }))
|
|
115
|
+
.toSorted((a, b) => b.bytes - a.bytes)[0];
|
|
116
|
+
return { initialRawBytes: bootRaw + css, largestScript: largest ?? null };
|
|
117
|
+
};
|
|
118
|
+
exports.initialFiguresOf = initialFiguresOf;
|
|
84
119
|
/**
|
|
85
120
|
* Own source files that lazily import each file. Who pulls something in is what says whether it is
|
|
86
121
|
* a screen of its own or a piece of one, so it is worked out before the screens are decided — and
|
|
@@ -6,8 +6,19 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.foreignFormat = exports.FOREIGN_FORMATS = exports.isMetafile = void 0;
|
|
8
8
|
const json_utils_1 = require("../json/json.utils");
|
|
9
|
-
/**
|
|
10
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Checks that what was dropped is a metafile before trying to analyse it. Every way in goes through
|
|
11
|
+
* here — the page, the command, a comparison — so this is what makes the type above true.
|
|
12
|
+
*
|
|
13
|
+
* Both halves, and as objects: `typeof null` is `'object'`, and until 02/10/2026 only `outputs` was
|
|
14
|
+
* checked. A file without `inputs` passed as a metafile and then failed halfway through the analysis,
|
|
15
|
+
* in whichever of the seven places that read `inputs` came first; now it is refused at the door with
|
|
16
|
+
* the message for a file that is not a stats file.
|
|
17
|
+
*/
|
|
18
|
+
const isMetafile = (value) => {
|
|
19
|
+
const record = (0, json_utils_1.asRecord)(value);
|
|
20
|
+
return (0, json_utils_1.asRecord)(record?.['inputs']) !== null && (0, json_utils_1.asRecord)(record?.['outputs']) !== null;
|
|
21
|
+
};
|
|
11
22
|
exports.isMetafile = isMetafile;
|
|
12
23
|
/** The formats by name, for reading one back out of an error code that carries it. */
|
|
13
24
|
exports.FOREIGN_FORMATS = new Set([
|
|
@@ -36,9 +47,6 @@ const foreignFormat = (value) => {
|
|
|
36
47
|
// Vite's manifest: every value is an entry with the file it produced.
|
|
37
48
|
const values = Object.values(data);
|
|
38
49
|
const looksLikeEntry = (entry) => typeof (0, json_utils_1.asRecord)(entry)?.['file'] === 'string';
|
|
39
|
-
|
|
40
|
-
return 'viteManifest';
|
|
41
|
-
}
|
|
42
|
-
return 'unknown';
|
|
50
|
+
return values.length > 0 && values.every(entry => looksLikeEntry(entry)) ? 'viteManifest' : 'unknown';
|
|
43
51
|
};
|
|
44
52
|
exports.foreignFormat = foreignFormat;
|
|
@@ -33,15 +33,21 @@ const splitDriftOf = (outputs, exact) => {
|
|
|
33
33
|
if (!isJs(chunk) || exact?.has((0, format_utils_1.baseName)(chunk))) {
|
|
34
34
|
continue;
|
|
35
35
|
}
|
|
36
|
-
const sum = Object.values(output.inputs ?? {}).reduce((total, one) => total +
|
|
36
|
+
const sum = Object.values(output.inputs ?? {}).reduce((total, one) => total + one.bytesInOutput, 0);
|
|
37
37
|
// A chunk the metafile does not break down says nothing either way, and counting its
|
|
38
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
|
-
|
|
41
|
-
measured += sum;
|
|
42
|
-
chunks += 1;
|
|
39
|
+
if (!(sum > 0 && output.bytes > 0)) {
|
|
40
|
+
continue;
|
|
43
41
|
}
|
|
42
|
+
file += output.bytes;
|
|
43
|
+
measured += sum;
|
|
44
|
+
chunks += 1;
|
|
44
45
|
}
|
|
45
|
-
|
|
46
|
+
// Why they differ is knowable for one bundler, and it is the one this was measured on: Angular's
|
|
47
|
+
// chunk optimizer bundles the chunks again with Rolldown after esbuild, and rewrites every
|
|
48
|
+
// per-file weight as that pass's rendered length shared out in proportion — before the final
|
|
49
|
+
// minification. So the parts add up to more than the file, by the same factor in every chunk.
|
|
50
|
+
const angular = Object.values(outputs).some(output => Object.keys(output.inputs ?? {}).some(input => input.includes('@angular/core')));
|
|
51
|
+
return chunks > 0 ? { file, measured, ratio: measured / file, chunks, angular } : null;
|
|
46
52
|
};
|
|
47
53
|
exports.splitDriftOf = splitDriftOf;
|
|
@@ -281,10 +281,12 @@ const readAssets = (input) => {
|
|
|
281
281
|
(0, exports.kindOf)(file.name) !== 'map' &&
|
|
282
282
|
!PRE_COMPRESSED.test(file.name) &&
|
|
283
283
|
!input.texts.has(file.name) &&
|
|
284
|
-
!/^index(
|
|
284
|
+
!/^index(?:\.[\w-]+)?\.html$/i.test(file.name))
|
|
285
285
|
: [],
|
|
286
286
|
referencesRead,
|
|
287
|
-
|
|
287
|
+
// A favicon and a touch icon holding the same picture are alternatives the browser picks one
|
|
288
|
+
// of, not a file downloaded twice under two names.
|
|
289
|
+
duplicates: duplicatesOf(input.files, input.hashes).filter(entry => entry.names.some(path => !input.icons?.has(path.split('/').at(-1) ?? path))),
|
|
288
290
|
contentCompared: !!input.hashes && input.hashes.size > 0,
|
|
289
291
|
inlined,
|
|
290
292
|
inlinedBytes: inlined.reduce((sum, row) => sum + row.bytes, 0),
|
|
@@ -17,7 +17,7 @@ exports.readCaching = exports.unhashableFiles = exports.unstableChunks = exports
|
|
|
17
17
|
* version number somebody wrote by hand, which is exactly the case this is meant to catch rather
|
|
18
18
|
* than accept.
|
|
19
19
|
*/
|
|
20
|
-
const HASHED = /[.\-_][\
|
|
20
|
+
const HASHED = /[.\-_][\w-]{8,}\.[\da-z]+$/;
|
|
21
21
|
/**
|
|
22
22
|
* The same thing when the hash **is** the whole name: `ChDGvcpR.js`, `DkjDNEOM.js`, `BauOL-29.js`.
|
|
23
23
|
*
|
|
@@ -29,7 +29,7 @@ const HASHED = /[.\-_][\dA-Za-z_-]{8,}\.[\da-z]+$/;
|
|
|
29
29
|
* no hash and stay reported. It costs a hand-written `AppShell.js` being taken for a hash, and that
|
|
30
30
|
* is the right way round to be wrong: the price is one missing line, not a false claim.
|
|
31
31
|
*/
|
|
32
|
-
const BARE_HASH = /^[\
|
|
32
|
+
const BARE_HASH = /^[\w-]{8,}\.[\da-z]+$/;
|
|
33
33
|
const MIXED_CASE = /(?=.*[a-z])(?=.*[A-Z])/;
|
|
34
34
|
/**
|
|
35
35
|
* A name somebody wrote, with something after it: `main-K7QW2X.js`, `chunk-A1B2.js`.
|
|
@@ -42,7 +42,7 @@ const WRITTEN_PREFIX = /^[a-z]{3,}[.\-_]/;
|
|
|
42
42
|
/** A version pinned in the query string: `app.js?v=3`. It defeats the cache on every deploy. */
|
|
43
43
|
const VERSIONED_QUERY = /[?&]v(?:er|ersion)?=/i;
|
|
44
44
|
/** The name with its content hash taken off, which is what makes two builds' files comparable. */
|
|
45
|
-
const unhashedName = (name) => name.replace(/[.\-_][\
|
|
45
|
+
const unhashedName = (name) => name.replace(/[.\-_][\w-]{8,}(\.[\da-z]+)$/, '$1');
|
|
46
46
|
exports.unhashedName = unhashedName;
|
|
47
47
|
/** A name that is nothing but a hash: `ChDGvcpR.js`. Taking the hash off it would leave `.js`. */
|
|
48
48
|
const isBareHash = (name) => BARE_HASH.test(name) && MIXED_CASE.test(name) && !WRITTEN_PREFIX.test(name);
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.readDeps = exports.readAudit = exports.readLock = void 0;
|
|
21
21
|
const json_utils_1 = require("../json/json.utils");
|
|
22
|
+
const pins_1 = require("./pins");
|
|
22
23
|
/** ` /lodash@4.17.21:` in pnpm, `"node_modules/lodash": {` in npm, `lodash@^4.0.0:` in yarn. */
|
|
23
24
|
const PNPM_ENTRY = /^ {2}\/?((?:@[^/@]+\/)?[^@/\s]+)@([^(:\s]+)/;
|
|
24
25
|
const YARN_ENTRY = /^"?((?:@[^/@]+\/)?[^@/\s]+)@[^:]*:?$/;
|
|
@@ -42,9 +43,11 @@ const readNpmLock = (lock) => {
|
|
|
42
43
|
for (const [path, entry] of installed) {
|
|
43
44
|
const name = nameFromPath(path);
|
|
44
45
|
const version = versionOf(entry);
|
|
45
|
-
if (name
|
|
46
|
-
|
|
46
|
+
if (!name || !version) {
|
|
47
|
+
continue;
|
|
47
48
|
}
|
|
49
|
+
const declares = Object.fromEntries(Object.entries((0, json_utils_1.asRecord)((0, json_utils_1.asRecord)(entry)?.['dependencies']) ?? {}).filter((pair) => typeof pair[1] === 'string'));
|
|
50
|
+
found.set(`${name}@${version}`, { name, version, requiredBy: [], declares });
|
|
48
51
|
}
|
|
49
52
|
// The older format, for a lock file written before npm 7. Same two fields, one level in.
|
|
50
53
|
const older = Object.entries((0, json_utils_1.asRecord)(lock['dependencies']) ?? {});
|
|
@@ -63,12 +66,32 @@ const readNpmLock = (lock) => {
|
|
|
63
66
|
* does not use `DOMParser`: what is wanted is two fields per entry, and a parser would be the only
|
|
64
67
|
* runtime dependency of a tool whose whole point is having none.
|
|
65
68
|
*/
|
|
66
|
-
const readYamlLock = (text) => {
|
|
69
|
+
const readYamlLock = (text, yarn) => {
|
|
67
70
|
const found = new Map();
|
|
68
71
|
const lines = text.split('\n');
|
|
69
72
|
let pending = null;
|
|
73
|
+
/** The yarn entry whose `dependencies:` block is being read, if one is. */
|
|
74
|
+
let current = null;
|
|
75
|
+
let inDependencies = false;
|
|
70
76
|
for (const line of lines) {
|
|
71
|
-
|
|
77
|
+
// A yarn entry's own dependencies, with the range each one is declared at. pnpm writes a
|
|
78
|
+
// block of the same shape under `snapshots:` with **resolved** versions, which would read
|
|
79
|
+
// as every dependency pinned exactly — so this is only done for yarn.
|
|
80
|
+
if (yarn && current) {
|
|
81
|
+
if (/^ {2}dependencies:\s*$/.test(line)) {
|
|
82
|
+
inDependencies = true;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
const dependency = /^ {4}"?((?:@[^\s"/]+\/)?[^\s":]+)"?:?\s+"?([^"\s]+)"?\s*$/.exec(line);
|
|
86
|
+
if (inDependencies && dependency?.[1] && dependency[2]) {
|
|
87
|
+
current.declares = { ...current.declares, [dependency[1]]: dependency[2] };
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (!/^ {4}/.test(line)) {
|
|
91
|
+
inDependencies = false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const pnpm = yarn ? null : PNPM_ENTRY.exec(line);
|
|
72
95
|
if (pnpm?.[1] && pnpm[2]) {
|
|
73
96
|
found.set(`${pnpm[1]}@${pnpm[2]}`, { name: pnpm[1], version: pnpm[2], requiredBy: [] });
|
|
74
97
|
pending = null;
|
|
@@ -77,11 +100,17 @@ const readYamlLock = (text) => {
|
|
|
77
100
|
// yarn writes the name on one line and the version on the next.
|
|
78
101
|
const version = YARN_VERSION.exec(line);
|
|
79
102
|
if (pending && version?.[1]) {
|
|
80
|
-
|
|
103
|
+
current = { name: pending, version: version[1], requiredBy: [] };
|
|
104
|
+
found.set(`${pending}@${version[1]}`, current);
|
|
81
105
|
pending = null;
|
|
82
106
|
continue;
|
|
83
107
|
}
|
|
84
|
-
|
|
108
|
+
const entry = YARN_ENTRY.exec(line)?.[1] ?? null;
|
|
109
|
+
if (entry) {
|
|
110
|
+
current = null;
|
|
111
|
+
inDependencies = false;
|
|
112
|
+
}
|
|
113
|
+
pending = entry;
|
|
85
114
|
}
|
|
86
115
|
return [...found.values()];
|
|
87
116
|
};
|
|
@@ -98,7 +127,7 @@ const readLock = (name, text) => {
|
|
|
98
127
|
const lock = (0, json_utils_1.asRecord)(parsed);
|
|
99
128
|
return lock ? readNpmLock(lock) : null;
|
|
100
129
|
}
|
|
101
|
-
return /lock\.ya?ml$|yarn\.lock$/i.test(name) ? readYamlLock(text) : null;
|
|
130
|
+
return /lock\.ya?ml$|yarn\.lock$/i.test(name) ? readYamlLock(text, /yarn\.lock$/i.test(name)) : null;
|
|
102
131
|
};
|
|
103
132
|
exports.readLock = readLock;
|
|
104
133
|
/**
|
|
@@ -220,6 +249,7 @@ const readDeps = (input) => {
|
|
|
220
249
|
multipleVersions: [...byName]
|
|
221
250
|
.filter(([name, entries]) => entries.length > 1 && shippedBytes.has(name))
|
|
222
251
|
.map(([name, entries]) => ({ name, versions: entries.map(entry => entry.version) })),
|
|
252
|
+
declared: (0, pins_1.declaredFromLock)(input.lock),
|
|
223
253
|
};
|
|
224
254
|
};
|
|
225
255
|
exports.readDeps = readDeps;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Whether a duplicated package can be deduplicated at all.
|
|
4
|
+
*
|
|
5
|
+
* "Force the resolution with an override" is the right advice when the two ranges overlap and the
|
|
6
|
+
* wrong one when a dependency **pins** an exact version: `@firebase/app` asks for `idb` at exactly
|
|
7
|
+
* `7.1.1`, and the only way to collapse that copy onto another is to hand Firebase a version it
|
|
8
|
+
* was never released against. When the two copies are a major version apart, that is a breaking
|
|
9
|
+
* change inside somebody else's package, and the report used to suggest it without a word.
|
|
10
|
+
*
|
|
11
|
+
* The ranges come from what the project already has: a `package-lock.json` or a `yarn.lock` write
|
|
12
|
+
* each package's declared dependencies, and the command reads the `package.json` of the parent in
|
|
13
|
+
* `node_modules` when the lock is pnpm's, which records resolved versions only. Nothing is fetched.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.pinsOf = exports.declaredFromLock = void 0;
|
|
17
|
+
/** `7.1.1`, `=7.1.1`, `v7.1.1`, `npm:7.1.1`: a single version, no range operator anywhere. */
|
|
18
|
+
const EXACT = /^(?:npm:)?[=v]?(\d+)\.(\d+)\.(\d+)(?:-[\w.-]+)?(?:\+[\w.-]+)?$/;
|
|
19
|
+
const majorOf = (version) => /^(?:npm:)?[=v]?(\d+)\./.exec(version ?? '')?.[1] ?? null;
|
|
20
|
+
/** What the lock file itself says each package declares. npm and yarn write it; pnpm does not. */
|
|
21
|
+
const declaredFromLock = (lock) => {
|
|
22
|
+
const declared = new Map();
|
|
23
|
+
const entries = lock ?? [];
|
|
24
|
+
for (const entry of entries) {
|
|
25
|
+
if (entry.declares && Object.keys(entry.declares).length > 0) {
|
|
26
|
+
declared.set(entry.name, { ...declared.get(entry.name), ...entry.declares });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return declared;
|
|
30
|
+
};
|
|
31
|
+
exports.declaredFromLock = declaredFromLock;
|
|
32
|
+
/** The pins of each duplicated package, by package name. Empty when nothing is pinned. */
|
|
33
|
+
const pinsOf = (duplicates, declared) => {
|
|
34
|
+
const found = new Map();
|
|
35
|
+
if (!declared || declared.size === 0) {
|
|
36
|
+
return found;
|
|
37
|
+
}
|
|
38
|
+
/** The pin one parent puts on one copy, or `null` when what it declares is a range. */
|
|
39
|
+
const pinOf = (dupe, copy, parent) => {
|
|
40
|
+
const range = declared.get(parent)?.[dupe.name]?.trim();
|
|
41
|
+
const exact = range ? EXACT.exec(range) : null;
|
|
42
|
+
if (!range || !exact) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
const others = dupe.copies.filter(other => other !== copy).map(other => majorOf(other.version));
|
|
46
|
+
return {
|
|
47
|
+
parent,
|
|
48
|
+
range,
|
|
49
|
+
version: `${exact[1]}.${exact[2]}.${exact[3]}`,
|
|
50
|
+
majorApart: others.some(major => major !== null && major !== exact[1]),
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
for (const dupe of duplicates) {
|
|
54
|
+
const pins = dupe.copies
|
|
55
|
+
.flatMap(copy => copy.viaPackages.map(parent => pinOf(dupe, copy, parent)))
|
|
56
|
+
.filter((pin) => pin !== null);
|
|
57
|
+
if (pins.length > 0) {
|
|
58
|
+
found.set(dupe.name, pins);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return found;
|
|
62
|
+
};
|
|
63
|
+
exports.pinsOf = pinsOf;
|