@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.
- package/README.md +272 -45
- package/dist/cli/cli/args.js +97 -116
- package/dist/cli/cli/gates.js +80 -14
- package/dist/cli/cli/main.js +275 -31
- package/dist/cli/cli/memory.js +114 -0
- package/dist/cli/cli/read/declared.js +52 -0
- package/dist/cli/cli/read/locate.js +214 -0
- package/dist/cli/cli/{read-build.js → read/read-build.js} +156 -87
- package/dist/cli/cli/read/read-config.js +120 -0
- package/dist/cli/cli/render/html-report.js +111 -0
- package/dist/cli/cli/render/render-agent.js +114 -0
- package/dist/cli/cli/render/render-asked.js +104 -0
- package/dist/cli/cli/render/render-badge.js +140 -0
- package/dist/cli/cli/{render-json.js → render/render-json.js} +26 -10
- package/dist/cli/cli/{render-markdown.js → render/render-markdown.js} +6 -6
- package/dist/cli/cli/{render-pr.js → render/render-pr.js} +37 -15
- package/dist/cli/cli/{render-sarif.js → render/render-sarif.js} +11 -6
- package/dist/cli/cli/{render-text.js → render/render-text.js} +169 -127
- package/dist/cli/cli/render/terminal.js +55 -0
- package/dist/cli/cli/report.js +76 -29
- package/dist/cli/cli/self-check.js +19 -23
- package/dist/cli/cli/since-last.js +45 -0
- package/dist/cli/cli/text/text-errors.js +124 -0
- package/dist/cli/cli/text/text.js +343 -0
- package/dist/cli/cli/text/usage.js +240 -0
- package/dist/cli/src/app/core/analysis/analysis.js +68 -24
- package/dist/cli/src/app/core/analysis/{barrels.js → graph/barrels.js} +10 -3
- package/dist/cli/src/app/core/analysis/{blast.js → graph/blast.js} +56 -17
- package/dist/cli/src/app/core/analysis/{cycles.js → graph/cycles.js} +1 -1
- package/dist/cli/src/app/core/analysis/{importers.js → graph/importers.js} +1 -1
- package/dist/cli/src/app/core/analysis/{insights.js → graph/insights.js} +10 -4
- package/dist/cli/src/app/core/analysis/invariant.js +1 -1
- package/dist/cli/src/app/core/analysis/metafile.types.js +21 -7
- package/dist/cli/src/app/core/analysis/{delivery.js → screens/delivery.js} +1 -1
- package/dist/cli/src/app/core/analysis/{entries.js → screens/entries.js} +87 -11
- package/dist/cli/src/app/core/analysis/screens/marks.js +32 -0
- package/dist/cli/src/app/core/analysis/screens/route-files.js +116 -0
- package/dist/cli/src/app/core/analysis/{sourcemap.js → sourcemap/sourcemap.js} +106 -7
- package/dist/cli/src/app/core/analysis/{split-drift.js → sourcemap/split-drift.js} +13 -7
- package/dist/cli/src/app/core/analysis/tool.js +83 -0
- package/dist/cli/src/app/core/assets/assets.js +137 -16
- package/dist/cli/src/app/core/baseline/baseline.js +0 -0
- package/dist/cli/src/app/core/{intake → build-text}/index-html.js +234 -29
- package/dist/cli/src/app/core/build-text/route-table.js +178 -0
- package/dist/cli/src/app/core/build-text/tool-marks.js +54 -0
- package/dist/cli/src/app/core/caching/caching.js +123 -45
- package/dist/cli/src/app/core/caching/from-analysis.js +20 -4
- package/dist/cli/src/app/core/config/config-text.js +90 -0
- package/dist/cli/src/app/core/config/config-values.js +358 -0
- package/dist/cli/src/app/core/config/loadline-config.js +81 -16
- package/dist/cli/src/app/core/config/merge-config.js +98 -0
- package/dist/cli/src/app/core/deps/deps.js +141 -23
- package/dist/cli/src/app/core/deps/pins.js +63 -0
- package/dist/cli/src/app/core/export/summary.js +54 -12
- package/dist/cli/src/app/core/findings/actions.js +65 -6
- package/dist/cli/src/app/core/findings/bundle/boot-single.js +76 -0
- package/dist/cli/src/app/core/findings/bundle/dupes.js +68 -0
- package/dist/cli/src/app/core/findings/{graph.js → bundle/graph.js} +32 -20
- package/dist/cli/src/app/core/findings/{own-in-boot.js → bundle/own-in-boot.js} +9 -5
- package/dist/cli/src/app/core/findings/{requests.js → bundle/requests.js} +3 -3
- package/dist/cli/src/app/core/findings/{shipped.js → bundle/shipped.js} +30 -18
- package/dist/cli/src/app/core/findings/compose.js +6 -1
- package/dist/cli/src/app/core/findings/effort.js +4 -0
- package/dist/cli/src/app/core/findings/finding.types.js +2 -0
- package/dist/cli/src/app/core/findings/findings.js +68 -55
- package/dist/cli/src/app/core/findings/{assets.js → folder/assets.js} +65 -16
- package/dist/cli/src/app/core/findings/{caching.js → folder/caching.js} +17 -10
- package/dist/cli/src/app/core/findings/{page.js → folder/page.js} +6 -2
- package/dist/cli/src/app/core/findings/{scan.js → folder/scan.js} +37 -13
- package/dist/cli/src/app/core/findings/kind-names.js +163 -0
- package/dist/cli/src/app/core/findings/{deps.js → supplied/deps.js} +13 -8
- package/dist/cli/src/app/core/findings/supplied/forbidden.js +71 -0
- package/dist/cli/src/app/core/findings/{situation.js → supplied/situation.js} +2 -2
- package/dist/cli/src/app/core/findings/text/causes.js +39 -0
- package/dist/cli/src/app/core/findings/text/finding-html.js +33 -0
- package/dist/cli/src/app/core/findings/{finding-text.js → text/finding-text.js} +307 -103
- package/dist/cli/src/app/core/findings/text/tool-advice.js +97 -0
- package/dist/cli/src/app/core/format/format.utils.js +172 -18
- package/dist/cli/src/app/core/format/ownership.js +93 -0
- package/dist/cli/src/app/core/i18n/en.js +180 -61
- package/dist/cli/src/app/core/i18n/es.js +192 -68
- package/dist/cli/src/app/core/intake/bundle-graph.js +285 -46
- package/dist/cli/src/app/core/intake/dist-files.js +87 -16
- package/dist/cli/src/app/core/intake/embedded.js +56 -0
- package/dist/cli/src/app/core/intake/unreached.js +139 -0
- package/dist/cli/src/app/core/intake/webpack-modules.js +185 -0
- package/dist/cli/src/app/core/intake/webpack-stats.js +298 -0
- package/dist/cli/src/app/core/project/budget-advice.js +14 -10
- package/dist/cli/src/app/core/project/project-context.js +89 -19
- package/dist/cli/src/app/core/project/project-name.js +36 -0
- package/dist/cli/src/app/core/scan/scan.js +116 -39
- package/dist/cli/src/app/core/scan/secrets.js +0 -0
- package/dist/cli/src/app/core/situation/situation-text.js +23 -0
- package/dist/cli/src/app/core/situation/situation.js +9 -8
- package/dist/cli/src/app/core/timing/timing.js +5 -2
- package/dist/cli/src/app/core/whatif/defer.js +29 -4
- package/dist/cli/src/app/core/whatif/source-importers.js +58 -0
- package/dist/cli/src/app/core/whatif/why.js +102 -0
- package/dist/cli/src/app/state/report-messages.utils.js +1 -4
- package/docs/CONFIG-REFERENCE.md +230 -0
- package/docs/CONFIG.md +511 -0
- package/docs/HOW-IT-WORKS.md +286 -25
- package/loadline.html +26 -24
- package/loadline.schema.json +1209 -0
- package/package.json +71 -35
- package/dist/cli/cli/text.js +0 -180
- package/dist/cli/src/app/core/findings/finding-html.js +0 -13
- /package/dist/cli/cli/{read-build.types.js → read/read-build.types.js} +0 -0
- /package/dist/cli/cli/{render-json.types.js → render/render-json.types.js} +0 -0
- /package/dist/cli/cli/{text.types.js → text/text.types.js} +0 -0
- /package/dist/cli/src/app/core/analysis/{exclusive.js → graph/exclusive.js} +0 -0
- /package/dist/cli/src/app/core/analysis/{insights.types.js → graph/insights.types.js} +0 -0
- /package/dist/cli/src/app/core/analysis/{module-graph.js → graph/module-graph.js} +0 -0
- /package/dist/cli/src/app/core/analysis/{sourcemap.types.js → sourcemap/sourcemap.types.js} +0 -0
- /package/dist/cli/src/app/core/findings/{finding-plain.js → text/finding-plain.js} +0 -0
|
@@ -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
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
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
|
-
|
|
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 } = (0, entries_1.browserSide)(meta.outputs, gzip ? new Set(gzip.keys()) : null);
|
|
82
|
-
const inputs = meta.inputs
|
|
98
|
+
const { outputs, serverOutputs, componentStyles, offPage } = (0, entries_1.browserSide)(meta.outputs, gzip ? new Set(gzip.keys()) : null);
|
|
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) =>
|
|
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 =>
|
|
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
|
|
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]);
|
|
@@ -243,19 +267,21 @@ const analyze = (meta, gzip, exact = null, announced = null, marks = null, limit
|
|
|
243
267
|
const sumOf = (chunks) => [...chunks].reduce((total, c) => total + sizeOf(c), 0);
|
|
244
268
|
const bootBytes = sumOf(boot);
|
|
245
269
|
const bootRawBytes = [...boot].reduce((total, chunk) => total + (outputs[chunk]?.bytes ?? 0), 0);
|
|
246
|
-
const
|
|
247
|
-
|
|
248
|
-
|
|
270
|
+
const { initialRawBytes, largestScript } = (0, entries_1.initialFiguresOf)(outputs, boot);
|
|
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));
|
|
249
274
|
const own = lazy.filter(chunk => screenCount.get(chunk) === 1);
|
|
250
275
|
const shared = lazy.filter(chunk => (screenCount.get(chunk) ?? 0) > 1);
|
|
251
276
|
// The bootstrap is already there when the router navigates, so it ends the walk: what
|
|
252
277
|
// is being counted is the round trips this screen adds on top of an app already running.
|
|
253
278
|
// What the loader asks for alongside the entry chunk starts in the same trip as it: a
|
|
254
279
|
// build that ships that list has already paid for those files by the time it parses.
|
|
255
|
-
|
|
256
|
-
const
|
|
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);
|
|
257
283
|
return {
|
|
258
|
-
|
|
284
|
+
...(0, route_files_1.routedName)(entry, routes, (0, format_utils_1.screenLabel)(entry.source, entry.chunk)),
|
|
259
285
|
source: entry.source,
|
|
260
286
|
files: boot.size + lazy.length,
|
|
261
287
|
boot: bootBytes,
|
|
@@ -271,8 +297,9 @@ const analyze = (meta, gzip, exact = null, announced = null, marks = null, limit
|
|
|
271
297
|
width: (0, delivery_1.widthOf)(chunkWaves),
|
|
272
298
|
chunkWaves,
|
|
273
299
|
};
|
|
274
|
-
})
|
|
275
|
-
|
|
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);
|
|
276
303
|
// What the first load costs in round trips. Only `index.html` can say, so without it the
|
|
277
304
|
// figure is absent rather than assumed.
|
|
278
305
|
const startup = announced ? (0, delivery_1.startupOf)(outputs, boot, announced) : null;
|
|
@@ -606,6 +633,7 @@ const analyze = (meta, gzip, exact = null, announced = null, marks = null, limit
|
|
|
606
633
|
roots: [mainSource, ...alsoStarted.map(([, out]) => out.entryPoint)].filter(file => typeof file === 'string'),
|
|
607
634
|
isOwn,
|
|
608
635
|
modules,
|
|
636
|
+
reachable,
|
|
609
637
|
boot,
|
|
610
638
|
bootBytesOf: file => bootBytesByInput.get(file) ?? 0,
|
|
611
639
|
screens,
|
|
@@ -619,16 +647,29 @@ const analyze = (meta, gzip, exact = null, announced = null, marks = null, limit
|
|
|
619
647
|
insights,
|
|
620
648
|
bootBytes,
|
|
621
649
|
bootRawBytes,
|
|
650
|
+
initialRawBytes,
|
|
651
|
+
largestScript,
|
|
652
|
+
tool: (0, tool_1.toolOf)(meta),
|
|
653
|
+
readFrom: meta.readFrom ?? 'metafile',
|
|
622
654
|
bootFiles: boot.size,
|
|
623
655
|
bootChunks: [...boot],
|
|
624
656
|
startup,
|
|
625
657
|
allChunks: Object.keys(outputs).filter(file => isJs(file)),
|
|
658
|
+
undescribedChunks: Object.keys(outputs).filter(file => isJs(file) && !outputs[file]?.inputs),
|
|
626
659
|
bootBuckets: [...buckets.values()].toSorted((a, b) => b.bytes - a.bytes),
|
|
627
660
|
bootBucketTotal,
|
|
628
661
|
serverOutputs,
|
|
662
|
+
offPage,
|
|
663
|
+
componentStyles,
|
|
629
664
|
deferredBlocks: (0, entries_1.labelledByWeight)(kinds.blocks, format_utils_1.screenLabel, sizeOf),
|
|
630
665
|
routeGroupers: (0, entries_1.labelledByWeight)(kinds.groupers, format_utils_1.screenLabel, sizeOf),
|
|
631
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)),
|
|
632
673
|
unreachable,
|
|
633
674
|
marks: marks ?? new Map(),
|
|
634
675
|
screens,
|
|
@@ -645,7 +686,10 @@ const analyze = (meta, gzip, exact = null, announced = null, marks = null, limit
|
|
|
645
686
|
ownFilesInBoot,
|
|
646
687
|
modules,
|
|
647
688
|
chainTo,
|
|
648
|
-
|
|
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',
|
|
649
693
|
splitDrift: (0, split_drift_1.splitDriftOf)(outputs, exact ?? null),
|
|
650
694
|
chunkOf: file => {
|
|
651
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("
|
|
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.
|
|
@@ -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;
|
|
@@ -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
|
-
|
|
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
|
-
/**
|
|
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
|
|
109
|
-
const
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
?
|
|
116
|
-
:
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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("
|
|
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("
|
|
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("
|
|
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
|
-
|
|
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
|
/**
|
|
@@ -4,10 +4,27 @@
|
|
|
4
4
|
* Reference: https://esbuild.github.io/api/#metafile
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.foreignFormat = exports.FOREIGN_FORMATS = exports.isMetafile = void 0;
|
|
7
|
+
exports.foreignFormat = exports.FOREIGN_FORMATS = exports.isMetafile = exports.fetchedTogether = void 0;
|
|
8
8
|
const json_utils_1 = require("../json/json.utils");
|
|
9
|
-
/**
|
|
10
|
-
const
|
|
9
|
+
/** `fetchedWith` of every output, in the shape `analyze` takes the preload lists of a folder in. */
|
|
10
|
+
const fetchedTogether = (outputs) => {
|
|
11
|
+
const together = Object.entries(outputs).flatMap(([chunk, output]) => output.fetchedWith && output.fetchedWith.length > 0 ? [[chunk, output.fetchedWith]] : []);
|
|
12
|
+
return together.length > 0 ? new Map(together) : null;
|
|
13
|
+
};
|
|
14
|
+
exports.fetchedTogether = fetchedTogether;
|
|
15
|
+
/**
|
|
16
|
+
* Checks that what was dropped is a metafile before trying to analyse it. Every way in goes through
|
|
17
|
+
* here — the page, the command, a comparison — so this is what makes the type above true.
|
|
18
|
+
*
|
|
19
|
+
* Both halves, and as objects: `typeof null` is `'object'`, and until 02/10/2026 only `outputs` was
|
|
20
|
+
* checked. A file without `inputs` passed as a metafile and then failed halfway through the analysis,
|
|
21
|
+
* in whichever of the seven places that read `inputs` came first; now it is refused at the door with
|
|
22
|
+
* the message for a file that is not a stats file.
|
|
23
|
+
*/
|
|
24
|
+
const isMetafile = (value) => {
|
|
25
|
+
const record = (0, json_utils_1.asRecord)(value);
|
|
26
|
+
return (0, json_utils_1.asRecord)(record?.['inputs']) !== null && (0, json_utils_1.asRecord)(record?.['outputs']) !== null;
|
|
27
|
+
};
|
|
11
28
|
exports.isMetafile = isMetafile;
|
|
12
29
|
/** The formats by name, for reading one back out of an error code that carries it. */
|
|
13
30
|
exports.FOREIGN_FORMATS = new Set([
|
|
@@ -36,9 +53,6 @@ const foreignFormat = (value) => {
|
|
|
36
53
|
// Vite's manifest: every value is an entry with the file it produced.
|
|
37
54
|
const values = Object.values(data);
|
|
38
55
|
const looksLikeEntry = (entry) => typeof (0, json_utils_1.asRecord)(entry)?.['file'] === 'string';
|
|
39
|
-
|
|
40
|
-
return 'viteManifest';
|
|
41
|
-
}
|
|
42
|
-
return 'unknown';
|
|
56
|
+
return values.length > 0 && values.every(entry => looksLikeEntry(entry)) ? 'viteManifest' : 'unknown';
|
|
43
57
|
};
|
|
44
58
|
exports.foreignFormat = foreignFormat;
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.startupOf = exports.criticalChainOf = exports.widthOf = exports.depthOf = exports.wavesFrom = exports.deliveryOf = void 0;
|
|
15
|
-
const format_utils_1 = require("
|
|
15
|
+
const format_utils_1 = require("../../format/format.utils");
|
|
16
16
|
/** Everyone downloads the bootstrap; anything else waits for a dynamic import to ask for it. */
|
|
17
17
|
const deliveryOf = (zone) => (zone === 'boot' ? 'eager' : 'lazy');
|
|
18
18
|
exports.deliveryOf = deliveryOf;
|
|
@@ -8,8 +8,8 @@
|
|
|
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;
|
|
12
|
-
const format_utils_1 = require("
|
|
11
|
+
exports.labelledByWeight = exports.classifyLazyEntries = exports.isDeferredBlock = exports.isRouteGrouper = exports.lazyLoadersOf = exports.initialFiguresOf = exports.browserSide = exports.ROUTE_FILE = void 0;
|
|
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
|
|
15
15
|
* metafile and most SSR setups still do, but this is only half the answer now: Angular 22 writes
|
|
@@ -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
|
/**
|
|
@@ -29,9 +29,18 @@ exports.ROUTE_FILE = new RegExp(String.raw `\.(?:${format_utils_1.ROUTE_SUFFIXES
|
|
|
29
29
|
* Two ways in, because a JSON chunk usually ships without a source map and then the only thing left
|
|
30
30
|
* is what the bundler called the file: the source itself ends in `.json`, or the chunk is named
|
|
31
31
|
* after the JSON it holds (`ru-RU.json-CCWdKmrX.js`, which is Vite's and Rollup's naming). The
|
|
32
|
-
* extension is the file's own, not a convention somebody here chose.
|
|
32
|
+
* extension is the file's own, not a convention somebody here chose. A JSON a plugin imports with a
|
|
33
|
+
* query on it (`es.json?hash=…`) is the same file; and a `*.config.*` loaded lazily is the
|
|
34
|
+
* configuration of something — Nuxt's i18n loads `i18n.config.ts` that way at startup, and it was
|
|
35
|
+
* a screen of 112 bytes that nobody can navigate to.
|
|
33
36
|
*/
|
|
34
|
-
|
|
37
|
+
/**
|
|
38
|
+
* A worker's own chunk: code that runs off the page, started on demand. Not a screen anybody
|
|
39
|
+
* navigates to — PocketBase's filter autocomplete runs one — and named that way by every bundler
|
|
40
|
+
* that writes one, after the `*.worker.js` it starts at.
|
|
41
|
+
*/
|
|
42
|
+
const WORKER_ENTRY = /(?:^|[.\-_])worker(?:[.\-_]|$)/i;
|
|
43
|
+
const DATA_ENTRY = /\.json(?:\?[^/]*)?$|\.json-[\w-]+\.m?js$|\.config\.[cm]?[jt]s$/;
|
|
35
44
|
/**
|
|
36
45
|
* A view: what Angular calls a component or a page, and what any framework defers inside one.
|
|
37
46
|
*
|
|
@@ -67,7 +76,27 @@ const VIEW_FILE = new RegExp(String.raw `\.(?:${format_utils_1.VIEW_SUFFIXES.joi
|
|
|
67
76
|
* wondering why the figures do not match the folder.
|
|
68
77
|
*/
|
|
69
78
|
const browserSide = (all, inFolder = null) => {
|
|
70
|
-
|
|
79
|
+
/**
|
|
80
|
+
* Component stylesheets first, and on their own: they are not missing from the folder, they are
|
|
81
|
+
* inside the JavaScript. Angular bundles each one apart, merges its output into the metafile and
|
|
82
|
+
* inlines the CSS into the component, so the name is in the metafile and never on disk. Counted
|
|
83
|
+
* by rule 2 they were reported as "the server side of a rendered build" on applications that
|
|
84
|
+
* have no server at all — fourteen of them on one, twenty-six on Loadline's own build.
|
|
85
|
+
*/
|
|
86
|
+
const componentStyles = Object.keys(all).filter(file => all[file]?.['ng-component'] === true);
|
|
87
|
+
const styled = new Set(componentStyles);
|
|
88
|
+
// What the folder reader found no screen downloads — the `nomodule` copy, a service worker —
|
|
89
|
+
// is a file of the folder and not of the server, so rule 2 below would never catch it.
|
|
90
|
+
const away = (kind) => Object.keys(all).filter(file => all[file]?.offPage === kind).length;
|
|
91
|
+
const offPage = {
|
|
92
|
+
legacy: away('legacy'),
|
|
93
|
+
serviceWorker: away('service-worker'),
|
|
94
|
+
server: away('server'),
|
|
95
|
+
ignored: away('ignored'),
|
|
96
|
+
};
|
|
97
|
+
const kept = (file) => !styled.has(file) && all[file]?.offPage === undefined;
|
|
98
|
+
const files = Object.keys(all).filter(file => kept(file));
|
|
99
|
+
const browserOnly = Object.fromEntries(Object.entries(all).filter(([file]) => kept(file)));
|
|
71
100
|
const elsewhere = (file) => SERVER_OUTPUT.test(file) || (inFolder !== null && !inFolder.has((0, format_utils_1.baseName)(file)));
|
|
72
101
|
const server = files.filter(file => elsewhere(file));
|
|
73
102
|
// Leaving everything out is never the answer. It means either a metafile of nothing but server
|
|
@@ -75,12 +104,37 @@ const browserSide = (all, inFolder = null) => {
|
|
|
75
104
|
// build than the stats file, where every name mismatches. Both are better read whole than
|
|
76
105
|
// reported as an empty application.
|
|
77
106
|
if (server.length === 0 || server.length === files.length) {
|
|
78
|
-
return { outputs:
|
|
107
|
+
return { outputs: browserOnly, serverOutputs: 0, componentStyles: componentStyles.length, offPage };
|
|
79
108
|
}
|
|
80
|
-
const outputs = Object.fromEntries(
|
|
81
|
-
return { outputs, serverOutputs: server.length };
|
|
109
|
+
const outputs = Object.fromEntries(Object.entries(browserOnly).filter(([file]) => !elsewhere(file)));
|
|
110
|
+
return { outputs, serverOutputs: server.length, componentStyles: componentStyles.length, offPage };
|
|
82
111
|
};
|
|
83
112
|
exports.browserSide = browserSide;
|
|
113
|
+
/**
|
|
114
|
+
* The figure Angular's `initial` budget checks, and the file an `anyScript` budget meets first.
|
|
115
|
+
*
|
|
116
|
+
* `initial` sums every initial file, scripts **and** the global stylesheet, raw. A stylesheet is
|
|
117
|
+
* initial when it is an entry of its own — `styles.css` is written with `angular:styles/global` as
|
|
118
|
+
* its entry point — and the component ones are already gone, inlined into the JavaScript. It is
|
|
119
|
+
* kept apart from the bootstrap's own figure because a budget suggested against one and checked
|
|
120
|
+
* against the other contradicted itself: 650/850 kB was proposed over 551 kB of JavaScript and
|
|
121
|
+
* CSS, and then reported as too loose against the 404 kB of JavaScript alone.
|
|
122
|
+
*
|
|
123
|
+
* @param boot the bootstrap chunks, already worked out from the graph.
|
|
124
|
+
*/
|
|
125
|
+
const initialFiguresOf = (outputs, boot) => {
|
|
126
|
+
const entries = Object.entries(outputs);
|
|
127
|
+
const bootRaw = [...boot].reduce((total, chunk) => total + (outputs[chunk]?.bytes ?? 0), 0);
|
|
128
|
+
const css = entries
|
|
129
|
+
.filter(([file, output]) => /\.css$/i.test(file) && !!output.entryPoint)
|
|
130
|
+
.reduce((total, [, output]) => total + output.bytes, 0);
|
|
131
|
+
const largest = entries
|
|
132
|
+
.filter(([file]) => /\.m?js$/.test(file))
|
|
133
|
+
.map(([file, output]) => ({ name: (0, format_utils_1.baseName)(file), bytes: output.bytes, boot: boot.has(file) }))
|
|
134
|
+
.toSorted((a, b) => b.bytes - a.bytes)[0];
|
|
135
|
+
return { initialRawBytes: bootRaw + css, largestScript: largest ?? null };
|
|
136
|
+
};
|
|
137
|
+
exports.initialFiguresOf = initialFiguresOf;
|
|
84
138
|
/**
|
|
85
139
|
* Own source files that lazily import each file. Who pulls something in is what says whether it is
|
|
86
140
|
* a screen of its own or a piece of one, so it is worked out before the screens are decided — and
|
|
@@ -183,6 +237,14 @@ const classifyLazyEntries = (entries, read) => {
|
|
|
183
237
|
* piece of it, which is twelve rows of a real report disappearing on one click.
|
|
184
238
|
*/
|
|
185
239
|
const lazySources = new Set(entries.filter(entry => !grouping.has(entry.source)).map(entry => entry.source));
|
|
240
|
+
/**
|
|
241
|
+
* What a worker imports statically is the worker's code, even when the page can also load it on
|
|
242
|
+
* its own. Excalidraw's font subsetting is a worker that imports `subset-shared`, which the page
|
|
243
|
+
* also imports lazily as a fallback: it was the heaviest screen of the report, at 1.53 MB.
|
|
244
|
+
*/
|
|
245
|
+
const ranByWorker = new Set(Object.entries(read.outputs)
|
|
246
|
+
.filter(([file]) => WORKER_ENTRY.test((0, format_utils_1.baseName)(file)))
|
|
247
|
+
.flatMap(([, out]) => (out.imports ?? []).filter(imp => imp.kind !== 'dynamic-import').map(imp => imp.path)));
|
|
186
248
|
const kindOf = (entry) => {
|
|
187
249
|
const mark = read.marks?.get(entry.source);
|
|
188
250
|
if (mark) {
|
|
@@ -193,16 +255,29 @@ const classifyLazyEntries = (entries, read) => {
|
|
|
193
255
|
if (DATA_ENTRY.test(entry.source)) {
|
|
194
256
|
return 'data';
|
|
195
257
|
}
|
|
258
|
+
if (WORKER_ENTRY.test((0, format_utils_1.baseName)(entry.source)) ||
|
|
259
|
+
WORKER_ENTRY.test((0, format_utils_1.baseName)(entry.chunk)) ||
|
|
260
|
+
ranByWorker.has(entry.chunk)) {
|
|
261
|
+
return 'workers';
|
|
262
|
+
}
|
|
196
263
|
if (grouping.has(entry.source)) {
|
|
197
264
|
return 'groupers';
|
|
198
265
|
}
|
|
199
|
-
|
|
266
|
+
// Where the code has a route table, it says which lazy chunks are places: a route's chunk is
|
|
267
|
+
// a screen whoever imports it, and one no route imports is not, piece of a page or not.
|
|
268
|
+
if (read.routed?.has(entry.chunk)) {
|
|
269
|
+
return 'screens';
|
|
270
|
+
}
|
|
271
|
+
const block = (0, exports.isDeferredBlock)(read.loaders.get(entry.source) ?? [], lazySources);
|
|
272
|
+
return block ? 'blocks' : read.routed ? 'onDemand' : 'screens';
|
|
200
273
|
};
|
|
201
274
|
const kinds = {
|
|
202
275
|
screens: [],
|
|
203
276
|
blocks: [],
|
|
204
277
|
groupers: [],
|
|
205
278
|
data: [],
|
|
279
|
+
workers: [],
|
|
280
|
+
onDemand: [],
|
|
206
281
|
};
|
|
207
282
|
for (const entry of entries) {
|
|
208
283
|
kinds[kindOf(entry)].push(entry);
|
|
@@ -212,6 +287,7 @@ const classifyLazyEntries = (entries, read) => {
|
|
|
212
287
|
exports.classifyLazyEntries = classifyLazyEntries;
|
|
213
288
|
/** Lazy entries as the report lists them: name and weight, heaviest first. */
|
|
214
289
|
const labelledByWeight = (entries, label, sizeOf) => entries
|
|
215
|
-
|
|
290
|
+
// With the chunk, so a build without maps reads `messages.es` and not the hash after it.
|
|
291
|
+
.map(entry => ({ source: entry.source, label: label(entry.source, entry.chunk), bytes: sizeOf(entry.chunk) }))
|
|
216
292
|
.toSorted((a, b) => b.bytes - a.bytes);
|
|
217
293
|
exports.labelledByWeight = labelledByWeight;
|