@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
|
@@ -10,13 +10,14 @@
|
|
|
10
10
|
*/
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.scanBuild = exports.exposureOf = void 0;
|
|
13
|
-
const sourcemap_1 = require("../analysis/sourcemap");
|
|
13
|
+
const sourcemap_1 = require("../analysis/sourcemap/sourcemap");
|
|
14
14
|
const format_utils_1 = require("../format/format.utils");
|
|
15
|
+
const ownership_1 = require("../format/ownership");
|
|
15
16
|
const json_utils_1 = require("../json/json.utils");
|
|
16
17
|
const catalog_1 = require("./catalog");
|
|
17
18
|
const secrets_1 = require("./secrets");
|
|
18
19
|
/** The legal comments a minifier keeps on purpose: `/*!` and anything with `@license`. */
|
|
19
|
-
const LEGAL_COMMENT = /\/\*[!*][\S
|
|
20
|
+
const LEGAL_COMMENT = /\/\*[!*][\s\S]*?\*\//g;
|
|
20
21
|
/**
|
|
21
22
|
* Licence identifiers, and how each one has to be treated.
|
|
22
23
|
*
|
|
@@ -56,7 +57,7 @@ const LICENCES = [
|
|
|
56
57
|
*/
|
|
57
58
|
const DEV_MARKERS = [
|
|
58
59
|
{ kind: 'consoleLogs', pattern: /\bconsole\.log\(/g },
|
|
59
|
-
{ kind: 'debugger', pattern: /\bdebugger\
|
|
60
|
+
{ kind: 'debugger', pattern: /\bdebugger\s*[;}]/g },
|
|
60
61
|
];
|
|
61
62
|
/**
|
|
62
63
|
* Leftovers read from the **inputs** the metafile names: a fact about what was compiled rather than
|
|
@@ -105,18 +106,17 @@ const licencesOf = (texts) => {
|
|
|
105
106
|
};
|
|
106
107
|
return [...found.values()].toSorted((a, b) => rank[a.class] - rank[b.class]);
|
|
107
108
|
};
|
|
108
|
-
|
|
109
|
-
|
|
109
|
+
/**
|
|
110
|
+
* One reader per chunk, built on first use and only for a chunk something matched in, so a build
|
|
111
|
+
* nobody has anything to attribute in pays nothing for it.
|
|
112
|
+
*/
|
|
113
|
+
const mapReaders = (texts, maps) => {
|
|
110
114
|
const readers = new Map();
|
|
111
|
-
|
|
112
|
-
* Where a position of a chunk came from, when the chunk has a map next to it. Built once per
|
|
113
|
-
* chunk and only for a chunk something matched in, so a build nobody has a leftover in pays
|
|
114
|
-
* nothing for this.
|
|
115
|
-
*/
|
|
116
|
-
const readerFor = (chunk, text) => {
|
|
115
|
+
return (chunk) => {
|
|
117
116
|
if (readers.has(chunk)) {
|
|
118
117
|
return readers.get(chunk) ?? null;
|
|
119
118
|
}
|
|
119
|
+
const text = texts.get(chunk) ?? '';
|
|
120
120
|
const map = maps.find(entry => entry.name === `${chunk}.map`);
|
|
121
121
|
let reader = null;
|
|
122
122
|
try {
|
|
@@ -151,22 +151,76 @@ const leftoversOf = (texts, modules, maps) => {
|
|
|
151
151
|
readers.set(chunk, reader);
|
|
152
152
|
return reader;
|
|
153
153
|
};
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Which package a `process.env.X` left in a chunk belongs to.
|
|
157
|
+
*
|
|
158
|
+
* With a source map, the position says it outright. Without one, the metafile still says which
|
|
159
|
+
* packages are inside that chunk, and a variable named after one of them is that package reading
|
|
160
|
+
* its own switch: `process.env.DEBUG` in a chunk carrying `debug` is the `debug` package, not a
|
|
161
|
+
* variable of the project that the build forgot to substitute. Anything else stays unattributed —
|
|
162
|
+
* guessing an author is the thing this file refuses to do everywhere else.
|
|
163
|
+
*/
|
|
164
|
+
const envOwners = (modules, readerFor) => {
|
|
165
|
+
const packagesIn = new Map();
|
|
166
|
+
for (const module of modules) {
|
|
167
|
+
const pkg = module.pkg ?? (0, format_utils_1.packageOf)(module.path);
|
|
168
|
+
if (!pkg) {
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
for (const place of module.places) {
|
|
172
|
+
const name = (0, format_utils_1.baseName)(place.chunk);
|
|
173
|
+
packagesIn.set(name, (packagesIn.get(name) ?? new Set()).add(pkg));
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return (chunk, index, match) => {
|
|
177
|
+
const source = readerFor(chunk)?.(index) ?? null;
|
|
178
|
+
if (source !== null) {
|
|
179
|
+
return (0, format_utils_1.packageOf)(source.replace(/^(?:\.\.\/)+/, ''));
|
|
180
|
+
}
|
|
181
|
+
const variable = match.replace(/^process\.env\./, '').toLowerCase();
|
|
182
|
+
const candidates = new Set([variable, variable.replaceAll('_', '-')]);
|
|
183
|
+
const inside = packagesIn.get(chunk) ?? new Set();
|
|
184
|
+
return [...inside].find(pkg => candidates.has(pkg.replace(/^@[^/]+\//, ''))) ?? null;
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
/** Average line length above which a chunk is minified: a minifier writes lines of thousands. */
|
|
188
|
+
const MINIFIED_LINE = 300;
|
|
189
|
+
/** Whether a chunk is minified, read from how long its lines are on average. */
|
|
190
|
+
const isMinified = (text) => text.length / (text.split('\n').length || 1) > MINIFIED_LINE;
|
|
191
|
+
/**
|
|
192
|
+
* Whether a match starts an indented line: in a minified chunk, that is text inside a string,
|
|
193
|
+
* because a minifier writes no line breaks and no indentation of its own. PocketBase ships its API
|
|
194
|
+
* documentation as template literals — `function (e) {↵ console.log(e.record);` — and those
|
|
195
|
+
* examples were 26 "development leftovers". Only asked of a minified chunk: in one that is not, an
|
|
196
|
+
* indented line is how real code looks.
|
|
197
|
+
*/
|
|
198
|
+
const startsIndentedLine = (text, index) => {
|
|
199
|
+
let start = index;
|
|
200
|
+
while (start > 0 && index - start < 200 && (text[start - 1] === ' ' || text[start - 1] === '\t')) {
|
|
201
|
+
start--;
|
|
202
|
+
}
|
|
203
|
+
return start < index && text[start - 1] === '\n';
|
|
204
|
+
};
|
|
205
|
+
const leftoversOf = (texts, modules, readerFor) => {
|
|
206
|
+
const found = [];
|
|
154
207
|
/**
|
|
155
208
|
* How many of a marker's matches in one chunk are the project's own, and whether that could be
|
|
156
209
|
* decided at all. Without a map the honest answer is "all of them, and I do not know whose".
|
|
157
210
|
*/
|
|
158
211
|
const countIn = (chunk, text, pattern) => {
|
|
159
|
-
const
|
|
212
|
+
const minified = isMinified(text);
|
|
213
|
+
const hits = [...text.matchAll(pattern)].filter(hit => !minified || !startsIndentedLine(text, hit.index));
|
|
160
214
|
if (hits.length === 0) {
|
|
161
215
|
return { count: 0, attributed: true };
|
|
162
216
|
}
|
|
163
|
-
const reader = readerFor(chunk
|
|
217
|
+
const reader = readerFor(chunk);
|
|
164
218
|
if (!reader) {
|
|
165
219
|
return { count: hits.length, attributed: false };
|
|
166
220
|
}
|
|
167
221
|
const mine = hits.filter(hit => {
|
|
168
222
|
const source = reader(hit.index);
|
|
169
|
-
return source !== null &&
|
|
223
|
+
return source !== null && (0, ownership_1.isOwnFile)(source.replace(/^(?:\.\.\/)+/, ''));
|
|
170
224
|
});
|
|
171
225
|
return { count: mine.length, attributed: true };
|
|
172
226
|
};
|
|
@@ -177,10 +231,11 @@ const leftoversOf = (texts, modules, maps) => {
|
|
|
177
231
|
for (const [chunk, text] of texts) {
|
|
178
232
|
const hits = countIn(chunk, text, pattern);
|
|
179
233
|
attributed &&= hits.attributed;
|
|
180
|
-
if (hits.count > 0) {
|
|
181
|
-
|
|
182
|
-
where.push(chunk);
|
|
234
|
+
if (!(hits.count > 0)) {
|
|
235
|
+
continue;
|
|
183
236
|
}
|
|
237
|
+
count += hits.count;
|
|
238
|
+
where.push(chunk);
|
|
184
239
|
}
|
|
185
240
|
if (count > 0) {
|
|
186
241
|
found.push({ kind, count, where, attributed });
|
|
@@ -231,6 +286,8 @@ const thirdPartyOf = (modules, boot) => {
|
|
|
231
286
|
})
|
|
232
287
|
.toSorted((a, b) => b.bootBytes - a.bootBytes || b.bytes - a.bytes);
|
|
233
288
|
};
|
|
289
|
+
/** An environment variable read in source: Node's way, and Vite's. */
|
|
290
|
+
const ENV_REFERENCE = /\b(?:process\.env|import\.meta\.env)\.[A-Z][\dA-Z_]{2,}/g;
|
|
234
291
|
/**
|
|
235
292
|
* What a deployed source map actually gives away.
|
|
236
293
|
*
|
|
@@ -242,39 +299,59 @@ const exposureOf = (maps) => {
|
|
|
242
299
|
if (maps.length === 0) {
|
|
243
300
|
return null;
|
|
244
301
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
302
|
+
// Every map read first: where the project starts in their paths is decided across all of them
|
|
303
|
+
// (see `projectRootsOf`), or a build written outside the project listed `excalidraw/…` in front
|
|
304
|
+
// of every one of its 702 files.
|
|
305
|
+
const read = maps.map(map => {
|
|
249
306
|
try {
|
|
250
307
|
// Both fields are checked entry by entry rather than asserted whole: the assertion
|
|
251
308
|
// made a map with one non-string in `sources` throw on the first `.includes`, and the
|
|
252
309
|
// catch below then dropped everything that map knew instead of the one bad entry.
|
|
253
310
|
const parsed = (0, json_utils_1.asRecord)(JSON.parse(map.text));
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
const contents = (0, json_utils_1.asArray)(parsed?.['sourcesContent']) ?? [];
|
|
261
|
-
hasContent ||= contents.some(content => typeof content === 'string' && content.length > 0);
|
|
262
|
-
for (const content of contents) {
|
|
263
|
-
envReferences += [...((0, json_utils_1.asText)(content) ?? '').matchAll(/\bprocess\.env\.[A-Z][\dA-Z_]{2,}/g)].length;
|
|
264
|
-
}
|
|
311
|
+
return {
|
|
312
|
+
sources: ((0, json_utils_1.asArray)(parsed?.['sources']) ?? []).map(source => (0, json_utils_1.asText)(source)),
|
|
313
|
+
contents: (0, json_utils_1.asArray)(parsed?.['sourcesContent']) ?? [],
|
|
314
|
+
};
|
|
265
315
|
}
|
|
266
316
|
catch {
|
|
267
317
|
// A map that will not parse says nothing about the build, only about the file.
|
|
318
|
+
return { sources: [], contents: [] };
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
const roots = (0, sourcemap_1.projectRootsOf)(read.map(map => map.sources.filter(source => source !== null)));
|
|
322
|
+
const paths = new Set();
|
|
323
|
+
let hasContent = false;
|
|
324
|
+
let envReferences = 0;
|
|
325
|
+
for (const [index, { sources, contents }] of read.entries()) {
|
|
326
|
+
const own = sources.map(source => source !== null && (0, ownership_1.isOwnFile)(source.replace(/^(?:\.\.\/)+/, '')));
|
|
327
|
+
for (const source of sources) {
|
|
328
|
+
if (source !== null && (0, ownership_1.isOwnFile)(source.replace(/^(?:\.\.\/)+/, ''))) {
|
|
329
|
+
// `App.vue?vue&type=script&setup=true&lang.ts` is `App.vue` again: the query is the
|
|
330
|
+
// compiler's, and counting it made one file of the project two.
|
|
331
|
+
paths.add((0, sourcemap_1.sourcePathOf)(source, roots[index] ?? '').replace(/\?.*$/, ''));
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
hasContent ||= contents.some(content => typeof content === 'string' && content.length > 0);
|
|
335
|
+
// In the project's own files only: every library checks `process.env.NODE_ENV`, and a Vue
|
|
336
|
+
// app read "394 references to environment variables" when its own code had none of those
|
|
337
|
+
// and one `import.meta.env.VITE_API_HOST`, which was not counted at all.
|
|
338
|
+
for (const [position, content] of contents.entries()) {
|
|
339
|
+
if (own[position]) {
|
|
340
|
+
envReferences += [...((0, json_utils_1.asText)(content) ?? '').matchAll(ENV_REFERENCE)].length;
|
|
341
|
+
}
|
|
268
342
|
}
|
|
269
343
|
}
|
|
270
344
|
return { maps: maps.length, ownFiles: paths.size, hasContent, paths: [...paths], envReferences };
|
|
271
345
|
};
|
|
272
346
|
exports.exposureOf = exposureOf;
|
|
273
|
-
const scanBuild = (input) =>
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
347
|
+
const scanBuild = (input) => {
|
|
348
|
+
const readerFor = mapReaders(input.texts, input.maps);
|
|
349
|
+
return {
|
|
350
|
+
secrets: (0, secrets_1.findSecrets)(input.texts, envOwners(input.modules, readerFor)),
|
|
351
|
+
leftovers: leftoversOf(input.texts, input.modules, readerFor),
|
|
352
|
+
licences: licencesOf(input.texts),
|
|
353
|
+
thirdParty: thirdPartyOf(input.modules, input.boot),
|
|
354
|
+
exposure: (0, exports.exposureOf)(input.maps),
|
|
355
|
+
};
|
|
356
|
+
};
|
|
280
357
|
exports.scanBuild = scanBuild;
|
|
Binary file
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* What is said about a `situation` block that got something wrong, in both languages of the report.
|
|
4
|
+
*
|
|
5
|
+
* Here and not in `config/config-text.ts` with the rest of the file's problems, although they are
|
|
6
|
+
* printed alongside them: the reader of the answers lives in this folder, and borrowing its words
|
|
7
|
+
* from `config` closed a loop — `config` reads the answers through this folder, the signals read
|
|
8
|
+
* them too, and `config` names the signals. Its own words are the only thing it needed from there.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.SITUATION_TEXT = void 0;
|
|
12
|
+
exports.SITUATION_TEXT = {
|
|
13
|
+
en: {
|
|
14
|
+
unknownAnswer: (key, given) => `Unknown answer in "situation.${key}": ${given}. It counts as unanswered.`,
|
|
15
|
+
badSituationNumber: (key, limit) => `"situation.${key}" is not a number between 0 and ${limit}. It is ignored.`,
|
|
16
|
+
badAnsweredAt: given => `"situation.answeredAt" is not a YYYY-MM-DD date: ${given}. It is ignored.`,
|
|
17
|
+
},
|
|
18
|
+
es: {
|
|
19
|
+
unknownAnswer: (key, given) => `Respuesta desconocida en "situation.${key}": ${given}. Cuenta como sin responder.`,
|
|
20
|
+
badSituationNumber: (key, limit) => `"situation.${key}" no es un número entre 0 y ${limit}. Se ignora.`,
|
|
21
|
+
badAnsweredAt: given => `"situation.answeredAt" no es una fecha AAAA-MM-DD: ${given}. Se ignora.`,
|
|
22
|
+
},
|
|
23
|
+
};
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.hasSituation = exports.isStaleSituation = exports.SITUATION_FRESH_DAYS = exports.readSituation = exports.importsChannel = exports.sessionBreadth = exports.WIDE_SESSION_SCREENS = exports.cascadeExposure = exports.LOW_EXPOSURE = exports.HIGH_EXPOSURE = exports.invalidationsPerWeek = exports.returningShare = exports.deploysPerWeek = exports.unanswered = exports.answeredCount = exports.QUESTIONS = exports.EMPTY_SITUATION = void 0;
|
|
18
|
+
const situation_text_1 = require("./situation-text");
|
|
18
19
|
/** Nobody has answered anything. It is also what a report with no `loadline.json` runs on. */
|
|
19
20
|
exports.EMPTY_SITUATION = {
|
|
20
21
|
navigation: 'unknown',
|
|
@@ -174,10 +175,9 @@ exports.importsChannel = importsChannel;
|
|
|
174
175
|
const OPTIONS = new Map(exports.QUESTIONS.map(question => [question.key, new Set([...question.options, 'unknown'])]));
|
|
175
176
|
const RAW_LIMITS = { screensPerSession: 1000, deploysPerWeek: 1000, returningPct: 100 };
|
|
176
177
|
const readNumber = (value, key) => {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
return value;
|
|
178
|
+
return typeof value !== 'number' || !Number.isFinite(value) || value < 0 || value > (RAW_LIMITS[key] ?? 0)
|
|
179
|
+
? null
|
|
180
|
+
: value;
|
|
181
181
|
};
|
|
182
182
|
const readText = (value) => typeof value === 'string' && value.trim().length > 0 ? value.trim() : null;
|
|
183
183
|
const DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
@@ -188,10 +188,11 @@ const DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
|
188
188
|
* acceptances make and for the same reason: the failure to avoid is a typo silently reading as an
|
|
189
189
|
* answer, because an answer is the only thing here that can move a colour.
|
|
190
190
|
*/
|
|
191
|
-
const readSituation = (value) => {
|
|
191
|
+
const readSituation = (value, lang = 'en') => {
|
|
192
192
|
if (!value || typeof value !== 'object') {
|
|
193
193
|
return { situation: exports.EMPTY_SITUATION, problems: [] };
|
|
194
194
|
}
|
|
195
|
+
const t = situation_text_1.SITUATION_TEXT[lang];
|
|
195
196
|
const raw = value;
|
|
196
197
|
const problems = [];
|
|
197
198
|
const situation = { ...exports.EMPTY_SITUATION };
|
|
@@ -201,7 +202,7 @@ const readSituation = (value) => {
|
|
|
201
202
|
continue;
|
|
202
203
|
}
|
|
203
204
|
if (typeof answer !== 'string' || !OPTIONS.get(question.key)?.has(answer)) {
|
|
204
|
-
problems.push(
|
|
205
|
+
problems.push(t.unknownAnswer(question.key, JSON.stringify(answer)));
|
|
205
206
|
continue;
|
|
206
207
|
}
|
|
207
208
|
// The five fields are five different string unions and the loop knows the key only as one
|
|
@@ -216,7 +217,7 @@ const readSituation = (value) => {
|
|
|
216
217
|
}
|
|
217
218
|
const number = readNumber(given, key);
|
|
218
219
|
if (number === null) {
|
|
219
|
-
problems.push(
|
|
220
|
+
problems.push(t.badSituationNumber(key, RAW_LIMITS[key] ?? 0));
|
|
220
221
|
continue;
|
|
221
222
|
}
|
|
222
223
|
situation[key] = number;
|
|
@@ -225,7 +226,7 @@ const readSituation = (value) => {
|
|
|
225
226
|
situation.answeredBy = readText(raw['answeredBy']);
|
|
226
227
|
const answeredAt = readText(raw['answeredAt']);
|
|
227
228
|
if (answeredAt !== null && !DATE.test(answeredAt)) {
|
|
228
|
-
problems.push(
|
|
229
|
+
problems.push(t.badAnsweredAt(answeredAt));
|
|
229
230
|
}
|
|
230
231
|
else {
|
|
231
232
|
situation.answeredAt = answeredAt;
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* of the same report far more than as an absolute.
|
|
28
28
|
*/
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.formatMs = exports.timingsOf = exports.timingOf = exports.PROFILE_IDS = exports.PROFILES = void 0;
|
|
30
|
+
exports.formatMs = exports.timingsOf = exports.timingOf = exports.scriptMsOf = exports.PROFILE_IDS = exports.PROFILES = void 0;
|
|
31
31
|
const KB = 1024;
|
|
32
32
|
/** Bits per second to bytes per second, with the usual ~10 % of protocol overhead taken off. */
|
|
33
33
|
const throughput = (mbps) => Math.round(((mbps * 1_000_000) / 8) * 0.9);
|
|
@@ -53,13 +53,16 @@ exports.PROFILE_IDS = ['slow4g', 'fast4g', 'cable'];
|
|
|
53
53
|
* three at once instead of flattening them into one number. `null` keeps the
|
|
54
54
|
* profiles exactly as they are defined above.
|
|
55
55
|
*/
|
|
56
|
+
/** Parse and compile of this much raw JavaScript, by the coefficient above. */
|
|
57
|
+
const scriptMsOf = (rawBytes) => (rawBytes / KB) * MS_PER_RAW_KB;
|
|
58
|
+
exports.scriptMsOf = scriptMsOf;
|
|
56
59
|
const timingOf = (bytes, rawBytes, waves, profile, latency = null) => {
|
|
57
60
|
// Scaled, not replaced: the three profiles differ in latency as much as in throughput, and a
|
|
58
61
|
// single figure applied to all of them would say a cable connection costs 150 ms per round trip.
|
|
59
62
|
const scale = latency === null ? 1 : latency / exports.PROFILES.slow4g.latencyMs;
|
|
60
63
|
const latencyMs = profile.latencyMs * scale * Math.max(1, waves);
|
|
61
64
|
const transferMs = (bytes / profile.bytesPerSecond) * 1000;
|
|
62
|
-
const scriptMs = (
|
|
65
|
+
const scriptMs = (0, exports.scriptMsOf)(rawBytes);
|
|
63
66
|
return {
|
|
64
67
|
profile: profile.id,
|
|
65
68
|
transferMs: Math.round(transferMs),
|
|
@@ -22,13 +22,34 @@
|
|
|
22
22
|
* paying for it.
|
|
23
23
|
*/
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.simulateDefer = void 0;
|
|
25
|
+
exports.simulateDefer = exports.blindBoot = exports.opaqueBootChunks = void 0;
|
|
26
26
|
const format_utils_1 = require("../format/format.utils");
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
28
|
+
* The bootstrap chunks whose inside is not known. That is a folder read without source maps, where
|
|
29
|
+
* what a chunk weighs is known and what it holds is not — and only that: a chunk holding no file of
|
|
30
|
+
* the project, like esbuild's runtime helpers, is known to hold none. See `undescribedChunks`.
|
|
30
31
|
*/
|
|
31
|
-
const
|
|
32
|
+
const opaqueBootChunks = (analysis) => {
|
|
33
|
+
const undescribed = new Set(analysis.undescribedChunks);
|
|
34
|
+
return analysis.bootChunks.filter(chunk => undescribed.has(chunk));
|
|
35
|
+
};
|
|
36
|
+
exports.opaqueBootChunks = opaqueBootChunks;
|
|
37
|
+
/**
|
|
38
|
+
* No chunk of the bootstrap says what is inside it: the folder came without source maps. What is
|
|
39
|
+
* said about the whole report — "no source maps here", "no saving can be measured" — is said on this,
|
|
40
|
+
* not on one chunk missing its map. Vite writes no map for the 84 bytes of `plugin-vue:export-helper`,
|
|
41
|
+
* and a folder with sixteen maps was announced as having none.
|
|
42
|
+
*/
|
|
43
|
+
const blindBoot = (analysis) => analysis.bootChunks.length > 0 && (0, exports.opaqueBootChunks)(analysis).length === analysis.bootChunks.length;
|
|
44
|
+
exports.blindBoot = blindBoot;
|
|
45
|
+
/**
|
|
46
|
+
* @param name a package name, a project folder as the breakdown spells it, or a source
|
|
47
|
+
* path. It is matched in that order, which is the order of how specific the
|
|
48
|
+
* answer is.
|
|
49
|
+
* @param importsKnown whether the build says which file imports which: a stats file does, a build
|
|
50
|
+
* folder read on its own does not. See `measurable`.
|
|
51
|
+
*/
|
|
52
|
+
const simulateDefer = (analysis, name, importsKnown = true) => {
|
|
32
53
|
const insights = analysis.insights();
|
|
33
54
|
const byBucket = insights.filesByBucket.get(name);
|
|
34
55
|
const kind = byBucket
|
|
@@ -63,6 +84,10 @@ const simulateDefer = (analysis, name) => {
|
|
|
63
84
|
after: Math.max(0, insights.bootTotal - saved),
|
|
64
85
|
screens: importers.map(file => screenOf.get(file)).filter(label => label !== undefined),
|
|
65
86
|
importers,
|
|
87
|
+
// Not finding the name is an answer only when every bootstrap chunk could have shown it.
|
|
88
|
+
// Without source maps "0 B" read as "deferring this saves nothing", of a package that the
|
|
89
|
+
// same build read with its stats.json showed inside the bootstrap.
|
|
90
|
+
measurable: importsKnown && (files.length > 0 || (0, exports.opaqueBootChunks)(analysis).length === 0),
|
|
66
91
|
};
|
|
67
92
|
};
|
|
68
93
|
exports.simulateDefer = simulateDefer;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Which files of the project import a package, read from the sources the maps carry.
|
|
4
|
+
*
|
|
5
|
+
* A build folder records which chunk holds what and never which file imports which: the bundler
|
|
6
|
+
* erased the `import` statements. The maps keep the original text of every file, though, and the
|
|
7
|
+
* statement is in it. So for a Vite, Rollup or Nuxt build — which write no stats file — "why is
|
|
8
|
+
* this package in my first load, and where would I cut it?" had the answer "the chain needs the
|
|
9
|
+
* stats.json" while the line that brings the package in was sitting in the folder.
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.importersInSources = void 0;
|
|
13
|
+
const sourcemap_1 = require("../analysis/sourcemap/sourcemap");
|
|
14
|
+
const ownership_1 = require("../format/ownership");
|
|
15
|
+
const json_utils_1 = require("../json/json.utils");
|
|
16
|
+
/** A package name as a literal inside a pattern: `@scope/name` and dots taken literally. */
|
|
17
|
+
const escape = (name) => name.replaceAll(/[$()*+.?[\\\]^{|}]/g, String.raw `\$&`);
|
|
18
|
+
/**
|
|
19
|
+
* `from 'pkg'`, `import 'pkg'` and `require('pkg')`, with or without a subpath: the imports that
|
|
20
|
+
* bring a package in with the file. Not `import('pkg')`, which is already the cut — Excalidraw's
|
|
21
|
+
* clipboard and dialog both use one, and named next to the one static import that does put mermaid
|
|
22
|
+
* in the first load, they sent the reader to the two files with nothing to change.
|
|
23
|
+
*
|
|
24
|
+
* Built per name, anchored on the quote, so it cannot wander across a file. `String.raw`, so every
|
|
25
|
+
* backslash below is one the pattern sees.
|
|
26
|
+
*/
|
|
27
|
+
const QUOTE = '[\'"`]';
|
|
28
|
+
const NOT_QUOTE = String.raw `[^'"${'`'}\s]`;
|
|
29
|
+
const importOf = (name) => new RegExp(`${String.raw `(?:\bfrom|\bimport|\brequire\s*\()\s*` + QUOTE + escape(name)}(?:/${NOT_QUOTE}*)?${QUOTE}`);
|
|
30
|
+
const importersInSources = (maps, name) => {
|
|
31
|
+
const pattern = importOf(name);
|
|
32
|
+
const read = maps.map(map => {
|
|
33
|
+
try {
|
|
34
|
+
const parsed = (0, json_utils_1.asRecord)(JSON.parse(map.text));
|
|
35
|
+
return {
|
|
36
|
+
sources: ((0, json_utils_1.asArray)(parsed?.['sources']) ?? []).map(source => (0, json_utils_1.asText)(source) ?? ''),
|
|
37
|
+
contents: ((0, json_utils_1.asArray)(parsed?.['sourcesContent']) ?? []).map(content => (0, json_utils_1.asText)(content)),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return { sources: [], contents: [] };
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
const roots = (0, sourcemap_1.projectRootsOf)(read.map(map => map.sources));
|
|
45
|
+
const found = new Set();
|
|
46
|
+
for (const [index, { sources, contents }] of read.entries()) {
|
|
47
|
+
for (const [position, source] of sources.entries()) {
|
|
48
|
+
const content = contents[position];
|
|
49
|
+
if ((0, ownership_1.isDependency)(source) || !content || !pattern.test(content)) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
// The compiler's query is not a file of its own: `App.vue?vue&type=script` is `App.vue`.
|
|
53
|
+
found.add((0, sourcemap_1.sourcePathOf)(source, roots[index] ?? '').replace(/\?.*$/, ''));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return [...found].toSorted((a, b) => a.localeCompare(b));
|
|
57
|
+
};
|
|
58
|
+
exports.importersInSources = importersInSources;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* "Why is this package in my first load, and where would I cut it out?"
|
|
4
|
+
*
|
|
5
|
+
* The page answers it in the search, one click at a time; a terminal, a pipeline or an agent had
|
|
6
|
+
* no way to ask. Nothing here is new arithmetic: the chain is the one the analysis already walks,
|
|
7
|
+
* and what cutting it would save is `simulateDefer`. What this adds is the one line in between —
|
|
8
|
+
* the file of yours where the `import()` would go — because a chain of nine steps that ends in a
|
|
9
|
+
* package nobody imports directly leaves that to be worked out by hand.
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.explainWhy = void 0;
|
|
13
|
+
const format_utils_1 = require("../format/format.utils");
|
|
14
|
+
const defer_1 = require("./defer");
|
|
15
|
+
/** The files of the build a name stands for: a package, a project folder or one file. */
|
|
16
|
+
const filesOf = (analysis, name) => analysis.modules.filter(module => module.path === name || module.pkg === name).map(module => module.path);
|
|
17
|
+
/** The shortest chain from the entry to any of the files, lazy boundaries included. */
|
|
18
|
+
const anyChain = (analysis, files) => {
|
|
19
|
+
let best = null;
|
|
20
|
+
for (const file of files) {
|
|
21
|
+
const chain = analysis.chainTo(file);
|
|
22
|
+
if (chain && (!best || chain.length < best.length)) {
|
|
23
|
+
best = chain;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return best;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* The last own file before the target, read on the raw chain — after `chainSteps` a scoped package
|
|
30
|
+
* and a path look alike. Packages in between are skipped: when `firebase` pulls `@firebase/app`
|
|
31
|
+
* in, the `import()` goes where your code imports `firebase`, not inside `node_modules`.
|
|
32
|
+
*/
|
|
33
|
+
const cutOf = (chain) => chain.slice(0, -1).findLast(file => !(0, format_utils_1.packageOf)(file)) ?? null;
|
|
34
|
+
/** The project's own files in the first load. */
|
|
35
|
+
const bootOwnFiles = (analysis) => {
|
|
36
|
+
const boot = new Set(analysis.bootChunks);
|
|
37
|
+
return new Set(analysis.modules
|
|
38
|
+
.filter(module => !module.pkg && module.places.some(place => boot.has(place.chunk)))
|
|
39
|
+
.map(module => module.path));
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* @param importsKnown whether the build says which file imports which. See `simulateDefer`.
|
|
43
|
+
* @param sourceImporters for a build that does not: the files of the project whose own source
|
|
44
|
+
* imports a name, read out of the maps. See `importersInSources`.
|
|
45
|
+
*/
|
|
46
|
+
const explainWhy = (analysis, name, importsKnown = true, sourceImporters = null) => {
|
|
47
|
+
const defer = (0, defer_1.simulateDefer)(analysis, name, importsKnown);
|
|
48
|
+
const result = (reach, chain) => {
|
|
49
|
+
const steps = chain ? (0, format_utils_1.chainSteps)(chain) : [];
|
|
50
|
+
const cut = chain ? cutOf(chain) : null;
|
|
51
|
+
const via = cut === null ? null : (steps[steps.indexOf(cut) + 1] ?? null);
|
|
52
|
+
const viaDefer = via === null ? null : via === name ? defer : (0, defer_1.simulateDefer)(analysis, via);
|
|
53
|
+
const bootFiles = bootOwnFiles(analysis);
|
|
54
|
+
const alsoIn = cut && viaDefer ? viaDefer.importers.filter(file => file !== cut && bootFiles.has(file)) : [];
|
|
55
|
+
const savesEverywhere = viaDefer?.saved ?? 0;
|
|
56
|
+
const saves = alsoIn.length > 0 ? 0 : savesEverywhere;
|
|
57
|
+
return { target: name, reach, steps, cut, via, saves, alsoIn, savesEverywhere, defer };
|
|
58
|
+
};
|
|
59
|
+
if (!importsKnown) {
|
|
60
|
+
if (defer.files.length > 0 || filesOf(analysis, name).length > 0) {
|
|
61
|
+
// Nothing of it in the first load: whatever the chain, it is not what anybody pays first.
|
|
62
|
+
if (defer.weight === 0) {
|
|
63
|
+
return result('deferred', null);
|
|
64
|
+
}
|
|
65
|
+
const readers = (sourceImporters?.(name) ?? []).filter(file => bootOwnFiles(analysis).has(file));
|
|
66
|
+
const [first, ...rest] = readers;
|
|
67
|
+
if (first) {
|
|
68
|
+
// The saving cannot be walked without the edges; what it weighs in the first load is
|
|
69
|
+
// the most an `import()` in every one of these could take off.
|
|
70
|
+
return {
|
|
71
|
+
...result('sourced', null),
|
|
72
|
+
cut: first,
|
|
73
|
+
alsoIn: rest,
|
|
74
|
+
via: name,
|
|
75
|
+
savesEverywhere: defer.weight,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return result('unchained', null);
|
|
79
|
+
}
|
|
80
|
+
return result((0, defer_1.opaqueBootChunks)(analysis).length > 0 ? 'unknown' : 'absent', null);
|
|
81
|
+
}
|
|
82
|
+
if (!defer.measurable) {
|
|
83
|
+
return result('unknown', null);
|
|
84
|
+
}
|
|
85
|
+
// Static imports only: the chain that makes it part of the first load, not merely one that
|
|
86
|
+
// reaches it. For a package it is the walk the analysis already did.
|
|
87
|
+
const boot = analysis.bootChains.get(name);
|
|
88
|
+
if (boot) {
|
|
89
|
+
return result('boot', boot);
|
|
90
|
+
}
|
|
91
|
+
const files = defer.files.length > 0 ? defer.files : filesOf(analysis, name);
|
|
92
|
+
if (files.length === 0) {
|
|
93
|
+
return result('absent', null);
|
|
94
|
+
}
|
|
95
|
+
const chain = anyChain(analysis, files);
|
|
96
|
+
if (!chain) {
|
|
97
|
+
return result('unreached', null);
|
|
98
|
+
}
|
|
99
|
+
// A file of yours, or a folder, in the bootstrap: `bootChains` only keys packages.
|
|
100
|
+
return result(defer.weight > 0 ? 'boot' : 'lazy', chain);
|
|
101
|
+
};
|
|
102
|
+
exports.explainWhy = explainWhy;
|
|
@@ -24,10 +24,7 @@ const foreignMessage = (format, t) => {
|
|
|
24
24
|
if (format === 'viteManifest') {
|
|
25
25
|
return t.errViteManifest;
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
return t.errVisualizer;
|
|
29
|
-
}
|
|
30
|
-
return t.errNotMetafile;
|
|
27
|
+
return format === 'visualizer' ? t.errVisualizer : t.errNotMetafile;
|
|
31
28
|
};
|
|
32
29
|
exports.foreignMessage = foreignMessage;
|
|
33
30
|
/**
|