@code-pushup/lighthouse-plugin 0.56.0 → 0.57.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/package.json +8 -7
- package/src/index.d.ts +6 -6
- package/src/index.js +7 -0
- package/src/index.js.map +1 -0
- package/src/lib/constants.js +8 -0
- package/src/lib/constants.js.map +1 -0
- package/src/lib/lighthouse-plugin.d.ts +1 -1
- package/src/lib/lighthouse-plugin.js +27 -0
- package/src/lib/lighthouse-plugin.js.map +1 -0
- package/src/lib/normalize-flags.d.ts +2 -2
- package/src/lib/normalize-flags.js +55 -0
- package/src/lib/normalize-flags.js.map +1 -0
- package/src/lib/runner/constants.js +78 -0
- package/src/lib/runner/constants.js.map +1 -0
- package/src/lib/runner/details/details.js +40 -0
- package/src/lib/runner/details/details.js.map +1 -0
- package/src/lib/runner/details/item-value.js +120 -0
- package/src/lib/runner/details/item-value.js.map +1 -0
- package/src/lib/runner/details/opportunity.type.js +49 -0
- package/src/lib/runner/details/opportunity.type.js.map +1 -0
- package/src/lib/runner/details/table.type.js +42 -0
- package/src/lib/runner/details/table.type.js.map +1 -0
- package/src/lib/runner/details/utils.js +7 -0
- package/src/lib/runner/details/utils.js.map +1 -0
- package/src/lib/runner/runner.d.ts +1 -1
- package/src/lib/runner/runner.js +28 -0
- package/src/lib/runner/runner.js.map +1 -0
- package/src/lib/runner/types.d.ts +1 -1
- package/src/lib/runner/types.js +2 -0
- package/src/lib/runner/types.js.map +1 -0
- package/src/lib/runner/utils.d.ts +2 -2
- package/src/lib/runner/utils.js +98 -0
- package/src/lib/runner/utils.js.map +1 -0
- package/src/lib/types.d.ts +2 -2
- package/src/lib/types.js +2 -0
- package/src/lib/types.js.map +1 -0
- package/src/lib/utils.d.ts +1 -1
- package/src/lib/utils.js +77 -0
- package/src/lib/utils.js.map +1 -0
- package/index.js +0 -1632
- package/src/lib/runner/index.d.ts +0 -3
package/index.js
DELETED
|
@@ -1,1632 +0,0 @@
|
|
|
1
|
-
// packages/plugin-lighthouse/package.json
|
|
2
|
-
var name = "@code-pushup/lighthouse-plugin";
|
|
3
|
-
var version = "0.56.0";
|
|
4
|
-
|
|
5
|
-
// packages/plugin-lighthouse/src/lib/constants.ts
|
|
6
|
-
import { DEFAULT_FLAGS } from "chrome-launcher/dist/flags.js";
|
|
7
|
-
import { join } from "node:path";
|
|
8
|
-
|
|
9
|
-
// packages/models/src/lib/implementation/schemas.ts
|
|
10
|
-
import { MATERIAL_ICONS } from "vscode-material-icons";
|
|
11
|
-
import { z } from "zod";
|
|
12
|
-
|
|
13
|
-
// packages/models/src/lib/implementation/limits.ts
|
|
14
|
-
var MAX_SLUG_LENGTH = 128;
|
|
15
|
-
var MAX_TITLE_LENGTH = 256;
|
|
16
|
-
var MAX_DESCRIPTION_LENGTH = 65536;
|
|
17
|
-
var MAX_ISSUE_MESSAGE_LENGTH = 1024;
|
|
18
|
-
|
|
19
|
-
// packages/models/src/lib/implementation/utils.ts
|
|
20
|
-
var slugRegex = /^[a-z\d]+(?:-[a-z\d]+)*$/;
|
|
21
|
-
var filenameRegex = /^(?!.*[ \\/:*?"<>|]).+$/;
|
|
22
|
-
function hasDuplicateStrings(strings) {
|
|
23
|
-
const sortedStrings = strings.toSorted();
|
|
24
|
-
const duplStrings = sortedStrings.filter(
|
|
25
|
-
(item, index) => index !== 0 && item === sortedStrings[index - 1]
|
|
26
|
-
);
|
|
27
|
-
return duplStrings.length === 0 ? false : [...new Set(duplStrings)];
|
|
28
|
-
}
|
|
29
|
-
function hasMissingStrings(toCheck, existing) {
|
|
30
|
-
const nonExisting = toCheck.filter((s) => !existing.includes(s));
|
|
31
|
-
return nonExisting.length === 0 ? false : nonExisting;
|
|
32
|
-
}
|
|
33
|
-
function errorItems(items, transform = (itemArr) => itemArr.join(", ")) {
|
|
34
|
-
return transform(items || []);
|
|
35
|
-
}
|
|
36
|
-
function exists(value) {
|
|
37
|
-
return value != null;
|
|
38
|
-
}
|
|
39
|
-
function getMissingRefsForCategories(categories2, plugins) {
|
|
40
|
-
if (!categories2 || categories2.length === 0) {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
const auditRefsFromCategory = categories2.flatMap(
|
|
44
|
-
({ refs }) => refs.filter(({ type }) => type === "audit").map(({ plugin, slug }) => `${plugin}/${slug}`)
|
|
45
|
-
);
|
|
46
|
-
const auditRefsFromPlugins = plugins.flatMap(
|
|
47
|
-
({ audits: audits2, slug: pluginSlug }) => audits2.map(({ slug }) => `${pluginSlug}/${slug}`)
|
|
48
|
-
);
|
|
49
|
-
const missingAuditRefs = hasMissingStrings(
|
|
50
|
-
auditRefsFromCategory,
|
|
51
|
-
auditRefsFromPlugins
|
|
52
|
-
);
|
|
53
|
-
const groupRefsFromCategory = categories2.flatMap(
|
|
54
|
-
({ refs }) => refs.filter(({ type }) => type === "group").map(({ plugin, slug }) => `${plugin}#${slug} (group)`)
|
|
55
|
-
);
|
|
56
|
-
const groupRefsFromPlugins = plugins.flatMap(
|
|
57
|
-
({ groups, slug: pluginSlug }) => Array.isArray(groups) ? groups.map(({ slug }) => `${pluginSlug}#${slug} (group)`) : []
|
|
58
|
-
);
|
|
59
|
-
const missingGroupRefs = hasMissingStrings(
|
|
60
|
-
groupRefsFromCategory,
|
|
61
|
-
groupRefsFromPlugins
|
|
62
|
-
);
|
|
63
|
-
const missingRefs = [missingAuditRefs, missingGroupRefs].filter((refs) => Array.isArray(refs) && refs.length > 0).flat();
|
|
64
|
-
return missingRefs.length > 0 ? missingRefs : false;
|
|
65
|
-
}
|
|
66
|
-
function missingRefsForCategoriesErrorMsg(categories2, plugins) {
|
|
67
|
-
const missingRefs = getMissingRefsForCategories(categories2, plugins);
|
|
68
|
-
return `The following category references need to point to an audit or group: ${errorItems(
|
|
69
|
-
missingRefs
|
|
70
|
-
)}`;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// packages/models/src/lib/implementation/schemas.ts
|
|
74
|
-
var tableCellValueSchema = z.union([z.string(), z.number(), z.boolean(), z.null()]).default(null);
|
|
75
|
-
function executionMetaSchema(options = {
|
|
76
|
-
descriptionDate: "Execution start date and time",
|
|
77
|
-
descriptionDuration: "Execution duration in ms"
|
|
78
|
-
}) {
|
|
79
|
-
return z.object({
|
|
80
|
-
date: z.string({ description: options.descriptionDate }),
|
|
81
|
-
duration: z.number({ description: options.descriptionDuration })
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
var slugSchema = z.string({ description: "Unique ID (human-readable, URL-safe)" }).regex(slugRegex, {
|
|
85
|
-
message: "The slug has to follow the pattern [0-9a-z] followed by multiple optional groups of -[0-9a-z]. e.g. my-slug"
|
|
86
|
-
}).max(MAX_SLUG_LENGTH, {
|
|
87
|
-
message: `slug can be max ${MAX_SLUG_LENGTH} characters long`
|
|
88
|
-
});
|
|
89
|
-
var descriptionSchema = z.string({ description: "Description (markdown)" }).max(MAX_DESCRIPTION_LENGTH).optional();
|
|
90
|
-
var urlSchema = z.string().url();
|
|
91
|
-
var docsUrlSchema = urlSchema.optional().or(z.literal("")).describe("Documentation site");
|
|
92
|
-
var titleSchema = z.string({ description: "Descriptive name" }).max(MAX_TITLE_LENGTH);
|
|
93
|
-
var scoreSchema = z.number({
|
|
94
|
-
description: "Value between 0 and 1"
|
|
95
|
-
}).min(0).max(1);
|
|
96
|
-
function metaSchema(options) {
|
|
97
|
-
const {
|
|
98
|
-
descriptionDescription,
|
|
99
|
-
titleDescription,
|
|
100
|
-
docsUrlDescription,
|
|
101
|
-
description
|
|
102
|
-
} = options ?? {};
|
|
103
|
-
return z.object(
|
|
104
|
-
{
|
|
105
|
-
title: titleDescription ? titleSchema.describe(titleDescription) : titleSchema,
|
|
106
|
-
description: descriptionDescription ? descriptionSchema.describe(descriptionDescription) : descriptionSchema,
|
|
107
|
-
docsUrl: docsUrlDescription ? docsUrlSchema.describe(docsUrlDescription) : docsUrlSchema
|
|
108
|
-
},
|
|
109
|
-
{ description }
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
var filePathSchema = z.string().trim().min(1, { message: "path is invalid" });
|
|
113
|
-
var fileNameSchema = z.string().trim().regex(filenameRegex, {
|
|
114
|
-
message: `The filename has to be valid`
|
|
115
|
-
}).min(1, { message: "file name is invalid" });
|
|
116
|
-
var positiveIntSchema = z.number().int().positive();
|
|
117
|
-
var nonnegativeNumberSchema = z.number().nonnegative();
|
|
118
|
-
function packageVersionSchema(options) {
|
|
119
|
-
const { versionDescription = "NPM version of the package", required } = options ?? {};
|
|
120
|
-
const packageSchema = z.string({ description: "NPM package name" });
|
|
121
|
-
const versionSchema = z.string({ description: versionDescription });
|
|
122
|
-
return z.object(
|
|
123
|
-
{
|
|
124
|
-
packageName: required ? packageSchema : packageSchema.optional(),
|
|
125
|
-
version: required ? versionSchema : versionSchema.optional()
|
|
126
|
-
},
|
|
127
|
-
{ description: "NPM package name and version of a published package" }
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
var weightSchema = nonnegativeNumberSchema.describe(
|
|
131
|
-
"Coefficient for the given score (use weight 0 if only for display)"
|
|
132
|
-
);
|
|
133
|
-
function weightedRefSchema(description, slugDescription) {
|
|
134
|
-
return z.object(
|
|
135
|
-
{
|
|
136
|
-
slug: slugSchema.describe(slugDescription),
|
|
137
|
-
weight: weightSchema.describe("Weight used to calculate score")
|
|
138
|
-
},
|
|
139
|
-
{ description }
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
function scorableSchema(description, refSchema, duplicateCheckFn, duplicateMessageFn) {
|
|
143
|
-
return z.object(
|
|
144
|
-
{
|
|
145
|
-
slug: slugSchema.describe('Human-readable unique ID, e.g. "performance"'),
|
|
146
|
-
refs: z.array(refSchema).min(1).refine(
|
|
147
|
-
(refs) => !duplicateCheckFn(refs),
|
|
148
|
-
(refs) => ({
|
|
149
|
-
message: duplicateMessageFn(refs)
|
|
150
|
-
})
|
|
151
|
-
).refine(hasNonZeroWeightedRef, () => ({
|
|
152
|
-
message: "In a category there has to be at least one ref with weight > 0"
|
|
153
|
-
}))
|
|
154
|
-
},
|
|
155
|
-
{ description }
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
var materialIconSchema = z.enum(MATERIAL_ICONS, {
|
|
159
|
-
description: "Icon from VSCode Material Icons extension"
|
|
160
|
-
});
|
|
161
|
-
function hasNonZeroWeightedRef(refs) {
|
|
162
|
-
return refs.reduce((acc, { weight }) => weight + acc, 0) !== 0;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// packages/models/src/lib/source.ts
|
|
166
|
-
import { z as z2 } from "zod";
|
|
167
|
-
var sourceFileLocationSchema = z2.object(
|
|
168
|
-
{
|
|
169
|
-
file: filePathSchema.describe("Relative path to source file in Git repo"),
|
|
170
|
-
position: z2.object(
|
|
171
|
-
{
|
|
172
|
-
startLine: positiveIntSchema.describe("Start line"),
|
|
173
|
-
startColumn: positiveIntSchema.describe("Start column").optional(),
|
|
174
|
-
endLine: positiveIntSchema.describe("End line").optional(),
|
|
175
|
-
endColumn: positiveIntSchema.describe("End column").optional()
|
|
176
|
-
},
|
|
177
|
-
{ description: "Location in file" }
|
|
178
|
-
).optional()
|
|
179
|
-
},
|
|
180
|
-
{ description: "Source file location" }
|
|
181
|
-
);
|
|
182
|
-
|
|
183
|
-
// packages/models/src/lib/audit.ts
|
|
184
|
-
import { z as z3 } from "zod";
|
|
185
|
-
var auditSchema = z3.object({
|
|
186
|
-
slug: slugSchema.describe("ID (unique within plugin)")
|
|
187
|
-
}).merge(
|
|
188
|
-
metaSchema({
|
|
189
|
-
titleDescription: "Descriptive name",
|
|
190
|
-
descriptionDescription: "Description (markdown)",
|
|
191
|
-
docsUrlDescription: "Link to documentation (rationale)",
|
|
192
|
-
description: "List of scorable metrics for the given plugin"
|
|
193
|
-
})
|
|
194
|
-
);
|
|
195
|
-
var pluginAuditsSchema = z3.array(auditSchema, {
|
|
196
|
-
description: "List of audits maintained in a plugin"
|
|
197
|
-
}).min(1).refine(
|
|
198
|
-
(auditMetadata) => !getDuplicateSlugsInAudits(auditMetadata),
|
|
199
|
-
(auditMetadata) => ({
|
|
200
|
-
message: duplicateSlugsInAuditsErrorMsg(auditMetadata)
|
|
201
|
-
})
|
|
202
|
-
);
|
|
203
|
-
function duplicateSlugsInAuditsErrorMsg(audits2) {
|
|
204
|
-
const duplicateRefs = getDuplicateSlugsInAudits(audits2);
|
|
205
|
-
return `In plugin audits the following slugs are not unique: ${errorItems(
|
|
206
|
-
duplicateRefs
|
|
207
|
-
)}`;
|
|
208
|
-
}
|
|
209
|
-
function getDuplicateSlugsInAudits(audits2) {
|
|
210
|
-
return hasDuplicateStrings(audits2.map(({ slug }) => slug));
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// packages/models/src/lib/audit-output.ts
|
|
214
|
-
import { z as z6 } from "zod";
|
|
215
|
-
|
|
216
|
-
// packages/models/src/lib/issue.ts
|
|
217
|
-
import { z as z4 } from "zod";
|
|
218
|
-
var issueSeveritySchema = z4.enum(["info", "warning", "error"], {
|
|
219
|
-
description: "Severity level"
|
|
220
|
-
});
|
|
221
|
-
var issueSchema = z4.object(
|
|
222
|
-
{
|
|
223
|
-
message: z4.string({ description: "Descriptive error message" }).max(MAX_ISSUE_MESSAGE_LENGTH),
|
|
224
|
-
severity: issueSeveritySchema,
|
|
225
|
-
source: sourceFileLocationSchema.optional()
|
|
226
|
-
},
|
|
227
|
-
{ description: "Issue information" }
|
|
228
|
-
);
|
|
229
|
-
|
|
230
|
-
// packages/models/src/lib/table.ts
|
|
231
|
-
import { z as z5 } from "zod";
|
|
232
|
-
var tableAlignmentSchema = z5.enum(["left", "center", "right"], {
|
|
233
|
-
description: "Cell alignment"
|
|
234
|
-
});
|
|
235
|
-
var tableColumnObjectSchema = z5.object({
|
|
236
|
-
key: z5.string(),
|
|
237
|
-
label: z5.string().optional(),
|
|
238
|
-
align: tableAlignmentSchema.optional()
|
|
239
|
-
});
|
|
240
|
-
var tableRowObjectSchema = z5.record(tableCellValueSchema, {
|
|
241
|
-
description: "Object row"
|
|
242
|
-
});
|
|
243
|
-
var tableRowPrimitiveSchema = z5.array(tableCellValueSchema, {
|
|
244
|
-
description: "Primitive row"
|
|
245
|
-
});
|
|
246
|
-
var tableSharedSchema = z5.object({
|
|
247
|
-
title: z5.string().optional().describe("Display title for table")
|
|
248
|
-
});
|
|
249
|
-
var tablePrimitiveSchema = tableSharedSchema.merge(
|
|
250
|
-
z5.object(
|
|
251
|
-
{
|
|
252
|
-
columns: z5.array(tableAlignmentSchema).optional(),
|
|
253
|
-
rows: z5.array(tableRowPrimitiveSchema)
|
|
254
|
-
},
|
|
255
|
-
{ description: "Table with primitive rows and optional alignment columns" }
|
|
256
|
-
)
|
|
257
|
-
);
|
|
258
|
-
var tableObjectSchema = tableSharedSchema.merge(
|
|
259
|
-
z5.object(
|
|
260
|
-
{
|
|
261
|
-
columns: z5.union([
|
|
262
|
-
z5.array(tableAlignmentSchema),
|
|
263
|
-
z5.array(tableColumnObjectSchema)
|
|
264
|
-
]).optional(),
|
|
265
|
-
rows: z5.array(tableRowObjectSchema)
|
|
266
|
-
},
|
|
267
|
-
{
|
|
268
|
-
description: "Table with object rows and optional alignment or object columns"
|
|
269
|
-
}
|
|
270
|
-
)
|
|
271
|
-
);
|
|
272
|
-
var tableSchema = (description = "Table information") => z5.union([tablePrimitiveSchema, tableObjectSchema], { description });
|
|
273
|
-
|
|
274
|
-
// packages/models/src/lib/audit-output.ts
|
|
275
|
-
var auditValueSchema = nonnegativeNumberSchema.describe("Raw numeric value");
|
|
276
|
-
var auditDisplayValueSchema = z6.string({ description: "Formatted value (e.g. '0.9 s', '2.1 MB')" }).optional();
|
|
277
|
-
var auditDetailsSchema = z6.object(
|
|
278
|
-
{
|
|
279
|
-
issues: z6.array(issueSchema, { description: "List of findings" }).optional(),
|
|
280
|
-
table: tableSchema("Table of related findings").optional()
|
|
281
|
-
},
|
|
282
|
-
{ description: "Detailed information" }
|
|
283
|
-
);
|
|
284
|
-
var auditOutputSchema = z6.object(
|
|
285
|
-
{
|
|
286
|
-
slug: slugSchema.describe("Reference to audit"),
|
|
287
|
-
displayValue: auditDisplayValueSchema,
|
|
288
|
-
value: auditValueSchema,
|
|
289
|
-
score: scoreSchema,
|
|
290
|
-
details: auditDetailsSchema.optional()
|
|
291
|
-
},
|
|
292
|
-
{ description: "Audit information" }
|
|
293
|
-
);
|
|
294
|
-
var auditOutputsSchema = z6.array(auditOutputSchema, {
|
|
295
|
-
description: "List of JSON formatted audit output emitted by the runner process of a plugin"
|
|
296
|
-
}).refine(
|
|
297
|
-
(audits2) => !getDuplicateSlugsInAudits2(audits2),
|
|
298
|
-
(audits2) => ({ message: duplicateSlugsInAuditsErrorMsg2(audits2) })
|
|
299
|
-
);
|
|
300
|
-
function duplicateSlugsInAuditsErrorMsg2(audits2) {
|
|
301
|
-
const duplicateRefs = getDuplicateSlugsInAudits2(audits2);
|
|
302
|
-
return `In plugin audits the slugs are not unique: ${errorItems(
|
|
303
|
-
duplicateRefs
|
|
304
|
-
)}`;
|
|
305
|
-
}
|
|
306
|
-
function getDuplicateSlugsInAudits2(audits2) {
|
|
307
|
-
return hasDuplicateStrings(audits2.map(({ slug }) => slug));
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
// packages/models/src/lib/category-config.ts
|
|
311
|
-
import { z as z7 } from "zod";
|
|
312
|
-
var categoryRefSchema = weightedRefSchema(
|
|
313
|
-
"Weighted references to audits and/or groups for the category",
|
|
314
|
-
"Slug of an audit or group (depending on `type`)"
|
|
315
|
-
).merge(
|
|
316
|
-
z7.object({
|
|
317
|
-
type: z7.enum(["audit", "group"], {
|
|
318
|
-
description: "Discriminant for reference kind, affects where `slug` is looked up"
|
|
319
|
-
}),
|
|
320
|
-
plugin: slugSchema.describe(
|
|
321
|
-
"Plugin slug (plugin should contain referenced audit or group)"
|
|
322
|
-
)
|
|
323
|
-
})
|
|
324
|
-
);
|
|
325
|
-
var categoryConfigSchema = scorableSchema(
|
|
326
|
-
"Category with a score calculated from audits and groups from various plugins",
|
|
327
|
-
categoryRefSchema,
|
|
328
|
-
getDuplicateRefsInCategoryMetrics,
|
|
329
|
-
duplicateRefsInCategoryMetricsErrorMsg
|
|
330
|
-
).merge(
|
|
331
|
-
metaSchema({
|
|
332
|
-
titleDescription: "Category Title",
|
|
333
|
-
docsUrlDescription: "Category docs URL",
|
|
334
|
-
descriptionDescription: "Category description",
|
|
335
|
-
description: "Meta info for category"
|
|
336
|
-
})
|
|
337
|
-
).merge(
|
|
338
|
-
z7.object({
|
|
339
|
-
isBinary: z7.boolean({
|
|
340
|
-
description: 'Is this a binary category (i.e. only a perfect score considered a "pass")?'
|
|
341
|
-
}).optional()
|
|
342
|
-
})
|
|
343
|
-
);
|
|
344
|
-
function duplicateRefsInCategoryMetricsErrorMsg(metrics) {
|
|
345
|
-
const duplicateRefs = getDuplicateRefsInCategoryMetrics(metrics);
|
|
346
|
-
return `In the categories, the following audit or group refs are duplicates: ${errorItems(
|
|
347
|
-
duplicateRefs
|
|
348
|
-
)}`;
|
|
349
|
-
}
|
|
350
|
-
function getDuplicateRefsInCategoryMetrics(metrics) {
|
|
351
|
-
return hasDuplicateStrings(
|
|
352
|
-
metrics.map(({ slug, type, plugin }) => `${type} :: ${plugin} / ${slug}`)
|
|
353
|
-
);
|
|
354
|
-
}
|
|
355
|
-
var categoriesSchema = z7.array(categoryConfigSchema, {
|
|
356
|
-
description: "Categorization of individual audits"
|
|
357
|
-
}).refine(
|
|
358
|
-
(categoryCfg) => !getDuplicateSlugCategories(categoryCfg),
|
|
359
|
-
(categoryCfg) => ({
|
|
360
|
-
message: duplicateSlugCategoriesErrorMsg(categoryCfg)
|
|
361
|
-
})
|
|
362
|
-
);
|
|
363
|
-
function duplicateSlugCategoriesErrorMsg(categories2) {
|
|
364
|
-
const duplicateStringSlugs = getDuplicateSlugCategories(categories2);
|
|
365
|
-
return `In the categories, the following slugs are duplicated: ${errorItems(
|
|
366
|
-
duplicateStringSlugs
|
|
367
|
-
)}`;
|
|
368
|
-
}
|
|
369
|
-
function getDuplicateSlugCategories(categories2) {
|
|
370
|
-
return hasDuplicateStrings(categories2.map(({ slug }) => slug));
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
// packages/models/src/lib/commit.ts
|
|
374
|
-
import { z as z8 } from "zod";
|
|
375
|
-
var commitSchema = z8.object(
|
|
376
|
-
{
|
|
377
|
-
hash: z8.string({ description: "Commit SHA (full)" }).regex(
|
|
378
|
-
/^[\da-f]{40}$/,
|
|
379
|
-
"Commit SHA should be a 40-character hexadecimal string"
|
|
380
|
-
),
|
|
381
|
-
message: z8.string({ description: "Commit message" }),
|
|
382
|
-
date: z8.coerce.date({
|
|
383
|
-
description: "Date and time when commit was authored"
|
|
384
|
-
}),
|
|
385
|
-
author: z8.string({
|
|
386
|
-
description: "Commit author name"
|
|
387
|
-
}).trim()
|
|
388
|
-
},
|
|
389
|
-
{ description: "Git commit" }
|
|
390
|
-
);
|
|
391
|
-
|
|
392
|
-
// packages/models/src/lib/core-config.ts
|
|
393
|
-
import { z as z14 } from "zod";
|
|
394
|
-
|
|
395
|
-
// packages/models/src/lib/persist-config.ts
|
|
396
|
-
import { z as z9 } from "zod";
|
|
397
|
-
var formatSchema = z9.enum(["json", "md"]);
|
|
398
|
-
var persistConfigSchema = z9.object({
|
|
399
|
-
outputDir: filePathSchema.describe("Artifacts folder").optional(),
|
|
400
|
-
filename: fileNameSchema.describe("Artifacts file name (without extension)").optional(),
|
|
401
|
-
format: z9.array(formatSchema).optional()
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
// packages/models/src/lib/plugin-config.ts
|
|
405
|
-
import { z as z12 } from "zod";
|
|
406
|
-
|
|
407
|
-
// packages/models/src/lib/group.ts
|
|
408
|
-
import { z as z10 } from "zod";
|
|
409
|
-
var groupRefSchema = weightedRefSchema(
|
|
410
|
-
"Weighted reference to a group",
|
|
411
|
-
"Reference slug to a group within this plugin (e.g. 'max-lines')"
|
|
412
|
-
);
|
|
413
|
-
var groupMetaSchema = metaSchema({
|
|
414
|
-
titleDescription: "Descriptive name for the group",
|
|
415
|
-
descriptionDescription: "Description of the group (markdown)",
|
|
416
|
-
docsUrlDescription: "Group documentation site",
|
|
417
|
-
description: "Group metadata"
|
|
418
|
-
});
|
|
419
|
-
var groupSchema = scorableSchema(
|
|
420
|
-
'A group aggregates a set of audits into a single score which can be referenced from a category. E.g. the group slug "performance" groups audits and can be referenced in a category',
|
|
421
|
-
groupRefSchema,
|
|
422
|
-
getDuplicateRefsInGroups,
|
|
423
|
-
duplicateRefsInGroupsErrorMsg
|
|
424
|
-
).merge(groupMetaSchema);
|
|
425
|
-
var groupsSchema = z10.array(groupSchema, {
|
|
426
|
-
description: "List of groups"
|
|
427
|
-
}).optional().refine(
|
|
428
|
-
(groups) => !getDuplicateSlugsInGroups(groups),
|
|
429
|
-
(groups) => ({
|
|
430
|
-
message: duplicateSlugsInGroupsErrorMsg(groups)
|
|
431
|
-
})
|
|
432
|
-
);
|
|
433
|
-
function duplicateRefsInGroupsErrorMsg(groups) {
|
|
434
|
-
const duplicateRefs = getDuplicateRefsInGroups(groups);
|
|
435
|
-
return `In plugin groups the following references are not unique: ${errorItems(
|
|
436
|
-
duplicateRefs
|
|
437
|
-
)}`;
|
|
438
|
-
}
|
|
439
|
-
function getDuplicateRefsInGroups(groups) {
|
|
440
|
-
return hasDuplicateStrings(groups.map(({ slug: ref }) => ref).filter(exists));
|
|
441
|
-
}
|
|
442
|
-
function duplicateSlugsInGroupsErrorMsg(groups) {
|
|
443
|
-
const duplicateRefs = getDuplicateSlugsInGroups(groups);
|
|
444
|
-
return `In groups the following slugs are not unique: ${errorItems(
|
|
445
|
-
duplicateRefs
|
|
446
|
-
)}`;
|
|
447
|
-
}
|
|
448
|
-
function getDuplicateSlugsInGroups(groups) {
|
|
449
|
-
return Array.isArray(groups) ? hasDuplicateStrings(groups.map(({ slug }) => slug)) : false;
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
// packages/models/src/lib/runner-config.ts
|
|
453
|
-
import { z as z11 } from "zod";
|
|
454
|
-
var outputTransformSchema = z11.function().args(z11.unknown()).returns(z11.union([auditOutputsSchema, z11.promise(auditOutputsSchema)]));
|
|
455
|
-
var runnerConfigSchema = z11.object(
|
|
456
|
-
{
|
|
457
|
-
command: z11.string({
|
|
458
|
-
description: "Shell command to execute"
|
|
459
|
-
}),
|
|
460
|
-
args: z11.array(z11.string({ description: "Command arguments" })).optional(),
|
|
461
|
-
outputFile: filePathSchema.describe("Output path"),
|
|
462
|
-
outputTransform: outputTransformSchema.optional()
|
|
463
|
-
},
|
|
464
|
-
{
|
|
465
|
-
description: "How to execute runner"
|
|
466
|
-
}
|
|
467
|
-
);
|
|
468
|
-
var onProgressSchema = z11.function().args(z11.unknown()).returns(z11.void());
|
|
469
|
-
var runnerFunctionSchema = z11.function().args(onProgressSchema.optional()).returns(z11.union([auditOutputsSchema, z11.promise(auditOutputsSchema)]));
|
|
470
|
-
|
|
471
|
-
// packages/models/src/lib/plugin-config.ts
|
|
472
|
-
var pluginMetaSchema = packageVersionSchema().merge(
|
|
473
|
-
metaSchema({
|
|
474
|
-
titleDescription: "Descriptive name",
|
|
475
|
-
descriptionDescription: "Description (markdown)",
|
|
476
|
-
docsUrlDescription: "Plugin documentation site",
|
|
477
|
-
description: "Plugin metadata"
|
|
478
|
-
})
|
|
479
|
-
).merge(
|
|
480
|
-
z12.object({
|
|
481
|
-
slug: slugSchema.describe("Unique plugin slug within core config"),
|
|
482
|
-
icon: materialIconSchema
|
|
483
|
-
})
|
|
484
|
-
);
|
|
485
|
-
var pluginDataSchema = z12.object({
|
|
486
|
-
runner: z12.union([runnerConfigSchema, runnerFunctionSchema]),
|
|
487
|
-
audits: pluginAuditsSchema,
|
|
488
|
-
groups: groupsSchema
|
|
489
|
-
});
|
|
490
|
-
var pluginConfigSchema = pluginMetaSchema.merge(pluginDataSchema).refine(
|
|
491
|
-
(pluginCfg) => !getMissingRefsFromGroups(pluginCfg),
|
|
492
|
-
(pluginCfg) => ({
|
|
493
|
-
message: missingRefsFromGroupsErrorMsg(pluginCfg)
|
|
494
|
-
})
|
|
495
|
-
);
|
|
496
|
-
function missingRefsFromGroupsErrorMsg(pluginCfg) {
|
|
497
|
-
const missingRefs = getMissingRefsFromGroups(pluginCfg);
|
|
498
|
-
return `The following group references need to point to an existing audit in this plugin config: ${errorItems(
|
|
499
|
-
missingRefs
|
|
500
|
-
)}`;
|
|
501
|
-
}
|
|
502
|
-
function getMissingRefsFromGroups(pluginCfg) {
|
|
503
|
-
return hasMissingStrings(
|
|
504
|
-
pluginCfg.groups?.flatMap(
|
|
505
|
-
({ refs: audits2 }) => audits2.map(({ slug: ref }) => ref)
|
|
506
|
-
) ?? [],
|
|
507
|
-
pluginCfg.audits.map(({ slug }) => slug)
|
|
508
|
-
);
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
// packages/models/src/lib/upload-config.ts
|
|
512
|
-
import { z as z13 } from "zod";
|
|
513
|
-
var uploadConfigSchema = z13.object({
|
|
514
|
-
server: urlSchema.describe("URL of deployed portal API"),
|
|
515
|
-
apiKey: z13.string({
|
|
516
|
-
description: "API key with write access to portal (use `process.env` for security)"
|
|
517
|
-
}),
|
|
518
|
-
organization: slugSchema.describe(
|
|
519
|
-
"Organization slug from Code PushUp portal"
|
|
520
|
-
),
|
|
521
|
-
project: slugSchema.describe("Project slug from Code PushUp portal"),
|
|
522
|
-
timeout: z13.number({ description: "Request timeout in minutes (default is 5)" }).positive().int().optional()
|
|
523
|
-
});
|
|
524
|
-
|
|
525
|
-
// packages/models/src/lib/core-config.ts
|
|
526
|
-
var unrefinedCoreConfigSchema = z14.object({
|
|
527
|
-
plugins: z14.array(pluginConfigSchema, {
|
|
528
|
-
description: "List of plugins to be used (official, community-provided, or custom)"
|
|
529
|
-
}).min(1),
|
|
530
|
-
/** portal configuration for persisting results */
|
|
531
|
-
persist: persistConfigSchema.optional(),
|
|
532
|
-
/** portal configuration for uploading results */
|
|
533
|
-
upload: uploadConfigSchema.optional(),
|
|
534
|
-
categories: categoriesSchema.optional()
|
|
535
|
-
});
|
|
536
|
-
var coreConfigSchema = refineCoreConfig(unrefinedCoreConfigSchema);
|
|
537
|
-
function refineCoreConfig(schema) {
|
|
538
|
-
return schema.refine(
|
|
539
|
-
({ categories: categories2, plugins }) => !getMissingRefsForCategories(categories2, plugins),
|
|
540
|
-
({ categories: categories2, plugins }) => ({
|
|
541
|
-
message: missingRefsForCategoriesErrorMsg(categories2, plugins)
|
|
542
|
-
})
|
|
543
|
-
);
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
// packages/models/src/lib/implementation/constants.ts
|
|
547
|
-
var DEFAULT_PERSIST_OUTPUT_DIR = ".code-pushup";
|
|
548
|
-
|
|
549
|
-
// packages/models/src/lib/report.ts
|
|
550
|
-
import { z as z15 } from "zod";
|
|
551
|
-
var auditReportSchema = auditSchema.merge(auditOutputSchema);
|
|
552
|
-
var pluginReportSchema = pluginMetaSchema.merge(
|
|
553
|
-
executionMetaSchema({
|
|
554
|
-
descriptionDate: "Start date and time of plugin run",
|
|
555
|
-
descriptionDuration: "Duration of the plugin run in ms"
|
|
556
|
-
})
|
|
557
|
-
).merge(
|
|
558
|
-
z15.object({
|
|
559
|
-
audits: z15.array(auditReportSchema).min(1),
|
|
560
|
-
groups: z15.array(groupSchema).optional()
|
|
561
|
-
})
|
|
562
|
-
).refine(
|
|
563
|
-
(pluginReport) => !getMissingRefsFromGroups2(pluginReport.audits, pluginReport.groups ?? []),
|
|
564
|
-
(pluginReport) => ({
|
|
565
|
-
message: missingRefsFromGroupsErrorMsg2(
|
|
566
|
-
pluginReport.audits,
|
|
567
|
-
pluginReport.groups ?? []
|
|
568
|
-
)
|
|
569
|
-
})
|
|
570
|
-
);
|
|
571
|
-
function missingRefsFromGroupsErrorMsg2(audits2, groups) {
|
|
572
|
-
const missingRefs = getMissingRefsFromGroups2(audits2, groups);
|
|
573
|
-
return `group references need to point to an existing audit in this plugin report: ${errorItems(
|
|
574
|
-
missingRefs
|
|
575
|
-
)}`;
|
|
576
|
-
}
|
|
577
|
-
function getMissingRefsFromGroups2(audits2, groups) {
|
|
578
|
-
return hasMissingStrings(
|
|
579
|
-
groups.flatMap(
|
|
580
|
-
({ refs: auditRefs }) => auditRefs.map(({ slug: ref }) => ref)
|
|
581
|
-
),
|
|
582
|
-
audits2.map(({ slug }) => slug)
|
|
583
|
-
);
|
|
584
|
-
}
|
|
585
|
-
var reportSchema = packageVersionSchema({
|
|
586
|
-
versionDescription: "NPM version of the CLI",
|
|
587
|
-
required: true
|
|
588
|
-
}).merge(
|
|
589
|
-
executionMetaSchema({
|
|
590
|
-
descriptionDate: "Start date and time of the collect run",
|
|
591
|
-
descriptionDuration: "Duration of the collect run in ms"
|
|
592
|
-
})
|
|
593
|
-
).merge(
|
|
594
|
-
z15.object(
|
|
595
|
-
{
|
|
596
|
-
plugins: z15.array(pluginReportSchema).min(1),
|
|
597
|
-
categories: z15.array(categoryConfigSchema).optional(),
|
|
598
|
-
commit: commitSchema.describe("Git commit for which report was collected").nullable()
|
|
599
|
-
},
|
|
600
|
-
{ description: "Collect output data" }
|
|
601
|
-
)
|
|
602
|
-
).refine(
|
|
603
|
-
({ categories: categories2, plugins }) => !getMissingRefsForCategories(categories2, plugins),
|
|
604
|
-
({ categories: categories2, plugins }) => ({
|
|
605
|
-
message: missingRefsForCategoriesErrorMsg(categories2, plugins)
|
|
606
|
-
})
|
|
607
|
-
);
|
|
608
|
-
|
|
609
|
-
// packages/models/src/lib/reports-diff.ts
|
|
610
|
-
import { z as z16 } from "zod";
|
|
611
|
-
function makeComparisonSchema(schema) {
|
|
612
|
-
const sharedDescription = schema.description || "Result";
|
|
613
|
-
return z16.object({
|
|
614
|
-
before: schema.describe(`${sharedDescription} (source commit)`),
|
|
615
|
-
after: schema.describe(`${sharedDescription} (target commit)`)
|
|
616
|
-
});
|
|
617
|
-
}
|
|
618
|
-
function makeArraysComparisonSchema(diffSchema, resultSchema, description) {
|
|
619
|
-
return z16.object(
|
|
620
|
-
{
|
|
621
|
-
changed: z16.array(diffSchema),
|
|
622
|
-
unchanged: z16.array(resultSchema),
|
|
623
|
-
added: z16.array(resultSchema),
|
|
624
|
-
removed: z16.array(resultSchema)
|
|
625
|
-
},
|
|
626
|
-
{ description }
|
|
627
|
-
);
|
|
628
|
-
}
|
|
629
|
-
var scorableMetaSchema = z16.object({
|
|
630
|
-
slug: slugSchema,
|
|
631
|
-
title: titleSchema,
|
|
632
|
-
docsUrl: docsUrlSchema
|
|
633
|
-
});
|
|
634
|
-
var scorableWithPluginMetaSchema = scorableMetaSchema.merge(
|
|
635
|
-
z16.object({
|
|
636
|
-
plugin: pluginMetaSchema.pick({ slug: true, title: true, docsUrl: true }).describe("Plugin which defines it")
|
|
637
|
-
})
|
|
638
|
-
);
|
|
639
|
-
var scorableDiffSchema = scorableMetaSchema.merge(
|
|
640
|
-
z16.object({
|
|
641
|
-
scores: makeComparisonSchema(scoreSchema).merge(
|
|
642
|
-
z16.object({
|
|
643
|
-
diff: z16.number().min(-1).max(1).describe("Score change (`scores.after - scores.before`)")
|
|
644
|
-
})
|
|
645
|
-
).describe("Score comparison")
|
|
646
|
-
})
|
|
647
|
-
);
|
|
648
|
-
var scorableWithPluginDiffSchema = scorableDiffSchema.merge(
|
|
649
|
-
scorableWithPluginMetaSchema
|
|
650
|
-
);
|
|
651
|
-
var categoryDiffSchema = scorableDiffSchema;
|
|
652
|
-
var groupDiffSchema = scorableWithPluginDiffSchema;
|
|
653
|
-
var auditDiffSchema = scorableWithPluginDiffSchema.merge(
|
|
654
|
-
z16.object({
|
|
655
|
-
values: makeComparisonSchema(auditValueSchema).merge(
|
|
656
|
-
z16.object({
|
|
657
|
-
diff: z16.number().describe("Value change (`values.after - values.before`)")
|
|
658
|
-
})
|
|
659
|
-
).describe("Audit `value` comparison"),
|
|
660
|
-
displayValues: makeComparisonSchema(auditDisplayValueSchema).describe(
|
|
661
|
-
"Audit `displayValue` comparison"
|
|
662
|
-
)
|
|
663
|
-
})
|
|
664
|
-
);
|
|
665
|
-
var categoryResultSchema = scorableMetaSchema.merge(
|
|
666
|
-
z16.object({ score: scoreSchema })
|
|
667
|
-
);
|
|
668
|
-
var groupResultSchema = scorableWithPluginMetaSchema.merge(
|
|
669
|
-
z16.object({ score: scoreSchema })
|
|
670
|
-
);
|
|
671
|
-
var auditResultSchema = scorableWithPluginMetaSchema.merge(
|
|
672
|
-
auditOutputSchema.pick({ score: true, value: true, displayValue: true })
|
|
673
|
-
);
|
|
674
|
-
var reportsDiffSchema = z16.object({
|
|
675
|
-
commits: makeComparisonSchema(commitSchema).nullable().describe("Commits identifying compared reports"),
|
|
676
|
-
portalUrl: urlSchema.optional().describe("Link to comparison page in Code PushUp portal"),
|
|
677
|
-
label: z16.string().optional().describe("Label (e.g. project name)"),
|
|
678
|
-
categories: makeArraysComparisonSchema(
|
|
679
|
-
categoryDiffSchema,
|
|
680
|
-
categoryResultSchema,
|
|
681
|
-
"Changes affecting categories"
|
|
682
|
-
),
|
|
683
|
-
groups: makeArraysComparisonSchema(
|
|
684
|
-
groupDiffSchema,
|
|
685
|
-
groupResultSchema,
|
|
686
|
-
"Changes affecting groups"
|
|
687
|
-
),
|
|
688
|
-
audits: makeArraysComparisonSchema(
|
|
689
|
-
auditDiffSchema,
|
|
690
|
-
auditResultSchema,
|
|
691
|
-
"Changes affecting audits"
|
|
692
|
-
)
|
|
693
|
-
}).merge(
|
|
694
|
-
packageVersionSchema({
|
|
695
|
-
versionDescription: "NPM version of the CLI (when `compare` was run)",
|
|
696
|
-
required: true
|
|
697
|
-
})
|
|
698
|
-
).merge(
|
|
699
|
-
executionMetaSchema({
|
|
700
|
-
descriptionDate: "Start date and time of the compare run",
|
|
701
|
-
descriptionDuration: "Duration of the compare run in ms"
|
|
702
|
-
})
|
|
703
|
-
);
|
|
704
|
-
|
|
705
|
-
// packages/plugin-lighthouse/src/lib/constants.ts
|
|
706
|
-
var DEFAULT_CHROME_FLAGS = [...DEFAULT_FLAGS, "--headless"];
|
|
707
|
-
var LIGHTHOUSE_PLUGIN_SLUG = "lighthouse";
|
|
708
|
-
var LIGHTHOUSE_OUTPUT_PATH = join(
|
|
709
|
-
DEFAULT_PERSIST_OUTPUT_DIR,
|
|
710
|
-
LIGHTHOUSE_PLUGIN_SLUG
|
|
711
|
-
);
|
|
712
|
-
|
|
713
|
-
// packages/plugin-lighthouse/src/lib/normalize-flags.ts
|
|
714
|
-
import { bold as bold9, yellow as yellow2 } from "ansis";
|
|
715
|
-
|
|
716
|
-
// packages/utils/src/lib/reports/utils.ts
|
|
717
|
-
import ansis from "ansis";
|
|
718
|
-
import { md } from "build-md";
|
|
719
|
-
|
|
720
|
-
// packages/utils/src/lib/reports/constants.ts
|
|
721
|
-
var TERMINAL_WIDTH = 80;
|
|
722
|
-
|
|
723
|
-
// packages/utils/src/lib/reports/utils.ts
|
|
724
|
-
function formatReportScore(score) {
|
|
725
|
-
const scaledScore = score * 100;
|
|
726
|
-
const roundedScore = Math.round(scaledScore);
|
|
727
|
-
return roundedScore === 100 && score !== 1 ? Math.floor(scaledScore).toString() : roundedScore.toString();
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
// packages/utils/src/lib/file-system.ts
|
|
731
|
-
import { bold, gray } from "ansis";
|
|
732
|
-
import { bundleRequire } from "bundle-require";
|
|
733
|
-
import { mkdir, readFile, readdir, rm, stat } from "node:fs/promises";
|
|
734
|
-
|
|
735
|
-
// packages/utils/src/lib/formatting.ts
|
|
736
|
-
function formatBytes(bytes, decimals = 2) {
|
|
737
|
-
const positiveBytes = Math.max(bytes, 0);
|
|
738
|
-
if (positiveBytes === 0) {
|
|
739
|
-
return "0 B";
|
|
740
|
-
}
|
|
741
|
-
const k = 1024;
|
|
742
|
-
const dm = decimals < 0 ? 0 : decimals;
|
|
743
|
-
const sizes = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
|
744
|
-
const i = Math.floor(Math.log(positiveBytes) / Math.log(k));
|
|
745
|
-
return `${Number.parseFloat((positiveBytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
|
|
746
|
-
}
|
|
747
|
-
function formatDuration(duration, granularity = 0) {
|
|
748
|
-
if (duration < 1e3) {
|
|
749
|
-
return `${granularity ? duration.toFixed(granularity) : duration} ms`;
|
|
750
|
-
}
|
|
751
|
-
return `${(duration / 1e3).toFixed(2)} s`;
|
|
752
|
-
}
|
|
753
|
-
function truncateText(text, options) {
|
|
754
|
-
const {
|
|
755
|
-
maxChars,
|
|
756
|
-
position = "end",
|
|
757
|
-
ellipsis = "..."
|
|
758
|
-
} = typeof options === "number" ? { maxChars: options } : options;
|
|
759
|
-
if (text.length <= maxChars) {
|
|
760
|
-
return text;
|
|
761
|
-
}
|
|
762
|
-
const maxLength = maxChars - ellipsis.length;
|
|
763
|
-
switch (position) {
|
|
764
|
-
case "start":
|
|
765
|
-
return ellipsis + text.slice(-maxLength).trim();
|
|
766
|
-
case "middle":
|
|
767
|
-
const halfMaxChars = Math.floor(maxLength / 2);
|
|
768
|
-
return text.slice(0, halfMaxChars).trim() + ellipsis + text.slice(-halfMaxChars).trim();
|
|
769
|
-
case "end":
|
|
770
|
-
return text.slice(0, maxLength).trim() + ellipsis;
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
// packages/utils/src/lib/logging.ts
|
|
775
|
-
import isaacs_cliui from "@isaacs/cliui";
|
|
776
|
-
import { cliui } from "@poppinss/cliui";
|
|
777
|
-
import { underline } from "ansis";
|
|
778
|
-
var singletonUiInstance;
|
|
779
|
-
function ui() {
|
|
780
|
-
if (singletonUiInstance === void 0) {
|
|
781
|
-
singletonUiInstance = cliui();
|
|
782
|
-
}
|
|
783
|
-
return {
|
|
784
|
-
...singletonUiInstance,
|
|
785
|
-
row: (args) => {
|
|
786
|
-
logListItem(args);
|
|
787
|
-
}
|
|
788
|
-
};
|
|
789
|
-
}
|
|
790
|
-
var singletonisaacUi;
|
|
791
|
-
function logListItem(args) {
|
|
792
|
-
if (singletonisaacUi === void 0) {
|
|
793
|
-
singletonisaacUi = isaacs_cliui({ width: TERMINAL_WIDTH });
|
|
794
|
-
}
|
|
795
|
-
singletonisaacUi.div(...args);
|
|
796
|
-
const content = singletonisaacUi.toString();
|
|
797
|
-
singletonisaacUi.rows = [];
|
|
798
|
-
singletonUiInstance?.logger.log(content);
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
// packages/utils/src/lib/file-system.ts
|
|
802
|
-
async function readTextFile(path) {
|
|
803
|
-
const buffer = await readFile(path);
|
|
804
|
-
return buffer.toString();
|
|
805
|
-
}
|
|
806
|
-
async function readJsonFile(path) {
|
|
807
|
-
const text = await readTextFile(path);
|
|
808
|
-
return JSON.parse(text);
|
|
809
|
-
}
|
|
810
|
-
async function ensureDirectoryExists(baseDir) {
|
|
811
|
-
try {
|
|
812
|
-
await mkdir(baseDir, { recursive: true });
|
|
813
|
-
return;
|
|
814
|
-
} catch (error) {
|
|
815
|
-
ui().logger.info(error.message);
|
|
816
|
-
if (error.code !== "EEXIST") {
|
|
817
|
-
throw error;
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
}
|
|
821
|
-
async function importModule(options) {
|
|
822
|
-
const { mod } = await bundleRequire(options);
|
|
823
|
-
if (typeof mod === "object" && "default" in mod) {
|
|
824
|
-
return mod.default;
|
|
825
|
-
}
|
|
826
|
-
return mod;
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
// packages/utils/src/lib/filter.ts
|
|
830
|
-
function filterItemRefsBy(items, refFilterFn) {
|
|
831
|
-
return items.map((item) => ({
|
|
832
|
-
...item,
|
|
833
|
-
refs: item.refs.filter(refFilterFn)
|
|
834
|
-
})).filter((item) => item.refs.length);
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
// packages/utils/src/lib/git/git.ts
|
|
838
|
-
import { simpleGit } from "simple-git";
|
|
839
|
-
|
|
840
|
-
// packages/utils/src/lib/transform.ts
|
|
841
|
-
function toArray(val) {
|
|
842
|
-
return Array.isArray(val) ? val : [val];
|
|
843
|
-
}
|
|
844
|
-
function capitalize(text) {
|
|
845
|
-
return `${text.charAt(0).toLocaleUpperCase()}${text.slice(
|
|
846
|
-
1
|
|
847
|
-
)}`;
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
// packages/utils/src/lib/git/git.commits-and-tags.ts
|
|
851
|
-
import { simpleGit as simpleGit2 } from "simple-git";
|
|
852
|
-
|
|
853
|
-
// packages/utils/src/lib/semver.ts
|
|
854
|
-
import { rcompare, valid } from "semver";
|
|
855
|
-
|
|
856
|
-
// packages/utils/src/lib/progress.ts
|
|
857
|
-
import { black, bold as bold2, gray as gray2, green } from "ansis";
|
|
858
|
-
import { MultiProgressBars } from "multi-progress-bars";
|
|
859
|
-
|
|
860
|
-
// packages/utils/src/lib/reports/generate-md-report.ts
|
|
861
|
-
import { MarkdownDocument as MarkdownDocument3, md as md4 } from "build-md";
|
|
862
|
-
|
|
863
|
-
// packages/utils/src/lib/text-formats/constants.ts
|
|
864
|
-
var NEW_LINE = "\n";
|
|
865
|
-
|
|
866
|
-
// packages/utils/src/lib/text-formats/html/details.ts
|
|
867
|
-
function details(title, content, cfg = { open: false }) {
|
|
868
|
-
return `<details${cfg.open ? " open" : ""}>${NEW_LINE}<summary>${title}</summary>${NEW_LINE}${// ⚠️ The blank line is needed to ensure Markdown in content is rendered correctly.
|
|
869
|
-
NEW_LINE}${content}${NEW_LINE}${// @TODO in the future we could consider adding it only if the content ends with a code block
|
|
870
|
-
// ⚠️ The blank line ensure Markdown in content is rendered correctly.
|
|
871
|
-
NEW_LINE}</details>${// ⚠️ The blank line is needed to ensure Markdown after details is rendered correctly.
|
|
872
|
-
NEW_LINE}`;
|
|
873
|
-
}
|
|
874
|
-
|
|
875
|
-
// packages/utils/src/lib/text-formats/html/font-style.ts
|
|
876
|
-
var boldElement = "b";
|
|
877
|
-
function bold3(text) {
|
|
878
|
-
return `<${boldElement}>${text}</${boldElement}>`;
|
|
879
|
-
}
|
|
880
|
-
var italicElement = "i";
|
|
881
|
-
function italic(text) {
|
|
882
|
-
return `<${italicElement}>${text}</${italicElement}>`;
|
|
883
|
-
}
|
|
884
|
-
var codeElement = "code";
|
|
885
|
-
function code(text) {
|
|
886
|
-
return `<${codeElement}>${text}</${codeElement}>`;
|
|
887
|
-
}
|
|
888
|
-
|
|
889
|
-
// packages/utils/src/lib/text-formats/html/link.ts
|
|
890
|
-
function link(href, text) {
|
|
891
|
-
return `<a href="${href}">${text || href}</a>`;
|
|
892
|
-
}
|
|
893
|
-
|
|
894
|
-
// packages/utils/src/lib/text-formats/table.ts
|
|
895
|
-
function rowToStringArray({ rows, columns = [] }) {
|
|
896
|
-
if (Array.isArray(rows.at(0)) && typeof columns.at(0) === "object") {
|
|
897
|
-
throw new TypeError(
|
|
898
|
-
"Column can`t be object when rows are primitive values"
|
|
899
|
-
);
|
|
900
|
-
}
|
|
901
|
-
return rows.map((row) => {
|
|
902
|
-
if (Array.isArray(row)) {
|
|
903
|
-
return row.map(String);
|
|
904
|
-
}
|
|
905
|
-
const objectRow = row;
|
|
906
|
-
if (columns.length === 0 || typeof columns.at(0) === "string") {
|
|
907
|
-
return Object.values(objectRow).map(
|
|
908
|
-
(value) => value == null ? "" : String(value)
|
|
909
|
-
);
|
|
910
|
-
}
|
|
911
|
-
return columns.map(
|
|
912
|
-
({ key }) => objectRow[key] == null ? "" : String(objectRow[key])
|
|
913
|
-
);
|
|
914
|
-
});
|
|
915
|
-
}
|
|
916
|
-
function columnsToStringArray({
|
|
917
|
-
rows,
|
|
918
|
-
columns = []
|
|
919
|
-
}) {
|
|
920
|
-
const firstRow = rows.at(0);
|
|
921
|
-
const primitiveRows = Array.isArray(firstRow);
|
|
922
|
-
if (typeof columns.at(0) === "string" && !primitiveRows) {
|
|
923
|
-
throw new Error("invalid union type. Caught by model parsing.");
|
|
924
|
-
}
|
|
925
|
-
if (columns.length === 0) {
|
|
926
|
-
if (Array.isArray(firstRow)) {
|
|
927
|
-
return firstRow.map((_, idx) => String(idx));
|
|
928
|
-
}
|
|
929
|
-
return Object.keys(firstRow);
|
|
930
|
-
}
|
|
931
|
-
if (typeof columns.at(0) === "string") {
|
|
932
|
-
return columns.map(String);
|
|
933
|
-
}
|
|
934
|
-
const cols = columns;
|
|
935
|
-
return cols.map(({ label, key }) => label ?? capitalize(key));
|
|
936
|
-
}
|
|
937
|
-
|
|
938
|
-
// packages/utils/src/lib/text-formats/html/table.ts
|
|
939
|
-
function wrap(elem, content) {
|
|
940
|
-
return `<${elem}>${content}</${elem}>${NEW_LINE}`;
|
|
941
|
-
}
|
|
942
|
-
function wrapRow(content) {
|
|
943
|
-
const elem = "tr";
|
|
944
|
-
return `<${elem}>${NEW_LINE}${content}</${elem}>${NEW_LINE}`;
|
|
945
|
-
}
|
|
946
|
-
function table(tableData) {
|
|
947
|
-
if (tableData.rows.length === 0) {
|
|
948
|
-
throw new Error("Data can't be empty");
|
|
949
|
-
}
|
|
950
|
-
const tableHeaderCols = columnsToStringArray(tableData).map((s) => wrap("th", s)).join("");
|
|
951
|
-
const tableHeaderRow = wrapRow(tableHeaderCols);
|
|
952
|
-
const tableBody = rowToStringArray(tableData).map((arr) => {
|
|
953
|
-
const columns = arr.map((s) => wrap("td", s)).join("");
|
|
954
|
-
return wrapRow(columns);
|
|
955
|
-
}).join("");
|
|
956
|
-
return wrap("table", `${NEW_LINE}${tableHeaderRow}${tableBody}`);
|
|
957
|
-
}
|
|
958
|
-
|
|
959
|
-
// packages/utils/src/lib/text-formats/index.ts
|
|
960
|
-
var html = {
|
|
961
|
-
bold: bold3,
|
|
962
|
-
italic,
|
|
963
|
-
code,
|
|
964
|
-
link,
|
|
965
|
-
details,
|
|
966
|
-
table
|
|
967
|
-
};
|
|
968
|
-
|
|
969
|
-
// packages/utils/src/lib/reports/formatting.ts
|
|
970
|
-
import {
|
|
971
|
-
MarkdownDocument,
|
|
972
|
-
md as md2
|
|
973
|
-
} from "build-md";
|
|
974
|
-
|
|
975
|
-
// packages/utils/src/lib/reports/generate-md-report-categoy-section.ts
|
|
976
|
-
import { MarkdownDocument as MarkdownDocument2, md as md3 } from "build-md";
|
|
977
|
-
|
|
978
|
-
// packages/utils/src/lib/reports/generate-md-reports-diff.ts
|
|
979
|
-
import {
|
|
980
|
-
MarkdownDocument as MarkdownDocument5,
|
|
981
|
-
md as md6
|
|
982
|
-
} from "build-md";
|
|
983
|
-
|
|
984
|
-
// packages/utils/src/lib/reports/generate-md-reports-diff-utils.ts
|
|
985
|
-
import { MarkdownDocument as MarkdownDocument4, md as md5 } from "build-md";
|
|
986
|
-
|
|
987
|
-
// packages/utils/src/lib/reports/log-stdout-summary.ts
|
|
988
|
-
import { bold as bold4, cyan, cyanBright, green as green2, red } from "ansis";
|
|
989
|
-
|
|
990
|
-
// packages/plugin-lighthouse/src/lib/runner/runner.ts
|
|
991
|
-
import { runLighthouse } from "lighthouse/cli/run.js";
|
|
992
|
-
import { dirname } from "node:path";
|
|
993
|
-
|
|
994
|
-
// packages/plugin-lighthouse/src/lib/runner/constants.ts
|
|
995
|
-
import {
|
|
996
|
-
defaultConfig
|
|
997
|
-
} from "lighthouse";
|
|
998
|
-
import { join as join2 } from "node:path";
|
|
999
|
-
var { audits, categories } = defaultConfig;
|
|
1000
|
-
var allRawLighthouseAudits = await Promise.all(
|
|
1001
|
-
(audits ?? []).map(loadLighthouseAudit)
|
|
1002
|
-
);
|
|
1003
|
-
var PLUGIN_SLUG = "lighthouse";
|
|
1004
|
-
var LIGHTHOUSE_NAVIGATION_AUDITS = allRawLighthouseAudits.filter(
|
|
1005
|
-
(audit) => audit.meta.supportedModes == null || Array.isArray(audit.meta.supportedModes) && audit.meta.supportedModes.includes("navigation")
|
|
1006
|
-
).map((audit) => ({
|
|
1007
|
-
slug: audit.meta.id,
|
|
1008
|
-
title: getMetaString(audit.meta.title),
|
|
1009
|
-
description: getMetaString(audit.meta.description)
|
|
1010
|
-
}));
|
|
1011
|
-
var navigationAuditSlugs = new Set(
|
|
1012
|
-
LIGHTHOUSE_NAVIGATION_AUDITS.map(({ slug }) => slug)
|
|
1013
|
-
);
|
|
1014
|
-
var LIGHTHOUSE_GROUPS = Object.entries(categories ?? {}).map(
|
|
1015
|
-
([id, category]) => ({
|
|
1016
|
-
slug: id,
|
|
1017
|
-
title: getMetaString(category.title),
|
|
1018
|
-
...category.description && {
|
|
1019
|
-
description: getMetaString(category.description)
|
|
1020
|
-
},
|
|
1021
|
-
refs: category.auditRefs.filter(({ id: auditSlug }) => navigationAuditSlugs.has(auditSlug)).map((ref) => ({
|
|
1022
|
-
slug: ref.id,
|
|
1023
|
-
weight: ref.weight
|
|
1024
|
-
}))
|
|
1025
|
-
})
|
|
1026
|
-
);
|
|
1027
|
-
function getMetaString(value) {
|
|
1028
|
-
if (typeof value === "string") {
|
|
1029
|
-
return value;
|
|
1030
|
-
}
|
|
1031
|
-
return value.formattedDefault;
|
|
1032
|
-
}
|
|
1033
|
-
async function loadLighthouseAudit(value) {
|
|
1034
|
-
if (typeof value === "object" && "implementation" in value) {
|
|
1035
|
-
return value.implementation;
|
|
1036
|
-
}
|
|
1037
|
-
if (typeof value === "function") {
|
|
1038
|
-
return value;
|
|
1039
|
-
}
|
|
1040
|
-
const path = typeof value === "string" ? value : value.path;
|
|
1041
|
-
const module = await import(`lighthouse/core/audits/${path}.js`);
|
|
1042
|
-
return module.default;
|
|
1043
|
-
}
|
|
1044
|
-
var LIGHTHOUSE_REPORT_NAME = "lighthouse-report.json";
|
|
1045
|
-
var DEFAULT_CLI_FLAGS = {
|
|
1046
|
-
// default values extracted from
|
|
1047
|
-
// https://github.com/GoogleChrome/lighthouse/blob/7d80178c37a1b600ea8f092fc0b098029799a659/cli/cli-flags.js#L80
|
|
1048
|
-
verbose: false,
|
|
1049
|
-
saveAssets: false,
|
|
1050
|
-
chromeFlags: DEFAULT_CHROME_FLAGS,
|
|
1051
|
-
port: 0,
|
|
1052
|
-
hostname: "127.0.0.1",
|
|
1053
|
-
view: false,
|
|
1054
|
-
channel: "cli",
|
|
1055
|
-
// custom overwrites in favour of the plugin
|
|
1056
|
-
// hide logs by default
|
|
1057
|
-
quiet: true,
|
|
1058
|
-
onlyAudits: [],
|
|
1059
|
-
skipAudits: [],
|
|
1060
|
-
onlyCategories: [],
|
|
1061
|
-
output: ["json"],
|
|
1062
|
-
outputPath: join2(LIGHTHOUSE_OUTPUT_PATH, LIGHTHOUSE_REPORT_NAME)
|
|
1063
|
-
};
|
|
1064
|
-
|
|
1065
|
-
// packages/plugin-lighthouse/src/lib/runner/utils.ts
|
|
1066
|
-
import { bold as bold8 } from "ansis";
|
|
1067
|
-
import log from "lighthouse-logger";
|
|
1068
|
-
import desktopConfig from "lighthouse/core/config/desktop-config.js";
|
|
1069
|
-
import experimentalConfig from "lighthouse/core/config/experimental-config.js";
|
|
1070
|
-
import perfConfig from "lighthouse/core/config/perf-config.js";
|
|
1071
|
-
|
|
1072
|
-
// packages/plugin-lighthouse/src/lib/runner/details/details.ts
|
|
1073
|
-
import { bold as bold7, yellow } from "ansis";
|
|
1074
|
-
|
|
1075
|
-
// packages/plugin-lighthouse/src/lib/runner/details/item-value.ts
|
|
1076
|
-
import { bold as bold5 } from "ansis";
|
|
1077
|
-
function trimSlice(item, maxLength = 0) {
|
|
1078
|
-
const str = String(item).trim();
|
|
1079
|
-
return maxLength > 0 ? str.slice(0, maxLength) : str;
|
|
1080
|
-
}
|
|
1081
|
-
function parseNodeValue(node) {
|
|
1082
|
-
const { selector = "" } = node ?? {};
|
|
1083
|
-
return selector;
|
|
1084
|
-
}
|
|
1085
|
-
function formatTableItemPropertyValue(itemValue, itemValueFormat) {
|
|
1086
|
-
if (itemValue == null) {
|
|
1087
|
-
return "";
|
|
1088
|
-
}
|
|
1089
|
-
if (itemValueFormat == null) {
|
|
1090
|
-
if (typeof itemValue === "string") {
|
|
1091
|
-
return trimSlice(itemValue);
|
|
1092
|
-
}
|
|
1093
|
-
if (typeof itemValue === "number") {
|
|
1094
|
-
return Number(itemValue);
|
|
1095
|
-
}
|
|
1096
|
-
if (typeof itemValue === "boolean") {
|
|
1097
|
-
return itemValue;
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
const parsedItemValue = parseTableItemPropertyValue(itemValue);
|
|
1101
|
-
switch (itemValueFormat) {
|
|
1102
|
-
case "bytes":
|
|
1103
|
-
return formatBytes(Number(parsedItemValue));
|
|
1104
|
-
case "code":
|
|
1105
|
-
return html.code(trimSlice(parsedItemValue));
|
|
1106
|
-
case "link":
|
|
1107
|
-
const link3 = parsedItemValue;
|
|
1108
|
-
return html.link(link3.url, link3.text);
|
|
1109
|
-
case "url":
|
|
1110
|
-
const url = parsedItemValue;
|
|
1111
|
-
return html.link(url);
|
|
1112
|
-
case "timespanMs":
|
|
1113
|
-
case "ms":
|
|
1114
|
-
return formatDuration(Number(parsedItemValue));
|
|
1115
|
-
case "node":
|
|
1116
|
-
return parseNodeValue(itemValue);
|
|
1117
|
-
case "source-location":
|
|
1118
|
-
return truncateText(String(parsedItemValue), 200);
|
|
1119
|
-
case "numeric":
|
|
1120
|
-
const num = Number(parsedItemValue);
|
|
1121
|
-
if (num.toFixed(3).toString().endsWith(".000")) {
|
|
1122
|
-
return String(num);
|
|
1123
|
-
}
|
|
1124
|
-
return String(num.toFixed(3));
|
|
1125
|
-
case "text":
|
|
1126
|
-
return truncateText(String(parsedItemValue), 500);
|
|
1127
|
-
case "multi":
|
|
1128
|
-
ui().logger.info(`Format type ${bold5("multi")} is not implemented`);
|
|
1129
|
-
return "";
|
|
1130
|
-
case "thumbnail":
|
|
1131
|
-
ui().logger.info(`Format type ${bold5("thumbnail")} is not implemented`);
|
|
1132
|
-
return "";
|
|
1133
|
-
}
|
|
1134
|
-
return itemValue;
|
|
1135
|
-
}
|
|
1136
|
-
function parseSimpleItemValue(item) {
|
|
1137
|
-
if (typeof item === "object") {
|
|
1138
|
-
const value = item.value;
|
|
1139
|
-
if (typeof value === "object") {
|
|
1140
|
-
return value.formattedDefault;
|
|
1141
|
-
}
|
|
1142
|
-
return value;
|
|
1143
|
-
}
|
|
1144
|
-
return item;
|
|
1145
|
-
}
|
|
1146
|
-
function parseTableItemPropertyValue(itemValue) {
|
|
1147
|
-
if (itemValue == null) {
|
|
1148
|
-
return "";
|
|
1149
|
-
}
|
|
1150
|
-
if (typeof itemValue === "string" || typeof itemValue === "number" || typeof itemValue === "boolean") {
|
|
1151
|
-
return parseSimpleItemValue(itemValue);
|
|
1152
|
-
}
|
|
1153
|
-
const objectValue = itemValue;
|
|
1154
|
-
const { type } = objectValue;
|
|
1155
|
-
switch (type) {
|
|
1156
|
-
case "code":
|
|
1157
|
-
case "url":
|
|
1158
|
-
return String(parseSimpleItemValue(objectValue));
|
|
1159
|
-
case "node":
|
|
1160
|
-
return parseNodeValue(objectValue);
|
|
1161
|
-
case "link":
|
|
1162
|
-
return objectValue;
|
|
1163
|
-
case "numeric":
|
|
1164
|
-
return Number(parseSimpleItemValue(objectValue));
|
|
1165
|
-
case "source-location":
|
|
1166
|
-
const { url } = objectValue;
|
|
1167
|
-
return String(url);
|
|
1168
|
-
case "subitems":
|
|
1169
|
-
ui().logger.info(`Value type ${bold5("subitems")} is not implemented`);
|
|
1170
|
-
return "";
|
|
1171
|
-
case "debugdata":
|
|
1172
|
-
ui().logger.info(`Value type ${bold5("debugdata")} is not implemented`, {
|
|
1173
|
-
silent: true
|
|
1174
|
-
});
|
|
1175
|
-
return "";
|
|
1176
|
-
}
|
|
1177
|
-
return parseSimpleItemValue(objectValue);
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1180
|
-
// packages/plugin-lighthouse/src/lib/runner/details/utils.ts
|
|
1181
|
-
import { bold as bold6 } from "ansis";
|
|
1182
|
-
var LighthouseAuditDetailsParsingError = class extends Error {
|
|
1183
|
-
constructor(type, rawTable, error) {
|
|
1184
|
-
super(
|
|
1185
|
-
`Parsing lighthouse report details ${bold6(
|
|
1186
|
-
type
|
|
1187
|
-
)} failed:
|
|
1188
|
-
Raw data:
|
|
1189
|
-
${JSON.stringify(rawTable, null, 2)}
|
|
1190
|
-
${error}`
|
|
1191
|
-
);
|
|
1192
|
-
}
|
|
1193
|
-
};
|
|
1194
|
-
|
|
1195
|
-
// packages/plugin-lighthouse/src/lib/runner/details/table.type.ts
|
|
1196
|
-
function parseTableToAuditDetailsTable(details2) {
|
|
1197
|
-
const { headings: rawHeadings, items } = details2;
|
|
1198
|
-
if (items.length === 0) {
|
|
1199
|
-
return void 0;
|
|
1200
|
-
}
|
|
1201
|
-
try {
|
|
1202
|
-
return tableSchema().parse({
|
|
1203
|
-
columns: parseTableColumns(rawHeadings),
|
|
1204
|
-
rows: items.map((row) => parseTableRow(row, rawHeadings))
|
|
1205
|
-
});
|
|
1206
|
-
} catch (error) {
|
|
1207
|
-
throw new LighthouseAuditDetailsParsingError(
|
|
1208
|
-
"table",
|
|
1209
|
-
{ items, headings: rawHeadings },
|
|
1210
|
-
error.message.toString()
|
|
1211
|
-
);
|
|
1212
|
-
}
|
|
1213
|
-
}
|
|
1214
|
-
function parseTableColumns(rawHeadings) {
|
|
1215
|
-
return rawHeadings.map(({ key, label }) => ({
|
|
1216
|
-
key: key ?? "",
|
|
1217
|
-
...typeof label === "string" && label.length > 0 ? { label } : {},
|
|
1218
|
-
align: "left"
|
|
1219
|
-
}));
|
|
1220
|
-
}
|
|
1221
|
-
function parseTableRow(tableItem, headings) {
|
|
1222
|
-
const keys = new Set(headings.map(({ key }) => key));
|
|
1223
|
-
const valueTypesByKey = new Map(
|
|
1224
|
-
headings.map(({ key, valueType }) => [key, valueType])
|
|
1225
|
-
);
|
|
1226
|
-
return Object.fromEntries(
|
|
1227
|
-
Object.entries(tableItem).filter(([key]) => keys.has(key)).map(([key, value]) => {
|
|
1228
|
-
const valueType = valueTypesByKey.get(key);
|
|
1229
|
-
return parseTableEntry([key, value], valueType);
|
|
1230
|
-
})
|
|
1231
|
-
);
|
|
1232
|
-
}
|
|
1233
|
-
function parseTableEntry([key, value], valueType) {
|
|
1234
|
-
if (value == null) {
|
|
1235
|
-
return [key, value];
|
|
1236
|
-
}
|
|
1237
|
-
return [key, formatTableItemPropertyValue(value, valueType)];
|
|
1238
|
-
}
|
|
1239
|
-
|
|
1240
|
-
// packages/plugin-lighthouse/src/lib/runner/details/opportunity.type.ts
|
|
1241
|
-
function parseOpportunityToAuditDetailsTable(details2) {
|
|
1242
|
-
const { headings: rawHeadings, items } = details2;
|
|
1243
|
-
if (items.length === 0) {
|
|
1244
|
-
return void 0;
|
|
1245
|
-
}
|
|
1246
|
-
try {
|
|
1247
|
-
return tableSchema().parse({
|
|
1248
|
-
title: "Opportunity",
|
|
1249
|
-
columns: parseTableColumns(rawHeadings),
|
|
1250
|
-
rows: items.map((row) => parseOpportunityItemToTableRow(row, rawHeadings))
|
|
1251
|
-
});
|
|
1252
|
-
} catch (error) {
|
|
1253
|
-
throw new LighthouseAuditDetailsParsingError(
|
|
1254
|
-
"opportunity",
|
|
1255
|
-
{ items, headings: rawHeadings },
|
|
1256
|
-
error.message.toString()
|
|
1257
|
-
);
|
|
1258
|
-
}
|
|
1259
|
-
}
|
|
1260
|
-
function parseOpportunityItemToTableRow(opportunityItem, headings) {
|
|
1261
|
-
const keys = new Set(headings.map(({ key }) => key));
|
|
1262
|
-
const valueTypesByKey = new Map(
|
|
1263
|
-
headings.map(({ key, valueType }) => [key, valueType])
|
|
1264
|
-
);
|
|
1265
|
-
return {
|
|
1266
|
-
...Object.fromEntries(
|
|
1267
|
-
Object.entries(opportunityItem).filter(([key]) => keys.has(key)).map(([key, value]) => {
|
|
1268
|
-
const valueType = valueTypesByKey.get(key);
|
|
1269
|
-
return parseOpportunityEntry([key, value], valueType);
|
|
1270
|
-
})
|
|
1271
|
-
)
|
|
1272
|
-
};
|
|
1273
|
-
}
|
|
1274
|
-
function parseOpportunityEntry([key, value], valueType) {
|
|
1275
|
-
switch (key) {
|
|
1276
|
-
case "url":
|
|
1277
|
-
return [key, html.link(String(value))];
|
|
1278
|
-
case "wastedPercent":
|
|
1279
|
-
return [key, `${Number(value).toFixed(2)} %`];
|
|
1280
|
-
case "totalBytes":
|
|
1281
|
-
case "wastedBytes":
|
|
1282
|
-
return [key, formatBytes(Number(value))];
|
|
1283
|
-
case "wastedMs":
|
|
1284
|
-
return [key, formatDuration(Number(value))];
|
|
1285
|
-
default:
|
|
1286
|
-
return parseTableEntry([key, value], valueType);
|
|
1287
|
-
}
|
|
1288
|
-
}
|
|
1289
|
-
|
|
1290
|
-
// packages/plugin-lighthouse/src/lib/runner/details/details.ts
|
|
1291
|
-
function toAuditDetails(details2) {
|
|
1292
|
-
if (details2 == null) {
|
|
1293
|
-
return {};
|
|
1294
|
-
}
|
|
1295
|
-
const { type } = details2;
|
|
1296
|
-
switch (type) {
|
|
1297
|
-
case "table":
|
|
1298
|
-
const table2 = parseTableToAuditDetailsTable(details2);
|
|
1299
|
-
return table2 ? { table: table2 } : {};
|
|
1300
|
-
case "opportunity":
|
|
1301
|
-
const opportunity = parseOpportunityToAuditDetailsTable(details2);
|
|
1302
|
-
return opportunity ? { table: opportunity } : {};
|
|
1303
|
-
}
|
|
1304
|
-
return {};
|
|
1305
|
-
}
|
|
1306
|
-
var unsupportedDetailTypes = /* @__PURE__ */ new Set([
|
|
1307
|
-
"debugdata",
|
|
1308
|
-
"treemap-data",
|
|
1309
|
-
"screenshot",
|
|
1310
|
-
"filmstrip",
|
|
1311
|
-
"criticalrequestchain"
|
|
1312
|
-
]);
|
|
1313
|
-
function logUnsupportedDetails(lhrAudits, { displayCount = 3 } = {}) {
|
|
1314
|
-
const slugsWithDetailParsingErrors = [
|
|
1315
|
-
...new Set(
|
|
1316
|
-
lhrAudits.filter(
|
|
1317
|
-
({ details: details2 }) => unsupportedDetailTypes.has(details2?.type)
|
|
1318
|
-
).map(({ details: details2 }) => details2?.type)
|
|
1319
|
-
)
|
|
1320
|
-
];
|
|
1321
|
-
if (slugsWithDetailParsingErrors.length > 0) {
|
|
1322
|
-
const postFix = (count) => count > displayCount ? ` and ${count - displayCount} more.` : "";
|
|
1323
|
-
ui().logger.debug(
|
|
1324
|
-
`${yellow("\u26A0")} Plugin ${bold7(
|
|
1325
|
-
PLUGIN_SLUG
|
|
1326
|
-
)} skipped parsing of unsupported audit details: ${bold7(
|
|
1327
|
-
slugsWithDetailParsingErrors.slice(0, displayCount).join(", ")
|
|
1328
|
-
)}${postFix(slugsWithDetailParsingErrors.length)}`
|
|
1329
|
-
);
|
|
1330
|
-
}
|
|
1331
|
-
}
|
|
1332
|
-
|
|
1333
|
-
// packages/plugin-lighthouse/src/lib/runner/utils.ts
|
|
1334
|
-
function normalizeAuditOutputs(auditOutputs, flags = { skipAudits: [] }) {
|
|
1335
|
-
const toSkip = new Set(flags.skipAudits ?? []);
|
|
1336
|
-
return auditOutputs.filter(({ slug }) => !toSkip.has(slug));
|
|
1337
|
-
}
|
|
1338
|
-
var LighthouseAuditParsingError = class extends Error {
|
|
1339
|
-
constructor(slug, error) {
|
|
1340
|
-
super(`
|
|
1341
|
-
Audit ${bold8(slug)} failed parsing details:
|
|
1342
|
-
${error.message}`);
|
|
1343
|
-
}
|
|
1344
|
-
};
|
|
1345
|
-
function formatBaseAuditOutput(lhrAudit) {
|
|
1346
|
-
const {
|
|
1347
|
-
id: slug,
|
|
1348
|
-
score,
|
|
1349
|
-
numericValue,
|
|
1350
|
-
displayValue,
|
|
1351
|
-
scoreDisplayMode
|
|
1352
|
-
} = lhrAudit;
|
|
1353
|
-
return {
|
|
1354
|
-
slug,
|
|
1355
|
-
score: score ?? 1,
|
|
1356
|
-
value: numericValue ?? score ?? 0,
|
|
1357
|
-
displayValue: displayValue ?? (scoreDisplayMode === "binary" ? score === 1 ? "passed" : "failed" : score ? `${formatReportScore(score)}%` : void 0)
|
|
1358
|
-
};
|
|
1359
|
-
}
|
|
1360
|
-
function processAuditDetails(auditOutput, details2) {
|
|
1361
|
-
try {
|
|
1362
|
-
const parsedDetails = toAuditDetails(details2);
|
|
1363
|
-
return Object.keys(parsedDetails).length > 0 ? { ...auditOutput, details: parsedDetails } : auditOutput;
|
|
1364
|
-
} catch (error) {
|
|
1365
|
-
throw new LighthouseAuditParsingError(auditOutput.slug, error);
|
|
1366
|
-
}
|
|
1367
|
-
}
|
|
1368
|
-
function toAuditOutputs(lhrAudits, { verbose = false } = {}) {
|
|
1369
|
-
if (verbose) {
|
|
1370
|
-
logUnsupportedDetails(lhrAudits);
|
|
1371
|
-
}
|
|
1372
|
-
return lhrAudits.map((audit) => {
|
|
1373
|
-
const auditOutput = formatBaseAuditOutput(audit);
|
|
1374
|
-
return audit.details == null ? auditOutput : processAuditDetails(auditOutput, audit.details);
|
|
1375
|
-
});
|
|
1376
|
-
}
|
|
1377
|
-
function determineAndSetLogLevel({
|
|
1378
|
-
verbose,
|
|
1379
|
-
quiet
|
|
1380
|
-
} = {}) {
|
|
1381
|
-
let logLevel = "info";
|
|
1382
|
-
if (verbose) {
|
|
1383
|
-
logLevel = "verbose";
|
|
1384
|
-
} else if (quiet) {
|
|
1385
|
-
logLevel = "silent";
|
|
1386
|
-
}
|
|
1387
|
-
log.setLevel(logLevel);
|
|
1388
|
-
return logLevel;
|
|
1389
|
-
}
|
|
1390
|
-
async function getConfig(options = {}) {
|
|
1391
|
-
const { configPath: filepath, preset } = options;
|
|
1392
|
-
if (filepath != null) {
|
|
1393
|
-
if (filepath.endsWith(".json")) {
|
|
1394
|
-
return readJsonFile(filepath);
|
|
1395
|
-
} else if (/\.(ts|js|mjs)$/.test(filepath)) {
|
|
1396
|
-
return importModule({ filepath, format: "esm" });
|
|
1397
|
-
} else {
|
|
1398
|
-
ui().logger.info(`Format of file ${filepath} not supported`);
|
|
1399
|
-
}
|
|
1400
|
-
} else if (preset != null) {
|
|
1401
|
-
switch (preset) {
|
|
1402
|
-
case "desktop":
|
|
1403
|
-
return desktopConfig;
|
|
1404
|
-
case "perf":
|
|
1405
|
-
return perfConfig;
|
|
1406
|
-
case "experimental":
|
|
1407
|
-
return experimentalConfig;
|
|
1408
|
-
default:
|
|
1409
|
-
ui().logger.info(`Preset "${preset}" is not supported`);
|
|
1410
|
-
}
|
|
1411
|
-
}
|
|
1412
|
-
return void 0;
|
|
1413
|
-
}
|
|
1414
|
-
|
|
1415
|
-
// packages/plugin-lighthouse/src/lib/runner/runner.ts
|
|
1416
|
-
function createRunnerFunction(urlUnderTest, flags = DEFAULT_CLI_FLAGS) {
|
|
1417
|
-
return async () => {
|
|
1418
|
-
const {
|
|
1419
|
-
configPath,
|
|
1420
|
-
preset,
|
|
1421
|
-
outputPath,
|
|
1422
|
-
...parsedFlags
|
|
1423
|
-
} = flags;
|
|
1424
|
-
const logLevel = determineAndSetLogLevel(parsedFlags);
|
|
1425
|
-
const config = await getConfig({ configPath, preset });
|
|
1426
|
-
if (outputPath) {
|
|
1427
|
-
await ensureDirectoryExists(dirname(outputPath));
|
|
1428
|
-
}
|
|
1429
|
-
const enrichedFlags = {
|
|
1430
|
-
...parsedFlags,
|
|
1431
|
-
logLevel,
|
|
1432
|
-
outputPath
|
|
1433
|
-
};
|
|
1434
|
-
const runnerResult = await runLighthouse(
|
|
1435
|
-
urlUnderTest,
|
|
1436
|
-
enrichedFlags,
|
|
1437
|
-
config
|
|
1438
|
-
);
|
|
1439
|
-
if (runnerResult == null) {
|
|
1440
|
-
throw new Error("Lighthouse did not produce a result.");
|
|
1441
|
-
}
|
|
1442
|
-
const { lhr } = runnerResult;
|
|
1443
|
-
const auditOutputs = toAuditOutputs(Object.values(lhr.audits), flags);
|
|
1444
|
-
return normalizeAuditOutputs(auditOutputs, enrichedFlags);
|
|
1445
|
-
};
|
|
1446
|
-
}
|
|
1447
|
-
|
|
1448
|
-
// packages/plugin-lighthouse/src/lib/normalize-flags.ts
|
|
1449
|
-
var { onlyCategories, ...originalDefaultCliFlags } = DEFAULT_CLI_FLAGS;
|
|
1450
|
-
var DEFAULT_LIGHTHOUSE_OPTIONS = {
|
|
1451
|
-
...originalDefaultCliFlags,
|
|
1452
|
-
onlyGroups: onlyCategories
|
|
1453
|
-
};
|
|
1454
|
-
var lighthouseUnsupportedCliFlags = [
|
|
1455
|
-
"precomputedLanternDataPath",
|
|
1456
|
-
// Path to the file where precomputed lantern data should be read from.
|
|
1457
|
-
"chromeIgnoreDefaultFlags",
|
|
1458
|
-
// ignore default flags from Lighthouse CLI
|
|
1459
|
-
// No error reporting implemented as in the source Sentry was involved
|
|
1460
|
-
// See: https://github.com/GoogleChrome/lighthouse/blob/d8ccf70692216b7fa047a4eaa2d1277b0b7fe947/cli/bin.js#L124
|
|
1461
|
-
"enableErrorReporting",
|
|
1462
|
-
// enable error reporting
|
|
1463
|
-
// lighthouse CLI specific debug logs
|
|
1464
|
-
"list-all-audits",
|
|
1465
|
-
// Prints a list of all available audits and exits.
|
|
1466
|
-
"list-locales",
|
|
1467
|
-
// Prints a list of all supported locales and exits.
|
|
1468
|
-
"list-trace-categories"
|
|
1469
|
-
// Prints a list of all required trace categories and exits.
|
|
1470
|
-
];
|
|
1471
|
-
var LIGHTHOUSE_UNSUPPORTED_CLI_FLAGS = new Set(lighthouseUnsupportedCliFlags);
|
|
1472
|
-
var REFINED_STRING_OR_STRING_ARRAY = /* @__PURE__ */ new Set([
|
|
1473
|
-
"onlyAudits",
|
|
1474
|
-
"onlyCategories",
|
|
1475
|
-
"skipAudits",
|
|
1476
|
-
"budgets",
|
|
1477
|
-
"chromeFlags"
|
|
1478
|
-
]);
|
|
1479
|
-
function normalizeFlags(flags) {
|
|
1480
|
-
const prefilledFlags = { ...DEFAULT_LIGHTHOUSE_OPTIONS, ...flags };
|
|
1481
|
-
logUnsupportedFlagsInUse(prefilledFlags);
|
|
1482
|
-
return Object.fromEntries(
|
|
1483
|
-
Object.entries(prefilledFlags).filter(
|
|
1484
|
-
([flagName]) => !LIGHTHOUSE_UNSUPPORTED_CLI_FLAGS.has(
|
|
1485
|
-
flagName
|
|
1486
|
-
)
|
|
1487
|
-
).map(([key, v]) => [key === "onlyGroups" ? "onlyCategories" : key, v]).filter(([_, v]) => !(Array.isArray(v) && v.length === 0)).map(([key, v]) => {
|
|
1488
|
-
if (!REFINED_STRING_OR_STRING_ARRAY.has(key)) {
|
|
1489
|
-
return [key, v];
|
|
1490
|
-
}
|
|
1491
|
-
return [key, Array.isArray(v) ? v : v == null ? [] : [v]];
|
|
1492
|
-
})
|
|
1493
|
-
);
|
|
1494
|
-
}
|
|
1495
|
-
function logUnsupportedFlagsInUse(flags, displayCount = 3) {
|
|
1496
|
-
const unsupportedFlagsInUse = Object.keys(flags).filter(
|
|
1497
|
-
(flag) => LIGHTHOUSE_UNSUPPORTED_CLI_FLAGS.has(flag)
|
|
1498
|
-
);
|
|
1499
|
-
if (unsupportedFlagsInUse.length > 0) {
|
|
1500
|
-
const postFix = (count) => count > displayCount ? ` and ${count - displayCount} more.` : "";
|
|
1501
|
-
ui().logger.debug(
|
|
1502
|
-
`${yellow2("\u26A0")} Plugin ${bold9(
|
|
1503
|
-
LIGHTHOUSE_PLUGIN_SLUG
|
|
1504
|
-
)} used unsupported flags: ${bold9(
|
|
1505
|
-
unsupportedFlagsInUse.slice(0, displayCount).join(", ")
|
|
1506
|
-
)}${postFix(unsupportedFlagsInUse.length)}`
|
|
1507
|
-
);
|
|
1508
|
-
}
|
|
1509
|
-
}
|
|
1510
|
-
|
|
1511
|
-
// packages/plugin-lighthouse/src/lib/utils.ts
|
|
1512
|
-
function lighthouseGroupRef(groupSlug, weight = 1) {
|
|
1513
|
-
return {
|
|
1514
|
-
plugin: LIGHTHOUSE_PLUGIN_SLUG,
|
|
1515
|
-
slug: groupSlug,
|
|
1516
|
-
type: "group",
|
|
1517
|
-
weight
|
|
1518
|
-
};
|
|
1519
|
-
}
|
|
1520
|
-
function lighthouseAuditRef(auditSlug, weight = 1) {
|
|
1521
|
-
return {
|
|
1522
|
-
plugin: LIGHTHOUSE_PLUGIN_SLUG,
|
|
1523
|
-
slug: auditSlug,
|
|
1524
|
-
type: "audit",
|
|
1525
|
-
weight
|
|
1526
|
-
};
|
|
1527
|
-
}
|
|
1528
|
-
var AuditsNotImplementedError = class extends Error {
|
|
1529
|
-
constructor(auditSlugs) {
|
|
1530
|
-
super(`audits: "${auditSlugs.join(", ")}" not implemented`);
|
|
1531
|
-
}
|
|
1532
|
-
};
|
|
1533
|
-
function validateAudits(audits2, onlyAudits) {
|
|
1534
|
-
const missingAudtis = toArray(onlyAudits).filter(
|
|
1535
|
-
(slug) => !audits2.some((audit) => audit.slug === slug)
|
|
1536
|
-
);
|
|
1537
|
-
if (missingAudtis.length > 0) {
|
|
1538
|
-
throw new AuditsNotImplementedError(missingAudtis);
|
|
1539
|
-
}
|
|
1540
|
-
return true;
|
|
1541
|
-
}
|
|
1542
|
-
var CategoriesNotImplementedError = class extends Error {
|
|
1543
|
-
constructor(categorySlugs) {
|
|
1544
|
-
super(`categories: "${categorySlugs.join(", ")}" not implemented`);
|
|
1545
|
-
}
|
|
1546
|
-
};
|
|
1547
|
-
function validateOnlyCategories(groups, onlyCategories2) {
|
|
1548
|
-
const missingCategories = toArray(onlyCategories2).filter(
|
|
1549
|
-
(slug) => groups.every((group) => group.slug !== slug)
|
|
1550
|
-
);
|
|
1551
|
-
if (missingCategories.length > 0) {
|
|
1552
|
-
throw new CategoriesNotImplementedError(missingCategories);
|
|
1553
|
-
}
|
|
1554
|
-
return true;
|
|
1555
|
-
}
|
|
1556
|
-
function filterAuditsAndGroupsByOnlyOptions(audits2, groups, options) {
|
|
1557
|
-
const {
|
|
1558
|
-
onlyAudits = [],
|
|
1559
|
-
skipAudits = [],
|
|
1560
|
-
onlyCategories: onlyCategories2 = []
|
|
1561
|
-
} = options ?? {};
|
|
1562
|
-
if (onlyCategories2.length > 0) {
|
|
1563
|
-
validateOnlyCategories(groups, onlyCategories2);
|
|
1564
|
-
const categorySlugs = new Set(onlyCategories2);
|
|
1565
|
-
const filteredGroups = groups.filter(
|
|
1566
|
-
({ slug }) => categorySlugs.has(slug)
|
|
1567
|
-
);
|
|
1568
|
-
const auditSlugsFromRemainingGroups = new Set(
|
|
1569
|
-
filteredGroups.flatMap(({ refs }) => refs.map(({ slug }) => slug))
|
|
1570
|
-
);
|
|
1571
|
-
return {
|
|
1572
|
-
audits: audits2.filter(
|
|
1573
|
-
({ slug }) => auditSlugsFromRemainingGroups.has(slug)
|
|
1574
|
-
),
|
|
1575
|
-
groups: filteredGroups
|
|
1576
|
-
};
|
|
1577
|
-
} else if (onlyAudits.length > 0 || skipAudits.length > 0) {
|
|
1578
|
-
validateAudits(audits2, onlyAudits);
|
|
1579
|
-
validateAudits(audits2, skipAudits);
|
|
1580
|
-
const onlyAuditSlugs = new Set(onlyAudits);
|
|
1581
|
-
const skipAuditSlugs = new Set(skipAudits);
|
|
1582
|
-
const filterAudits = ({ slug }) => !// audit is NOT in given onlyAuditSlugs
|
|
1583
|
-
(onlyAudits.length > 0 && !onlyAuditSlugs.has(slug) || // audit IS in given skipAuditSlugs
|
|
1584
|
-
skipAudits.length > 0 && skipAuditSlugs.has(slug));
|
|
1585
|
-
return {
|
|
1586
|
-
audits: audits2.filter(filterAudits),
|
|
1587
|
-
groups: filterItemRefsBy(groups, filterAudits)
|
|
1588
|
-
};
|
|
1589
|
-
}
|
|
1590
|
-
return {
|
|
1591
|
-
audits: audits2,
|
|
1592
|
-
groups
|
|
1593
|
-
};
|
|
1594
|
-
}
|
|
1595
|
-
|
|
1596
|
-
// packages/plugin-lighthouse/src/lib/lighthouse-plugin.ts
|
|
1597
|
-
function lighthousePlugin(url, flags) {
|
|
1598
|
-
const { skipAudits, onlyAudits, onlyCategories: onlyCategories2, ...unparsedFlags } = normalizeFlags(flags ?? {});
|
|
1599
|
-
const { audits: audits2, groups } = filterAuditsAndGroupsByOnlyOptions(
|
|
1600
|
-
LIGHTHOUSE_NAVIGATION_AUDITS,
|
|
1601
|
-
LIGHTHOUSE_GROUPS,
|
|
1602
|
-
{ skipAudits, onlyAudits, onlyCategories: onlyCategories2 }
|
|
1603
|
-
);
|
|
1604
|
-
return {
|
|
1605
|
-
slug: LIGHTHOUSE_PLUGIN_SLUG,
|
|
1606
|
-
packageName: name,
|
|
1607
|
-
version,
|
|
1608
|
-
title: "Lighthouse",
|
|
1609
|
-
icon: "lighthouse",
|
|
1610
|
-
audits: audits2,
|
|
1611
|
-
groups,
|
|
1612
|
-
runner: createRunnerFunction(url, {
|
|
1613
|
-
skipAudits,
|
|
1614
|
-
onlyAudits,
|
|
1615
|
-
onlyCategories: onlyCategories2,
|
|
1616
|
-
...unparsedFlags
|
|
1617
|
-
})
|
|
1618
|
-
};
|
|
1619
|
-
}
|
|
1620
|
-
|
|
1621
|
-
// packages/plugin-lighthouse/src/index.ts
|
|
1622
|
-
var src_default = lighthousePlugin;
|
|
1623
|
-
export {
|
|
1624
|
-
DEFAULT_CHROME_FLAGS,
|
|
1625
|
-
LIGHTHOUSE_OUTPUT_PATH,
|
|
1626
|
-
LIGHTHOUSE_PLUGIN_SLUG,
|
|
1627
|
-
LIGHTHOUSE_REPORT_NAME,
|
|
1628
|
-
src_default as default,
|
|
1629
|
-
lighthouseAuditRef,
|
|
1630
|
-
lighthouseGroupRef,
|
|
1631
|
-
lighthousePlugin
|
|
1632
|
-
};
|