@bymaksym/loadline 1.0.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 (112) hide show
  1. package/README.md +211 -43
  2. package/dist/cli/cli/args.js +79 -128
  3. package/dist/cli/cli/gates.js +80 -14
  4. package/dist/cli/cli/main.js +164 -33
  5. package/dist/cli/cli/memory.js +40 -4
  6. package/dist/cli/cli/{declared.js → read/declared.js} +1 -1
  7. package/dist/cli/cli/read/locate.js +214 -0
  8. package/dist/cli/cli/{read-build.js → read/read-build.js} +149 -84
  9. package/dist/cli/cli/read/read-config.js +120 -0
  10. package/dist/cli/cli/{html-report.js → render/html-report.js} +14 -10
  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} +18 -5
  15. package/dist/cli/cli/{render-markdown.js → render/render-markdown.js} +5 -5
  16. package/dist/cli/cli/{render-pr.js → render/render-pr.js} +33 -13
  17. package/dist/cli/cli/{render-sarif.js → render/render-sarif.js} +8 -3
  18. package/dist/cli/cli/{render-text.js → render/render-text.js} +118 -111
  19. package/dist/cli/cli/render/terminal.js +55 -0
  20. package/dist/cli/cli/report.js +68 -27
  21. package/dist/cli/cli/self-check.js +19 -23
  22. package/dist/cli/cli/since-last.js +2 -2
  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 +63 -23
  27. package/dist/cli/src/app/core/analysis/{barrels.js → graph/barrels.js} +1 -1
  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 +7 -1
  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} +50 -9
  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} +1 -1
  40. package/dist/cli/src/app/core/analysis/tool.js +83 -0
  41. package/dist/cli/src/app/core/assets/assets.js +134 -15
  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 +168 -13
  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 +121 -43
  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 +104 -16
  53. package/dist/cli/src/app/core/export/summary.js +29 -5
  54. package/dist/cli/src/app/core/findings/actions.js +3 -1
  55. package/dist/cli/src/app/core/findings/{boot-single.js → bundle/boot-single.js} +3 -3
  56. package/dist/cli/src/app/core/findings/{dupes.js → bundle/dupes.js} +8 -5
  57. package/dist/cli/src/app/core/findings/{graph.js → bundle/graph.js} +30 -18
  58. package/dist/cli/src/app/core/findings/{own-in-boot.js → bundle/own-in-boot.js} +9 -5
  59. package/dist/cli/src/app/core/findings/{requests.js → bundle/requests.js} +3 -3
  60. package/dist/cli/src/app/core/findings/{shipped.js → bundle/shipped.js} +28 -14
  61. package/dist/cli/src/app/core/findings/compose.js +6 -1
  62. package/dist/cli/src/app/core/findings/effort.js +2 -0
  63. package/dist/cli/src/app/core/findings/finding.types.js +1 -0
  64. package/dist/cli/src/app/core/findings/findings.js +48 -19
  65. package/dist/cli/src/app/core/findings/{assets.js → folder/assets.js} +38 -14
  66. package/dist/cli/src/app/core/findings/{caching.js → folder/caching.js} +16 -9
  67. package/dist/cli/src/app/core/findings/{page.js → folder/page.js} +6 -2
  68. package/dist/cli/src/app/core/findings/{scan.js → folder/scan.js} +25 -11
  69. package/dist/cli/src/app/core/findings/kind-names.js +163 -0
  70. package/dist/cli/src/app/core/findings/{deps.js → supplied/deps.js} +13 -8
  71. package/dist/cli/src/app/core/findings/supplied/forbidden.js +71 -0
  72. package/dist/cli/src/app/core/findings/{situation.js → supplied/situation.js} +2 -2
  73. package/dist/cli/src/app/core/findings/text/causes.js +39 -0
  74. package/dist/cli/src/app/core/findings/{finding-html.js → text/finding-html.js} +8 -1
  75. package/dist/cli/src/app/core/findings/{finding-text.js → text/finding-text.js} +208 -77
  76. package/dist/cli/src/app/core/findings/text/tool-advice.js +97 -0
  77. package/dist/cli/src/app/core/format/format.utils.js +158 -11
  78. package/dist/cli/src/app/core/format/ownership.js +93 -0
  79. package/dist/cli/src/app/core/i18n/en.js +76 -17
  80. package/dist/cli/src/app/core/i18n/es.js +82 -22
  81. package/dist/cli/src/app/core/intake/bundle-graph.js +281 -43
  82. package/dist/cli/src/app/core/intake/dist-files.js +82 -14
  83. package/dist/cli/src/app/core/intake/embedded.js +11 -1
  84. package/dist/cli/src/app/core/intake/unreached.js +139 -0
  85. package/dist/cli/src/app/core/intake/webpack-modules.js +185 -0
  86. package/dist/cli/src/app/core/intake/webpack-stats.js +298 -0
  87. package/dist/cli/src/app/core/project/project-context.js +16 -4
  88. package/dist/cli/src/app/core/project/project-name.js +36 -0
  89. package/dist/cli/src/app/core/scan/scan.js +58 -19
  90. package/dist/cli/src/app/core/scan/secrets.js +23 -3
  91. package/dist/cli/src/app/core/situation/situation-text.js +23 -0
  92. package/dist/cli/src/app/core/situation/situation.js +6 -4
  93. package/dist/cli/src/app/core/timing/timing.js +5 -2
  94. package/dist/cli/src/app/core/whatif/defer.js +29 -4
  95. package/dist/cli/src/app/core/whatif/source-importers.js +58 -0
  96. package/dist/cli/src/app/core/whatif/why.js +102 -0
  97. package/docs/CONFIG-REFERENCE.md +230 -0
  98. package/docs/CONFIG.md +511 -0
  99. package/docs/HOW-IT-WORKS.md +286 -25
  100. package/loadline.html +24 -20
  101. package/loadline.schema.json +1209 -0
  102. package/package.json +35 -29
  103. package/dist/cli/cli/locate.js +0 -60
  104. package/dist/cli/cli/text.js +0 -215
  105. /package/dist/cli/cli/{read-build.types.js → read/read-build.types.js} +0 -0
  106. /package/dist/cli/cli/{render-json.types.js → render/render-json.types.js} +0 -0
  107. /package/dist/cli/cli/{text.types.js → text/text.types.js} +0 -0
  108. /package/dist/cli/src/app/core/analysis/{exclusive.js → graph/exclusive.js} +0 -0
  109. /package/dist/cli/src/app/core/analysis/{insights.types.js → graph/insights.types.js} +0 -0
  110. /package/dist/cli/src/app/core/analysis/{module-graph.js → graph/module-graph.js} +0 -0
  111. /package/dist/cli/src/app/core/analysis/{sourcemap.types.js → sourcemap/sourcemap.types.js} +0 -0
  112. /package/dist/cli/src/app/core/findings/{finding-plain.js → text/finding-plain.js} +0 -0
