@bymaksym/loadline 1.2.0 → 1.3.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 +1 -1
- package/dist/cli/cli/main.js +7 -4
- package/dist/cli/cli/read/locate.js +61 -0
- package/dist/cli/cli/read/read-build.js +7 -4
- package/dist/cli/cli/read/read-config.js +21 -3
- package/dist/cli/cli/render/render-json.js +1 -0
- package/dist/cli/cli/render/render-text.js +25 -1
- package/dist/cli/cli/report.js +10 -3
- package/dist/cli/cli/text/text-errors.js +14 -0
- package/dist/cli/cli/text/text.js +4 -0
- package/dist/cli/cli/text/usage.js +4 -4
- package/dist/cli/src/app/core/analysis/analysis.js +18 -4
- package/dist/cli/src/app/core/analysis/sourcemap/index-map.js +193 -0
- package/dist/cli/src/app/core/analysis/sourcemap/sourcemap.js +2 -1
- package/dist/cli/src/app/core/analysis/sourcemap/split-drift.js +39 -1
- package/dist/cli/src/app/core/assets/assets.js +35 -6
- package/dist/cli/src/app/core/caching/caching.js +1 -0
- package/dist/cli/src/app/core/deps/deps.js +68 -19
- package/dist/cli/src/app/core/export/summary.js +2 -1
- package/dist/cli/src/app/core/findings/actions.js +24 -3
- package/dist/cli/src/app/core/findings/bundle/dupes.js +22 -7
- package/dist/cli/src/app/core/findings/bundle/requests.js +1 -0
- package/dist/cli/src/app/core/findings/bundle/shipped.js +17 -2
- package/dist/cli/src/app/core/findings/effort.js +5 -5
- package/dist/cli/src/app/core/findings/folder/assets.js +13 -2
- package/dist/cli/src/app/core/findings/folder/caching.js +5 -5
- package/dist/cli/src/app/core/findings/folder/scan.js +2 -7
- package/dist/cli/src/app/core/findings/supplied/forbidden.js +1 -1
- package/dist/cli/src/app/core/findings/text/finding-html.js +25 -2
- package/dist/cli/src/app/core/findings/text/finding-text.js +88 -42
- package/dist/cli/src/app/core/findings/text/tool-advice.js +33 -1
- package/dist/cli/src/app/core/format/format.utils.js +14 -1
- package/dist/cli/src/app/core/i18n/en.js +57 -0
- package/dist/cli/src/app/core/i18n/es.js +57 -0
- package/dist/cli/src/app/core/intake/bundle-graph.js +2 -1
- package/dist/cli/src/app/core/intake/native-export.js +84 -0
- package/dist/cli/src/app/core/project/budget-advice.js +22 -1
- package/dist/cli/src/app/core/project/project-name.js +32 -4
- package/dist/cli/src/app/core/scan/scan.js +56 -8
- package/dist/cli/src/app/core/situation/situation.js +3 -3
- package/dist/cli/src/app/core/whatif/source-importers.js +2 -1
- package/docs/CONFIG.md +2 -1
- package/docs/HOW-IT-WORKS.md +90 -7
- package/loadline.html +23 -21
- package/package.json +38 -39
|
@@ -16,10 +16,48 @@
|
|
|
16
16
|
* Both numbers were already in the file. Nobody had subtracted them.
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.splitDriftOf = void 0;
|
|
19
|
+
exports.splitDriftOf = exports.chunkScalesOf = void 0;
|
|
20
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
|
+
/**
|
|
24
|
+
* How far a chunk's parts may be from its weight before they are scaled to it: the same 5 % and
|
|
25
|
+
* kilobyte the `splitDrift` signal needs before it says anything (`shipped.ts`). Below that it is a
|
|
26
|
+
* wrapper's worth of bytes, and every figure stays the metafile's own.
|
|
27
|
+
*/
|
|
28
|
+
const SCALE_FROM_RATIO = 0.05;
|
|
29
|
+
const SCALE_FROM_BYTES = 1024;
|
|
30
|
+
/**
|
|
31
|
+
* The factor each chunk's per-file weights are multiplied by so they add up to the file: its weight
|
|
32
|
+
* over what its parts sum to, for every chunk whose parts add up to more than it by more than the
|
|
33
|
+
* margin above and no source map measured. Absent for the rest, which is a factor of one.
|
|
34
|
+
*
|
|
35
|
+
* Without it, an Angular 22 build without maps read "Bootstrap 117 kB" over "≈117 kB of packages
|
|
36
|
+
* against ≈30 kB of your own", 147 between them, and one package was 53 kB in a card and 72 kB in
|
|
37
|
+
* the next; only the card about the drift said why. Angular's optimizer shares a chunk's length out
|
|
38
|
+
* in proportion before the last minification, so the proportion is right and the total is not:
|
|
39
|
+
* scaled, the parts add up to the file again, and what a map would have measured (93 + 25 = 118
|
|
40
|
+
* on the same build) is what comes out within a few per cent. The `splitDrift` card still says the
|
|
41
|
+
* metafile was off, and by how much: these figures are a proportion, not a measurement.
|
|
42
|
+
*/
|
|
43
|
+
const chunkScalesOf = (outputs, exact) => {
|
|
44
|
+
const scales = new Map();
|
|
45
|
+
for (const [chunk, output] of Object.entries(outputs)) {
|
|
46
|
+
if (!isJs(chunk) || exact?.has((0, format_utils_1.baseName)(chunk))) {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const sum = Object.values(output.inputs ?? {}).reduce((total, one) => total + one.bytesInOutput, 0);
|
|
50
|
+
// Only down. Parts that add up to less than the file are the norm — a runtime, a wrapper, a
|
|
51
|
+
// banner nobody's file claims — and scaling them up would hand those bytes to the modules.
|
|
52
|
+
// Parts that add up to more than the file cannot all be in it.
|
|
53
|
+
const over = sum - output.bytes;
|
|
54
|
+
if (output.bytes > 0 && over / output.bytes >= SCALE_FROM_RATIO && over >= SCALE_FROM_BYTES) {
|
|
55
|
+
scales.set(chunk, output.bytes / sum);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return scales;
|
|
59
|
+
};
|
|
60
|
+
exports.chunkScalesOf = chunkScalesOf;
|
|
23
61
|
/**
|
|
24
62
|
* @param outputs the browser side of the build, already separated from the server one.
|
|
25
63
|
* @param exact chunk name → the per-file weights a source map measured. Those chunks are left
|
|
@@ -256,6 +256,7 @@ const duplicatesOf = (files, hashes) => {
|
|
|
256
256
|
bytes: group[0]?.bytes ?? 0,
|
|
257
257
|
wasted: (group.length - 1) * (group[0]?.bytes ?? 0),
|
|
258
258
|
named: null,
|
|
259
|
+
icons: false,
|
|
259
260
|
}))
|
|
260
261
|
.toSorted((a, b) => b.wasted - a.wasted);
|
|
261
262
|
};
|
|
@@ -343,12 +344,35 @@ exports.withLateBoot = withLateBoot;
|
|
|
343
344
|
/** @param inline what the page's inline scripts weigh, in the unit of `weigh` (`inlineScriptsIn`). */
|
|
344
345
|
const firstTripIn = (input, weigh, weighPath = null, inline = 0) => firstTripOf(input, weigherOf(input.files, weigh, weighPath), inline);
|
|
345
346
|
exports.firstTripIn = firstTripIn;
|
|
347
|
+
/** The files a web app manifest or a Windows tile configuration lists: icons, by what lists them. */
|
|
348
|
+
const ICON_LISTS = /(?:manifest\.json|\.webmanifest|browserconfig\.xml)$/i;
|
|
349
|
+
/** A `<meta>` tag, whole. Linear: no nested quantifier, and `[^>]` cannot run past the tag. */
|
|
350
|
+
const META_TAG = /<meta\b[^>]*>/gi;
|
|
351
|
+
/**
|
|
352
|
+
* Every name the page or its icon lists give as an icon for some platform: the `<link rel>` icons,
|
|
353
|
+
* what a manifest or `browserconfig.xml` names, and the `msapplication-*` metas. Which one a visitor
|
|
354
|
+
* downloads depends on the browser, and it is one of them.
|
|
355
|
+
*/
|
|
356
|
+
const platformIconsOf = (input) => {
|
|
357
|
+
const icons = new Set(input.icons);
|
|
358
|
+
const lists = [...input.texts].filter(([name]) => ICON_LISTS.test(name)).map(([, text]) => text);
|
|
359
|
+
const metas = input.html
|
|
360
|
+
? [...input.html.matchAll(META_TAG)].map(([tag]) => tag).filter(tag => /msapplication/i.test(tag))
|
|
361
|
+
: [];
|
|
362
|
+
for (const file of input.files) {
|
|
363
|
+
if ((0, exports.kindOf)(file.name) === 'image' && [...lists, ...metas].some(text => text.includes(file.name))) {
|
|
364
|
+
icons.add(file.name);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
return icons;
|
|
368
|
+
};
|
|
346
369
|
const readAssets = (input) => {
|
|
347
370
|
const sizes = new Map(input.files.map(file => [file.name, file.bytes]));
|
|
348
371
|
const sizeOf = (name) => input.weigh?.get(name) ?? sizes.get(name) ?? 0;
|
|
349
372
|
const referenced = referencedNames(input);
|
|
350
373
|
const referencesRead = input.texts.size > 0 || input.html !== null;
|
|
351
374
|
const inlined = inlinedOf(input.texts);
|
|
375
|
+
const iconNames = platformIconsOf(input);
|
|
352
376
|
// Scripts only. A prefetched font or picture is a different conversation and a much smaller
|
|
353
377
|
// one; what makes this worth a line is a framework fetching whole routes nobody asked for.
|
|
354
378
|
// Matched by the path the page wrote where it can be, and weighed per path: by name alone,
|
|
@@ -388,12 +412,17 @@ const readAssets = (input) => {
|
|
|
388
412
|
// of, not a file downloaded twice under two names.
|
|
389
413
|
duplicates: duplicatesOf(input.files, input.hashes)
|
|
390
414
|
.filter(entry => entry.names.some(path => !input.icons?.has(path.split('/').at(-1) ?? path)))
|
|
391
|
-
.map(entry =>
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
415
|
+
.map(entry => {
|
|
416
|
+
const names = entry.names.map(path => path.split('/').at(-1) ?? path);
|
|
417
|
+
const asIcon = names.filter(name => iconNames.has(name));
|
|
418
|
+
return {
|
|
419
|
+
...entry,
|
|
420
|
+
named: referencesRead ? names.filter(name => referenced.has(name)).length : null,
|
|
421
|
+
icons: asIcon.length > 0 &&
|
|
422
|
+
names.every(name => (0, exports.kindOf)(name) === 'image') &&
|
|
423
|
+
names.every(name => iconNames.has(name) || !referenced.has(name)),
|
|
424
|
+
};
|
|
425
|
+
}),
|
|
397
426
|
contentCompared: !!input.hashes && input.hashes.size > 0,
|
|
398
427
|
inlined,
|
|
399
428
|
inlinedBytes: inlined.reduce((sum, row) => sum + row.bytes, 0),
|
|
@@ -20,8 +20,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
20
20
|
exports.readDeps = exports.readAudit = exports.readLock = void 0;
|
|
21
21
|
const json_utils_1 = require("../json/json.utils");
|
|
22
22
|
const pins_1 = require("./pins");
|
|
23
|
-
/**
|
|
24
|
-
|
|
23
|
+
/**
|
|
24
|
+
* ` /lodash@4.17.21:` in pnpm 8, ` '@angular/core@22.1.0(rxjs@7.8.2)':` in pnpm 9 — quoted when
|
|
25
|
+
* scoped, with the peers it was resolved against in brackets — `"node_modules/lodash": {` in npm,
|
|
26
|
+
* `lodash@^4.0.0:` in yarn. The quote was not expected, and a pnpm 9 lock read every scoped package
|
|
27
|
+
* as one named `'` at version `angular/core@…`.
|
|
28
|
+
*/
|
|
29
|
+
const PNPM_ENTRY = /^ {2}['"]?\/?((?:@[^\s"'/@]+\/)?[^\s"'/@]+)@([^\s"'():]+)/;
|
|
30
|
+
/** A pnpm entry's block of dependencies: ` dependencies:`, ` optionalDependencies:`. */
|
|
31
|
+
const PNPM_DEPENDENCIES = /^ {4}(?:optionalD|d)ependencies:\s*$/;
|
|
32
|
+
/** One of them: ` '@jridgewell/gen-mapping': 0.3.13`, ` tslib: 2.8.1`. */
|
|
33
|
+
const PNPM_DEPENDENCY = /^ {6}['"]?((?:@[^\s"'/]+\/)?[^\s"':]+)['"]?:/;
|
|
25
34
|
const YARN_ENTRY = /^"?((?:@[^/@]+\/)?[^@/\s]+)@[^:]*:?$/;
|
|
26
35
|
const YARN_VERSION = /^\s+version:?\s+"?([^"\s]+)"?/;
|
|
27
36
|
const SEVERITIES = new Set(['critical', 'high', 'moderate', 'low', 'info']);
|
|
@@ -69,13 +78,55 @@ const readNpmLock = (lock) => {
|
|
|
69
78
|
return [...found.values()];
|
|
70
79
|
};
|
|
71
80
|
/**
|
|
72
|
-
* The pnpm and yarn formats
|
|
81
|
+
* The pnpm and yarn formats are read line by line: regular expressions rather than a YAML parser, on
|
|
82
|
+
* purpose and for the same reason `index-html.ts` does not use `DOMParser`. What is wanted is a few
|
|
83
|
+
* fields per entry, and a parser would be the only runtime dependency of a tool whose whole point is
|
|
84
|
+
* having none.
|
|
73
85
|
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
86
|
+
* pnpm's lock: every entry of `packages:` and, when the entry lists them, what it depends on — under
|
|
87
|
+
* `snapshots:` in pnpm 9, under the entry itself in pnpm 8. The same `name@version` appears in both
|
|
88
|
+
* blocks of a pnpm 9 lock (and once per set of peers in `snapshots:`), and is one package.
|
|
89
|
+
*
|
|
90
|
+
* Only names are kept from the dependencies, as `requires`: the versions there are resolved, not
|
|
91
|
+
* the ranges declared, so they say who brings whom and nothing about pinning (see `declares`).
|
|
92
|
+
* Before this, "who brings this dependency" came out empty for every package of a pnpm project.
|
|
77
93
|
*/
|
|
78
|
-
const
|
|
94
|
+
const readPnpmLock = (text) => {
|
|
95
|
+
const found = new Map();
|
|
96
|
+
let current = null;
|
|
97
|
+
let inDependencies = false;
|
|
98
|
+
for (const line of text.split('\n')) {
|
|
99
|
+
const entry = PNPM_ENTRY.exec(line);
|
|
100
|
+
if (entry?.[1] && entry[2]) {
|
|
101
|
+
const key = `${entry[1]}@${entry[2]}`;
|
|
102
|
+
current = found.get(key) ?? { name: entry[1], version: entry[2], requiredBy: [] };
|
|
103
|
+
found.set(key, current);
|
|
104
|
+
inDependencies = false;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
// Any other key at the top or one level in — `importers:`, ` .:`, `snapshots:` — ends the
|
|
108
|
+
// entry: the importers' own dependencies are the project's, and belong to no package.
|
|
109
|
+
if (/^ {0,2}\S/.test(line)) {
|
|
110
|
+
current = null;
|
|
111
|
+
inDependencies = false;
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (!current) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (/^ {4}\S/.test(line)) {
|
|
118
|
+
inDependencies = PNPM_DEPENDENCIES.test(line);
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const dependency = inDependencies ? PNPM_DEPENDENCY.exec(line)?.[1] : undefined;
|
|
122
|
+
if (dependency && !(current.requires ?? []).includes(dependency)) {
|
|
123
|
+
current.requires = [...(current.requires ?? []), dependency];
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return [...found.values()];
|
|
127
|
+
};
|
|
128
|
+
/** yarn's lock: the name on one line, the version on the next, then the entry's `dependencies:`. */
|
|
129
|
+
const readYarnLock = (text) => {
|
|
79
130
|
const found = new Map();
|
|
80
131
|
const lines = text.split('\n');
|
|
81
132
|
let pending = null;
|
|
@@ -85,8 +136,8 @@ const readYamlLock = (text, yarn) => {
|
|
|
85
136
|
for (const line of lines) {
|
|
86
137
|
// A yarn entry's own dependencies, with the range each one is declared at. pnpm writes a
|
|
87
138
|
// block of the same shape under `snapshots:` with **resolved** versions, which would read
|
|
88
|
-
// as every dependency pinned exactly — so
|
|
89
|
-
if (
|
|
139
|
+
// as every dependency pinned exactly — so there they are only names (`readPnpmLock`).
|
|
140
|
+
if (current) {
|
|
90
141
|
if (/^ {2}dependencies:\s*$/.test(line)) {
|
|
91
142
|
inDependencies = true;
|
|
92
143
|
continue;
|
|
@@ -100,12 +151,6 @@ const readYamlLock = (text, yarn) => {
|
|
|
100
151
|
inDependencies = false;
|
|
101
152
|
}
|
|
102
153
|
}
|
|
103
|
-
const pnpm = yarn ? null : PNPM_ENTRY.exec(line);
|
|
104
|
-
if (pnpm?.[1] && pnpm[2]) {
|
|
105
|
-
found.set(`${pnpm[1]}@${pnpm[2]}`, { name: pnpm[1], version: pnpm[2], requiredBy: [] });
|
|
106
|
-
pending = null;
|
|
107
|
-
continue;
|
|
108
|
-
}
|
|
109
154
|
// yarn writes the name on one line and the version on the next.
|
|
110
155
|
const version = YARN_VERSION.exec(line);
|
|
111
156
|
if (pending && version?.[1]) {
|
|
@@ -136,7 +181,10 @@ const readLock = (name, text) => {
|
|
|
136
181
|
const lock = (0, json_utils_1.asRecord)(parsed);
|
|
137
182
|
return lock ? readNpmLock(lock) : null;
|
|
138
183
|
}
|
|
139
|
-
|
|
184
|
+
if (/yarn\.lock$/i.test(name)) {
|
|
185
|
+
return readYarnLock(text);
|
|
186
|
+
}
|
|
187
|
+
return /lock\.ya?ml$/i.test(name) ? readPnpmLock(text) : null;
|
|
140
188
|
};
|
|
141
189
|
exports.readLock = readLock;
|
|
142
190
|
/**
|
|
@@ -276,7 +324,7 @@ const readDeps = (input) => {
|
|
|
276
324
|
const parents = new Map();
|
|
277
325
|
for (const entry of locked) {
|
|
278
326
|
byName.set(entry.name, [...(byName.get(entry.name) ?? []), entry]);
|
|
279
|
-
const declared = Object.keys(entry.declares ?? {});
|
|
327
|
+
const declared = [...Object.keys(entry.declares ?? {}), ...(entry.requires ?? [])];
|
|
280
328
|
for (const dependency of declared) {
|
|
281
329
|
parents.set(dependency, (parents.get(dependency) ?? new Set()).add(entry.name));
|
|
282
330
|
}
|
|
@@ -285,8 +333,9 @@ const readDeps = (input) => {
|
|
|
285
333
|
* The shortest chain from something the project asked for to the package that pulls `name` in,
|
|
286
334
|
* walked up what each lock entry declares. Nothing filled `requiredBy`, so "each one comes with
|
|
287
335
|
* the dependency chain that pulls it" was printed over chains that were always empty. Empty
|
|
288
|
-
* still when the lock does not record what each entry
|
|
289
|
-
*
|
|
336
|
+
* still when the lock does not record what each entry depends on, or when nothing the project
|
|
337
|
+
* asked for is up the chain. pnpm's lock records it with resolved versions: those walk the
|
|
338
|
+
* chain (`requires`) and never decide a pin (`declares`).
|
|
290
339
|
*/
|
|
291
340
|
const chainOf = (name) => {
|
|
292
341
|
const seen = new Set([name]);
|
|
@@ -74,7 +74,8 @@ const summaryText = (input) => {
|
|
|
74
74
|
'',
|
|
75
75
|
`${words.boot}: ${bootLine}`,
|
|
76
76
|
...(input.since ? [input.since] : []),
|
|
77
|
-
|
|
77
|
+
// Not a first trip of 0 B under a bootstrap of 985 kB: that is no page having been read.
|
|
78
|
+
...(input.firstTrip === null || input.firstTrip <= 0 ? [] : [`${words.trip}: ${(0, format_utils_1.formatBytes)(input.firstTrip)}`]),
|
|
78
79
|
`${words.screens}: ${analysis.screens.length}`,
|
|
79
80
|
...(worst ? [`${words.worst}: ${worst.label} — ${(0, format_utils_1.formatBytes)(worst.total)}`] : []),
|
|
80
81
|
// The ones worth a look, out of all of them: "Signals: 2" next to another format's 7
|
|
@@ -89,10 +89,26 @@ const savingInUnit = (analysis, total) => {
|
|
|
89
89
|
exports.savingInUnit = savingInUnit;
|
|
90
90
|
/** Most severe first. `ok` never reaches the list: a verdict that all is well is not a task. */
|
|
91
91
|
const SEVERITY_RANK = { high: 0, mid: 1, info: 2, ok: 3 };
|
|
92
|
+
/**
|
|
93
|
+
* The signals about how Loadline measured rather than about the build: no source maps, a split
|
|
94
|
+
* that does not add up, chunks the report cannot reach. Each has a fix — a flag on the build — and
|
|
95
|
+
* none of them takes a byte off what a visitor downloads.
|
|
96
|
+
*/
|
|
97
|
+
const ABOUT_THE_MEASUREMENT = new Set(['noSourceMaps', 'splitDrift', 'unreachable']);
|
|
98
|
+
/**
|
|
99
|
+
* Where a signal goes in the list before anything else is compared: what can be fixed in the build,
|
|
100
|
+
* then what fixes the report, then what the card itself says cannot be fixed from this project.
|
|
101
|
+
*/
|
|
102
|
+
const tierOf = (finding) => (finding.unfixable ? 2 : ABOUT_THE_MEASUREMENT.has(finding.kind) ? 1 : 0);
|
|
92
103
|
/**
|
|
93
104
|
* The signals in the order somebody would do them.
|
|
94
105
|
*
|
|
95
|
-
* **
|
|
106
|
+
* **What can be fixed in the build first**; then what is about the measurement (a flag that makes the
|
|
107
|
+
* report exact and takes nothing off a visit); then what the card says cannot be fixed from here.
|
|
108
|
+
* On espaciot-app, with no signal saving a kilobyte, the list opened with a duplicate whose own card
|
|
109
|
+
* said "accept the signal and wait", and the third line was about how Loadline measures.
|
|
110
|
+
*
|
|
111
|
+
* **Then severity, then bytes per unit of effort.** Sorting by score alone put twelve medium and
|
|
96
112
|
* informative signals ahead of a high one that names no saving in kilobytes — a key leaked into the
|
|
97
113
|
* bundle saves nothing and is still the first thing anybody should touch. The score orders within a
|
|
98
114
|
* severity, which is where comparing kilobytes against effort makes sense.
|
|
@@ -112,7 +128,12 @@ const rankActions = (findings) => findings
|
|
|
112
128
|
})
|
|
113
129
|
.filter(action => action.effort !== 'none' || action.finding.severity === 'high')
|
|
114
130
|
.filter(action => action.finding.severity !== 'ok')
|
|
115
|
-
.toSorted((a, b) =>
|
|
131
|
+
.toSorted((a, b) => tierOf(a.finding) - tierOf(b.finding) ||
|
|
132
|
+
SEVERITY_RANK[a.finding.severity] - SEVERITY_RANK[b.finding.severity] ||
|
|
116
133
|
b.score - a.score ||
|
|
117
|
-
b.saving - a.saving
|
|
134
|
+
b.saving - a.saving ||
|
|
135
|
+
// With no saving to compare — the usual case on a small app — the figure the signal
|
|
136
|
+
// is about, then the cheaper fix: not the order the signals happened to be built in.
|
|
137
|
+
(b.finding.size ?? 0) - (a.finding.size ?? 0) ||
|
|
138
|
+
effort_1.EFFORT_WEIGHT[a.effort] - effort_1.EFFORT_WEIGHT[b.effort]);
|
|
118
139
|
exports.rankActions = rankActions;
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.buildDupesFindings = void 0;
|
|
13
13
|
const pins_1 = require("../../deps/pins");
|
|
14
|
-
const format_utils_1 = require("../../format/format.utils");
|
|
15
14
|
const actions_1 = require("../actions");
|
|
16
15
|
const finding_html_1 = require("../text/finding-html");
|
|
17
16
|
const finding_text_1 = require("../text/finding-text");
|
|
@@ -24,11 +23,22 @@ const buildDupesFindings = (analysis, lang, declared) => {
|
|
|
24
23
|
// A copy's weight is its modules', raw: shown at the ratio the bootstrap compresses by.
|
|
25
24
|
const scale = (0, actions_1.unitScale)(analysis);
|
|
26
25
|
const pins = (0, pins_1.pinsOf)(analysis.duplicates, declared);
|
|
27
|
-
const
|
|
28
|
-
const parents = (apart) => {
|
|
29
|
-
const names = [
|
|
26
|
+
const pinsFor = (dupes) => dupes.flatMap(dupe => pins.get(dupe.name) ?? []);
|
|
27
|
+
const parents = (dupes, apart) => {
|
|
28
|
+
const names = [
|
|
29
|
+
...new Set(pinsFor(dupes)
|
|
30
|
+
.filter(pin => pin.majorApart === apart)
|
|
31
|
+
.map(pin => pin.parent)),
|
|
32
|
+
];
|
|
30
33
|
return names.length > 0 ? names.map(name => (0, finding_html_1.mono)(name)).join(', ') : null;
|
|
31
34
|
};
|
|
35
|
+
const names = (dupes) => dupes.map(dupe => (0, finding_html_1.mono)(dupe.name)).join(', ');
|
|
36
|
+
// Each package gets the advice that fits it, and every one of them is named: one sentence for the
|
|
37
|
+
// whole card said "accept the signal and wait" of `idb` and nothing at all of `tslib`.
|
|
38
|
+
const apart = analysis.duplicates.filter(dupe => (pins.get(dupe.name) ?? []).some(pin => pin.majorApart));
|
|
39
|
+
const movable = analysis.duplicates.filter(dupe => !apart.includes(dupe));
|
|
40
|
+
const viaDependency = movable.filter(dupe => dupe.copies.some(copy => copy.importers.length === 0));
|
|
41
|
+
const direct = movable.filter(dupe => !viaDependency.includes(dupe));
|
|
32
42
|
const list = analysis.duplicates
|
|
33
43
|
.map(dupe => {
|
|
34
44
|
const copies = dupe.copies
|
|
@@ -39,7 +49,7 @@ const buildDupesFindings = (analysis, lang, declared) => {
|
|
|
39
49
|
under: copy.under,
|
|
40
50
|
size: (0, actions_1.formatSaving)(copy.bytes, scale),
|
|
41
51
|
zone: text.dupeZone[copy.zone],
|
|
42
|
-
chain: copy.chain ? (0, finding_html_1.
|
|
52
|
+
chain: copy.chain ? (0, finding_html_1.chainHtmlOf)(copy.chain, analysis.lazyStep) : null,
|
|
43
53
|
own: copy.importers.length > 0 ? copy.importers.map(file => (0, finding_html_1.mono)(file)).join(', ') : null,
|
|
44
54
|
via: copy.viaPackages.length > 0 ? copy.viaPackages.map(pkg => (0, finding_html_1.mono)(pkg)).join(', ') : null,
|
|
45
55
|
pinned: pin ? { parent: (0, finding_html_1.mono)(pin.parent), range: (0, finding_html_1.mono)(pin.range) } : null,
|
|
@@ -54,13 +64,18 @@ const buildDupesFindings = (analysis, lang, declared) => {
|
|
|
54
64
|
severity: 'mid',
|
|
55
65
|
target: { tab: 'search', key: firstDupe.name },
|
|
56
66
|
kind: 'dupes',
|
|
67
|
+
// When every copy is held a major apart by a parent, the card's own advice is to wait.
|
|
68
|
+
...(movable.length === 0 && { unfixable: true }),
|
|
57
69
|
...text.dupes({
|
|
58
70
|
count: analysis.duplicates.length,
|
|
59
71
|
list,
|
|
60
72
|
viaDependency: analysis.duplicates.some(dupe => dupe.copies.some(copy => copy.importers.length === 0)),
|
|
61
73
|
inBoot: analysis.duplicates.some(dupe => dupe.inBoot),
|
|
62
|
-
|
|
63
|
-
|
|
74
|
+
apart: apart.length > 0 ? { packages: names(apart), parents: parents(apart, true) ?? '' } : null,
|
|
75
|
+
override: viaDependency.length > 0
|
|
76
|
+
? { packages: names(viaDependency), pinnedSame: parents(viaDependency, false) }
|
|
77
|
+
: null,
|
|
78
|
+
align: direct.length > 0 ? names(direct) : null,
|
|
64
79
|
}),
|
|
65
80
|
},
|
|
66
81
|
];
|
|
@@ -66,6 +66,7 @@ const slowScreenFindings = (analysis, lang, c) => {
|
|
|
66
66
|
// the arithmetic instead of asking anybody to take `3` on faith.
|
|
67
67
|
latencyMs: c.latencyMs,
|
|
68
68
|
worstMs: worst.waves * c.latencyMs,
|
|
69
|
+
tool: analysis.tool,
|
|
69
70
|
list: slow
|
|
70
71
|
.toSorted((a, b) => b.waves - a.waves)
|
|
71
72
|
.map(screen => named(screen))
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
* be wrong for the library that comes out next year and right only for the ones in fashion today.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.buildFolderFindings = exports.buildShippedFindings = void 0;
|
|
18
|
+
exports.buildFolderFindings = exports.unreadMapCount = exports.mapCount = exports.buildShippedFindings = void 0;
|
|
19
|
+
const index_map_1 = require("../../analysis/sourcemap/index-map");
|
|
19
20
|
const format_utils_1 = require("../../format/format.utils");
|
|
20
21
|
const finding_text_1 = require("../text/finding-text");
|
|
21
22
|
/**
|
|
@@ -213,6 +214,20 @@ const driftFinding = (drift, lang, tool) => {
|
|
|
213
214
|
},
|
|
214
215
|
];
|
|
215
216
|
};
|
|
217
|
+
/**
|
|
218
|
+
* How many source maps the folder carries, counted once for every card that says it: the map files
|
|
219
|
+
* read, and only when there are none of those (a report restored without its files) the chunks a
|
|
220
|
+
* map split. `sourceMaps` counted the second and `sourceExposed` the first, and one folder came out
|
|
221
|
+
* with 43 maps in one card and 44 in the next.
|
|
222
|
+
*/
|
|
223
|
+
const mapCount = (maps, splitChunks) => maps.length > 0 ? maps.length : splitChunks;
|
|
224
|
+
exports.mapCount = mapCount;
|
|
225
|
+
/**
|
|
226
|
+
* The map files that split no chunk and are not in a format this reads: what the report has to say
|
|
227
|
+
* is "a map it does not read" rather than "no map". Only those without a split are parsed again.
|
|
228
|
+
*/
|
|
229
|
+
const unreadMapCount = (maps, split) => maps.filter(map => !split(map.name.replace(/\.map$/i, '')) && !(0, index_map_1.isReadableMap)(map.text)).length;
|
|
230
|
+
exports.unreadMapCount = unreadMapCount;
|
|
216
231
|
const buildFolderFindings = (build, lang) => {
|
|
217
232
|
// The drift is about the metafile, not about the folder, so it is raised whichever way in was
|
|
218
233
|
// used and whether or not the maps are there: the early returns below are about the folder.
|
|
@@ -223,7 +238,7 @@ const buildFolderFindings = (build, lang) => {
|
|
|
223
238
|
{
|
|
224
239
|
severity: 'info',
|
|
225
240
|
kind: 'sourceMaps',
|
|
226
|
-
...finding_text_1.TEXT[lang].sourceMaps({ count: build.sourceMaps, tool: build.tool }),
|
|
241
|
+
...finding_text_1.TEXT[lang].sourceMaps({ count: build.sourceMaps, tool: build.tool, unread: build.unreadMaps ?? 0 }),
|
|
227
242
|
},
|
|
228
243
|
];
|
|
229
244
|
}
|
|
@@ -62,13 +62,13 @@ exports.EFFORT = {
|
|
|
62
62
|
clean: 'none',
|
|
63
63
|
unreachable: 'none',
|
|
64
64
|
// Context when it only means "no breakdown by package", but on a folder whose every screen row
|
|
65
|
-
// is a content hash it is
|
|
66
|
-
//
|
|
67
|
-
//
|
|
65
|
+
// is a content hash it is worth doing: you cannot move a screen's code when you cannot tell which
|
|
66
|
+
// screen the row is. The fix is a flag — `--stats-json`, or source maps on — so it belongs with
|
|
67
|
+
// the configuration ones. It is about the measurement, not the build, and `rankActions` puts it
|
|
68
|
+
// after what takes bytes off a visit: on the list, it is one more task, not the first.
|
|
68
69
|
noSourceMaps: 'config',
|
|
69
70
|
// The same shape of thing and the same way out: a flag on the build, and the figures inside the
|
|
70
|
-
// chunks stop reading high.
|
|
71
|
-
// first thing to do — every saving on the list below is quoted in the unit it corrects.
|
|
71
|
+
// chunks stop reading high. About the report rather than the bundle, so it ranks with the one above.
|
|
72
72
|
splitDrift: 'config',
|
|
73
73
|
// A `preconnect` is one tag in the `<head>`, and it is the whole of what can be done about a
|
|
74
74
|
// handshake short of moving the files back. When the page already warms them there is nothing
|
|
@@ -43,6 +43,10 @@ const buildAssetFindings = (assets, lang, c, repoPaths = null, verified = false)
|
|
|
43
43
|
.flatMap(family => family.files)
|
|
44
44
|
.filter(file => spare.has(file.name))
|
|
45
45
|
.reduce((sum, file) => sum + file.bytes, 0);
|
|
46
|
+
// The family with the most weights, named with its real count: the card said "seven weights of
|
|
47
|
+
// one family to use two" whatever the folder held, and over a build with three it was wrong.
|
|
48
|
+
const weightsOf = (family) => family.files.filter(file => !family.superseded.includes(file.name)).length;
|
|
49
|
+
const widest = manyWeights.toSorted((a, b) => weightsOf(b) - weightsOf(a))[0];
|
|
46
50
|
if (fonts.length > 0 && (fontBytes >= c.shippedMinBytes || superseded.length > 0)) {
|
|
47
51
|
findings.push({
|
|
48
52
|
// A second format is clutter on the server, not bytes on the wire: on its own it is
|
|
@@ -57,6 +61,7 @@ const buildAssetFindings = (assets, lang, c, repoPaths = null, verified = false)
|
|
|
57
61
|
spare: (0, format_utils_1.formatBytes)(spareBytes),
|
|
58
62
|
superseded: named(superseded),
|
|
59
63
|
preloaded: named(fonts.flatMap(family => family.preloaded)),
|
|
64
|
+
widest: widest ? { name: widest.name, weights: weightsOf(widest) } : null,
|
|
60
65
|
list: fonts
|
|
61
66
|
.map(family => `${(0, finding_html_1.mono)(family.name)} — ${text.fileCount(family.files.length)}, ${(0, format_utils_1.formatBytes)(family.bytes)}, ${family.formats.join('/')}`)
|
|
62
67
|
.join(' · '),
|
|
@@ -89,8 +94,13 @@ const buildAssetFindings = (assets, lang, c, repoPaths = null, verified = false)
|
|
|
89
94
|
// downloaded, and two copies with one of them named cost the deploy, not the visit.
|
|
90
95
|
const listOf = (entries) => entries.map(entry => `${named(entry.names)} (${(0, format_utils_1.formatBytes)(entry.bytes)} ${text.each})`).join(' · ');
|
|
91
96
|
const wastedBy = (entries) => entries.reduce((sum, entry) => sum + entry.wasted, 0);
|
|
92
|
-
|
|
93
|
-
|
|
97
|
+
// Icons for different platforms apart: a favicon generator writes the same picture as the
|
|
98
|
+
// Android, the Apple and the Windows icon, each browser takes one, and the card said a visitor
|
|
99
|
+
// downloads all three — with medium severity, next to an image signal counting two requests.
|
|
100
|
+
const icons = assets.duplicates.filter(entry => entry.icons);
|
|
101
|
+
const others = assets.duplicates.filter(entry => !entry.icons);
|
|
102
|
+
const travels = others.filter(entry => entry.named === null || entry.named > 1);
|
|
103
|
+
const stored = others.filter(entry => entry.named !== null && entry.named <= 1);
|
|
94
104
|
const wasted = wastedBy(travels);
|
|
95
105
|
if (assets.duplicates.length > 0) {
|
|
96
106
|
findings.push({
|
|
@@ -107,6 +117,7 @@ const buildAssetFindings = (assets, lang, c, repoPaths = null, verified = false)
|
|
|
107
117
|
list: listOf(stored),
|
|
108
118
|
none: stored.every(entry => entry.named === 0),
|
|
109
119
|
},
|
|
120
|
+
icons: { count: icons.length, list: listOf(icons) },
|
|
110
121
|
}),
|
|
111
122
|
});
|
|
112
123
|
}
|
|
@@ -66,9 +66,7 @@ const buildCascadeShapeFindings = (analysis, lang, situation = situation_1.EMPTY
|
|
|
66
66
|
];
|
|
67
67
|
};
|
|
68
68
|
exports.buildCascadeShapeFindings = buildCascadeShapeFindings;
|
|
69
|
-
const buildCachingFindings = (caching, lang, c, situation = situation_1.EMPTY_SITUATION,
|
|
70
|
-
/** What wrote the build, for which setting the advice on splitting names. */
|
|
71
|
-
tool) => {
|
|
69
|
+
const buildCachingFindings = (caching, lang, c, { situation = situation_1.EMPTY_SITUATION, tool, } = {}) => {
|
|
72
70
|
const text = finding_text_1.TEXT[lang];
|
|
73
71
|
const findings = [];
|
|
74
72
|
// 1 · What the update costs. The figure that does not exist anywhere else, and the one this
|
|
@@ -133,12 +131,14 @@ tool) => {
|
|
|
133
131
|
...text.unstableChunk({
|
|
134
132
|
count: unstable.length,
|
|
135
133
|
name: worst.name,
|
|
136
|
-
pct:
|
|
134
|
+
pct: (0, format_utils_1.formatShare)(worst.vendorRatio),
|
|
135
|
+
own: (0, format_utils_1.formatBytes)(worst.ownBytes),
|
|
136
|
+
vendor: `${worst.estimated ? '≈' : ''}${(0, format_utils_1.formatBytes)(worst.vendorBytes)}`,
|
|
137
137
|
size: `${worst.estimated ? '≈' : ''}${(0, format_utils_1.formatBytes)(wasted)}`,
|
|
138
138
|
inBoot: worst.inBoot,
|
|
139
139
|
tool,
|
|
140
140
|
list: unstable
|
|
141
|
-
.map(chunk => `${(0, finding_html_1.mono)(chunk.name)} — ${
|
|
141
|
+
.map(chunk => `${(0, finding_html_1.mono)(chunk.name)} — ${(0, format_utils_1.formatShare)(chunk.vendorRatio)} % ${chunk.estimated ? '≈' : ''}${(0, format_utils_1.formatBytes)(chunk.vendorBytes)}, ${text.ownInChunk((0, format_utils_1.formatBytes)(chunk.ownBytes))}${chunk.inBoot ? ' (bootstrap)' : ''}`)
|
|
142
142
|
.join(' · '),
|
|
143
143
|
}),
|
|
144
144
|
});
|
|
@@ -15,13 +15,7 @@ const finding_text_1 = require("../text/finding-text");
|
|
|
15
15
|
const named = (items) => items.map(item => (0, finding_html_1.mono)(item)).join(', ');
|
|
16
16
|
/** The ones that are a problem whatever else is true, as opposed to a build pointed at the wrong place. */
|
|
17
17
|
const ALWAYS_SERIOUS = new Set(['privateKey', 'awsKey', 'githubToken', 'slackToken', 'googleKey']);
|
|
18
|
-
|
|
19
|
-
* @param scale how the raw weights of packages are said in the report's unit: `unitScale` of the
|
|
20
|
-
* analysis. Raw by default, which is what a raw report needs and nothing more.
|
|
21
|
-
*/
|
|
22
|
-
const buildScanFindings = (scan, lang, c, scale = actions_1.RAW_SCALE,
|
|
23
|
-
/** What wrote the build: which setting the advice on source maps names, and whose console it may be. */
|
|
24
|
-
tool) => {
|
|
18
|
+
const buildScanFindings = (scan, lang, c, { scale = actions_1.RAW_SCALE, tool, } = {}) => {
|
|
25
19
|
const sized = (bytes) => (0, actions_1.formatSaving)(bytes, scale);
|
|
26
20
|
const text = finding_text_1.TEXT[lang];
|
|
27
21
|
const findings = [];
|
|
@@ -77,6 +71,7 @@ tool) => {
|
|
|
77
71
|
broken: breaking.length > 0,
|
|
78
72
|
unattributed,
|
|
79
73
|
tool,
|
|
74
|
+
copied: named([...new Set(leftovers.flatMap(item => item.copied))]),
|
|
80
75
|
list: leftovers
|
|
81
76
|
.map(item => `${text.leftoverNames[item.kind]} ×${item.count} (${named(item.where)})`)
|
|
82
77
|
.join(' · '),
|
|
@@ -62,7 +62,7 @@ const buildForbiddenFindings = (analysis, rules, lang) => {
|
|
|
62
62
|
size: (0, format_utils_1.formatBytes)(bytes),
|
|
63
63
|
names: names.slice(0, LISTED).map(name => (0, finding_html_1.mono)(name)),
|
|
64
64
|
more: Math.max(0, names.length - LISTED),
|
|
65
|
-
chain: chain && chain.length > 1 ? (0, finding_html_1.
|
|
65
|
+
chain: chain && chain.length > 1 ? (0, finding_html_1.chainHtmlOf)(chain, analysis.lazyStep) : null,
|
|
66
66
|
}),
|
|
67
67
|
},
|
|
68
68
|
];
|
|
@@ -1,16 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.escapeHtml = exports.fewNamed = exports.chainHtmlOf = exports.chainHtml = exports.mono = void 0;
|
|
4
|
+
const format_utils_1 = require("../../format/format.utils");
|
|
2
5
|
/**
|
|
3
6
|
* The two bits of markup every signal is written with. Signal text carries HTML on purpose: a file
|
|
4
7
|
* name or a version number set apart from the sentence is what makes it findable at a glance.
|
|
5
8
|
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.escapeHtml = exports.fewNamed = exports.chainHtml = exports.mono = void 0;
|
|
8
9
|
/** A name as code: a file, a package, a configuration key. */
|
|
9
10
|
const mono = (text) => `<span class="mono">${text}</span>`;
|
|
10
11
|
exports.mono = mono;
|
|
11
12
|
/** An import chain as HTML: each step in monospace, joined by a separator. */
|
|
12
13
|
const chainHtml = (steps) => steps.map(step => (0, exports.mono)(step)).join(' › ');
|
|
13
14
|
exports.chainHtml = chainHtml;
|
|
15
|
+
/**
|
|
16
|
+
* A chain of source files as HTML, with every step a dynamic `import()` reaches marked as one:
|
|
17
|
+
* `main.ts › teams.service.ts › import() › @microsoft/teams-js`. Files of one package collapse into
|
|
18
|
+
* the package, as `chainSteps` does; the mark goes before the step the `import()` first enters.
|
|
19
|
+
*/
|
|
20
|
+
const chainHtmlOf = (chain, lazy) => {
|
|
21
|
+
const steps = [];
|
|
22
|
+
for (const file of chain) {
|
|
23
|
+
const name = (0, format_utils_1.packageOf)(file) ?? file;
|
|
24
|
+
const last = steps.at(-1);
|
|
25
|
+
if (last?.name === name) {
|
|
26
|
+
last.lazy ||= !!lazy?.(file);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
steps.push({ name, lazy: !!lazy?.(file) });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return steps
|
|
33
|
+
.map((step, index) => `${index > 0 && step.lazy ? `${(0, exports.mono)('import()')} › ` : ''}${(0, exports.mono)(step.name)}`)
|
|
34
|
+
.join(' › ');
|
|
35
|
+
};
|
|
36
|
+
exports.chainHtmlOf = chainHtmlOf;
|
|
14
37
|
/**
|
|
15
38
|
* A list of names cut to the first few, with how many were left out. For the lists that grow with
|
|
16
39
|
* the project rather than with the problem: the hundred files importing `@angular/core` pasted into
|