@bymaksym/loadline 1.0.0 → 1.2.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 +229 -43
- package/dist/cli/cli/args.js +79 -128
- package/dist/cli/cli/gates.js +80 -14
- package/dist/cli/cli/main.js +164 -33
- package/dist/cli/cli/memory.js +40 -4
- package/dist/cli/cli/{declared.js → read/declared.js} +1 -1
- package/dist/cli/cli/read/locate.js +214 -0
- package/dist/cli/cli/{read-build.js → read/read-build.js} +149 -84
- package/dist/cli/cli/read/read-config.js +120 -0
- package/dist/cli/cli/{html-report.js → render/html-report.js} +14 -10
- 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} +18 -5
- package/dist/cli/cli/{render-markdown.js → render/render-markdown.js} +5 -5
- package/dist/cli/cli/{render-pr.js → render/render-pr.js} +33 -13
- package/dist/cli/cli/{render-sarif.js → render/render-sarif.js} +8 -3
- package/dist/cli/cli/{render-text.js → render/render-text.js} +118 -111
- package/dist/cli/cli/render/terminal.js +55 -0
- package/dist/cli/cli/report.js +68 -27
- package/dist/cli/cli/self-check.js +19 -23
- package/dist/cli/cli/since-last.js +2 -2
- 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 +63 -23
- package/dist/cli/src/app/core/analysis/{barrels.js → graph/barrels.js} +1 -1
- 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 +7 -1
- 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} +50 -9
- 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} +1 -1
- package/dist/cli/src/app/core/analysis/tool.js +83 -0
- package/dist/cli/src/app/core/assets/assets.js +134 -15
- package/dist/cli/src/app/core/baseline/baseline.js +0 -0
- package/dist/cli/src/app/core/{intake → build-text}/index-html.js +168 -13
- 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 +121 -43
- 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 +104 -16
- package/dist/cli/src/app/core/export/summary.js +29 -5
- package/dist/cli/src/app/core/findings/actions.js +3 -1
- package/dist/cli/src/app/core/findings/{boot-single.js → bundle/boot-single.js} +3 -3
- package/dist/cli/src/app/core/findings/{dupes.js → bundle/dupes.js} +8 -5
- package/dist/cli/src/app/core/findings/{graph.js → bundle/graph.js} +30 -18
- 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} +28 -14
- package/dist/cli/src/app/core/findings/compose.js +6 -1
- package/dist/cli/src/app/core/findings/effort.js +2 -0
- package/dist/cli/src/app/core/findings/finding.types.js +1 -0
- package/dist/cli/src/app/core/findings/findings.js +48 -19
- package/dist/cli/src/app/core/findings/{assets.js → folder/assets.js} +38 -14
- package/dist/cli/src/app/core/findings/{caching.js → folder/caching.js} +16 -9
- 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} +25 -11
- 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/{finding-html.js → text/finding-html.js} +8 -1
- package/dist/cli/src/app/core/findings/{finding-text.js → text/finding-text.js} +208 -77
- package/dist/cli/src/app/core/findings/text/tool-advice.js +97 -0
- package/dist/cli/src/app/core/format/format.utils.js +158 -11
- package/dist/cli/src/app/core/format/ownership.js +93 -0
- package/dist/cli/src/app/core/i18n/en.js +76 -17
- package/dist/cli/src/app/core/i18n/es.js +82 -22
- package/dist/cli/src/app/core/intake/bundle-graph.js +281 -43
- package/dist/cli/src/app/core/intake/dist-files.js +82 -14
- package/dist/cli/src/app/core/intake/embedded.js +11 -1
- 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/project-context.js +16 -4
- package/dist/cli/src/app/core/project/project-name.js +36 -0
- package/dist/cli/src/app/core/scan/scan.js +58 -19
- package/dist/cli/src/app/core/scan/secrets.js +23 -3
- package/dist/cli/src/app/core/situation/situation-text.js +23 -0
- package/dist/cli/src/app/core/situation/situation.js +6 -4
- 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/docs/CONFIG-REFERENCE.md +230 -0
- package/docs/CONFIG.md +511 -0
- package/docs/HOW-IT-WORKS.md +286 -25
- package/loadline.html +24 -20
- package/loadline.schema.json +1209 -0
- package/package.json +35 -29
- package/dist/cli/cli/locate.js +0 -60
- package/dist/cli/cli/text.js +0 -215
- /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
|
@@ -4,8 +4,14 @@
|
|
|
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
|
+
/** `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;
|
|
9
15
|
/**
|
|
10
16
|
* Checks that what was dropped is a metafile before trying to analyse it. Every way in goes through
|
|
11
17
|
* here — the page, the command, a comparison — so this is what makes the type above true.
|
|
@@ -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;
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
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("
|
|
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
|
|
@@ -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
|
*
|
|
@@ -76,8 +85,18 @@ const browserSide = (all, inFolder = null) => {
|
|
|
76
85
|
*/
|
|
77
86
|
const componentStyles = Object.keys(all).filter(file => all[file]?.['ng-component'] === true);
|
|
78
87
|
const styled = new Set(componentStyles);
|
|
79
|
-
|
|
80
|
-
|
|
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)));
|
|
81
100
|
const elsewhere = (file) => SERVER_OUTPUT.test(file) || (inFolder !== null && !inFolder.has((0, format_utils_1.baseName)(file)));
|
|
82
101
|
const server = files.filter(file => elsewhere(file));
|
|
83
102
|
// Leaving everything out is never the answer. It means either a metafile of nothing but server
|
|
@@ -85,10 +104,10 @@ const browserSide = (all, inFolder = null) => {
|
|
|
85
104
|
// build than the stats file, where every name mismatches. Both are better read whole than
|
|
86
105
|
// reported as an empty application.
|
|
87
106
|
if (server.length === 0 || server.length === files.length) {
|
|
88
|
-
return { outputs: browserOnly, serverOutputs: 0, componentStyles: componentStyles.length };
|
|
107
|
+
return { outputs: browserOnly, serverOutputs: 0, componentStyles: componentStyles.length, offPage };
|
|
89
108
|
}
|
|
90
109
|
const outputs = Object.fromEntries(Object.entries(browserOnly).filter(([file]) => !elsewhere(file)));
|
|
91
|
-
return { outputs, serverOutputs: server.length, componentStyles: componentStyles.length };
|
|
110
|
+
return { outputs, serverOutputs: server.length, componentStyles: componentStyles.length, offPage };
|
|
92
111
|
};
|
|
93
112
|
exports.browserSide = browserSide;
|
|
94
113
|
/**
|
|
@@ -218,6 +237,14 @@ const classifyLazyEntries = (entries, read) => {
|
|
|
218
237
|
* piece of it, which is twelve rows of a real report disappearing on one click.
|
|
219
238
|
*/
|
|
220
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)));
|
|
221
248
|
const kindOf = (entry) => {
|
|
222
249
|
const mark = read.marks?.get(entry.source);
|
|
223
250
|
if (mark) {
|
|
@@ -228,16 +255,29 @@ const classifyLazyEntries = (entries, read) => {
|
|
|
228
255
|
if (DATA_ENTRY.test(entry.source)) {
|
|
229
256
|
return 'data';
|
|
230
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
|
+
}
|
|
231
263
|
if (grouping.has(entry.source)) {
|
|
232
264
|
return 'groupers';
|
|
233
265
|
}
|
|
234
|
-
|
|
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';
|
|
235
273
|
};
|
|
236
274
|
const kinds = {
|
|
237
275
|
screens: [],
|
|
238
276
|
blocks: [],
|
|
239
277
|
groupers: [],
|
|
240
278
|
data: [],
|
|
279
|
+
workers: [],
|
|
280
|
+
onDemand: [],
|
|
241
281
|
};
|
|
242
282
|
for (const entry of entries) {
|
|
243
283
|
kinds[kindOf(entry)].push(entry);
|
|
@@ -247,6 +287,7 @@ const classifyLazyEntries = (entries, read) => {
|
|
|
247
287
|
exports.classifyLazyEntries = classifyLazyEntries;
|
|
248
288
|
/** Lazy entries as the report lists them: name and weight, heaviest first. */
|
|
249
289
|
const labelledByWeight = (entries, label, sizeOf) => entries
|
|
250
|
-
|
|
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) }))
|
|
251
292
|
.toSorted((a, b) => b.bytes - a.bytes);
|
|
252
293
|
exports.labelledByWeight = labelledByWeight;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The screens `loadline.json` says are screens, and the pieces it says are pieces.
|
|
4
|
+
*
|
|
5
|
+
* Telling a screen from a piece of one is partly done by reading file names (`entries.ts`), and no
|
|
6
|
+
* set of names fits every project. The page has had a button for each row since the rules were
|
|
7
|
+
* written; this is the same correction written down once, in the file the team already reviews,
|
|
8
|
+
* so the command reads it too and nobody clicks it again in their own browser.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.configuredMarks = void 0;
|
|
12
|
+
const format_utils_1 = require("../../format/format.utils");
|
|
13
|
+
/**
|
|
14
|
+
* Every lazy entry of the build a pattern of `build.screens` names, with what it says it is. The
|
|
15
|
+
* first pattern that names an entry decides, in the order the file lists them.
|
|
16
|
+
*/
|
|
17
|
+
const configuredMarks = (screens, meta) => {
|
|
18
|
+
const marks = new Map();
|
|
19
|
+
const patterns = Object.entries(screens ?? {});
|
|
20
|
+
if (patterns.length === 0) {
|
|
21
|
+
return marks;
|
|
22
|
+
}
|
|
23
|
+
for (const output of Object.values(meta.outputs)) {
|
|
24
|
+
const source = output.entryPoint;
|
|
25
|
+
const said = source ? patterns.find(([pattern]) => (0, format_utils_1.namedBy)(pattern, source)) : undefined;
|
|
26
|
+
if (source && said && !marks.has(source)) {
|
|
27
|
+
marks.set(source, said[1] === 'piece' ? 'block' : 'screen');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return marks;
|
|
31
|
+
};
|
|
32
|
+
exports.configuredMarks = configuredMarks;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* What a screen reached through a lazy route file pays for, and what the lazy entries that are not
|
|
4
|
+
* screens add up to. Kept out of `analysis.ts`, which only calls them.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.routedName = exports.routedChunks = exports.byLabel = exports.packagesOnDemand = exports.wavesThrough = exports.reachedThrough = void 0;
|
|
8
|
+
const route_table_1 = require("../../build-text/route-table");
|
|
9
|
+
const ownership_1 = require("../../format/ownership");
|
|
10
|
+
const delivery_1 = require("./delivery");
|
|
11
|
+
/** Most route files nested in front of a screen that is still believed: a cycle has no end. */
|
|
12
|
+
const MAX_DEPTH = 8;
|
|
13
|
+
/**
|
|
14
|
+
* The route files each screen is reached through, outermost first, and the chunks it downloads
|
|
15
|
+
* with them. A lazy `profile.routes.ts` is downloaded before the screens under it, together with
|
|
16
|
+
* whatever it imports statically — in Angular RealWorld, the profile header every profile screen
|
|
17
|
+
* shows — and those bytes and that trip belonged to no screen: the two profile screens read 2.8 kB
|
|
18
|
+
* and two trips short.
|
|
19
|
+
*
|
|
20
|
+
* Only when every chunk asking for the screen is one of those route files: a screen the router can
|
|
21
|
+
* also reach directly does not have to wait for one.
|
|
22
|
+
*/
|
|
23
|
+
const reachedThrough = (screens, groupers, outputs) => {
|
|
24
|
+
const byChunk = new Map(groupers.map(grouper => [grouper.chunk, grouper]));
|
|
25
|
+
const importers = new Map();
|
|
26
|
+
for (const [file, out] of Object.entries(outputs)) {
|
|
27
|
+
const lazy = (out.imports ?? []).filter(imp => imp.kind === 'dynamic-import');
|
|
28
|
+
for (const imp of lazy) {
|
|
29
|
+
importers.set(imp.path, [...(importers.get(imp.path) ?? []), file]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const viaOf = (chunk) => {
|
|
33
|
+
const chain = [];
|
|
34
|
+
for (let at = chunk; chain.length < MAX_DEPTH;) {
|
|
35
|
+
const asking = importers.get(at) ?? [];
|
|
36
|
+
const grouper = asking.length > 0 ? byChunk.get(asking[0] ?? '') : undefined;
|
|
37
|
+
if (!grouper || asking.some(file => !byChunk.has(file)) || chain.includes(grouper)) {
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
chain.unshift(grouper);
|
|
41
|
+
at = grouper.chunk;
|
|
42
|
+
}
|
|
43
|
+
return chain;
|
|
44
|
+
};
|
|
45
|
+
return new Map(screens.map(entry => {
|
|
46
|
+
const via = viaOf(entry.chunk);
|
|
47
|
+
return [entry.chunk, { via, set: new Set([...entry.set, ...via.flatMap(grouper => [...grouper.set])]) }];
|
|
48
|
+
}));
|
|
49
|
+
};
|
|
50
|
+
exports.reachedThrough = reachedThrough;
|
|
51
|
+
/**
|
|
52
|
+
* The round trips of a screen: the route files it is reached through arrive first, one after
|
|
53
|
+
* another, and its own chunks start once the last of them has been parsed. What the loader asks for
|
|
54
|
+
* alongside a chunk starts in the same trip as it (`parallel`).
|
|
55
|
+
*/
|
|
56
|
+
const wavesThrough = (outputs, starts, boot, parallel) => {
|
|
57
|
+
const waves = new Map();
|
|
58
|
+
for (const chunk of starts) {
|
|
59
|
+
const offset = (0, delivery_1.depthOf)(waves);
|
|
60
|
+
const seeds = [chunk, ...(parallel?.get(chunk) ?? [])];
|
|
61
|
+
for (const [reached, trip] of (0, delivery_1.wavesFrom)(outputs, seeds, boot)) {
|
|
62
|
+
if (!waves.has(reached)) {
|
|
63
|
+
waves.set(reached, trip + offset);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return waves;
|
|
68
|
+
};
|
|
69
|
+
exports.wavesThrough = wavesThrough;
|
|
70
|
+
/**
|
|
71
|
+
* The packages a screen pulls in with `await import()` when it needs them: mermaid's diagrams,
|
|
72
|
+
* katex, a PDF reader. Not screens, and not nothing either — with source maps they appeared in no
|
|
73
|
+
* figure and no list at all, 654 kB of Excalidraw among them.
|
|
74
|
+
*
|
|
75
|
+
* @param lazyHere a lazy target reachable from the entry and not in the first load: one asked for
|
|
76
|
+
* lazily and statically both is in the first load, and says so there.
|
|
77
|
+
*/
|
|
78
|
+
const packagesOnDemand = (entries, lazyHere) => entries
|
|
79
|
+
.filter(([file, out]) => lazyHere(file) && (0, ownership_1.isDependency)(out.entryPoint ?? ''))
|
|
80
|
+
.map(([file, out]) => ({ chunk: file, source: out.entryPoint ?? '' }));
|
|
81
|
+
exports.packagesOnDemand = packagesOnDemand;
|
|
82
|
+
/**
|
|
83
|
+
* One row per package: mermaid writes a chunk per diagram type, and twenty-seven rows of "mermaid"
|
|
84
|
+
* say less than one with all of them added up.
|
|
85
|
+
*/
|
|
86
|
+
const byLabel = (rows) => [
|
|
87
|
+
...rows
|
|
88
|
+
.reduce((merged, row) => {
|
|
89
|
+
const known = merged.get(row.label);
|
|
90
|
+
merged.set(row.label, known ? { ...known, bytes: known.bytes + row.bytes } : row);
|
|
91
|
+
return merged;
|
|
92
|
+
}, new Map())
|
|
93
|
+
.values(),
|
|
94
|
+
].toSorted((a, b) => b.bytes - a.bytes);
|
|
95
|
+
exports.byLabel = byLabel;
|
|
96
|
+
/**
|
|
97
|
+
* The chunks the route table sends a route to, when there is a table: two routes at least, because
|
|
98
|
+
* one `{ path, component: () => import() }` can be a coincidence of naming and two are a router.
|
|
99
|
+
* `null` without one, and then every lazy entry is judged the way it always was.
|
|
100
|
+
*/
|
|
101
|
+
const routedChunks = (routes) => routes && routes.size >= 2 ? new Set(routes.keys()) : null;
|
|
102
|
+
exports.routedChunks = routedChunks;
|
|
103
|
+
/**
|
|
104
|
+
* What a screen is called, and the routes that open it. The label stays what the source map gave
|
|
105
|
+
* it — a `gates.screens` entry is keyed on it — except when there was no map and the label would
|
|
106
|
+
* be the hash in the chunk's name: then the router's name for it is the better one by far.
|
|
107
|
+
*/
|
|
108
|
+
const routedName = (entry, routes, fallback) => {
|
|
109
|
+
const own = routes?.get(entry.chunk) ?? [];
|
|
110
|
+
// A named route first, then one with a path of its own: Angular's `path: ''` is the index of
|
|
111
|
+
// wherever the routes are mounted, and three screens called "/" say nothing.
|
|
112
|
+
const best = own.find(route => route.name) ?? own.find(route => route.path !== '') ?? own[0];
|
|
113
|
+
const label = entry.source === entry.chunk && best ? (0, route_table_1.routeLabel)(best) : fallback;
|
|
114
|
+
return { label, routes: own.map(route => (0, route_table_1.routeLabel)(route)) };
|
|
115
|
+
};
|
|
116
|
+
exports.routedName = routedName;
|
|
@@ -18,8 +18,15 @@
|
|
|
18
18
|
* accents or emoji.
|
|
19
19
|
*/
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.resolveSplits = exports.readSourceMaps = exports.resolveSources = exports.sourcePathOf = exports.bytesBySource = exports.sourceAt = exports.segmentsOf = exports.isSourceMap = void 0;
|
|
21
|
+
exports.resolveSplits = exports.readSourceMaps = exports.resolveSources = exports.sourcePathOf = exports.projectRootsOf = exports.projectRootOf = exports.bytesBySource = exports.sourceAt = exports.segmentsOf = exports.isSourceMap = exports.isScriptMapName = void 0;
|
|
22
22
|
const VLQ_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
23
|
+
/**
|
|
24
|
+
* Whether a file name is the source map of a script. Not only `*.js.map`: ember-cli hashes each map
|
|
25
|
+
* on its own (`vendor-427cc….map` next to `vendor-8e0b….js`), and a folder holding three of them
|
|
26
|
+
* was told it held none, in the same report that read them.
|
|
27
|
+
*/
|
|
28
|
+
const isScriptMapName = (name) => /\.map$/i.test(name) && !/\.css\.map$/i.test(name);
|
|
29
|
+
exports.isScriptMapName = isScriptMapName;
|
|
23
30
|
const isSourceMap = (value) => {
|
|
24
31
|
if (!value || typeof value !== 'object') {
|
|
25
32
|
return false;
|
|
@@ -126,12 +133,102 @@ const bytesBySource = (map, code) => {
|
|
|
126
133
|
return bytes;
|
|
127
134
|
};
|
|
128
135
|
exports.bytesBySource = bytesBySource;
|
|
136
|
+
/** The `./` and `../` a map uses to climb out of the output folder. */
|
|
137
|
+
const CLIMB = /^(?:\.\.?\/)+/;
|
|
138
|
+
/**
|
|
139
|
+
* webpack names a map's sources under a scheme of its own: `webpack:///./src/main.js` in webpack 4,
|
|
140
|
+
* `webpack://my-app/./src/main.js` in webpack 5, and its runtime `webpack/bootstrap` or
|
|
141
|
+
* `webpack/runtime/…`. Without the scheme they are the paths its stats file names; the runtime is
|
|
142
|
+
* webpack's, filed under `node_modules/webpack` as the stats reader files it.
|
|
143
|
+
*/
|
|
144
|
+
const withoutWebpackScheme = (source) => {
|
|
145
|
+
const path = source.replace(/^webpack:\/\/[^/]*\//, '');
|
|
146
|
+
if (path === source) {
|
|
147
|
+
return source;
|
|
148
|
+
}
|
|
149
|
+
return /^webpack\/(?:bootstrap|runtime\/)/.test(path) ? `node_modules/${path}` : path;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* The folder a map's sources share above the project, when the build was written outside it.
|
|
153
|
+
*
|
|
154
|
+
* A map names its sources relative to where the chunk was written. With the output folder inside
|
|
155
|
+
* the project, `../src/x.ts` and `../node_modules/react/index.js` come out as `src/x.ts` and
|
|
156
|
+
* `node_modules/react/index.js` once the climbing is dropped. Written outside it — `--outDir
|
|
157
|
+
* ../../build` — they climb further and come out as `excalidraw/src/x.ts` and
|
|
158
|
+
* `excalidraw/node_modules/react/…`, and the project's own name read as a folder a second copy of
|
|
159
|
+
* every package was nested in: "react, shipped twice", and against a baseline built the ordinary
|
|
160
|
+
* way, every screen new and gone at once.
|
|
161
|
+
*
|
|
162
|
+
* It is the folder in front of the outermost `node_modules/` when the map holds no package at the
|
|
163
|
+
* top level, every other `node_modules/` sits under it, and some of the project's own files do too. `''` otherwise, which leaves every
|
|
164
|
+
* path as it was — and a workspace package's own `node_modules`, next to the top-level one, is a
|
|
165
|
+
* real second copy and stays one.
|
|
166
|
+
*/
|
|
167
|
+
const projectRootOf = (sources) => {
|
|
168
|
+
const clean = sources.map(source => withoutWebpackScheme(source).replace(CLIMB, ''));
|
|
169
|
+
const roots = new Set(clean.filter(path => path.includes('node_modules/')).map(path => path.slice(0, path.indexOf('node_modules/'))));
|
|
170
|
+
// The shortest one is the project's own `node_modules`; a workspace package's nested one sits
|
|
171
|
+
// under it (`packages/ui/node_modules/…`) and stays a copy of its own once the root is off.
|
|
172
|
+
const [root] = [...roots].toSorted((a, b) => a.length - b.length);
|
|
173
|
+
if (!root || [...roots].some(other => !other.startsWith(root))) {
|
|
174
|
+
return '';
|
|
175
|
+
}
|
|
176
|
+
return clean.some(path => path.startsWith(root) && !path.includes('node_modules/')) ? root : '';
|
|
177
|
+
};
|
|
178
|
+
exports.projectRootOf = projectRootOf;
|
|
179
|
+
/**
|
|
180
|
+
* `projectRootOf` for every map of a build at once. A map holding only the project's own files
|
|
181
|
+
* carries no `node_modules/` to tell where the project starts, and kept its `excalidraw/…` in front
|
|
182
|
+
* while the maps next to it lost theirs; such a map takes the root the others agreed on, when they
|
|
183
|
+
* agreed on one and every source of it sits under it. A map that does carry packages keeps its own
|
|
184
|
+
* answer: a worker can be written at another depth than the chunks around it.
|
|
185
|
+
*/
|
|
186
|
+
const projectRootsOf = (maps) => {
|
|
187
|
+
const own = maps.map(sources => (0, exports.projectRootOf)(sources));
|
|
188
|
+
const agreed = new Set(own.filter(root => root !== ''));
|
|
189
|
+
const [shared] = agreed;
|
|
190
|
+
return maps.map((sources, index) => {
|
|
191
|
+
const answer = own[index] ?? '';
|
|
192
|
+
if (answer !== '' || agreed.size !== 1 || !shared) {
|
|
193
|
+
return answer;
|
|
194
|
+
}
|
|
195
|
+
// A map with nothing of the project's own to confirm it — a chunk of one package — or with
|
|
196
|
+
// nothing but the project's own: under the agreed root throughout, it is under it.
|
|
197
|
+
const clean = sources.map(source => withoutWebpackScheme(source).replace(CLIMB, ''));
|
|
198
|
+
return clean.length > 0 && clean.every(path => path.startsWith(shared)) ? shared : '';
|
|
199
|
+
});
|
|
200
|
+
};
|
|
201
|
+
exports.projectRootsOf = projectRootsOf;
|
|
129
202
|
/**
|
|
130
203
|
* A source as the rest of the tool names it: the `./` and `../` a map uses to climb out of the
|
|
131
|
-
* output folder dropped,
|
|
204
|
+
* output folder dropped, and the project's folder when the map climbed past it (`projectRootOf`),
|
|
205
|
+
* which leaves the path the metafile would have written.
|
|
132
206
|
*/
|
|
133
|
-
const sourcePathOf = (source
|
|
207
|
+
const sourcePathOf = (source, root = '') => {
|
|
208
|
+
const path = withoutWebpackScheme(source).replace(CLIMB, '');
|
|
209
|
+
return installedAs(root && path.startsWith(root) ? path.slice(root.length) : path);
|
|
210
|
+
};
|
|
134
211
|
exports.sourcePathOf = sourcePathOf;
|
|
212
|
+
/**
|
|
213
|
+
* Third-party code written where a build tool other than npm's resolution puts it, moved under
|
|
214
|
+
* `node_modules/` so every rule that tells yours from theirs reads it as theirs.
|
|
215
|
+
*
|
|
216
|
+
* ember-cli is the case: its maps name an addon `addon-tree-output/ember-data/…`, Ember itself
|
|
217
|
+
* `@ember/-internals/…` and `@glimmer/runtime.js` with nothing in front, and what the app copies
|
|
218
|
+
* in `vendor/…`. None of it says `node_modules`, so a real Ember build had `ember-data` and Glimmer
|
|
219
|
+
* listed as "files of yours" taking 79 kB of its bootstrap, and no package at all. The project's
|
|
220
|
+
* own sources never start with a scope, and a top-level `vendor/` is third-party by its name.
|
|
221
|
+
*/
|
|
222
|
+
const installedAs = (path) => {
|
|
223
|
+
if (path.includes('node_modules/')) {
|
|
224
|
+
return path;
|
|
225
|
+
}
|
|
226
|
+
const copied = /^(?:addon-tree-output|vendor)\/(.+)$/.exec(path);
|
|
227
|
+
if (copied) {
|
|
228
|
+
return `node_modules/${copied[1] ?? ''}`;
|
|
229
|
+
}
|
|
230
|
+
return /^@[\w.-]+\//.test(path) ? `node_modules/${path}` : path;
|
|
231
|
+
};
|
|
135
232
|
/**
|
|
136
233
|
* Angular compiles a component's template into the component, so the map has a stretch coming from
|
|
137
234
|
* `x.component.html` while the metafile only knows `x.component.ts`. Without folding one into the
|
|
@@ -147,7 +244,7 @@ const CODE_EXTENSIONS = ['.ts', '.tsx', '.mts', '.js', '.mjs'];
|
|
|
147
244
|
* What is left over is matched by file name, and only when there is exactly one candidate: a wrong
|
|
148
245
|
* guess would move weight onto an unrelated file, which is worse than leaving it out.
|
|
149
246
|
*/
|
|
150
|
-
const resolveSources = (sources, inputs) => {
|
|
247
|
+
const resolveSources = (sources, inputs, root = '') => {
|
|
151
248
|
const known = new Set(inputs);
|
|
152
249
|
const byFileName = new Map();
|
|
153
250
|
for (const input of inputs) {
|
|
@@ -155,7 +252,7 @@ const resolveSources = (sources, inputs) => {
|
|
|
155
252
|
byFileName.set(name, [...(byFileName.get(name) ?? []), input]);
|
|
156
253
|
}
|
|
157
254
|
return sources.map(source => {
|
|
158
|
-
const path = (0, exports.sourcePathOf)(source);
|
|
255
|
+
const path = (0, exports.sourcePathOf)(source, root);
|
|
159
256
|
if (known.has(path)) {
|
|
160
257
|
return path;
|
|
161
258
|
}
|
|
@@ -212,9 +309,11 @@ const resolveSplits = (splits, inputs) => {
|
|
|
212
309
|
return null;
|
|
213
310
|
}
|
|
214
311
|
const resolved = new Map();
|
|
215
|
-
|
|
312
|
+
const roots = (0, exports.projectRootsOf)([...splits.values()].map(split => [...split.keys()]));
|
|
313
|
+
const entries = [...splits].entries();
|
|
314
|
+
for (const [position, [chunk, split]] of entries) {
|
|
216
315
|
const sources = [...split.keys()];
|
|
217
|
-
const mapped = (0, exports.resolveSources)(sources, inputs);
|
|
316
|
+
const mapped = (0, exports.resolveSources)(sources, inputs, roots[position] ?? '');
|
|
218
317
|
const byInput = new Map();
|
|
219
318
|
for (const [index, source] of sources.entries()) {
|
|
220
319
|
const input = mapped[index];
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.splitDriftOf = void 0;
|
|
20
|
-
const format_utils_1 = require("
|
|
20
|
+
const format_utils_1 = require("../../format/format.utils");
|
|
21
21
|
/** `.mjs` is what esbuild writes with `--out-extension:.js=.mjs`, and what several setups ship. */
|
|
22
22
|
const isJs = (file) => /\.m?js$/.test(file);
|
|
23
23
|
/**
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* What wrote the build: the bundler, and the framework above it.
|
|
4
|
+
*
|
|
5
|
+
* The report gives advice — "build with source maps", "split the dependencies into their own
|
|
6
|
+
* chunk", "the console.log inside @angular/core" — and until 09/10/2026 it gave it in Vite's words
|
|
7
|
+
* and Angular's to everybody. An Ember build read "`sourcemap: true` in Vite" and was told its
|
|
8
|
+
* console calls might be Angular's. The tool is already in what is read: the reader knows when it
|
|
9
|
+
* translated a webpack stats file or found Stencil's component list (`Metafile.builtBy`), and the
|
|
10
|
+
* source paths name the framework's packages. Nothing here is asked of the person.
|
|
11
|
+
*
|
|
12
|
+
* `null` in either half when nothing says it: the advice then names the common tools, as before.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.toolOf = exports.toolLabel = exports.TOOL_NAMES = void 0;
|
|
16
|
+
const format_utils_1 = require("../format/format.utils");
|
|
17
|
+
/** How each name is written for a person. */
|
|
18
|
+
exports.TOOL_NAMES = {
|
|
19
|
+
esbuild: 'esbuild',
|
|
20
|
+
webpack: 'webpack',
|
|
21
|
+
vite: 'Vite',
|
|
22
|
+
rollup: 'Rollup',
|
|
23
|
+
requirejs: 'RequireJS',
|
|
24
|
+
angular: 'Angular',
|
|
25
|
+
react: 'React',
|
|
26
|
+
vue: 'Vue',
|
|
27
|
+
svelte: 'Svelte',
|
|
28
|
+
sveltekit: 'SvelteKit',
|
|
29
|
+
nuxt: 'Nuxt',
|
|
30
|
+
sapper: 'Sapper',
|
|
31
|
+
stencil: 'Stencil',
|
|
32
|
+
ember: 'Ember',
|
|
33
|
+
polymer: 'Polymer',
|
|
34
|
+
preact: 'Preact',
|
|
35
|
+
solid: 'Solid',
|
|
36
|
+
next: 'Next.js',
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Packages that name a framework, the more specific first: a SvelteKit app ships `svelte` too, a
|
|
40
|
+
* Nuxt app `vue`, a Next.js app `react`. The first one found in the order of this list wins.
|
|
41
|
+
*/
|
|
42
|
+
const FRAMEWORK_PACKAGES = [
|
|
43
|
+
['@angular/core', 'angular'],
|
|
44
|
+
['@sveltejs/kit', 'sveltekit'],
|
|
45
|
+
['@sapper/app', 'sapper'],
|
|
46
|
+
['@sapper/internal', 'sapper'],
|
|
47
|
+
['nuxt', 'nuxt'],
|
|
48
|
+
['next', 'next'],
|
|
49
|
+
['@stencil/core', 'stencil'],
|
|
50
|
+
['ember-source', 'ember'],
|
|
51
|
+
['@ember/component', 'ember'],
|
|
52
|
+
['@glimmer/runtime', 'ember'],
|
|
53
|
+
['@polymer/polymer', 'polymer'],
|
|
54
|
+
['@polymer/lit-element', 'polymer'],
|
|
55
|
+
['preact', 'preact'],
|
|
56
|
+
['solid-js', 'solid'],
|
|
57
|
+
['react-dom', 'react'],
|
|
58
|
+
['vue', 'vue'],
|
|
59
|
+
['svelte', 'svelte'],
|
|
60
|
+
];
|
|
61
|
+
/** A file of the bundler's own, which only it puts in a build. */
|
|
62
|
+
const BUNDLER_FILES = [
|
|
63
|
+
[/vite\/(?:preload-helper|modulepreload-polyfill)/, 'vite'],
|
|
64
|
+
[/node_modules\/webpack\/(?:runtime|buildin|bootstrap)/, 'webpack'],
|
|
65
|
+
];
|
|
66
|
+
/** The tool as a person reads it — `Stencil + Rollup`, `Angular + webpack` — or `null` when nothing said. */
|
|
67
|
+
const toolLabel = (tool) => {
|
|
68
|
+
const names = [tool.framework, tool.bundler].filter(name => name !== null).map(name => exports.TOOL_NAMES[name]);
|
|
69
|
+
return names.length > 0 ? names.join(' + ') : null;
|
|
70
|
+
};
|
|
71
|
+
exports.toolLabel = toolLabel;
|
|
72
|
+
const toolOf = (meta) => {
|
|
73
|
+
const inputs = Object.keys(meta.inputs);
|
|
74
|
+
const packages = new Set(inputs.map(path => (0, format_utils_1.packageOf)(path)).filter(name => name !== null));
|
|
75
|
+
const found = FRAMEWORK_PACKAGES.find(([name]) => packages.has(name))?.[1] ?? null;
|
|
76
|
+
const bundled = BUNDLER_FILES.find(([file]) => inputs.some(path => file.test(path)))?.[1] ?? null;
|
|
77
|
+
// A metafile somebody else wrote is esbuild's: Angular's application builder and plain esbuild
|
|
78
|
+
// are the two that write one. What a reader of Loadline's made says what it read.
|
|
79
|
+
const said = meta.builtBy;
|
|
80
|
+
const bundler = said?.bundler ?? bundled ?? (meta.readFrom ? null : 'esbuild');
|
|
81
|
+
return { bundler, framework: found ?? said?.framework ?? null };
|
|
82
|
+
};
|
|
83
|
+
exports.toolOf = toolOf;
|