@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
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* `--format agent`: the report as a coding agent or a script wants it — what to do, in order, each
|
|
4
|
+
* step with the file or package it is about, the import chain that puts it there and what doing it
|
|
5
|
+
* is worth. No prose.
|
|
6
|
+
*
|
|
7
|
+
* The JSON holds all of this and more, but an agent reading it spends most of its context on the
|
|
8
|
+
* paragraphs written for people, and still has to join three places — the action, its signal and a
|
|
9
|
+
* `--why` — to know where to type. Here each action is already joined, one per few lines, in an
|
|
10
|
+
* order that does not change between runs of the same build.
|
|
11
|
+
*
|
|
12
|
+
* It is English and its keys never change, whatever `--lang` says: it is read by programs, and a
|
|
13
|
+
* program parsing `saving=` should not have to know Spanish.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.renderAgent = void 0;
|
|
17
|
+
const criteria_1 = require("../../src/app/core/criteria/criteria");
|
|
18
|
+
const actions_1 = require("../../src/app/core/findings/actions");
|
|
19
|
+
const finding_plain_1 = require("../../src/app/core/findings/text/finding-plain");
|
|
20
|
+
const format_utils_1 = require("../../src/app/core/format/format.utils");
|
|
21
|
+
const defer_1 = require("../../src/app/core/whatif/defer");
|
|
22
|
+
const why_1 = require("../../src/app/core/whatif/why");
|
|
23
|
+
/** How many actions: enough to plan an afternoon, few enough to read before acting. */
|
|
24
|
+
const ACTIONS_SHOWN = 5;
|
|
25
|
+
/** `name=value` with no space in the value — `28kB`, not `28 kB` — so a line splits on spaces. */
|
|
26
|
+
const field = (name, value) => `${name}=${String(value).replaceAll(/\s+/g, '')}`;
|
|
27
|
+
const renderAgent = (report, violations, anyAsked) => {
|
|
28
|
+
const { analysis, criteria, comparison } = report;
|
|
29
|
+
const scale = (0, actions_1.unitScale)(analysis);
|
|
30
|
+
const measurable = !(0, defer_1.blindBoot)(analysis);
|
|
31
|
+
const count = (severity) => report.findings.filter(finding => finding.severity === severity).length;
|
|
32
|
+
const head = [
|
|
33
|
+
'loadline agent v1',
|
|
34
|
+
[
|
|
35
|
+
field('build', report.statsName),
|
|
36
|
+
field('unit', report.mode),
|
|
37
|
+
field('boot', (0, format_utils_1.formatBytes)(analysis.bootBytes)),
|
|
38
|
+
field('verdict', (0, criteria_1.rate)(analysis.bootBytes, criteria.bootOk, criteria.bootBad)),
|
|
39
|
+
field('screens', analysis.screens.length),
|
|
40
|
+
// Without it every saving below is "not known", not zero.
|
|
41
|
+
field('measurable', measurable ? 'yes' : 'no'),
|
|
42
|
+
].join(' '),
|
|
43
|
+
[
|
|
44
|
+
field('signals', report.findings.length),
|
|
45
|
+
field('high', count('high')),
|
|
46
|
+
field('mid', count('mid')),
|
|
47
|
+
field('info', count('info')),
|
|
48
|
+
].join(' '),
|
|
49
|
+
];
|
|
50
|
+
const gates = anyAsked
|
|
51
|
+
? violations.length === 0
|
|
52
|
+
? ['gates: passed']
|
|
53
|
+
: ['gates: failed', ...violations.map(violation => ` - ${violation.message}`)]
|
|
54
|
+
: ['gates: none asked'];
|
|
55
|
+
const growth = comparison
|
|
56
|
+
? [
|
|
57
|
+
`baseline: ${field('name', comparison.baselineName)} ${field('boot', (0, format_utils_1.formatDelta)(comparison.boot.diff))}`,
|
|
58
|
+
...comparison.bootCauses.slice(0, ACTIONS_SHOWN).map(cause => {
|
|
59
|
+
const figure = `${comparison.causesEstimated ? '≈' : ''}${(0, format_utils_1.formatDelta)(Math.round(cause.diff * comparison.causesRatio))}`;
|
|
60
|
+
return ` - ${field('cause', cause.name)} ${field('change', cause.change)} ${field('diff', figure)}${cause.own ? ' own' : ''}`;
|
|
61
|
+
}),
|
|
62
|
+
]
|
|
63
|
+
: [];
|
|
64
|
+
// The chain and the cut only where the signal is about one package or one file in the bootstrap.
|
|
65
|
+
const actions = (0, actions_1.rankActions)(report.findings)
|
|
66
|
+
.slice(0, ACTIONS_SHOWN)
|
|
67
|
+
.flatMap((action, index) => {
|
|
68
|
+
const { finding } = action;
|
|
69
|
+
const key = finding.target?.key ?? '';
|
|
70
|
+
const why = key ? (0, why_1.explainWhy)(analysis, key) : null;
|
|
71
|
+
// Not for a whole folder: its chain would be the chain to one file in it, and the cut
|
|
72
|
+
// would be the saving of that file, which is not what the signal is about.
|
|
73
|
+
const reached = why?.reach === 'boot' && why.defer.kind !== 'folder' ? why : null;
|
|
74
|
+
return [
|
|
75
|
+
`${index + 1}. ${[
|
|
76
|
+
field('kind', finding.kind),
|
|
77
|
+
...(key ? [field('key', key)] : []),
|
|
78
|
+
field('severity', finding.severity),
|
|
79
|
+
field('saving', action.saving > 0 ? (0, actions_1.formatSaving)(action.saving, scale) : measurable ? '0' : 'unknown'),
|
|
80
|
+
field('effort', action.effort),
|
|
81
|
+
].join(' ')}`,
|
|
82
|
+
` title: ${(0, finding_plain_1.plainText)(finding.title)}`,
|
|
83
|
+
...(reached ? [` chain: ${reached.steps.join(' > ')}`] : []),
|
|
84
|
+
...(reached?.cut && reached.via && reached.saves > 0
|
|
85
|
+
? [
|
|
86
|
+
` cut: ${field('in', reached.cut)} ${field('defer', reached.via)} ${field('saves', (0, actions_1.formatSaving)(reached.saves, scale))}`,
|
|
87
|
+
]
|
|
88
|
+
: []),
|
|
89
|
+
// Imported by several files of the first load: one cut is nothing, all of them are
|
|
90
|
+
// the saving. Every file is named, because an agent edits the ones it is given.
|
|
91
|
+
...(reached?.cut && reached.via && reached.alsoIn.length > 0 && reached.savesEverywhere > 0
|
|
92
|
+
? [
|
|
93
|
+
` cut: ${field('in', [reached.cut, ...reached.alsoIn].join(','))} ${field('defer', reached.via)} ${field('saves', (0, actions_1.formatSaving)(reached.savesEverywhere, scale))}`,
|
|
94
|
+
]
|
|
95
|
+
: []),
|
|
96
|
+
];
|
|
97
|
+
});
|
|
98
|
+
const asked = [
|
|
99
|
+
...report.whatIf.map(result => result.measurable
|
|
100
|
+
? `what-if ${field('target', result.target)} ${field('saves', (0, actions_1.formatSaving)(result.saved, scale))}`
|
|
101
|
+
: `what-if ${field('target', result.target)} saves=unknown`),
|
|
102
|
+
...report.why.map(result => `why ${field('target', result.target)} ${field('reach', result.reach)}${result.steps.length > 0 ? ` chain=${result.steps.join('>')}` : ''}${result.cut ? ` ${field('cut', result.cut)}` : ''}`),
|
|
103
|
+
];
|
|
104
|
+
return [
|
|
105
|
+
...head,
|
|
106
|
+
...gates,
|
|
107
|
+
...growth,
|
|
108
|
+
actions.length > 0 ? 'actions:' : 'actions: none',
|
|
109
|
+
...actions,
|
|
110
|
+
...asked,
|
|
111
|
+
'',
|
|
112
|
+
].join('\n');
|
|
113
|
+
};
|
|
114
|
+
exports.renderAgent = renderAgent;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The answers to what the command was asked about by name: `--what-if` and `--why`. Both print
|
|
4
|
+
* only when asked, both answer about a package, a folder or a file, and `--why` quotes the same
|
|
5
|
+
* saving `--what-if` computes, so they live together.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.whyBlock = exports.whatIfBlock = void 0;
|
|
9
|
+
const actions_1 = require("../../src/app/core/findings/actions");
|
|
10
|
+
const text_1 = require("../text/text");
|
|
11
|
+
const terminal_1 = require("./terminal");
|
|
12
|
+
/**
|
|
13
|
+
* "What would the first load weigh without this?", for each name asked about.
|
|
14
|
+
*
|
|
15
|
+
* The saving is exact — the graph walked without those files — and the note under it says what is
|
|
16
|
+
* deliberately not recomputed, because a simulated re-chunking would produce round trips that look
|
|
17
|
+
* exactly like the measured ones and are not.
|
|
18
|
+
*/
|
|
19
|
+
const whatIfBlock = (report, palette) => {
|
|
20
|
+
if (report.whatIf.length === 0) {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
const text = text_1.CLI_TEXT[report.lang];
|
|
24
|
+
// In the report's unit, like the headline above it: see `unitScale`.
|
|
25
|
+
const scale = (0, actions_1.unitScale)(report.analysis);
|
|
26
|
+
const rows = report.whatIf.map(result => result.measurable
|
|
27
|
+
? [
|
|
28
|
+
result.target,
|
|
29
|
+
(0, actions_1.formatSaving)(result.weight, scale),
|
|
30
|
+
palette.bold((0, actions_1.formatSaving)(result.saved, scale)),
|
|
31
|
+
(0, actions_1.formatRemaining)(report.analysis, result.saved, result.after),
|
|
32
|
+
result.screens.length > 0 ? result.screens.join(', ') : text.whatIfNobody,
|
|
33
|
+
]
|
|
34
|
+
: [
|
|
35
|
+
result.target,
|
|
36
|
+
// What it weighs in the bootstrap holds even where the saving cannot be worked out.
|
|
37
|
+
result.files.length > 0 ? (0, actions_1.formatSaving)(result.weight, scale) : '—',
|
|
38
|
+
// A name nothing matches is not "cannot be measured": it is not there, and a
|
|
39
|
+
// misspelt package read like a real one that could not be weighed.
|
|
40
|
+
palette.warn(result.files.length > 0 ? text.whatIfUnknown : text.whatIfAbsent),
|
|
41
|
+
'—',
|
|
42
|
+
'—',
|
|
43
|
+
]);
|
|
44
|
+
// "The saving is exact" over a table of nothing but "cannot be measured" said the opposite of
|
|
45
|
+
// the table; why it cannot be is what is worth saying there instead.
|
|
46
|
+
const measured = report.whatIf.some(result => result.measurable);
|
|
47
|
+
const unknown = report.whatIf.some(result => !result.measurable && result.files.length > 0);
|
|
48
|
+
const note = [
|
|
49
|
+
...(measured ? [scale.estimated ? `${text.whatIfNote} ${text.whatIfEstimated}` : text.whatIfNote] : []),
|
|
50
|
+
...(unknown ? [text.whatIfUnknownWhy] : []),
|
|
51
|
+
].join(' ');
|
|
52
|
+
return [
|
|
53
|
+
'',
|
|
54
|
+
palette.bold(text.headWhatIf),
|
|
55
|
+
...(note ? (0, terminal_1.wrap)(note, terminal_1.WIDTH).map(line => palette.dim(line)) : []),
|
|
56
|
+
...(0, terminal_1.table)([
|
|
57
|
+
{ head: text.colWhatIf, right: false },
|
|
58
|
+
{ head: text.colSize, right: true },
|
|
59
|
+
{ head: text.colSaving, right: true },
|
|
60
|
+
{ head: text.colAfter, right: true },
|
|
61
|
+
{ head: text.colWhoPays, right: false },
|
|
62
|
+
], rows, palette),
|
|
63
|
+
];
|
|
64
|
+
};
|
|
65
|
+
exports.whatIfBlock = whatIfBlock;
|
|
66
|
+
/**
|
|
67
|
+
* "Why is this in the first load?", for each name asked about: the chain, then where to cut it.
|
|
68
|
+
* The saving is the `--what-if` figure for the same name, so the two flags cannot disagree.
|
|
69
|
+
*/
|
|
70
|
+
const whyBlock = (report, palette) => {
|
|
71
|
+
if (report.why.length === 0) {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
const text = text_1.CLI_TEXT[report.lang];
|
|
75
|
+
const scale = (0, actions_1.unitScale)(report.analysis);
|
|
76
|
+
const answer = (result) => {
|
|
77
|
+
// Wrapped like the prose around it, and the name bold where it starts: an answer that is a
|
|
78
|
+
// whole sentence ran a hundred and thirty columns past the edge of the report.
|
|
79
|
+
const [first = '', ...rest] = (0, terminal_1.wrap)(`${result.target} — ${text.whyReach[result.reach]}${result.steps.length > 0 ? ':' : ''}`, terminal_1.WIDTH);
|
|
80
|
+
const head = [palette.bold(result.target) + first.slice(result.target.length), ...rest];
|
|
81
|
+
const chain = result.steps.map((step, index) => ` ${index === 0 ? '' : '→ '}${step}`);
|
|
82
|
+
if (result.reach === 'sourced' && result.cut && result.via) {
|
|
83
|
+
const files = [result.cut, ...result.alsoIn];
|
|
84
|
+
const sentence = text.whyCutSourced(files, result.via, (0, actions_1.formatSaving)(result.savesEverywhere, scale));
|
|
85
|
+
return ['', ...head, ...(0, terminal_1.wrap)(sentence, terminal_1.WIDTH - 4).map(line => ` ${line}`)];
|
|
86
|
+
}
|
|
87
|
+
if (result.reach !== 'boot') {
|
|
88
|
+
return ['', ...head, ...chain];
|
|
89
|
+
}
|
|
90
|
+
const { screens } = result.defer;
|
|
91
|
+
const through = result.via !== result.target;
|
|
92
|
+
const payers = !through && screens.length > 0 ? screens.join(', ') : null;
|
|
93
|
+
const cut = result.cut && result.via
|
|
94
|
+
? result.saves > 0
|
|
95
|
+
? text.whyCut(result.cut, result.via, (0, actions_1.formatSaving)(result.saves, scale), through, payers)
|
|
96
|
+
: result.alsoIn.length > 0
|
|
97
|
+
? text.whyCutAlso(result.cut, result.alsoIn, (0, actions_1.formatSaving)(result.savesEverywhere, scale))
|
|
98
|
+
: text.whyCutShared(result.cut)
|
|
99
|
+
: text.whyNoCut;
|
|
100
|
+
return ['', ...head, ...chain, ...(0, terminal_1.wrap)(cut, terminal_1.WIDTH - 4).map(line => ` ${line}`)];
|
|
101
|
+
};
|
|
102
|
+
return ['', palette.bold(text.headWhy), ...report.why.flatMap(result => answer(result))];
|
|
103
|
+
};
|
|
104
|
+
exports.whyBlock = whyBlock;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The first load as a badge: an SVG for a README or a pull request, the one piece of the report
|
|
4
|
+
* people see without running the tool.
|
|
5
|
+
*
|
|
6
|
+
* It copies the look of shields.io's "flat" style on purpose. A README already holds a row of those,
|
|
7
|
+
* and a badge that looks like none of its neighbours reads as an advert rather than a figure. It is
|
|
8
|
+
* drawn here rather than fetched from shields because the command fetches nothing, and a badge that
|
|
9
|
+
* depends on somebody else's server goes grey the day that server is down.
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.renderBadge = exports.escapeXml = exports.textWidth = exports.BADGE_COLOR = void 0;
|
|
13
|
+
const criteria_1 = require("../../src/app/core/criteria/criteria");
|
|
14
|
+
const format_utils_1 = require("../../src/app/core/format/format.utils");
|
|
15
|
+
/**
|
|
16
|
+
* The label, in the two languages of `--lang`. Here rather than in `text.ts` with the rest of the
|
|
17
|
+
* command's words: the badge is the only thing that says it, and two words do not earn an entry
|
|
18
|
+
* in a table every other format reads.
|
|
19
|
+
*/
|
|
20
|
+
const LABEL = { en: 'first load', es: 'primera carga' };
|
|
21
|
+
/**
|
|
22
|
+
* The colour of the value, by the same verdict the text report paints the bootstrap with. Each one
|
|
23
|
+
* holds white text at 4.5:1 or more (WCAG AA): shields' own amber does not, and a badge is read at
|
|
24
|
+
* eleven pixels, which is exactly where low contrast stops being legible.
|
|
25
|
+
*/
|
|
26
|
+
exports.BADGE_COLOR = {
|
|
27
|
+
good: '#2e7d32',
|
|
28
|
+
ok: '#9a6700',
|
|
29
|
+
bad: '#c62828',
|
|
30
|
+
};
|
|
31
|
+
const LABEL_COLOR = '#555';
|
|
32
|
+
const HEIGHT = 20;
|
|
33
|
+
/** Space on each side of a text, as shields leaves it. */
|
|
34
|
+
const PADDING = 6;
|
|
35
|
+
const FONT = 'Verdana,Geneva,DejaVu Sans,sans-serif';
|
|
36
|
+
/**
|
|
37
|
+
* Widths of Verdana at 11px, by groups of characters. There is no font to measure in a terminal,
|
|
38
|
+
* and a lookup that is roughly right and always the same is better here than one that is exact on
|
|
39
|
+
* one machine: the text is also told its length (`textLength`), so a guess a pixel off squeezes or
|
|
40
|
+
* spreads the letters a little instead of running past the edge.
|
|
41
|
+
*/
|
|
42
|
+
const NARROW = new Set("ijl.,:;|!'");
|
|
43
|
+
const SLIM = new Set(' frtI()[]-/');
|
|
44
|
+
const WIDE = new Set('mwMW%');
|
|
45
|
+
const DIGIT_WIDTH = 7;
|
|
46
|
+
const UPPER_WIDTH = 7.5;
|
|
47
|
+
const LOWER_WIDTH = 6.5;
|
|
48
|
+
const charWidth = (char) => {
|
|
49
|
+
if (NARROW.has(char)) {
|
|
50
|
+
return 3;
|
|
51
|
+
}
|
|
52
|
+
if (SLIM.has(char)) {
|
|
53
|
+
return 4;
|
|
54
|
+
}
|
|
55
|
+
if (WIDE.has(char)) {
|
|
56
|
+
return 10;
|
|
57
|
+
}
|
|
58
|
+
if (/\d/.test(char)) {
|
|
59
|
+
return DIGIT_WIDTH;
|
|
60
|
+
}
|
|
61
|
+
return char === char.toLowerCase() ? LOWER_WIDTH : UPPER_WIDTH;
|
|
62
|
+
};
|
|
63
|
+
/** The estimated width of a text at 11px, whole pixels. Exported for the test. */
|
|
64
|
+
const textWidth = (text) => {
|
|
65
|
+
// By code point, which is what a glyph roughly is for the labels and figures this ever draws.
|
|
66
|
+
let width = 0;
|
|
67
|
+
for (const char of text) {
|
|
68
|
+
width += charWidth(char);
|
|
69
|
+
}
|
|
70
|
+
return Math.ceil(width);
|
|
71
|
+
};
|
|
72
|
+
exports.textWidth = textWidth;
|
|
73
|
+
// The quotes by number: every XML parser knows those, and they read the same in an attribute either
|
|
74
|
+
// way it is quoted.
|
|
75
|
+
const ESCAPES = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' };
|
|
76
|
+
/** Text and attribute values both go through this: a name with `&` in it is not XML. */
|
|
77
|
+
const escapeXml = (text) => text.replaceAll(/[&<>"']/g, char => ESCAPES[char] ?? char);
|
|
78
|
+
exports.escapeXml = escapeXml;
|
|
79
|
+
/**
|
|
80
|
+
* The change against the baseline, as the badge shows it and as it is read out. The arrow is for
|
|
81
|
+
* the eye; a screen reader says "down-pointing triangle" for it, so the accessible name gets the
|
|
82
|
+
* signed figure instead.
|
|
83
|
+
*/
|
|
84
|
+
const changeOf = (report) => {
|
|
85
|
+
const boot = report.comparison?.boot;
|
|
86
|
+
// Nothing before means no ratio: "+100 %" of nothing would be a number nobody can use.
|
|
87
|
+
if (!boot || boot.before === 0) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
if (boot.diff === 0) {
|
|
91
|
+
return { shown: '±0 %', spoken: '±0 %' };
|
|
92
|
+
}
|
|
93
|
+
const percent = Math.round(Math.abs(boot.ratio) * 100);
|
|
94
|
+
// A change that rounds to nothing still happened: "▲0 %" would read as a contradiction.
|
|
95
|
+
const figure = percent === 0 ? '<1 %' : `${percent} %`;
|
|
96
|
+
return boot.diff > 0
|
|
97
|
+
? { shown: `▲${figure}`, spoken: `+${figure}` }
|
|
98
|
+
: { shown: `▼${figure}`, spoken: `−${figure}` };
|
|
99
|
+
};
|
|
100
|
+
/** One half of the badge's text: the shadow shields draws under it, then the text itself. */
|
|
101
|
+
const halfText = (text, centre, width) => {
|
|
102
|
+
const content = (0, exports.escapeXml)(text);
|
|
103
|
+
return (`<text aria-hidden="true" x="${centre}" y="15" fill="#010101" fill-opacity=".3" textLength="${width}">${content}</text>` +
|
|
104
|
+
`<text x="${centre}" y="14" textLength="${width}">${content}</text>`);
|
|
105
|
+
};
|
|
106
|
+
/** The badge for `--format badge`, an SVG document with nothing outside it to load. */
|
|
107
|
+
const renderBadge = (report) => {
|
|
108
|
+
const { analysis, criteria } = report;
|
|
109
|
+
const label = LABEL[report.lang];
|
|
110
|
+
const change = changeOf(report);
|
|
111
|
+
const size = (0, format_utils_1.formatBytes)(analysis.bootBytes);
|
|
112
|
+
const value = change ? `${size} ${change.shown}` : size;
|
|
113
|
+
const spoken = `${label}: ${change ? `${size}, ${change.spoken}` : size}`;
|
|
114
|
+
const color = exports.BADGE_COLOR[(0, criteria_1.rate)(analysis.bootBytes, criteria.bootOk, criteria.bootBad)];
|
|
115
|
+
const labelText = (0, exports.textWidth)(label);
|
|
116
|
+
const valueText = (0, exports.textWidth)(value);
|
|
117
|
+
const labelWidth = labelText + PADDING * 2;
|
|
118
|
+
const valueWidth = valueText + PADDING * 2;
|
|
119
|
+
const width = labelWidth + valueWidth;
|
|
120
|
+
const name = (0, exports.escapeXml)(spoken);
|
|
121
|
+
return [
|
|
122
|
+
`<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${HEIGHT}" role="img" aria-label="${name}">`,
|
|
123
|
+
`<title>${name}</title>`,
|
|
124
|
+
'<linearGradient id="loadline-shine" x2="0" y2="100%">',
|
|
125
|
+
'<stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/>',
|
|
126
|
+
'</linearGradient>',
|
|
127
|
+
`<clipPath id="loadline-round"><rect width="${width}" height="${HEIGHT}" rx="3" fill="#fff"/></clipPath>`,
|
|
128
|
+
'<g clip-path="url(#loadline-round)">',
|
|
129
|
+
`<rect width="${labelWidth}" height="${HEIGHT}" fill="${LABEL_COLOR}"/>`,
|
|
130
|
+
`<rect x="${labelWidth}" width="${valueWidth}" height="${HEIGHT}" fill="${color}"/>`,
|
|
131
|
+
`<rect width="${width}" height="${HEIGHT}" fill="url(#loadline-shine)"/>`,
|
|
132
|
+
'</g>',
|
|
133
|
+
`<g fill="#fff" text-anchor="middle" font-family="${FONT}" font-size="11">`,
|
|
134
|
+
halfText(label, labelWidth / 2, labelText),
|
|
135
|
+
halfText(value, labelWidth + valueWidth / 2, valueText),
|
|
136
|
+
'</g>',
|
|
137
|
+
'</svg>',
|
|
138
|
+
].join('\n');
|
|
139
|
+
};
|
|
140
|
+
exports.renderBadge = renderBadge;
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
/** The report as data. Shape and its rules: `render-json.types.ts`. */
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.renderJson = void 0;
|
|
5
|
-
const criteria_1 = require("
|
|
6
|
-
const actions_1 = require("
|
|
7
|
-
const finding_plain_1 = require("
|
|
8
|
-
const budget_advice_1 = require("
|
|
9
|
-
const timing_1 = require("
|
|
5
|
+
const criteria_1 = require("../../src/app/core/criteria/criteria");
|
|
6
|
+
const actions_1 = require("../../src/app/core/findings/actions");
|
|
7
|
+
const finding_plain_1 = require("../../src/app/core/findings/text/finding-plain");
|
|
8
|
+
const budget_advice_1 = require("../../src/app/core/project/budget-advice");
|
|
9
|
+
const timing_1 = require("../../src/app/core/timing/timing");
|
|
10
|
+
const defer_1 = require("../../src/app/core/whatif/defer");
|
|
10
11
|
const comparisonOf = (report) => {
|
|
11
12
|
const comparison = report.comparison;
|
|
12
13
|
if (!comparison) {
|
|
@@ -20,6 +21,7 @@ const comparisonOf = (report) => {
|
|
|
20
21
|
newScreens: comparison.newScreens.map(screen => screen.label),
|
|
21
22
|
goneScreens: comparison.goneScreens.map(screen => screen.label),
|
|
22
23
|
newBootPackages: comparison.newBootPackages,
|
|
24
|
+
bootCauses: comparison.bootCauses,
|
|
23
25
|
};
|
|
24
26
|
};
|
|
25
27
|
const screensOf = (report) => report.analysis.screens.map(screen => {
|
|
@@ -32,8 +34,10 @@ const screensOf = (report) => report.analysis.screens.map(screen => {
|
|
|
32
34
|
shared: screen.shared,
|
|
33
35
|
own: screen.own,
|
|
34
36
|
total: screen.total,
|
|
37
|
+
routes: screen.routes ?? [],
|
|
35
38
|
verdict: (0, criteria_1.rate)(screen.total, report.criteria.screenOk, report.criteria.screenBad),
|
|
36
39
|
delta: delta ? delta.total : null,
|
|
40
|
+
causes: delta?.causes ?? null,
|
|
37
41
|
};
|
|
38
42
|
});
|
|
39
43
|
/** The two lists of lazy entries that are not screens, in the order the report shows them. */
|
|
@@ -52,7 +56,9 @@ const renderJson = (report, violations, anyAsked) => {
|
|
|
52
56
|
mode: report.mode,
|
|
53
57
|
unit: report.unit,
|
|
54
58
|
splitSource: analysis.splitSource,
|
|
59
|
+
builtWith: analysis.tool,
|
|
55
60
|
serverOutputs: analysis.serverOutputs,
|
|
61
|
+
offPage: analysis.offPage,
|
|
56
62
|
pageCss: report.pageCssBytes === null ? null : { bytes: report.pageCssBytes, files: report.pageCssFiles },
|
|
57
63
|
firstTrip: report.assets?.firstTrip ?? null,
|
|
58
64
|
assets: report.assets
|
|
@@ -77,6 +83,10 @@ const renderJson = (report, violations, anyAsked) => {
|
|
|
77
83
|
deferred: entriesOf(analysis.deferredBlocks),
|
|
78
84
|
groupers: entriesOf(analysis.routeGroupers),
|
|
79
85
|
data: entriesOf(analysis.lazyData),
|
|
86
|
+
packages: entriesOf(analysis.lazyPackages),
|
|
87
|
+
workers: entriesOf(analysis.lazyWorkers),
|
|
88
|
+
onDemand: entriesOf(analysis.lazyOnDemand),
|
|
89
|
+
routeTable: analysis.routeTable,
|
|
80
90
|
shared: analysis.sharedChunks.map(chunk => ({
|
|
81
91
|
file: chunk.file,
|
|
82
92
|
name: chunk.name,
|
|
@@ -86,6 +96,7 @@ const renderJson = (report, violations, anyAsked) => {
|
|
|
86
96
|
})),
|
|
87
97
|
findings: report.findings.map(finding => ({
|
|
88
98
|
kind: finding.kind,
|
|
99
|
+
...(finding.target?.key && { key: finding.target.key }),
|
|
89
100
|
severity: finding.severity,
|
|
90
101
|
chip: (0, finding_plain_1.plainText)(finding.chip),
|
|
91
102
|
title: (0, finding_plain_1.plainText)(finding.title),
|
|
@@ -102,7 +113,9 @@ const renderJson = (report, violations, anyAsked) => {
|
|
|
102
113
|
})),
|
|
103
114
|
saving: (0, actions_1.totalSaving)(analysis, report.findings),
|
|
104
115
|
savingInUnit: (0, actions_1.savingInUnit)(analysis, (0, actions_1.totalSaving)(analysis, report.findings)),
|
|
116
|
+
measurable: !(0, defer_1.blindBoot)(analysis),
|
|
105
117
|
whatIf: report.whatIf,
|
|
118
|
+
why: report.why,
|
|
106
119
|
timing: (0, timing_1.timingsOf)(analysis.bootBytes + (report.pageCssBytes ?? 0), analysis.bootRawBytes, analysis.startup?.waves ?? 1, criteria.latencyMs),
|
|
107
120
|
budget: advice,
|
|
108
121
|
caching: report.caching,
|
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.renderMarkdown = void 0;
|
|
9
|
-
const markdown_table_utils_1 = require("
|
|
10
|
-
const finding_plain_1 = require("
|
|
11
|
-
const ui_1 = require("
|
|
12
|
-
const gates_1 = require("
|
|
13
|
-
const text_1 = require("
|
|
9
|
+
const markdown_table_utils_1 = require("../../src/app/core/export/markdown-table.utils");
|
|
10
|
+
const finding_plain_1 = require("../../src/app/core/findings/text/finding-plain");
|
|
11
|
+
const ui_1 = require("../../src/app/core/i18n/ui");
|
|
12
|
+
const gates_1 = require("../gates");
|
|
13
|
+
const text_1 = require("../text/text");
|
|
14
14
|
const renderMarkdown = (report, violations, anyAsked) => {
|
|
15
15
|
const text = text_1.CLI_TEXT[report.lang];
|
|
16
16
|
const strings = ui_1.UI[report.lang];
|
|
@@ -14,18 +14,23 @@
|
|
|
14
14
|
*/
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.renderPrComment = exports.PR_MARKER = void 0;
|
|
17
|
-
const markdown_table_utils_1 = require("
|
|
18
|
-
const actions_1 = require("
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
17
|
+
const markdown_table_utils_1 = require("../../src/app/core/export/markdown-table.utils");
|
|
18
|
+
const actions_1 = require("../../src/app/core/findings/actions");
|
|
19
|
+
const kind_names_1 = require("../../src/app/core/findings/kind-names");
|
|
20
|
+
const finding_plain_1 = require("../../src/app/core/findings/text/finding-plain");
|
|
21
|
+
const format_utils_1 = require("../../src/app/core/format/format.utils");
|
|
22
|
+
const ui_1 = require("../../src/app/core/i18n/ui");
|
|
23
|
+
const gates_1 = require("../gates");
|
|
24
|
+
const text_1 = require("../text/text");
|
|
24
25
|
/**
|
|
25
26
|
* What a bot looks for to find its own previous comment. It is an HTML comment, so it is invisible
|
|
26
27
|
* in the rendered page and survives being edited by hand.
|
|
27
28
|
*/
|
|
28
29
|
exports.PR_MARKER = '<!-- loadline-report -->';
|
|
30
|
+
/** Below GitHub's 65,536 characters for a comment, with room for what a bot adds around it. */
|
|
31
|
+
const PR_BUDGET = 60_000;
|
|
32
|
+
/** What is kept of each signal's text once the comment is over the budget. */
|
|
33
|
+
const PR_BODY_CAP = 600;
|
|
29
34
|
const details = (summary, body) => `<details>\n<summary>${summary}</summary>\n\n${body}\n\n</details>`;
|
|
30
35
|
const renderPrComment = (report, violations, anyAsked) => {
|
|
31
36
|
const text = text_1.CLI_TEXT[report.lang];
|
|
@@ -38,8 +43,13 @@ const renderPrComment = (report, violations, anyAsked) => {
|
|
|
38
43
|
// Which signals came and went. It is the line the person opening the merge request reads, and
|
|
39
44
|
// the only one that makes fixing something visible.
|
|
40
45
|
if (comparison?.findingsComparable) {
|
|
41
|
-
|
|
42
|
-
|
|
46
|
+
// By what they say, not by their internal kind: a new one is in this report and carries
|
|
47
|
+
// its chip; a fixed one is not, and is named by what that kind of signal is about.
|
|
48
|
+
const names = kind_names_1.KIND_NAMES[report.lang];
|
|
49
|
+
const chipOf = (kind, key) => report.findings.find(finding => finding.kind === kind && (finding.target?.key ?? '') === key)?.chip ??
|
|
50
|
+
names[kind];
|
|
51
|
+
const fixed = comparison.goneFindings.map(finding => `${names[finding.kind]}${finding.key ? ` (\`${finding.key}\`)` : ''}`);
|
|
52
|
+
const added = comparison.newFindings.map(finding => chipOf(finding.kind, finding.key));
|
|
43
53
|
if (fixed.length > 0 || added.length > 0) {
|
|
44
54
|
lines.push('', [
|
|
45
55
|
fixed.length > 0 ? `✅ ${text.prFixed(fixed.length)}: ${fixed.join(', ')}` : '',
|
|
@@ -55,7 +65,8 @@ const renderPrComment = (report, violations, anyAsked) => {
|
|
|
55
65
|
const scale = (0, actions_1.unitScale)(analysis);
|
|
56
66
|
const rows = actions.map((action, index) => `| ${index + 1} | ${(0, finding_plain_1.plainText)(action.finding.title)} | ${action.saving > 0 ? (0, actions_1.formatSaving)(action.saving, scale) : '—'} | ${text.effortLabel[action.effort]} |`);
|
|
57
67
|
lines.push('', `#### ${text.headActions}`, `| # | ${text.colAction} | ${text.colSaving} | ${text.colEffort} |`, '| --: | --- | --: | --- |', ...rows);
|
|
58
|
-
|
|
68
|
+
// As in the text: a total of nothing is not a figure worth a line in somebody's review.
|
|
69
|
+
if (total.counted > 0 && total.bytes > 0) {
|
|
59
70
|
const words = (0, actions_1.savingWords)(analysis, total);
|
|
60
71
|
lines.push('', `_${text.totalSaving(words.saving, words.after, total.counted, words.estimated)}_`);
|
|
61
72
|
}
|
|
@@ -65,13 +76,22 @@ const renderPrComment = (report, violations, anyAsked) => {
|
|
|
65
76
|
? `✅ ${text.passed}`
|
|
66
77
|
: [...(0, gates_1.violationLines)(violations).map(line => `- ❌ ${line}`), '', text.failed(violations.length)].join('\n'));
|
|
67
78
|
}
|
|
68
|
-
// Everything the report says, folded. Nothing is dropped: the rule is to group, never to trim
|
|
69
|
-
|
|
79
|
+
// Everything the report says, folded. Nothing is dropped: the rule is to group, never to trim —
|
|
80
|
+
// until the comment would not be posted at all. GitHub refuses one over 65,536 characters, and
|
|
81
|
+
// Excalidraw's came to 64,314, most of it one signal listing 702 paths. Over the budget, each
|
|
82
|
+
// signal's text is cut to its first lines and says where the rest is; titles and the table stay.
|
|
83
|
+
const restWith = (cap) => [
|
|
70
84
|
(0, markdown_table_utils_1.markdownTable)(analysis, comparison, strings, report.unit),
|
|
71
85
|
'',
|
|
72
86
|
`#### ${text.headSignals}`,
|
|
73
|
-
...report.findings.map(finding =>
|
|
87
|
+
...report.findings.map(finding => {
|
|
88
|
+
const body = (0, finding_plain_1.plainText)(finding.body);
|
|
89
|
+
const shown = cap !== null && body.length > cap ? `${body.slice(0, cap).trimEnd()}… ${text.prCut}` : body;
|
|
90
|
+
return `- **${(0, finding_plain_1.plainText)(finding.title)}** — ${shown}\n ${text.fix}: ${(0, finding_plain_1.plainText)(finding.fix)}`;
|
|
91
|
+
}),
|
|
74
92
|
].join('\n');
|
|
93
|
+
const full = restWith(null);
|
|
94
|
+
const rest = lines.join('\n').length + full.length > PR_BUDGET ? restWith(PR_BODY_CAP) : full;
|
|
75
95
|
lines.push('', details(text.prDetails, rest));
|
|
76
96
|
return `${lines.join('\n')}\n`;
|
|
77
97
|
};
|
|
@@ -12,8 +12,9 @@
|
|
|
12
12
|
*/
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.renderSarif = void 0;
|
|
15
|
-
const finding_types_1 = require("
|
|
16
|
-
const finding_plain_1 = require("
|
|
15
|
+
const finding_types_1 = require("../../src/app/core/findings/finding.types");
|
|
16
|
+
const finding_plain_1 = require("../../src/app/core/findings/text/finding-plain");
|
|
17
|
+
const ownership_1 = require("../../src/app/core/format/ownership");
|
|
17
18
|
/** SARIF has three levels that matter to a code-scanning view; the report has four. */
|
|
18
19
|
const LEVEL = {
|
|
19
20
|
high: 'error',
|
|
@@ -29,8 +30,12 @@ const LEVEL = {
|
|
|
29
30
|
* which is true and checkable.
|
|
30
31
|
*/
|
|
31
32
|
const locationOf = (finding, fallback) => {
|
|
33
|
+
const ownFile = (path) => /\.[a-z]+$/i.test(path) && (0, ownership_1.isOwnFile)(path);
|
|
32
34
|
const key = finding.target?.key ?? '';
|
|
33
|
-
|
|
35
|
+
// Then the files the signal is about, which several carry when their key is a folder or a
|
|
36
|
+
// package: anchored to the build folder, 16 of 18 results of a real report pointed at nothing a
|
|
37
|
+
// code-scanning view can open, while `bigFile` named App.tsx in its own text.
|
|
38
|
+
return ownFile(key) ? key : (finding.sources?.find(source => ownFile(source)) ?? fallback);
|
|
34
39
|
};
|
|
35
40
|
const renderSarif = (report) => {
|
|
36
41
|
const fallback = report.statsName;
|