@@ -0,0 +1,240 @@
1
+ "use strict";
2
+ /**
3
+ * `loadline --help`, in both languages of the report. `--lang es --help` printed it in English, the
4
+ * one page of the command somebody reads before anything else.
5
+ *
6
+ * The flags, the formats and the commands are the same in both: they are what is typed.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.USAGE = void 0;
10
+ const EN = `Loadline — weight per screen, from the terminal.
11
+
12
+ Usage
13
+ loadline <build root|stats.json|browser folder> [options]
14
+
15
+ The root of an Angular build — dist/<app> — is enough: browser-stats.json (Angular 22.2+) or
16
+ stats.json, and the browser/ folder next to it, are found on their own.
17
+
18
+ A build folder works on its own too: its chunks carry the import graph, so anything that emits ES
19
+ modules — Vite, Rollup, Rolldown, esbuild — is read without a stats file. It has to hold the
20
+ index.html of the build, which is what names the chunk the application starts at.
21
+
22
+ Reading the build
23
+ --dist <folder> The build output (the "browser" folder). Gives gzip figures, brotli when
24
+ it carries .br files, and exact per-file weights when it carries .js.map.
25
+ Not needed when the folder is what is being analysed.
26
+ --entry <script> A script the application starts at, when the page starts it in a way
27
+ this does not read: "client.*.js", with * for the hash. Repeatable; the
28
+ same as build.entries of loadline.json, for one run.
29
+ --baseline <file> A previous stats.json or a Loadline export, to compare against.
30
+ --export <file> Write this build's snapshot there, to be the --baseline of a later run.
31
+ The other half of --baseline, and the only one a build that writes no
32
+ stats.json has: a folder read as a graph could be compared against a
33
+ baseline and never produce one.
34
+ --lock <file> pnpm-lock.yaml, package-lock.json or yarn.lock. Says which packages you
35
+ did not ask for directly and what pulls each one in, reading what the
36
+ project asks for from the package.json next to it.
37
+ --audit <file.json> The output of "pnpm audit --json", "npm audit --json" or "yarn audit
38
+ --json". Crossed with what actually ships: "3 of your 47 are in the
39
+ first load" instead of "you have 47". Nothing is fetched — both files
40
+ are ones you already have.
41
+ --project <folder> Where angular.json, package.json and the pipeline file live. Adds the
42
+ budget checks. Not read unless asked for.
43
+ --mode raw|gzip|brotli Which figure the report is in. Default: the best --dist allows.
44
+ --criteria <file.json> Thresholds replacing the recommended ones. The Criteria tab of the page
45
+ writes this file with its "Download criteria" button.
46
+ --config <file.json> loadline.json: the thresholds, the gates and the signals the team has
47
+ decided to live with, kept next to the code. Without the flag, a
48
+ loadline.json in the working directory is read if there is one. Flags on
49
+ the command line win over the file.
50
+ --print-config Print that loadline.json with everything it "extends" joined in, and
51
+ stop: which threshold won, without reading three files. Needs no build.
52
+ The page cannot follow "extends"; drop what this prints on it instead.
53
+
54
+ Output
55
+ --format <format> text, summary, json, markdown, pr-comment, sarif, agent or badge.
56
+ Default: text.
57
+ summary is the whole report in a dozen lines — the figures, what to
58
+ fix first and nothing else — for a pipeline step that runs next to
59
+ twenty others and should not bury them.
60
+ pr-comment writes the comment a bot leaves on a merge request, with
61
+ an HTML marker so the next run edits it instead of adding a
62
+ sixteenth one. sarif anchors each signal to a file, which is what
63
+ GitHub's code scanning reads. agent is for a coding agent or a
64
+ script: the five actions worth most, each with its file or package,
65
+ import chain and saving, as fixed key=value lines and no prose.
66
+ badge is an SVG of the first load — "first load | 133 kB", with the
67
+ change when there is a --baseline — coloured by its verdict, to
68
+ commit next to a README or attach to a pull request.
69
+ --html <file> Also write the page — treemap, search, every chunk — with this build
70
+ already loaded into it. One self-contained file: nothing to drag in,
71
+ nothing fetched, opens offline.
72
+ --open Open what --html wrote.
73
+ --lang en|es Default: en.
74
+ --no-color Never emit colour. It is off already when stdout is not a terminal.
75
+ --no-cache Do not remember this run. By default each run is kept in
76
+ node_modules/.cache/loadline and the next one says what moved —
77
+ "bootstrap 156 kB → 129 kB" — without a --baseline.
78
+
79
+ Failing the build
80
+ --max-boot <size> Fail when the bootstrap is over it.
81
+ --max-screen <size> Fail when the total download of a screen is over it.
82
+ --max-own <size> Fail when the own code of a screen is over it.
83
+ --max-growth <size> With --baseline: fail when the bootstrap or a screen grows by more.
84
+ --max-growth-pct <n> The same, as a percentage.
85
+ --fail-on high|mid|none Fail when a signal of that severity is raised. Default: none.
86
+ --fail-on-new-package Fail when a package enters the bootstrap that was not in the baseline,
87
+ or that the "packages" list of loadline.json does not name.
88
+
89
+ Asking what if
90
+ --what-if <name> What the first load would weigh without that package, folder or file —
91
+ the figure to have BEFORE spending the afternoon. Exact: the graph is
92
+ walked without those files, and what stops being reachable is what stops
93
+ being downloaded. It does not re-chunk the build, so the round trips and
94
+ the per-screen totals are not recomputed and the output says so.
95
+ Repeatable.
96
+ --why <name> Why that package, folder or file is in the first load: the chain of
97
+ imports from the entry point, the file of yours where an import()
98
+ would take it out, and what that would save. Repeatable.
99
+
100
+ Checking the tool itself
101
+ --self-check Work the bootstrap out twice — once by walking the import graph, once
102
+ by closing what index.html announces — and fail when the two disagree.
103
+ It says nothing about the bundle: it catches the build changing shape
104
+ under Loadline, which is how the figures go wrong without an error.
105
+ Needs the index.html, so pass the build folder or add --dist. Prints
106
+ the check and nothing else.
107
+
108
+ Exit codes
109
+ 0 ran, nothing broke a gate.
110
+ 1 a gate broke.
111
+ 2 the arguments or the files could not be used.
112
+
113
+ Examples
114
+ loadline dist/app
115
+ loadline dist/app --html loadline.html --open
116
+ loadline dist/app/browser
117
+ loadline dist/app/stats.json --dist dist/app/browser
118
+ loadline dist/app/stats.json --dist dist/app/browser --max-boot 350kB --fail-on high
119
+ loadline dist/app/stats.json --baseline prev/stats.json --max-growth 20kB --format json
120
+ loadline dist --export loadline-baseline.json
121
+ loadline dist --baseline loadline-baseline.json --max-growth 20kB
122
+ loadline dist/app/stats.json --dist dist/app/browser --self-check
123
+ `;
124
+ const ES = `Loadline — el peso de cada pantalla, desde la terminal.
125
+
126
+ Uso
127
+ loadline <raíz del build|stats.json|carpeta browser> [opciones]
128
+
129
+ Basta con la raíz de un build de Angular — dist/<app> —: browser-stats.json (Angular 22.2+) o
130
+ stats.json, y la carpeta browser/ de al lado, se encuentran solos.
131
+
132
+ Una carpeta de build también sirve sola: sus chunks llevan el grafo de imports, así que todo lo
133
+ que emite módulos ES — Vite, Rollup, Rolldown, esbuild — se lee sin fichero de stats. Tiene que
134
+ traer el index.html del build, que es lo que nombra el chunk por el que arranca la aplicación.
135
+
136
+ Leer el build
137
+ --dist <carpeta> La salida del build (la carpeta "browser"). Da las cifras gzip, brotli si
138
+ trae ficheros .br, y el peso exacto de cada fichero si trae .js.map. No
139
+ hace falta cuando la carpeta es lo que se analiza.
140
+ --entry <script> Un script por el que arranca la aplicación, cuando la página lo arranca
141
+ de una forma que esto no lee: "client.*.js", con * para el hash.
142
+ Repetible; lo mismo que build.entries de loadline.json, para una vez.
143
+ --baseline <fichero> Un stats.json anterior o una exportación de Loadline, para comparar.
144
+ --export <fichero> Escribe ahí la foto de este build, para ser la --baseline de otra
145
+ ejecución. La otra mitad de --baseline, y la única que tiene un build
146
+ que no escribe stats.json: una carpeta leída como grafo podía compararse
147
+ con una baseline y nunca producir una.
148
+ --lock <fichero> pnpm-lock.yaml, package-lock.json o yarn.lock. Dice qué paquetes no
149
+ pediste tú directamente y qué trae cada uno, leyendo lo que pide el
150
+ proyecto del package.json de al lado.
151
+ --audit <fichero.json> La salida de "pnpm audit --json", "npm audit --json" o "yarn audit
152
+ --json", cruzada con lo que de verdad se envía: "3 de tus 47 están en
153
+ la primera carga" en vez de "tienes 47". No se descarga nada: los dos
154
+ ficheros ya los tienes.
155
+ --project <carpeta> Donde están angular.json, package.json y el fichero del pipeline. Añade
156
+ las comprobaciones de budgets. No se lee si no se pide.
157
+ --mode raw|gzip|brotli En qué cifra va el informe. Por defecto: la mejor que permita --dist.
158
+ --criteria <fichero.json>
159
+ Umbrales que sustituyen a los recomendados. La pestaña Criterios de la
160
+ página escribe este fichero con su botón "Descargar criterios".
161
+ --config <fichero.json> loadline.json: los umbrales, los gates y las señales que el equipo ha
162
+ decidido aceptar, junto al código. Sin la opción, se lee el
163
+ loadline.json del directorio de trabajo si lo hay. Las opciones de la
164
+ línea de comandos ganan al fichero.
165
+ --print-config Muestra ese loadline.json con todo lo que hereda con "extends" ya
166
+ unido, y para: qué umbral ha ganado, sin leer tres ficheros. No necesita
167
+ build. La página no puede seguir "extends"; suéltale lo que esto escribe.
168
+
169
+ Salida
170
+ --format <formato> text, summary, json, markdown, pr-comment, sarif, agent o badge.
171
+ Por defecto: text.
172
+ summary es el informe entero en una docena de líneas — las cifras,
173
+ qué arreglar primero y nada más —, para un paso del pipeline que
174
+ va junto a otros veinte y no debe taparlos.
175
+ pr-comment escribe el comentario que deja un bot en una merge
176
+ request, con una marca HTML para que la siguiente ejecución lo
177
+ edite en vez de añadir el decimosexto. sarif ancla cada señal a un
178
+ fichero, que es lo que lee el code scanning de GitHub. agent es
179
+ para un agente de código o un script: las cinco acciones que más
180
+ valen, cada una con su fichero o paquete, cadena de imports y
181
+ ahorro, en líneas clave=valor fijas y sin prosa.
182
+ badge es un SVG de la primera carga — "first load | 133 kB", con el
183
+ cambio si hay --baseline —, coloreado según el veredicto, para
184
+ ponerlo junto a un README o adjuntarlo a una pull request.
185
+ --html <fichero> Escribe también la página — treemap, búsqueda, cada chunk — con
186
+ este build ya cargado. Un único fichero autocontenido: nada que
187
+ arrastrar, nada que descargar, se abre sin conexión.
188
+ --open Abre lo que ha escrito --html.
189
+ --lang en|es Por defecto: en.
190
+ --no-color Nunca escribe color. Ya va sin él cuando stdout no es una terminal.
191
+ --no-cache No recuerda esta ejecución. Por defecto cada ejecución se guarda en
192
+ node_modules/.cache/loadline y la siguiente dice qué se ha movido —
193
+ "bootstrap 156 kB → 129 kB" — sin --baseline.
194
+
195
+ Romper el build
196
+ --max-boot <tamaño> Falla si el bootstrap lo supera.
197
+ --max-screen <tamaño> Falla si la descarga total de una pantalla lo supera.
198
+ --max-own <tamaño> Falla si el código propio de una pantalla lo supera.
199
+ --max-growth <tamaño> Con --baseline: falla si el bootstrap o una pantalla crece más que eso.
200
+ --max-growth-pct <n> Lo mismo, en porcentaje.
201
+ --fail-on high|mid|none Falla si sale una señal de esa gravedad. Por defecto: none.
202
+ --fail-on-new-package Falla si entra en el bootstrap un paquete que no estaba en la baseline,
203
+ o que no nombra la lista "packages" de loadline.json.
204
+
205
+ Preguntar qué pasaría
206
+ --what-if <nombre> Cuánto pesaría la primera carga sin ese paquete, carpeta o fichero: la
207
+ cifra que conviene tener ANTES de dedicarle la tarde. Exacta: se recorre
208
+ el grafo sin esos ficheros, y lo que deja de alcanzarse es lo que deja
209
+ de descargarse. No vuelve a trocear el build, así que las idas y vueltas
210
+ y los totales por pantalla no se recalculan, y la salida lo dice.
211
+ Repetible.
212
+ --why <nombre> Por qué ese paquete, carpeta o fichero está en la primera carga: la
213
+ cadena de imports desde el punto de entrada, el fichero tuyo donde un
214
+ import() lo sacaría, y cuánto ahorraría. Repetible.
215
+
216
+ Comprobar la propia herramienta
217
+ --self-check Calcula el bootstrap dos veces — recorriendo el grafo de imports y
218
+ cerrando lo que anuncia el index.html — y falla si no coinciden. No dice
219
+ nada del bundle: detecta que el build ha cambiado de forma por debajo de
220
+ Loadline, que es como las cifras se equivocan sin dar error. Necesita el
221
+ index.html, así que pasa la carpeta del build o añade --dist. Imprime la
222
+ comprobación y nada más.
223
+
224
+ Códigos de salida
225
+ 0 se ha ejecutado y no se ha roto ningún gate.
226
+ 1 se ha roto un gate.
227
+ 2 no se han podido usar los argumentos o los ficheros.
228
+
229
+ Ejemplos
230
+ loadline dist/app
231
+ loadline dist/app --html loadline.html --open
232
+ loadline dist/app/browser
233
+ loadline dist/app/stats.json --dist dist/app/browser
234
+ loadline dist/app/stats.json --dist dist/app/browser --max-boot 350kB --fail-on high
235
+ loadline dist/app/stats.json --baseline prev/stats.json --max-growth 20kB --format json
236
+ loadline dist --export loadline-baseline.json
237
+ loadline dist --baseline loadline-baseline.json --max-growth 20kB
238
+ loadline dist/app/stats.json --dist dist/app/browser --self-check
239
+ `;
240
+ exports.USAGE = { en: EN, es: ES };
@@ -3,14 +3,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.analyze = void 0;
4
4
  const criteria_1 = require("../criteria/criteria");
5
5
  const format_utils_1 = require("../format/format.utils");
6
- const blast_1 = require("./blast");
7
- const delivery_1 = require("./delivery");
8
- const entries_1 = require("./entries");
9
- const importers_1 = require("./importers");
10
- const insights_1 = require("./insights");
11
- const split_drift_1 = require("./split-drift");
6
+ const ownership_1 = require("../format/ownership");
7
+ const blast_1 = require("./graph/blast");
8
+ const importers_1 = require("./graph/importers");
9
+ const insights_1 = require("./graph/insights");
10
+ const metafile_types_1 = require("./metafile.types");
11
+ const delivery_1 = require("./screens/delivery");
12
+ const entries_1 = require("./screens/entries");
13
+ const route_files_1 = require("./screens/route-files");
14
+ const split_drift_1 = require("./sourcemap/split-drift");
15
+ const tool_1 = require("./tool");
12
16
  /** pnpm writes the version into the path, which is what puts a number on each copy. */
