@bymaksym/loadline 0.1.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +272 -45
- package/dist/cli/cli/args.js +97 -116
- package/dist/cli/cli/gates.js +80 -14
- package/dist/cli/cli/main.js +275 -31
- package/dist/cli/cli/memory.js +114 -0
- package/dist/cli/cli/read/declared.js +52 -0
- package/dist/cli/cli/read/locate.js +214 -0
- package/dist/cli/cli/{read-build.js → read/read-build.js} +156 -87
- package/dist/cli/cli/read/read-config.js +120 -0
- package/dist/cli/cli/render/html-report.js +111 -0
- package/dist/cli/cli/render/render-agent.js +114 -0
- package/dist/cli/cli/render/render-asked.js +104 -0
- package/dist/cli/cli/render/render-badge.js +140 -0
- package/dist/cli/cli/{render-json.js → render/render-json.js} +26 -10
- package/dist/cli/cli/{render-markdown.js → render/render-markdown.js} +6 -6
- package/dist/cli/cli/{render-pr.js → render/render-pr.js} +37 -15
- package/dist/cli/cli/{render-sarif.js → render/render-sarif.js} +11 -6
- package/dist/cli/cli/{render-text.js → render/render-text.js} +169 -127
- package/dist/cli/cli/render/terminal.js +55 -0
- package/dist/cli/cli/report.js +76 -29
- package/dist/cli/cli/self-check.js +19 -23
- package/dist/cli/cli/since-last.js +45 -0
- package/dist/cli/cli/text/text-errors.js +124 -0
- package/dist/cli/cli/text/text.js +343 -0
- package/dist/cli/cli/text/usage.js +240 -0
- package/dist/cli/src/app/core/analysis/analysis.js +68 -24
- package/dist/cli/src/app/core/analysis/{barrels.js → graph/barrels.js} +10 -3
- package/dist/cli/src/app/core/analysis/{blast.js → graph/blast.js} +56 -17
- package/dist/cli/src/app/core/analysis/{cycles.js → graph/cycles.js} +1 -1
- package/dist/cli/src/app/core/analysis/{importers.js → graph/importers.js} +1 -1
- package/dist/cli/src/app/core/analysis/{insights.js → graph/insights.js} +10 -4
- package/dist/cli/src/app/core/analysis/invariant.js +1 -1
- package/dist/cli/src/app/core/analysis/metafile.types.js +21 -7
- package/dist/cli/src/app/core/analysis/{delivery.js → screens/delivery.js} +1 -1
- package/dist/cli/src/app/core/analysis/{entries.js → screens/entries.js} +87 -11
- package/dist/cli/src/app/core/analysis/screens/marks.js +32 -0
- package/dist/cli/src/app/core/analysis/screens/route-files.js +116 -0
- package/dist/cli/src/app/core/analysis/{sourcemap.js → sourcemap/sourcemap.js} +106 -7
- package/dist/cli/src/app/core/analysis/{split-drift.js → sourcemap/split-drift.js} +13 -7
- package/dist/cli/src/app/core/analysis/tool.js +83 -0
- package/dist/cli/src/app/core/assets/assets.js +137 -16
- package/dist/cli/src/app/core/baseline/baseline.js +0 -0
- package/dist/cli/src/app/core/{intake → build-text}/index-html.js +234 -29
- package/dist/cli/src/app/core/build-text/route-table.js +178 -0
- package/dist/cli/src/app/core/build-text/tool-marks.js +54 -0
- package/dist/cli/src/app/core/caching/caching.js +123 -45
- package/dist/cli/src/app/core/caching/from-analysis.js +20 -4
- package/dist/cli/src/app/core/config/config-text.js +90 -0
- package/dist/cli/src/app/core/config/config-values.js +358 -0
- package/dist/cli/src/app/core/config/loadline-config.js +81 -16
- package/dist/cli/src/app/core/config/merge-config.js +98 -0
- package/dist/cli/src/app/core/deps/deps.js +141 -23
- package/dist/cli/src/app/core/deps/pins.js +63 -0
- package/dist/cli/src/app/core/export/summary.js +54 -12
- package/dist/cli/src/app/core/findings/actions.js +65 -6
- package/dist/cli/src/app/core/findings/bundle/boot-single.js +76 -0
- package/dist/cli/src/app/core/findings/bundle/dupes.js +68 -0
- package/dist/cli/src/app/core/findings/{graph.js → bundle/graph.js} +32 -20
- package/dist/cli/src/app/core/findings/{own-in-boot.js → bundle/own-in-boot.js} +9 -5
- package/dist/cli/src/app/core/findings/{requests.js → bundle/requests.js} +3 -3
- package/dist/cli/src/app/core/findings/{shipped.js → bundle/shipped.js} +30 -18
- package/dist/cli/src/app/core/findings/compose.js +6 -1
- package/dist/cli/src/app/core/findings/effort.js +4 -0
- package/dist/cli/src/app/core/findings/finding.types.js +2 -0
- package/dist/cli/src/app/core/findings/findings.js +68 -55
- package/dist/cli/src/app/core/findings/{assets.js → folder/assets.js} +65 -16
- package/dist/cli/src/app/core/findings/{caching.js → folder/caching.js} +17 -10
- package/dist/cli/src/app/core/findings/{page.js → folder/page.js} +6 -2
- package/dist/cli/src/app/core/findings/{scan.js → folder/scan.js} +37 -13
- package/dist/cli/src/app/core/findings/kind-names.js +163 -0
- package/dist/cli/src/app/core/findings/{deps.js → supplied/deps.js} +13 -8
- package/dist/cli/src/app/core/findings/supplied/forbidden.js +71 -0
- package/dist/cli/src/app/core/findings/{situation.js → supplied/situation.js} +2 -2
- package/dist/cli/src/app/core/findings/text/causes.js +39 -0
- package/dist/cli/src/app/core/findings/text/finding-html.js +33 -0
- package/dist/cli/src/app/core/findings/{finding-text.js → text/finding-text.js} +307 -103
- package/dist/cli/src/app/core/findings/text/tool-advice.js +97 -0
- package/dist/cli/src/app/core/format/format.utils.js +172 -18
- package/dist/cli/src/app/core/format/ownership.js +93 -0
- package/dist/cli/src/app/core/i18n/en.js +180 -61
- package/dist/cli/src/app/core/i18n/es.js +192 -68
- package/dist/cli/src/app/core/intake/bundle-graph.js +285 -46
- package/dist/cli/src/app/core/intake/dist-files.js +87 -16
- package/dist/cli/src/app/core/intake/embedded.js +56 -0
- package/dist/cli/src/app/core/intake/unreached.js +139 -0
- package/dist/cli/src/app/core/intake/webpack-modules.js +185 -0
- package/dist/cli/src/app/core/intake/webpack-stats.js +298 -0
- package/dist/cli/src/app/core/project/budget-advice.js +14 -10
- package/dist/cli/src/app/core/project/project-context.js +89 -19
- package/dist/cli/src/app/core/project/project-name.js +36 -0
- package/dist/cli/src/app/core/scan/scan.js +116 -39
- package/dist/cli/src/app/core/scan/secrets.js +0 -0
- package/dist/cli/src/app/core/situation/situation-text.js +23 -0
- package/dist/cli/src/app/core/situation/situation.js +9 -8
- package/dist/cli/src/app/core/timing/timing.js +5 -2
- package/dist/cli/src/app/core/whatif/defer.js +29 -4
- package/dist/cli/src/app/core/whatif/source-importers.js +58 -0
- package/dist/cli/src/app/core/whatif/why.js +102 -0
- package/dist/cli/src/app/state/report-messages.utils.js +1 -4
- package/docs/CONFIG-REFERENCE.md +230 -0
- package/docs/CONFIG.md +511 -0
- package/docs/HOW-IT-WORKS.md +286 -25
- package/loadline.html +26 -24
- package/loadline.schema.json +1209 -0
- package/package.json +71 -35
- package/dist/cli/cli/text.js +0 -180
- package/dist/cli/src/app/core/findings/finding-html.js +0 -13
- /package/dist/cli/cli/{read-build.types.js → read/read-build.types.js} +0 -0
- /package/dist/cli/cli/{render-json.types.js → render/render-json.types.js} +0 -0
- /package/dist/cli/cli/{text.types.js → text/text.types.js} +0 -0
- /package/dist/cli/src/app/core/analysis/{exclusive.js → graph/exclusive.js} +0 -0
- /package/dist/cli/src/app/core/analysis/{insights.types.js → graph/insights.types.js} +0 -0
- /package/dist/cli/src/app/core/analysis/{module-graph.js → graph/module-graph.js} +0 -0
- /package/dist/cli/src/app/core/analysis/{sourcemap.types.js → sourcemap/sourcemap.types.js} +0 -0
- /package/dist/cli/src/app/core/findings/{finding-plain.js → text/finding-plain.js} +0 -0
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The blocks of `loadline.json` other than the acceptances and the answers, read the same way they
|
|
4
|
+
* are: whatever cannot be understood is named in a problem and left out, never ignored in silence.
|
|
5
|
+
*
|
|
6
|
+
* Silence was the failure. `"maxBot": "350kB"` switched no gate on, `"maxBoot": "big"` switched it
|
|
7
|
+
* off, and a criterion with a typo in its name kept the recommended value — each one a build judged
|
|
8
|
+
* by something other than what the file says, with nothing on screen to show it.
|
|
9
|
+
*
|
|
10
|
+
* It also lets every size be written one way. The criteria used to be bytes (`174080`) while the
|
|
11
|
+
* gates were text (`"350kB"`); both are accepted everywhere now, and a share can be `"25%"` as well
|
|
12
|
+
* as `0.25`. What comes out is the shape it always was — bytes and fractions — so nothing that
|
|
13
|
+
* reads the file had to change.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.readBuildHints = exports.readForbidden = exports.readPackages = exports.readGatesBlock = exports.readCriteriaBlock = exports.readMode = exports.readExtends = exports.unknownTopKeys = exports.readSizeValue = exports.UNIT_OF = exports.SIZE_GATE_KEYS = exports.TOP_KEYS = exports.SCHEMA_URL = void 0;
|
|
17
|
+
const route_table_1 = require("../build-text/route-table");
|
|
18
|
+
const criteria_1 = require("../criteria/criteria");
|
|
19
|
+
const finding_types_1 = require("../findings/finding.types");
|
|
20
|
+
const project_context_1 = require("../project/project-context");
|
|
21
|
+
const config_text_1 = require("./config-text");
|
|
22
|
+
/**
|
|
23
|
+
* Where the published schema lives: the package on npm, through a CDN that serves its files. Here
|
|
24
|
+
* and not next to the schema's builder because the page writes it into every file it exports, and
|
|
25
|
+
* importing it from there carried the whole generator — every signal's name — into the page.
|
|
26
|
+
*/
|
|
27
|
+
exports.SCHEMA_URL = 'https://unpkg.com/@bymaksym/loadline/loadline.schema.json';
|
|
28
|
+
/** Every key the file may have at its top level. `$schema` is the editor's, and is read by nobody. */
|
|
29
|
+
exports.TOP_KEYS = [
|
|
30
|
+
'$schema',
|
|
31
|
+
'tool',
|
|
32
|
+
'version',
|
|
33
|
+
'extends',
|
|
34
|
+
'mode',
|
|
35
|
+
'criteria',
|
|
36
|
+
'gates',
|
|
37
|
+
'packages',
|
|
38
|
+
'accepted',
|
|
39
|
+
'forbidden',
|
|
40
|
+
'situation',
|
|
41
|
+
'build',
|
|
42
|
+
];
|
|
43
|
+
/** The gates whose value is a size. */
|
|
44
|
+
exports.SIZE_GATE_KEYS = ['maxBoot', 'maxScreen', 'maxOwn', 'maxGrowth'];
|
|
45
|
+
const GATE_KEYS = new Set([
|
|
46
|
+
...exports.SIZE_GATE_KEYS,
|
|
47
|
+
'maxGrowthPct',
|
|
48
|
+
'failOn',
|
|
49
|
+
'failOnNewPackage',
|
|
50
|
+
'failOnSignals',
|
|
51
|
+
'screens',
|
|
52
|
+
]);
|
|
53
|
+
const KINDS = new Set(finding_types_1.FINDING_KINDS);
|
|
54
|
+
const MODES = new Set(['raw', 'gzip', 'brotli']);
|
|
55
|
+
const FAIL_ON = new Set(['high', 'mid', 'none']);
|
|
56
|
+
/** Below this a number with no unit is a size somebody meant in kilobytes: nothing is that small. */
|
|
57
|
+
const BARE_FLOOR = 1000;
|
|
58
|
+
const BARE = /^\d+(?:\.\d+)?$/;
|
|
59
|
+
/** The unit of every criterion, the second threshold of a pair included. */
|
|
60
|
+
exports.UNIT_OF = new Map(criteria_1.CRITERIA_FIELDS.flatMap(field => [
|
|
61
|
+
[field.key, field.unit],
|
|
62
|
+
...(field.pairWith ? [[field.pairWith, field.unit]] : []),
|
|
63
|
+
]));
|
|
64
|
+
/**
|
|
65
|
+
* A size: `"350kB"`, `"1.5MB"`, or bytes as a number. A bare figure under a thousand is refused,
|
|
66
|
+
* because `350` meaning 350 bytes is never what was meant and it fails every build.
|
|
67
|
+
*/
|
|
68
|
+
const readSizeValue = (value, where, t = config_text_1.CONFIG_TEXT.en) => {
|
|
69
|
+
const typed = typeof value === 'string' ? value.trim() : value;
|
|
70
|
+
const bytes = (0, project_context_1.parseSize)(typed);
|
|
71
|
+
if (bytes === null) {
|
|
72
|
+
return { problem: t.notSize(where, JSON.stringify(value)) };
|
|
73
|
+
}
|
|
74
|
+
const bare = typeof typed === 'number' || BARE.test(String(typed));
|
|
75
|
+
return bare && bytes < BARE_FLOOR ? { problem: t.bareSize(where, String(typed)) } : { value: bytes };
|
|
76
|
+
};
|
|
77
|
+
exports.readSizeValue = readSizeValue;
|
|
78
|
+
/** A share: `"25%"` or the fraction `0.25`. */
|
|
79
|
+
const readShare = (value, where, t) => {
|
|
80
|
+
if (typeof value === 'number' && Number.isFinite(value) && value >= 0) {
|
|
81
|
+
return { value };
|
|
82
|
+
}
|
|
83
|
+
const match = typeof value === 'string' ? /^\s*(\d+(?:\.\d+)?)\s*%\s*$/.exec(value) : null;
|
|
84
|
+
return match?.[1] ? { value: Number(match[1]) / 100 } : { problem: t.notShare(where, JSON.stringify(value)) };
|
|
85
|
+
};
|
|
86
|
+
const readNumber = (value, where, t) => typeof value === 'number' && Number.isFinite(value) && value >= 0
|
|
87
|
+
? { value }
|
|
88
|
+
: { problem: t.notNumber(where, JSON.stringify(value)) };
|
|
89
|
+
const isRecord = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
|
|
90
|
+
/** The keys at the top of the file that nothing reads, each one a problem. */
|
|
91
|
+
const unknownTopKeys = (file, t = config_text_1.CONFIG_TEXT.en) => Object.keys(file)
|
|
92
|
+
.filter(key => !exports.TOP_KEYS.includes(key))
|
|
93
|
+
.map(key => t.unknownTopKey(key));
|
|
94
|
+
exports.unknownTopKeys = unknownTopKeys;
|
|
95
|
+
/**
|
|
96
|
+
* `extends`: one name or a list of them, read as a list. One it cannot read is a problem for the
|
|
97
|
+
* gates, because whatever the base would have guarded is not guarded.
|
|
98
|
+
*/
|
|
99
|
+
const readExtends = (value, t = config_text_1.CONFIG_TEXT.en) => {
|
|
100
|
+
if (value === undefined) {
|
|
101
|
+
return { problems: [] };
|
|
102
|
+
}
|
|
103
|
+
const names = typeof value === 'string' ? [value] : value;
|
|
104
|
+
return Array.isArray(names) && names.length > 0 && names.every(name => typeof name === 'string' && name !== '')
|
|
105
|
+
? { names: names, problems: [] }
|
|
106
|
+
: { problems: [t.badExtends] };
|
|
107
|
+
};
|
|
108
|
+
exports.readExtends = readExtends;
|
|
109
|
+
const readMode = (value, t = config_text_1.CONFIG_TEXT.en) => {
|
|
110
|
+
if (value === undefined) {
|
|
111
|
+
return { problems: [] };
|
|
112
|
+
}
|
|
113
|
+
return typeof value === 'string' && MODES.has(value)
|
|
114
|
+
? { mode: value, problems: [] }
|
|
115
|
+
: { problems: [t.badMode(JSON.stringify(value))] };
|
|
116
|
+
};
|
|
117
|
+
exports.readMode = readMode;
|
|
118
|
+
const readCriteriaBlock = (value, t = config_text_1.CONFIG_TEXT.en) => {
|
|
119
|
+
if (value === undefined) {
|
|
120
|
+
return { problems: [] };
|
|
121
|
+
}
|
|
122
|
+
if (!isRecord(value)) {
|
|
123
|
+
return { problems: [t.criteriaNotObject] };
|
|
124
|
+
}
|
|
125
|
+
const known = new Set(Object.keys(criteria_1.RECOMMENDED.raw));
|
|
126
|
+
const criteria = {};
|
|
127
|
+
const problems = [];
|
|
128
|
+
for (const [key, raw] of Object.entries(value)) {
|
|
129
|
+
if (!known.has(key)) {
|
|
130
|
+
problems.push(t.unknownCriterion(key));
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const unit = exports.UNIT_OF.get(key);
|
|
134
|
+
const where = `"criteria.${key}"`;
|
|
135
|
+
const read = unit === 'kb'
|
|
136
|
+
? (0, exports.readSizeValue)(raw, where, t)
|
|
137
|
+
: unit === 'pct'
|
|
138
|
+
? readShare(raw, where, t)
|
|
139
|
+
: readNumber(raw, where, t);
|
|
140
|
+
if ('problem' in read) {
|
|
141
|
+
problems.push(t.recommendedStays(read.problem));
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
criteria[key] = read.value;
|
|
145
|
+
}
|
|
146
|
+
return { criteria, problems };
|
|
147
|
+
};
|
|
148
|
+
exports.readCriteriaBlock = readCriteriaBlock;
|
|
149
|
+
/**
|
|
150
|
+
* The gates, with each size checked here rather than at the moment it is used: a size that does
|
|
151
|
+
* not parse used to become "no gate", which is the quietest way a pipeline can stop guarding.
|
|
152
|
+
*/
|
|
153
|
+
const readGatesBlock = (value, t = config_text_1.CONFIG_TEXT.en) => {
|
|
154
|
+
if (value === undefined) {
|
|
155
|
+
return { problems: [] };
|
|
156
|
+
}
|
|
157
|
+
if (!isRecord(value)) {
|
|
158
|
+
return { problems: [t.gatesNotObject] };
|
|
159
|
+
}
|
|
160
|
+
const gates = {};
|
|
161
|
+
const problems = [];
|
|
162
|
+
const off = (problem) => {
|
|
163
|
+
problems.push(t.gateOff(problem));
|
|
164
|
+
};
|
|
165
|
+
for (const key of Object.keys(value)) {
|
|
166
|
+
if (!GATE_KEYS.has(key)) {
|
|
167
|
+
problems.push(t.unknownGate(key));
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
for (const key of exports.SIZE_GATE_KEYS) {
|
|
171
|
+
if (value[key] === undefined) {
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
const read = (0, exports.readSizeValue)(value[key], `"gates.${key}"`, t);
|
|
175
|
+
if ('problem' in read) {
|
|
176
|
+
off(read.problem);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
gates[key] = read.value;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (value['maxGrowthPct'] !== undefined) {
|
|
183
|
+
const raw = value['maxGrowthPct'];
|
|
184
|
+
const read = typeof raw === 'string'
|
|
185
|
+
? readShare(raw, '"gates.maxGrowthPct"', t)
|
|
186
|
+
: readNumber(raw, '"gates.maxGrowthPct"', t);
|
|
187
|
+
if ('problem' in read) {
|
|
188
|
+
off(read.problem);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
// `10` and `"10%"` both mean ten per cent here: the file has always written it as `10`.
|
|
192
|
+
gates.maxGrowthPct = typeof raw === 'string' ? read.value * 100 : read.value;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (value['failOn'] !== undefined) {
|
|
196
|
+
if (typeof value['failOn'] === 'string' && FAIL_ON.has(value['failOn'])) {
|
|
197
|
+
gates.failOn = value['failOn'];
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
off(t.badFailOn(JSON.stringify(value['failOn'])));
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if (value['failOnNewPackage'] !== undefined) {
|
|
204
|
+
if (typeof value['failOnNewPackage'] === 'boolean') {
|
|
205
|
+
gates.failOnNewPackage = value['failOnNewPackage'];
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
off(t.badFailOnNewPackage);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
// A name that is not a signal is a gate that guards nothing, so it stops the run like any other
|
|
212
|
+
// unreadable gate; the names that are signals still apply.
|
|
213
|
+
const signals = value['failOnSignals'];
|
|
214
|
+
if (signals !== undefined) {
|
|
215
|
+
if (Array.isArray(signals) && signals.every(item => typeof item === 'string')) {
|
|
216
|
+
const kinds = [];
|
|
217
|
+
for (const kind of signals) {
|
|
218
|
+
if (KINDS.has(kind)) {
|
|
219
|
+
kinds.push(kind);
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
off(t.unknownFailOnSignal(kind));
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
gates.failOnSignals = kinds;
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
off(t.badFailOnSignals);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const screens = value['screens'];
|
|
232
|
+
if (screens !== undefined) {
|
|
233
|
+
if (isRecord(screens)) {
|
|
234
|
+
gates.screens = {};
|
|
235
|
+
for (const [screen, raw] of Object.entries(screens)) {
|
|
236
|
+
const read = (0, exports.readSizeValue)(raw, `"gates.screens.${screen}"`, t);
|
|
237
|
+
if ('problem' in read) {
|
|
238
|
+
off(read.problem);
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
gates.screens[screen] = read.value;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
off(t.badScreens);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return { gates, problems };
|
|
250
|
+
};
|
|
251
|
+
exports.readGatesBlock = readGatesBlock;
|
|
252
|
+
const readPackages = (value, t = config_text_1.CONFIG_TEXT.en) => {
|
|
253
|
+
if (value === undefined) {
|
|
254
|
+
return { problems: [] };
|
|
255
|
+
}
|
|
256
|
+
return Array.isArray(value) && value.every(item => typeof item === 'string')
|
|
257
|
+
? { packages: value, problems: [] }
|
|
258
|
+
: { problems: [t.badPackages] };
|
|
259
|
+
};
|
|
260
|
+
exports.readPackages = readPackages;
|
|
261
|
+
const PLACES = new Set(['bootstrap', 'anywhere']);
|
|
262
|
+
/**
|
|
263
|
+
* The `forbidden` list. Every entry it cannot use is a problem **for the gates**, not a line to
|
|
264
|
+
* print: a rule with a typo in it forbids nothing, and a build that ships what it was meant to stop
|
|
265
|
+
* would pass with nothing but a warning in the log.
|
|
266
|
+
*/
|
|
267
|
+
const readForbidden = (value, t = config_text_1.CONFIG_TEXT.en) => {
|
|
268
|
+
if (value === undefined) {
|
|
269
|
+
return { problems: [] };
|
|
270
|
+
}
|
|
271
|
+
if (!Array.isArray(value)) {
|
|
272
|
+
return { problems: [t.forbiddenNotList] };
|
|
273
|
+
}
|
|
274
|
+
const forbidden = [];
|
|
275
|
+
const problems = [];
|
|
276
|
+
for (const [index, entry] of value.entries()) {
|
|
277
|
+
const rule = isRecord(entry) ? entry : {};
|
|
278
|
+
const pkg = typeof rule['package'] === 'string' && rule['package'] !== '' ? rule['package'] : undefined;
|
|
279
|
+
const path = typeof rule['path'] === 'string' && rule['path'] !== '' ? rule['path'] : undefined;
|
|
280
|
+
const where = pkg ?? path ?? `#${index + 1}`;
|
|
281
|
+
const place = rule['in'] ?? 'anywhere';
|
|
282
|
+
const why = typeof rule['why'] === 'string' ? rule['why'].trim() : '';
|
|
283
|
+
if ((pkg === undefined) === (path === undefined)) {
|
|
284
|
+
problems.push(t.forbiddenWhat(where));
|
|
285
|
+
}
|
|
286
|
+
else if (typeof place !== 'string' || !PLACES.has(place)) {
|
|
287
|
+
problems.push(t.forbiddenIn(where, JSON.stringify(place)));
|
|
288
|
+
}
|
|
289
|
+
else if (why === '') {
|
|
290
|
+
problems.push(t.forbiddenNoWhy(where));
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
forbidden.push({
|
|
294
|
+
...(pkg && { package: pkg }),
|
|
295
|
+
...(path && { path }),
|
|
296
|
+
in: place,
|
|
297
|
+
why,
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return { forbidden, problems };
|
|
302
|
+
};
|
|
303
|
+
exports.readForbidden = readForbidden;
|
|
304
|
+
/** The `build` block: lists of file names and paths, each read on its own so one bad list keeps the others. */
|
|
305
|
+
const readBuildHints = (value, t = config_text_1.CONFIG_TEXT.en) => {
|
|
306
|
+
if (value === undefined) {
|
|
307
|
+
return { problems: [] };
|
|
308
|
+
}
|
|
309
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
310
|
+
return { problems: [t.badBuild] };
|
|
311
|
+
}
|
|
312
|
+
const block = value;
|
|
313
|
+
const names = (key) => {
|
|
314
|
+
const list = block[key];
|
|
315
|
+
return Array.isArray(list) && list.every(item => typeof item === 'string' && item !== '') ? list : undefined;
|
|
316
|
+
};
|
|
317
|
+
const entries = names('entries');
|
|
318
|
+
const ignore = names('ignore');
|
|
319
|
+
const own = names('own');
|
|
320
|
+
const dependencies = names('dependencies');
|
|
321
|
+
const routeKeys = names('routeKeys');
|
|
322
|
+
const problems = ['entries', 'ignore', 'own', 'dependencies', 'routeKeys']
|
|
323
|
+
.filter(key => block[key] !== undefined && names(key) === undefined)
|
|
324
|
+
.map(key => t.badBuildList(key));
|
|
325
|
+
// A key is a property name; anything else could not be one, and would go into a pattern.
|
|
326
|
+
problems.push(...(routeKeys ?? []).filter(key => !(0, route_table_1.isRouteKey)(key)).map(key => t.badRouteKey(key)));
|
|
327
|
+
const marked = block['screens'];
|
|
328
|
+
const screens = {};
|
|
329
|
+
if (marked !== undefined && (!marked || typeof marked !== 'object' || Array.isArray(marked))) {
|
|
330
|
+
problems.push(t.badBuildScreens);
|
|
331
|
+
}
|
|
332
|
+
const said = Object.entries(marked && typeof marked === 'object' ? marked : {});
|
|
333
|
+
for (const [pattern, kind] of said) {
|
|
334
|
+
if (kind === 'screen' || kind === 'piece') {
|
|
335
|
+
screens[pattern] = kind;
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
problems.push(t.badBuildScreen(pattern));
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
const page = block['page'];
|
|
342
|
+
if (page !== undefined && (typeof page !== 'string' || page === '')) {
|
|
343
|
+
problems.push(t.badBuildPage);
|
|
344
|
+
}
|
|
345
|
+
return {
|
|
346
|
+
build: {
|
|
347
|
+
...(entries && { entries }),
|
|
348
|
+
...(ignore && { ignore }),
|
|
349
|
+
...(own && { own }),
|
|
350
|
+
...(dependencies && { dependencies }),
|
|
351
|
+
...(routeKeys && { routeKeys: routeKeys.filter(key => (0, route_table_1.isRouteKey)(key)) }),
|
|
352
|
+
...(Object.keys(screens).length > 0 && { screens }),
|
|
353
|
+
...(typeof page === 'string' && page !== '' && { page }),
|
|
354
|
+
},
|
|
355
|
+
problems,
|
|
356
|
+
};
|
|
357
|
+
};
|
|
358
|
+
exports.readBuildHints = readBuildHints;
|
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
* and printed, and the run carries on with whatever of the file could be understood.
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.writeConfig = exports.applyAcceptances = exports.readConfig = exports.isLoadlineConfig = void 0;
|
|
10
|
+
exports.writeConfig = exports.applyAcceptances = exports.sameFolderReading = exports.readConfig = exports.isLoadlineConfig = void 0;
|
|
11
11
|
const finding_types_1 = require("../findings/finding.types");
|
|
12
12
|
const situation_1 = require("../situation/situation");
|
|
13
|
+
const config_text_1 = require("./config-text");
|
|
14
|
+
const config_values_1 = require("./config-values");
|
|
13
15
|
const KINDS = new Set(finding_types_1.FINDING_KINDS);
|
|
14
16
|
const DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
15
17
|
/** Tells the file apart from anything else somebody points `--config` at. */
|
|
@@ -26,41 +28,104 @@ exports.isLoadlineConfig = isLoadlineConfig;
|
|
|
26
28
|
*
|
|
27
29
|
* An acceptance is dropped when it names a signal that does not exist or gives no reason: both are
|
|
28
30
|
* ways of suppressing something by accident, and a suppression nobody meant is worse than a noisy
|
|
29
|
-
* report.
|
|
31
|
+
* report. Every other block is read by `config-values.ts`, which does the same with what it cannot
|
|
32
|
+
* understand: leaves it out, and names it.
|
|
30
33
|
*/
|
|
31
|
-
const readConfig = (value) => {
|
|
34
|
+
const readConfig = (value, lang = 'en') => {
|
|
35
|
+
const t = config_text_1.CONFIG_TEXT[lang];
|
|
32
36
|
if (!(0, exports.isLoadlineConfig)(value)) {
|
|
33
|
-
return {
|
|
37
|
+
return {
|
|
38
|
+
config: null,
|
|
39
|
+
problems: [t.notConfig],
|
|
40
|
+
gateProblems: [],
|
|
41
|
+
};
|
|
34
42
|
}
|
|
35
|
-
const
|
|
43
|
+
const file = value;
|
|
44
|
+
const mode = (0, config_values_1.readMode)(file['mode'], t);
|
|
45
|
+
const criteria = (0, config_values_1.readCriteriaBlock)(file['criteria'], t);
|
|
46
|
+
const gates = (0, config_values_1.readGatesBlock)(file['gates'], t);
|
|
47
|
+
const packages = (0, config_values_1.readPackages)(file['packages'], t);
|
|
48
|
+
const build = (0, config_values_1.readBuildHints)(file['build'], t);
|
|
49
|
+
const forbidden = (0, config_values_1.readForbidden)(file['forbidden'], t);
|
|
50
|
+
const bases = (0, config_values_1.readExtends)(file['extends'], t);
|
|
51
|
+
const problems = [
|
|
52
|
+
...build.problems,
|
|
53
|
+
...(0, config_values_1.unknownTopKeys)(file, t),
|
|
54
|
+
...mode.problems,
|
|
55
|
+
...criteria.problems,
|
|
56
|
+
...gates.problems,
|
|
57
|
+
...packages.problems,
|
|
58
|
+
...forbidden.problems,
|
|
59
|
+
...bases.problems,
|
|
60
|
+
];
|
|
36
61
|
const accepted = [];
|
|
37
|
-
const
|
|
62
|
+
const listed = value.accepted;
|
|
63
|
+
if (listed !== undefined && !Array.isArray(listed)) {
|
|
64
|
+
problems.push(t.acceptedNotList);
|
|
65
|
+
}
|
|
66
|
+
const entries = (Array.isArray(listed) ? listed : []).filter((entry) => !!entry && typeof entry === 'object');
|
|
38
67
|
for (const entry of entries) {
|
|
39
68
|
const where = entry.key ? `${entry.kind} · ${entry.key}` : entry.kind;
|
|
40
69
|
if (!KINDS.has(entry.kind)) {
|
|
41
|
-
problems.push(
|
|
70
|
+
problems.push(t.unknownAccepted(entry.kind));
|
|
42
71
|
continue;
|
|
43
72
|
}
|
|
44
73
|
if (!entry.why || entry.why.trim().length === 0) {
|
|
45
|
-
problems.push(
|
|
74
|
+
problems.push(t.noWhy(where));
|
|
46
75
|
continue;
|
|
47
76
|
}
|
|
77
|
+
// `"12kB"` as readily as bytes, like every other size in the file. One that cannot be read
|
|
78
|
+
// is dropped from the entry, which then covers the signal at any size, and says so.
|
|
79
|
+
const bytes = entry.bytes === undefined ? null : (0, config_values_1.readSizeValue)(entry.bytes, t.bytesOf(where), t);
|
|
80
|
+
const sized = bytes && 'problem' in bytes ? { ...entry, bytes: undefined } : { ...entry, bytes: bytes?.value };
|
|
81
|
+
if (bytes && 'problem' in bytes) {
|
|
82
|
+
problems.push(t.ignored(bytes.problem));
|
|
83
|
+
}
|
|
48
84
|
if (entry.until && !DATE.test(entry.until)) {
|
|
49
|
-
problems.push(
|
|
50
|
-
accepted.push({ ...
|
|
85
|
+
problems.push(t.badUntil(where, entry.until));
|
|
86
|
+
accepted.push({ ...sized, until: undefined });
|
|
51
87
|
continue;
|
|
52
88
|
}
|
|
53
|
-
accepted.push(
|
|
89
|
+
accepted.push(sized);
|
|
54
90
|
}
|
|
55
91
|
// The five answers get the same treatment as the acceptances, and for the same reason: an
|
|
56
92
|
// answer nobody recognises has to become "unanswered" and a line to print, never a silent
|
|
57
93
|
// nothing. An answer is the only thing in this file that can move a colour, so a typo in one
|
|
58
94
|
// is the one mistake here that would change a verdict without anybody noticing.
|
|
59
|
-
const { situation, problems: situationProblems } = (0, situation_1.readSituation)(value.situation);
|
|
95
|
+
const { situation, problems: situationProblems } = (0, situation_1.readSituation)(value.situation, lang);
|
|
60
96
|
problems.push(...situationProblems);
|
|
61
|
-
|
|
97
|
+
const read = {
|
|
98
|
+
...(typeof file['$schema'] === 'string' && { $schema: file['$schema'] }),
|
|
99
|
+
tool: 'loadline',
|
|
100
|
+
version: 1,
|
|
101
|
+
...(bases.names && { extends: bases.names }),
|
|
102
|
+
...(mode.mode && { mode: mode.mode }),
|
|
103
|
+
...(criteria.criteria && { criteria: criteria.criteria }),
|
|
104
|
+
...(gates.gates && { gates: gates.gates }),
|
|
105
|
+
...(packages.packages && { packages: packages.packages }),
|
|
106
|
+
...(forbidden.forbidden && { forbidden: forbidden.forbidden }),
|
|
107
|
+
...(build.build && { build: build.build }),
|
|
108
|
+
accepted,
|
|
109
|
+
situation,
|
|
110
|
+
};
|
|
111
|
+
// A rule of `forbidden` that cannot be read is a guard that switched itself off, the same as a
|
|
112
|
+
// gate that cannot be: it stops the command rather than being printed and passed.
|
|
113
|
+
return { config: read, problems, gateProblems: [...gates.problems, ...forbidden.problems, ...bases.problems] };
|
|
62
114
|
};
|
|
63
115
|
exports.readConfig = readConfig;
|
|
116
|
+
/**
|
|
117
|
+
* Whether two `build` blocks read a folder the same way: the same `entries`, `ignore`, `page` and
|
|
118
|
+
* `routeKeys`.
|
|
119
|
+
*
|
|
120
|
+
* `screens`, `own` and `dependencies` are left out on purpose. They reclassify what was read as the
|
|
121
|
+
* report is drawn, so they apply on their own; the other four decide which files are read, from
|
|
122
|
+
* where and with which edges, and a change in them means reading the folder again.
|
|
123
|
+
*/
|
|
124
|
+
const sameFolderReading = (a, b) => {
|
|
125
|
+
const reading = (hints) => JSON.stringify([hints?.entries ?? [], hints?.ignore ?? [], hints?.page ?? null, hints?.routeKeys ?? []]);
|
|
126
|
+
return reading(a) === reading(b);
|
|
127
|
+
};
|
|
128
|
+
exports.sameFolderReading = sameFolderReading;
|
|
64
129
|
/** Which named thing a signal is about, as an acceptance would name it. */
|
|
65
130
|
const keyOf = (finding) => finding.target?.key ?? '';
|
|
66
131
|
/**
|
|
@@ -89,7 +154,7 @@ const applyAcceptances = (findings, config, today = new Date()) => {
|
|
|
89
154
|
continue;
|
|
90
155
|
}
|
|
91
156
|
const expired = !!entry.until && entry.until < day;
|
|
92
|
-
const grew = entry.bytes !== undefined && (finding.saving ?? 0) > entry.bytes;
|
|
157
|
+
const grew = entry.bytes !== undefined && (finding.size ?? finding.saving ?? 0) > entry.bytes;
|
|
93
158
|
const lapse = expired ? 'expired' : grew ? 'grew' : null;
|
|
94
159
|
accepted.push({ finding, entry, lapse });
|
|
95
160
|
if (lapse) {
|
|
@@ -104,7 +169,7 @@ exports.applyAcceptances = applyAcceptances;
|
|
|
104
169
|
*
|
|
105
170
|
* The whole criteria object goes in, not only what was changed: the file has to pin every threshold
|
|
106
171
|
* or the next release of the tool silently moves one of them, which is the same drift this file
|
|
107
|
-
* exists to end.
|
|
172
|
+
* exists to end — unless the file extends a base, which pins them instead (`criteriaToWrite`). `$schema` goes first, so the file opens in an editor that already knows every key.
|
|
108
173
|
*/
|
|
109
|
-
const writeConfig = (config) => `${JSON.stringify({ tool: 'loadline', version: 1, ...config }, null, 4)}\n`;
|
|
174
|
+
const writeConfig = (config) => `${JSON.stringify({ $schema: config_values_1.SCHEMA_URL, tool: 'loadline', version: 1, ...config }, null, 4)}\n`;
|
|
110
175
|
exports.writeConfig = writeConfig;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Joining a `loadline.json` with the files it `extends`: what a company writes once and twenty
|
|
4
|
+
* repositories inherit.
|
|
5
|
+
*
|
|
6
|
+
* **One rule, so nobody has to look it up: objects join key by key, lists add up, and the file that
|
|
7
|
+
* extends wins.** It is the rule Biome and webpack follow, and the opposite of `tsconfig.json`,
|
|
8
|
+
* where a list in the child replaces the base's whole — the surprise that file is best known for.
|
|
9
|
+
* Here the lists are things a repository wants to add to: the packages the base allows plus one,
|
|
10
|
+
* the base's acceptances plus its own. What adding cannot do is take something of the base away,
|
|
11
|
+
* and the file already has the way to do that with a reason attached: an entry in `accepted`.
|
|
12
|
+
*
|
|
13
|
+
* Two keys do not join:
|
|
14
|
+
*
|
|
15
|
+
* - **`situation`** is not inherited. It is a team's answers about its own releases and users,
|
|
16
|
+
* with a name and a date on them, and inheriting it would put somebody else's name on this
|
|
17
|
+
* repository's report.
|
|
18
|
+
* - **`mode`** cannot change. The base wrote its sizes in its unit; a file that extends it and
|
|
19
|
+
* says another unit would have every inherited threshold read in the wrong one. That stops the
|
|
20
|
+
* command, like a gate that cannot be read.
|
|
21
|
+
*
|
|
22
|
+
* Nothing here reads a disk: the command finds the files, the page has none to find, and both
|
|
23
|
+
* join them the same way.
|
|
24
|
+
*/
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.criteriaToWrite = exports.mergeConfigs = void 0;
|
|
27
|
+
const criteria_1 = require("../criteria/criteria");
|
|
28
|
+
const config_text_1 = require("./config-text");
|
|
29
|
+
/** Both lists, the first one's order kept and nothing twice. */
|
|
30
|
+
const added = (first, second) => first || second ? [...new Set([...(first ?? []), ...(second ?? [])])] : undefined;
|
|
31
|
+
/** Both objects, the second one's keys winning. */
|
|
32
|
+
const joined = (base, own) => base || own ? { ...base, ...own } : undefined;
|
|
33
|
+
/**
|
|
34
|
+
* `own` on top of `base`. `base` is what `own` extends, already joined with whatever it extends in
|
|
35
|
+
* turn. `own.extends` is dropped from the result: it has been followed, and what comes out is a
|
|
36
|
+
* file that says everything itself.
|
|
37
|
+
*
|
|
38
|
+
* The acceptances of the file that extends go **first**: the first entry that covers a signal is
|
|
39
|
+
* the one applied, and the closer decision is the one that should be.
|
|
40
|
+
*/
|
|
41
|
+
const mergeConfigs = (base, own, names, t = config_text_1.CONFIG_TEXT.en) => {
|
|
42
|
+
const gateProblems = base.mode && own.mode && base.mode !== own.mode
|
|
43
|
+
? [t.extendsMode(names.own, names.base, base.mode, own.mode)]
|
|
44
|
+
: [];
|
|
45
|
+
const gates = joined(base.gates, own.gates);
|
|
46
|
+
const screens = joined(base.gates?.screens, own.gates?.screens);
|
|
47
|
+
const failOnSignals = added(base.gates?.failOnSignals, own.gates?.failOnSignals);
|
|
48
|
+
const build = joined(base.build, own.build);
|
|
49
|
+
const entries = added(base.build?.entries, own.build?.entries);
|
|
50
|
+
const ignore = added(base.build?.ignore, own.build?.ignore);
|
|
51
|
+
const buildScreens = joined(base.build?.screens, own.build?.screens);
|
|
52
|
+
const mode = own.mode ?? base.mode;
|
|
53
|
+
const criteria = joined(base.criteria, own.criteria);
|
|
54
|
+
const packages = added(base.packages, own.packages);
|
|
55
|
+
const forbidden = added(base.forbidden, own.forbidden);
|
|
56
|
+
const accepted = added(own.accepted, base.accepted);
|
|
57
|
+
const config = {
|
|
58
|
+
...(own.$schema && { $schema: own.$schema }),
|
|
59
|
+
tool: 'loadline',
|
|
60
|
+
version: 1,
|
|
61
|
+
...(mode && { mode }),
|
|
62
|
+
...(criteria && { criteria }),
|
|
63
|
+
...(gates && {
|
|
64
|
+
gates: { ...gates, ...(screens && { screens }), ...(failOnSignals && { failOnSignals }) },
|
|
65
|
+
}),
|
|
66
|
+
...(packages && { packages }),
|
|
67
|
+
...(accepted && { accepted }),
|
|
68
|
+
...(forbidden && { forbidden }),
|
|
69
|
+
...(build && {
|
|
70
|
+
build: {
|
|
71
|
+
...build,
|
|
72
|
+
...(entries && { entries }),
|
|
73
|
+
...(ignore && { ignore }),
|
|
74
|
+
...(buildScreens && { screens: buildScreens }),
|
|
75
|
+
},
|
|
76
|
+
}),
|
|
77
|
+
...(own.situation && { situation: own.situation }),
|
|
78
|
+
};
|
|
79
|
+
return { config, gateProblems };
|
|
80
|
+
};
|
|
81
|
+
exports.mergeConfigs = mergeConfigs;
|
|
82
|
+
/**
|
|
83
|
+
* The thresholds the page writes into the file it exports.
|
|
84
|
+
*
|
|
85
|
+
* Every one of them, normally: a file that pins all forty cannot be moved by the next release of
|
|
86
|
+
* the tool. But a file that `extends` a base already has its pins there, and writing all forty into
|
|
87
|
+
* it would override every one of the base's — the repository would stop following the base the
|
|
88
|
+
* first time somebody exported, with nothing to show it. So then only the thresholds that differ
|
|
89
|
+
* from the recommended ones go in: what was changed here, and nothing the base decides.
|
|
90
|
+
*/
|
|
91
|
+
const criteriaToWrite = (criteria, mode, inherits) => {
|
|
92
|
+
if (!inherits) {
|
|
93
|
+
return criteria;
|
|
94
|
+
}
|
|
95
|
+
const recommended = criteria_1.RECOMMENDED[mode];
|
|
96
|
+
return Object.fromEntries(Object.entries(criteria).filter(([key, value]) => recommended[key] !== value));
|
|
97
|
+
};
|
|
98
|
+
exports.criteriaToWrite = criteriaToWrite;
|