13
17
  const PNPM_COPY = /node_modules\/\.pnpm\/((?:@[^+]+\+)?[^@]+)@([^/]+)\//;
18
+ /**
19
+ * The version at the head of a pnpm directory name. pnpm appends the peers it resolved against,
20
+ * and on a long name a hash of them: `@angular+material@22.1.6_2ffb4168…` is version `22.1.6`,
21
+ * which the report used to print with the hash attached. A name too long for the disk is cut and
22
+ * hashed, version included — `@angular+platform-browser@2_49839d…` — and what survives is not a
23
+ * version: none is said rather than `2`.
24
+ */
25
+ const PNPM_VERSION = /^\d+\.\d+\.\d+(?:-[\da-z.]+)?/i;
14
26
  /**
15
27
  * Which installed copy of a package a file belongs to.
16
28
  *
@@ -28,7 +40,11 @@ const PNPM_COPY = /node_modules\/\.pnpm\/((?:@[^+]+\+)?[^@]+)@([^/]+)\//;
28
40
  */
29
41
  const copyOf = (input, pkg) => {
30
42
  const marker = input.lastIndexOf('node_modules/');
31
- if (marker === -1) {
43
+ // A file of Angular's own source maps names the folder Angular was built in, not where it was
44
+ // installed: it belongs to whichever copy is there and says nothing of which. Counted as one,
45
+ // every Angular package read through its maps came out "shipped twice", the second copy being
46
+ // the same files under that other path.
47
+ if (marker === -1 || format_utils_1.ANGULAR_BAZEL.test(input)) {
32
48
  return null;
33
49
  }
34
50
  // '' when the package is installed at the top level, which is a copy like any other.
@@ -45,7 +61,7 @@ const copyOf = (input, pkg) => {
45
61
  const folder = at.replaceAll(/^[./]+|\/+$/g, '');
46
62
  return {
47
63
  at,
48
- version: own ? (pnpm?.[2] ?? null) : null,
64
+ version: own ? (PNPM_VERSION.exec(pnpm?.[2] ?? '')?.[0] ?? null) : null,
49
65
  under: own || !at ? null : (pnpmName ?? (0, format_utils_1.packageOf)(at) ?? (folder || null)),
50
66
  };
51
67
  };
@@ -73,17 +89,20 @@ const copyOf = (input, pkg) => {
73
89
  * graph again.
74
90
  * @param parallel chunks the loader asks for in the same round trip as a lazy one, when the build
75
91
  * writes that list into the call. Vite does; esbuild does not, and there the map
76
- * is empty and nothing changes.
92
+ * is empty and nothing changes. Without it, what a webpack stats file says
93
+ * (`fetchedWith`) stands in.
77
94
  */
78
- const analyze = (meta, gzip, exact = null, announced = null, marks = null, limits = criteria_1.RECOMMENDED.raw, parallel = null) => {
95
+ const analyze = (meta, gzip, exact = null, announced = null, marks = null, limits = criteria_1.RECOMMENDED.raw, parallel = null, routes = null) => {
79
96
  // The keys of `gzip` are every asset of the build folder: the measured answer to what a
80
97
  // browser can actually download, which is what tells the two sides of an SSR build apart.
81
- const { outputs, serverOutputs, componentStyles } = (0, entries_1.browserSide)(meta.outputs, gzip ? new Set(gzip.keys()) : null);
98
+ const { outputs, serverOutputs, componentStyles, offPage } = (0, entries_1.browserSide)(meta.outputs, gzip ? new Set(gzip.keys()) : null);
82
99
  const inputs = meta.inputs;
100
+ // A stats file of webpack says what travels together on the chunks themselves.
101
+ const together = parallel ?? (0, metafile_types_1.fetchedTogether)(meta.outputs);
83
102
  // `.mjs` is what esbuild writes with `--out-extension:.js=.mjs`, and what several setups ship.
84
103
  // Filtering on `.js` alone left those builds with no entry at all and threw `NO_ENTRIES`.
85
104
  const isJs = (file) => /\.m?js$/.test(file);
86
- const isOwn = (input) => !input.includes('node_modules');
105
+ const isOwn = (input) => (0, ownership_1.isOwnFile)(input);
87
106
  /** Source-graph edges that keep files in the same chunk: anything but a lazy boundary or an external. */
88
107
  const travelsTogether = (imp) => !imp.external && imp.kind !== 'dynamic-import';
89
108
  /**
@@ -201,6 +220,7 @@ const analyze = (meta, gzip, exact = null, announced = null, marks = null, limit
201
220
  const unreachable = Object.keys(outputs)
202
221
  .filter(file => isJs(file) && !reachable.has(file))
203
222
  .map(file => ({ file, bytes: outputs[file]?.bytes ?? 0 }));
223
+ const lazyPackageEntries = (0, route_files_1.packagesOnDemand)(entries, chunk => lazyTargets.has(chunk) && reachable.has(chunk) && !boot.has(chunk));
204
224
  const lazyOwnEntries = entries
205
225
  .filter(([file]) => lazyTargets.has(file))
206
226
  // And reachable from where the application starts. A chunk only some other unreachable
@@ -209,7 +229,7 @@ const analyze = (meta, gzip, exact = null, announced = null, marks = null, limit
209
229
  .filter(([file]) => reachable.has(file))
210
230
  .map(([file, out]) => ({ chunk: file, source: out.entryPoint ?? '', set: reach(file) }))
211
231
  // A screen is project code: an `await import('xlsx')` also produces a lazy entry and is not one.
212
- .filter(entry => !entry.source.includes('node_modules'));
232
+ .filter(entry => (0, ownership_1.isOwnFile)(entry.source));
213
233
  // Which of them are screens, which are pieces of one and which only group routes. The three
214
234
  // rules and their reasons are in `entries.ts`; a mark, when there is one, overrules them.
215
235
  const kinds = (0, entries_1.classifyLazyEntries)(lazyOwnEntries, {
@@ -219,12 +239,16 @@ const analyze = (meta, gzip, exact = null, announced = null, marks = null, limit
219
239
  loaders: lazyLoaders,
220
240
  marks,
221
241
  grouperMaxBytes: limits.grouperMaxBytes,
242
+ routed: (0, route_files_1.routedChunks)(routes),
222
243
  });
244
+ // The route files a screen is reached through, and what it downloads with them: see `route-files.ts`.
245
+ const reached = (0, route_files_1.reachedThrough)(kinds.screens, kinds.groupers, outputs);
246
+ const setOf = (entry) => reached.get(entry.chunk)?.set ?? entry.set;
223
247
  // How many screens each lazy chunk appears in. Every shared-chunk figure builds on this counter.
224
248
  const screenCount = new Map();
225
249
  const chunkScreens = new Map();
226
250
  for (const entry of kinds.screens) {
227
- const lazyChunks = [...entry.set].filter(chunk => !boot.has(chunk));
251
+ const lazyChunks = [...setOf(entry)].filter(chunk => !boot.has(chunk));
228
252
  for (const chunk of lazyChunks) {
229
253
  screenCount.set(chunk, (screenCount.get(chunk) ?? 0) + 1);
230
254
  chunkScreens.set(chunk, [...(chunkScreens.get(chunk) ?? []), entry.source]);
@@ -244,19 +268,20 @@ const analyze = (meta, gzip, exact = null, announced = null, marks = null, limit
244
268
  const bootBytes = sumOf(boot);
245
269
  const bootRawBytes = [...boot].reduce((total, chunk) => total + (outputs[chunk]?.bytes ?? 0), 0);
246
270
  const { initialRawBytes, largestScript } = (0, entries_1.initialFiguresOf)(outputs, boot);
247
- const screens = kinds.screens
248
- .map(entry => {
249
- const lazy = [...entry.set].filter(chunk => !boot.has(chunk));
271
+ // Unique names: two routes ending in the same file name are told apart by their folders.
272
+ const screens = (0, format_utils_1.uniqueLabels)(kinds.screens.map(entry => {
273
+ const lazy = [...setOf(entry)].filter(chunk => !boot.has(chunk));
250
274
  const own = lazy.filter(chunk => screenCount.get(chunk) === 1);
251
275
  const shared = lazy.filter(chunk => (screenCount.get(chunk) ?? 0) > 1);
252
276
  // The bootstrap is already there when the router navigates, so it ends the walk: what
253
277
  // is being counted is the round trips this screen adds on top of an app already running.
254
278
  // What the loader asks for alongside the entry chunk starts in the same trip as it: a
255
279
  // build that ships that list has already paid for those files by the time it parses.
256
- const together = parallel?.get(entry.chunk) ?? [];
257
- const chunkWaves = (0, delivery_1.wavesFrom)(outputs, [entry.chunk, ...together], boot);
280
+ // And the route files it is reached through arrive before it, one after another.
281
+ const via = (reached.get(entry.chunk)?.via ?? []).map(grouper => grouper.chunk);
282
+ const chunkWaves = (0, route_files_1.wavesThrough)(outputs, [...via, entry.chunk], boot, together);
258
283
  return {
259
- label: (0, format_utils_1.screenLabel)(entry.source),
284
+ ...(0, route_files_1.routedName)(entry, routes, (0, format_utils_1.screenLabel)(entry.source, entry.chunk)),
260
285
  source: entry.source,
261
286
  files: boot.size + lazy.length,
262
287
  boot: bootBytes,
@@ -272,8 +297,9 @@ const analyze = (meta, gzip, exact = null, announced = null, marks = null, limit
272
297
  width: (0, delivery_1.widthOf)(chunkWaves),
273
298
  chunkWaves,
274
299
  };
275
- })
276
- .toSorted((a, b) => b.total - a.total);
300
+ }),
301
+ // Without source maps a screen's source is its chunk, and only its hash tells two apart.
302
+ source => source in outputs).toSorted((a, b) => b.total - a.total);
277
303
  // What the first load costs in round trips. Only `index.html` can say, so without it the
278
304
  // figure is absent rather than assumed.
279
305
  const startup = announced ? (0, delivery_1.startupOf)(outputs, boot, announced) : null;
@@ -607,6 +633,7 @@ const analyze = (meta, gzip, exact = null, announced = null, marks = null, limit
607
633
  roots: [mainSource, ...alsoStarted.map(([, out]) => out.entryPoint)].filter(file => typeof file === 'string'),
608
634
  isOwn,
609
635
  modules,
636
+ reachable,
610
637
  boot,
611
638
  bootBytesOf: file => bootBytesByInput.get(file) ?? 0,
612
639
  screens,
@@ -622,17 +649,27 @@ const analyze = (meta, gzip, exact = null, announced = null, marks = null, limit
622
649
  bootRawBytes,
623
650
  initialRawBytes,
624
651
  largestScript,
652
+ tool: (0, tool_1.toolOf)(meta),
653
+ readFrom: meta.readFrom ?? 'metafile',
625
654
  bootFiles: boot.size,
626
655
  bootChunks: [...boot],
627
656
  startup,
628
657
  allChunks: Object.keys(outputs).filter(file => isJs(file)),
658
+ undescribedChunks: Object.keys(outputs).filter(file => isJs(file) && !outputs[file]?.inputs),
629
659
  bootBuckets: [...buckets.values()].toSorted((a, b) => b.bytes - a.bytes),
630
660
  bootBucketTotal,
631
661
  serverOutputs,
662
+ offPage,
632
663
  componentStyles,
633
664
  deferredBlocks: (0, entries_1.labelledByWeight)(kinds.blocks, format_utils_1.screenLabel, sizeOf),
634
665
  routeGroupers: (0, entries_1.labelledByWeight)(kinds.groupers, format_utils_1.screenLabel, sizeOf),
635
666
  lazyData: (0, entries_1.labelledByWeight)(kinds.data, format_utils_1.screenLabel, sizeOf),
667
+ lazyWorkers: (0, entries_1.labelledByWeight)(kinds.workers, format_utils_1.screenLabel, sizeOf),
668
+ lazyOnDemand: (0, entries_1.labelledByWeight)(kinds.onDemand, format_utils_1.screenLabel, sizeOf),
669
+ routeTable: routes ? (0, route_files_1.routedChunks)(routes) !== null : null,
670
+ // One row per package: mermaid writes a chunk per diagram type, and twenty-seven rows of
671
+ // "mermaid" say less than one with all of them added up.
672
+ lazyPackages: (0, route_files_1.byLabel)((0, entries_1.labelledByWeight)(lazyPackageEntries, source => (0, format_utils_1.packageOf)(source) ?? (0, format_utils_1.screenLabel)(source), sizeOf)),
636
673
  unreachable,
637
674
  marks: marks ?? new Map(),
638
675
  screens,
@@ -649,7 +686,10 @@ const analyze = (meta, gzip, exact = null, announced = null, marks = null, limit
649
686
  ownFilesInBoot,
650
687
  modules,
651
688
  chainTo,
652
- splitSource: exact && exact.size > 0 ? 'sourcemap' : 'metafile',
689
+ // From the maps only when a map covers something the application reaches. Polymer ships maps
690
+ // for its polyfill bundles alone, and the report opened with "weight per file read from the
691
+ // source maps" right above "no source maps in this folder".
692
+ splitSource: [...reachable].some(chunk => exact?.has((0, format_utils_1.baseName)(chunk))) ? 'sourcemap' : 'metafile',
653
693
  splitDrift: (0, split_drift_1.splitDriftOf)(outputs, exact ?? null),
654
694
  chunkOf: file => {
655
695
  const cached = chunkCache.get(file);
@@ -18,7 +18,7 @@
18
18
  */
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
20
  exports.packageBarrels = exports.ownBarrels = void 0;
21
- const format_utils_1 = require("../format/format.utils");
21
+ const format_utils_1 = require("../../format/format.utils");
22
22
  const module_graph_1 = require("./module-graph");
23
23
  /**
24
24
  * How many bytes of source one re-export line is worth.
@@ -21,6 +21,8 @@
21
21
  */
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.blastRadiusOf = exports.cascadeShapeOf = exports.chunkImportersOf = void 0;
24
+ const caching_1 = require("../../caching/caching");
25
+ const format_utils_1 = require("../../format/format.utils");
24
26
  /**
25
27
  * The reverse edges the cascade travels along: for each chunk, the chunks that carry its file name
26
28
  * inside them.
@@ -34,8 +36,11 @@ const chunkImportersOf = (outputs) => {
34
36
  const importers = new Map();
35
37
  for (const [chunk, output] of Object.entries(outputs)) {
36
38
  // Externals name nothing of this build, and an import of a file the build does not emit
37
- // has no hash to move.
38
- const targets = (output.imports ?? []).filter(imp => !imp.external && outputs[imp.path]);
39
+ // has no hash to move. Nor does one of a file whose name carries none: Solid's Rollup setup
40
+ // writes its entry as `index.js`, which changes content on every leaf change and never
41
+ // changes name, so the eight chunks importing it never change for it — and the report said
42
+ // touching any leaf moved the whole build.
43
+ const targets = (output.imports ?? []).filter(imp => !imp.external && outputs[imp.path] && (0, caching_1.carriesHash)((0, format_utils_1.baseName)(imp.path)));
39
44
  for (const imp of targets) {
40
45
  const known = importers.get(imp.path);
41
46
  if (known) {
@@ -95,30 +100,64 @@ const namesPerChunk = (analysis) => {
95
100
  }
96
101
  return counts;
97
102
  };
98
- /** Bytes under which a chunk full of names is a runtime map rather than a bundle of code. */
103
+ /**
104
+ * Bytes on disk under which a chunk full of names is a runtime map rather than a bundle of code.
105
+ * Raw, whatever the report is in: compared with the report's figure, the same chunk was a runtime
106
+ * chunk in gzip (3 kB) and not in raw (9 kB), and the verdict flipped with `--mode`.
107
+ */
99
108
  const RUNTIME_CHUNK_BYTES = 4 * 1024;
100
109
  /** From what share of the build a chunk counts as "nearly everything names it". */
101
110
  const HUB_SHARE = 0.5;
111
+ /** A chunk's size on disk, from the tree that carries it next to the report's figure. */
112
+ const rawBytesOf = (analysis, chunk) => {
113
+ const node = analysis.tree.find(entry => entry.id === chunk);
114
+ return node?.rawBytes ?? node?.bytes ?? analysis.chunkOf(chunk)?.bytes ?? 0;
115
+ };
102
116
  /**
103
117
  * What the build's own topology says about how far a change travels. See `CascadeShape`.
104
118
  */
105
119
  const cascadeShapeOf = (analysis) => {
106
120
  const counts = namesPerChunk(analysis);
107
121
  const total = analysis.allChunks.length;
108
- const [hub, names] = [...counts].toSorted((a, b) => b[1] - a[1])[0] ?? [null, 0];
109
- const named = hub ? (analysis.chunkImporters.get(hub)?.length ?? 0) : 0;
110
- const bytes = hub ? (analysis.chunkOf(hub)?.bytes ?? 0) : 0;
111
- // A small file that names most of the build and is imported by most of it is the runtime-chunk
112
- // shape: the names live in one place, so nothing else carries anybody else's.
113
- const concentrated = total > 0 && names >= total * HUB_SHARE;
114
- const risk = !hub || !concentrated
115
- ? 'mid'
116
- : bytes <= RUNTIME_CHUNK_BYTES
117
- ? 'low'
118
- : named >= total * HUB_SHARE
119
- ? 'high'
120
- : 'mid';
121
- return { risk, hub, names, named, bytes };
122
+ const most = total * HUB_SHARE;
123
+ const namedBy = (chunk) => analysis.chunkImporters.get(chunk)?.length ?? 0;
124
+ const shapeOf = (hub, risk, via) => ({
125
+ risk,
126
+ hub,
127
+ names: hub ? (counts.get(hub) ?? 0) : 0,
128
+ named: hub ? namedBy(hub) : 0,
129
+ bytes: hub ? (analysis.chunkOf(hub)?.bytes ?? 0) : 0,
130
+ concentrated: !!hub && total > 0 && (counts.get(hub) ?? 0) >= most,
131
+ hubInBoot: !!hub && analysis.bootChunks.includes(hub),
132
+ via,
133
+ });
134
+ const [hub] = [...counts].toSorted((a, b) => b[1] - a[1])[0] ?? [null];
135
+ const names = hub ? (counts.get(hub) ?? 0) : 0;
136
+ const concentrated = !!hub && total > 0 && names >= most;
137
+ const importedByMost = !!hub && namedBy(hub) >= most;
138
+ // A small file that names most of the build **and** is imported by most of it is the runtime
139
+ // chunk: the names live in one place, so nothing else carries anybody else's. Imported by few,
140
+ // it is not that shape at all — Angular RealWorld's was a lazy screen naming twelve chunks.
141
+ if (concentrated && importedByMost) {
142
+ return shapeOf(hub, rawBytesOf(analysis, hub) <= RUNTIME_CHUNK_BYTES ? 'low' : 'high', 'names');
143
+ }
144
+ // The other way round: the chunk most of the build imports. Its name is inside every one of
145
+ // them, so whatever changes inside it renames them all — the framework chunk of an Angular
146
+ // build, the entry chunk of a Vite one. Unless it is a runtime map, which changes on its own.
147
+ // A chunk the maps say holds nothing but dependencies is left out: everybody importing a vendor
148
+ // chunk is the split working, since it only changes when a dependency does. Vue's runtime,
149
+ // imported by 15 of 17 chunks, was otherwise this build's "high risk".
150
+ const vendorOnly = (chunk) => {
151
+ const inside = analysis.modules.filter(module => module.places.some(place => place.chunk === chunk));
152
+ return inside.length > 0 && inside.every(module => module.pkg !== null);
153
+ };
154
+ const [shared] = [...analysis.chunkImporters]
155
+ .filter(([chunk]) => !vendorOnly(chunk))
156
+ .map(([chunk, naming]) => [chunk, naming.length])
157
+ .toSorted((a, b) => b[1] - a[1])[0] ?? [null];
158
+ return shared && total >= 3 && namedBy(shared) >= most && rawBytesOf(analysis, shared) > RUNTIME_CHUNK_BYTES
159
+ ? shapeOf(shared, 'high', 'imports')
160
+ : shapeOf(hub ?? null, 'mid', 'names');
122
161
  };
123
162
  exports.cascadeShapeOf = cascadeShapeOf;
124
163
  /**
@@ -13,7 +13,7 @@
13
13
  */
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.folderCycles = exports.fileCycles = void 0;
16
- const format_utils_1 = require("../format/format.utils");
16
+ const format_utils_1 = require("../../format/format.utils");
17
17
  const module_graph_1 = require("./module-graph");
18
18
  /**
19
19
  * Cycles between files.
@@ -9,7 +9,7 @@
9
9
  */
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.importGraphOf = void 0;
12
- const format_utils_1 = require("../format/format.utils");
12
+ const format_utils_1 = require("../../format/format.utils");
13
13
  const importGraphOf = (inputs, isOwn) => {
14
14
  const packages = new Map();
15
15
  const ownFiles = new Map();
@@ -12,7 +12,7 @@
12
12
  */
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.graphInsightsOf = void 0;
15
- const format_utils_1 = require("../format/format.utils");
15
+ const format_utils_1 = require("../../format/format.utils");
16
16
  const barrels_1 = require("./barrels");
17
17
  const cycles_1 = require("./cycles");
18
18
  const exclusive_1 = require("./exclusive");
@@ -76,7 +76,11 @@ const mixedImports = (inputs, byPath, boot) => {
76
76
  * two places because two sets of screens reach it and neither is a subset of the other. It is
77
77
  * money thrown away that appears in no list, and the fix is configuration rather than code.
78
78
  */
79
- const paidTwice = (modules) => modules
79
+ const paidTwice = (modules, reachable) => modules
80
+ .map(entry => {
81
+ const places = entry.places.filter(place => reachable.has(place.chunk));
82
+ return { ...entry, places, bytes: places.reduce((sum, place) => sum + place.bytes, 0) };
83
+ })
80
84
  .filter(entry => entry.places.length > 1)
81
85
  .map((entry) => ({
82
86
  path: entry.path,
@@ -166,7 +170,7 @@ const graphInsightsOf = (input) => {
166
170
  const weigher = (0, exclusive_1.exclusiveWeigher)(graph, input.roots, input.bootBytesOf);
167
171
  const label = (path) => (0, format_utils_1.shortName)(path);
168
172
  const cycleInput = { graph, isOwn: input.isOwn, shippedBytesOf, inBoot, label };
169
- const twiceOver = paidTwice(input.modules);
173
+ const twiceOver = paidTwice(input.modules, input.reachable);
170
174
  return {
171
175
  exclusive: (0, exclusive_1.exclusiveByBucket)(weigher, input.filesByBucket),
172
176
  exclusiveOf: weigher.of,
@@ -176,7 +180,9 @@ const graphInsightsOf = (input) => {
176
180
  ownBarrels: (0, barrels_1.ownBarrels)({
177
181
  graph,
178
182
  inputs: input.inputs,
179
- isOwn: input.isOwn,
183
+ // Where the application starts is no barrel, however short: taking it out takes the
184
+ // application out. An Angular 8 `main.ts` — five imports in 559 bytes — read as one.
185
+ isOwn: path => input.isOwn(path) && !input.roots.includes(path),
180
186
  shippedBytesOf,
181
187
  inBoot,
182
188
  exclusiveOf: weigher.of,
@@ -22,7 +22,7 @@
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.checkBoot = exports.isSameBoot = void 0;
24
24
  const format_utils_1 = require("../format/format.utils");
25
- const delivery_1 = require("./delivery");
25
+ const delivery_1 = require("./screens/delivery");
26
26
  /** Chunk names, in a fixed order: what is being read is a diff, and a diff has to be stable. */
27
27
  const byName = (a, b) => a.localeCompare(b);
28
28
  /**