@code-pushup/coverage-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/bin.js +3 -0
- package/src/bin.js.map +1 -0
- package/src/index.d.ts +3 -3
- package/src/index.js +4 -0
- package/src/index.js.map +1 -0
- package/src/lib/config.js +54 -0
- package/src/lib/config.js.map +1 -0
- package/src/lib/coverage-plugin.d.ts +1 -1
- package/src/lib/coverage-plugin.js +57 -0
- package/src/lib/coverage-plugin.js.map +1 -0
- package/src/lib/nx/coverage-paths.d.ts +1 -1
- package/src/lib/nx/coverage-paths.js +94 -0
- package/src/lib/nx/coverage-paths.js.map +1 -0
- package/src/lib/runner/constants.js +7 -0
- package/src/lib/runner/constants.js.map +1 -0
- package/src/lib/runner/index.d.ts +1 -1
- package/src/lib/runner/index.js +45 -0
- package/src/lib/runner/index.js.map +1 -0
- package/src/lib/runner/lcov/lcov-runner.d.ts +1 -1
- package/src/lib/runner/lcov/lcov-runner.js +90 -0
- package/src/lib/runner/lcov/lcov-runner.js.map +1 -0
- package/src/lib/runner/lcov/merge-lcov.js +103 -0
- package/src/lib/runner/lcov/merge-lcov.js.map +1 -0
- package/src/lib/runner/lcov/parse-lcov.js +5 -0
- package/src/lib/runner/lcov/parse-lcov.js.map +1 -0
- package/src/lib/runner/lcov/transform.d.ts +2 -2
- package/src/lib/runner/lcov/transform.js +111 -0
- package/src/lib/runner/lcov/transform.js.map +1 -0
- package/src/lib/runner/lcov/types.d.ts +1 -1
- package/src/lib/runner/lcov/types.js +2 -0
- package/src/lib/runner/lcov/types.js.map +1 -0
- package/src/lib/runner/lcov/utils.d.ts +1 -1
- package/src/lib/runner/lcov/utils.js +25 -0
- package/src/lib/runner/lcov/utils.js.map +1 -0
- package/src/lib/utils.d.ts +1 -1
- package/src/lib/utils.js +22 -0
- package/src/lib/utils.js.map +1 -0
- package/bin.js +0 -1236
- package/index.js +0 -1065
package/bin.js
DELETED
|
@@ -1,1236 +0,0 @@
|
|
|
1
|
-
// packages/plugin-coverage/src/lib/runner/index.ts
|
|
2
|
-
import { bold as bold5 } from "ansis";
|
|
3
|
-
import { writeFile } from "node:fs/promises";
|
|
4
|
-
import { dirname as dirname2 } from "node:path";
|
|
5
|
-
|
|
6
|
-
// packages/models/src/lib/implementation/schemas.ts
|
|
7
|
-
import { MATERIAL_ICONS } from "vscode-material-icons";
|
|
8
|
-
import { z } from "zod";
|
|
9
|
-
|
|
10
|
-
// packages/models/src/lib/implementation/limits.ts
|
|
11
|
-
var MAX_SLUG_LENGTH = 128;
|
|
12
|
-
var MAX_TITLE_LENGTH = 256;
|
|
13
|
-
var MAX_DESCRIPTION_LENGTH = 65536;
|
|
14
|
-
var MAX_ISSUE_MESSAGE_LENGTH = 1024;
|
|
15
|
-
|
|
16
|
-
// packages/models/src/lib/implementation/utils.ts
|
|
17
|
-
var slugRegex = /^[a-z\d]+(?:-[a-z\d]+)*$/;
|
|
18
|
-
var filenameRegex = /^(?!.*[ \\/:*?"<>|]).+$/;
|
|
19
|
-
function hasDuplicateStrings(strings) {
|
|
20
|
-
const sortedStrings = strings.toSorted();
|
|
21
|
-
const duplStrings = sortedStrings.filter(
|
|
22
|
-
(item, index) => index !== 0 && item === sortedStrings[index - 1]
|
|
23
|
-
);
|
|
24
|
-
return duplStrings.length === 0 ? false : [...new Set(duplStrings)];
|
|
25
|
-
}
|
|
26
|
-
function hasMissingStrings(toCheck, existing) {
|
|
27
|
-
const nonExisting = toCheck.filter((s) => !existing.includes(s));
|
|
28
|
-
return nonExisting.length === 0 ? false : nonExisting;
|
|
29
|
-
}
|
|
30
|
-
function errorItems(items, transform = (itemArr) => itemArr.join(", ")) {
|
|
31
|
-
return transform(items || []);
|
|
32
|
-
}
|
|
33
|
-
function exists(value) {
|
|
34
|
-
return value != null;
|
|
35
|
-
}
|
|
36
|
-
function getMissingRefsForCategories(categories, plugins) {
|
|
37
|
-
if (!categories || categories.length === 0) {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
const auditRefsFromCategory = categories.flatMap(
|
|
41
|
-
({ refs }) => refs.filter(({ type }) => type === "audit").map(({ plugin, slug }) => `${plugin}/${slug}`)
|
|
42
|
-
);
|
|
43
|
-
const auditRefsFromPlugins = plugins.flatMap(
|
|
44
|
-
({ audits, slug: pluginSlug }) => audits.map(({ slug }) => `${pluginSlug}/${slug}`)
|
|
45
|
-
);
|
|
46
|
-
const missingAuditRefs = hasMissingStrings(
|
|
47
|
-
auditRefsFromCategory,
|
|
48
|
-
auditRefsFromPlugins
|
|
49
|
-
);
|
|
50
|
-
const groupRefsFromCategory = categories.flatMap(
|
|
51
|
-
({ refs }) => refs.filter(({ type }) => type === "group").map(({ plugin, slug }) => `${plugin}#${slug} (group)`)
|
|
52
|
-
);
|
|
53
|
-
const groupRefsFromPlugins = plugins.flatMap(
|
|
54
|
-
({ groups, slug: pluginSlug }) => Array.isArray(groups) ? groups.map(({ slug }) => `${pluginSlug}#${slug} (group)`) : []
|
|
55
|
-
);
|
|
56
|
-
const missingGroupRefs = hasMissingStrings(
|
|
57
|
-
groupRefsFromCategory,
|
|
58
|
-
groupRefsFromPlugins
|
|
59
|
-
);
|
|
60
|
-
const missingRefs = [missingAuditRefs, missingGroupRefs].filter((refs) => Array.isArray(refs) && refs.length > 0).flat();
|
|
61
|
-
return missingRefs.length > 0 ? missingRefs : false;
|
|
62
|
-
}
|
|
63
|
-
function missingRefsForCategoriesErrorMsg(categories, plugins) {
|
|
64
|
-
const missingRefs = getMissingRefsForCategories(categories, plugins);
|
|
65
|
-
return `The following category references need to point to an audit or group: ${errorItems(
|
|
66
|
-
missingRefs
|
|
67
|
-
)}`;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// packages/models/src/lib/implementation/schemas.ts
|
|
71
|
-
var tableCellValueSchema = z.union([z.string(), z.number(), z.boolean(), z.null()]).default(null);
|
|
72
|
-
function executionMetaSchema(options = {
|
|
73
|
-
descriptionDate: "Execution start date and time",
|
|
74
|
-
descriptionDuration: "Execution duration in ms"
|
|
75
|
-
}) {
|
|
76
|
-
return z.object({
|
|
77
|
-
date: z.string({ description: options.descriptionDate }),
|
|
78
|
-
duration: z.number({ description: options.descriptionDuration })
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
var slugSchema = z.string({ description: "Unique ID (human-readable, URL-safe)" }).regex(slugRegex, {
|
|
82
|
-
message: "The slug has to follow the pattern [0-9a-z] followed by multiple optional groups of -[0-9a-z]. e.g. my-slug"
|
|
83
|
-
}).max(MAX_SLUG_LENGTH, {
|
|
84
|
-
message: `slug can be max ${MAX_SLUG_LENGTH} characters long`
|
|
85
|
-
});
|
|
86
|
-
var descriptionSchema = z.string({ description: "Description (markdown)" }).max(MAX_DESCRIPTION_LENGTH).optional();
|
|
87
|
-
var urlSchema = z.string().url();
|
|
88
|
-
var docsUrlSchema = urlSchema.optional().or(z.literal("")).describe("Documentation site");
|
|
89
|
-
var titleSchema = z.string({ description: "Descriptive name" }).max(MAX_TITLE_LENGTH);
|
|
90
|
-
var scoreSchema = z.number({
|
|
91
|
-
description: "Value between 0 and 1"
|
|
92
|
-
}).min(0).max(1);
|
|
93
|
-
function metaSchema(options) {
|
|
94
|
-
const {
|
|
95
|
-
descriptionDescription,
|
|
96
|
-
titleDescription,
|
|
97
|
-
docsUrlDescription,
|
|
98
|
-
description
|
|
99
|
-
} = options ?? {};
|
|
100
|
-
return z.object(
|
|
101
|
-
{
|
|
102
|
-
title: titleDescription ? titleSchema.describe(titleDescription) : titleSchema,
|
|
103
|
-
description: descriptionDescription ? descriptionSchema.describe(descriptionDescription) : descriptionSchema,
|
|
104
|
-
docsUrl: docsUrlDescription ? docsUrlSchema.describe(docsUrlDescription) : docsUrlSchema
|
|
105
|
-
},
|
|
106
|
-
{ description }
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
var filePathSchema = z.string().trim().min(1, { message: "path is invalid" });
|
|
110
|
-
var fileNameSchema = z.string().trim().regex(filenameRegex, {
|
|
111
|
-
message: `The filename has to be valid`
|
|
112
|
-
}).min(1, { message: "file name is invalid" });
|
|
113
|
-
var positiveIntSchema = z.number().int().positive();
|
|
114
|
-
var nonnegativeNumberSchema = z.number().nonnegative();
|
|
115
|
-
function packageVersionSchema(options) {
|
|
116
|
-
const { versionDescription = "NPM version of the package", required } = options ?? {};
|
|
117
|
-
const packageSchema = z.string({ description: "NPM package name" });
|
|
118
|
-
const versionSchema = z.string({ description: versionDescription });
|
|
119
|
-
return z.object(
|
|
120
|
-
{
|
|
121
|
-
packageName: required ? packageSchema : packageSchema.optional(),
|
|
122
|
-
version: required ? versionSchema : versionSchema.optional()
|
|
123
|
-
},
|
|
124
|
-
{ description: "NPM package name and version of a published package" }
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
var weightSchema = nonnegativeNumberSchema.describe(
|
|
128
|
-
"Coefficient for the given score (use weight 0 if only for display)"
|
|
129
|
-
);
|
|
130
|
-
function weightedRefSchema(description, slugDescription) {
|
|
131
|
-
return z.object(
|
|
132
|
-
{
|
|
133
|
-
slug: slugSchema.describe(slugDescription),
|
|
134
|
-
weight: weightSchema.describe("Weight used to calculate score")
|
|
135
|
-
},
|
|
136
|
-
{ description }
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
function scorableSchema(description, refSchema, duplicateCheckFn, duplicateMessageFn) {
|
|
140
|
-
return z.object(
|
|
141
|
-
{
|
|
142
|
-
slug: slugSchema.describe('Human-readable unique ID, e.g. "performance"'),
|
|
143
|
-
refs: z.array(refSchema).min(1).refine(
|
|
144
|
-
(refs) => !duplicateCheckFn(refs),
|
|
145
|
-
(refs) => ({
|
|
146
|
-
message: duplicateMessageFn(refs)
|
|
147
|
-
})
|
|
148
|
-
).refine(hasNonZeroWeightedRef, () => ({
|
|
149
|
-
message: "In a category there has to be at least one ref with weight > 0"
|
|
150
|
-
}))
|
|
151
|
-
},
|
|
152
|
-
{ description }
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
var materialIconSchema = z.enum(MATERIAL_ICONS, {
|
|
156
|
-
description: "Icon from VSCode Material Icons extension"
|
|
157
|
-
});
|
|
158
|
-
function hasNonZeroWeightedRef(refs) {
|
|
159
|
-
return refs.reduce((acc, { weight }) => weight + acc, 0) !== 0;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// packages/models/src/lib/source.ts
|
|
163
|
-
import { z as z2 } from "zod";
|
|
164
|
-
var sourceFileLocationSchema = z2.object(
|
|
165
|
-
{
|
|
166
|
-
file: filePathSchema.describe("Relative path to source file in Git repo"),
|
|
167
|
-
position: z2.object(
|
|
168
|
-
{
|
|
169
|
-
startLine: positiveIntSchema.describe("Start line"),
|
|
170
|
-
startColumn: positiveIntSchema.describe("Start column").optional(),
|
|
171
|
-
endLine: positiveIntSchema.describe("End line").optional(),
|
|
172
|
-
endColumn: positiveIntSchema.describe("End column").optional()
|
|
173
|
-
},
|
|
174
|
-
{ description: "Location in file" }
|
|
175
|
-
).optional()
|
|
176
|
-
},
|
|
177
|
-
{ description: "Source file location" }
|
|
178
|
-
);
|
|
179
|
-
|
|
180
|
-
// packages/models/src/lib/audit.ts
|
|
181
|
-
import { z as z3 } from "zod";
|
|
182
|
-
var auditSchema = z3.object({
|
|
183
|
-
slug: slugSchema.describe("ID (unique within plugin)")
|
|
184
|
-
}).merge(
|
|
185
|
-
metaSchema({
|
|
186
|
-
titleDescription: "Descriptive name",
|
|
187
|
-
descriptionDescription: "Description (markdown)",
|
|
188
|
-
docsUrlDescription: "Link to documentation (rationale)",
|
|
189
|
-
description: "List of scorable metrics for the given plugin"
|
|
190
|
-
})
|
|
191
|
-
);
|
|
192
|
-
var pluginAuditsSchema = z3.array(auditSchema, {
|
|
193
|
-
description: "List of audits maintained in a plugin"
|
|
194
|
-
}).min(1).refine(
|
|
195
|
-
(auditMetadata) => !getDuplicateSlugsInAudits(auditMetadata),
|
|
196
|
-
(auditMetadata) => ({
|
|
197
|
-
message: duplicateSlugsInAuditsErrorMsg(auditMetadata)
|
|
198
|
-
})
|
|
199
|
-
);
|
|
200
|
-
function duplicateSlugsInAuditsErrorMsg(audits) {
|
|
201
|
-
const duplicateRefs = getDuplicateSlugsInAudits(audits);
|
|
202
|
-
return `In plugin audits the following slugs are not unique: ${errorItems(
|
|
203
|
-
duplicateRefs
|
|
204
|
-
)}`;
|
|
205
|
-
}
|
|
206
|
-
function getDuplicateSlugsInAudits(audits) {
|
|
207
|
-
return hasDuplicateStrings(audits.map(({ slug }) => slug));
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// packages/models/src/lib/audit-output.ts
|
|
211
|
-
import { z as z6 } from "zod";
|
|
212
|
-
|
|
213
|
-
// packages/models/src/lib/issue.ts
|
|
214
|
-
import { z as z4 } from "zod";
|
|
215
|
-
var issueSeveritySchema = z4.enum(["info", "warning", "error"], {
|
|
216
|
-
description: "Severity level"
|
|
217
|
-
});
|
|
218
|
-
var issueSchema = z4.object(
|
|
219
|
-
{
|
|
220
|
-
message: z4.string({ description: "Descriptive error message" }).max(MAX_ISSUE_MESSAGE_LENGTH),
|
|
221
|
-
severity: issueSeveritySchema,
|
|
222
|
-
source: sourceFileLocationSchema.optional()
|
|
223
|
-
},
|
|
224
|
-
{ description: "Issue information" }
|
|
225
|
-
);
|
|
226
|
-
|
|
227
|
-
// packages/models/src/lib/table.ts
|
|
228
|
-
import { z as z5 } from "zod";
|
|
229
|
-
var tableAlignmentSchema = z5.enum(["left", "center", "right"], {
|
|
230
|
-
description: "Cell alignment"
|
|
231
|
-
});
|
|
232
|
-
var tableColumnObjectSchema = z5.object({
|
|
233
|
-
key: z5.string(),
|
|
234
|
-
label: z5.string().optional(),
|
|
235
|
-
align: tableAlignmentSchema.optional()
|
|
236
|
-
});
|
|
237
|
-
var tableRowObjectSchema = z5.record(tableCellValueSchema, {
|
|
238
|
-
description: "Object row"
|
|
239
|
-
});
|
|
240
|
-
var tableRowPrimitiveSchema = z5.array(tableCellValueSchema, {
|
|
241
|
-
description: "Primitive row"
|
|
242
|
-
});
|
|
243
|
-
var tableSharedSchema = z5.object({
|
|
244
|
-
title: z5.string().optional().describe("Display title for table")
|
|
245
|
-
});
|
|
246
|
-
var tablePrimitiveSchema = tableSharedSchema.merge(
|
|
247
|
-
z5.object(
|
|
248
|
-
{
|
|
249
|
-
columns: z5.array(tableAlignmentSchema).optional(),
|
|
250
|
-
rows: z5.array(tableRowPrimitiveSchema)
|
|
251
|
-
},
|
|
252
|
-
{ description: "Table with primitive rows and optional alignment columns" }
|
|
253
|
-
)
|
|
254
|
-
);
|
|
255
|
-
var tableObjectSchema = tableSharedSchema.merge(
|
|
256
|
-
z5.object(
|
|
257
|
-
{
|
|
258
|
-
columns: z5.union([
|
|
259
|
-
z5.array(tableAlignmentSchema),
|
|
260
|
-
z5.array(tableColumnObjectSchema)
|
|
261
|
-
]).optional(),
|
|
262
|
-
rows: z5.array(tableRowObjectSchema)
|
|
263
|
-
},
|
|
264
|
-
{
|
|
265
|
-
description: "Table with object rows and optional alignment or object columns"
|
|
266
|
-
}
|
|
267
|
-
)
|
|
268
|
-
);
|
|
269
|
-
var tableSchema = (description = "Table information") => z5.union([tablePrimitiveSchema, tableObjectSchema], { description });
|
|
270
|
-
|
|
271
|
-
// packages/models/src/lib/audit-output.ts
|
|
272
|
-
var auditValueSchema = nonnegativeNumberSchema.describe("Raw numeric value");
|
|
273
|
-
var auditDisplayValueSchema = z6.string({ description: "Formatted value (e.g. '0.9 s', '2.1 MB')" }).optional();
|
|
274
|
-
var auditDetailsSchema = z6.object(
|
|
275
|
-
{
|
|
276
|
-
issues: z6.array(issueSchema, { description: "List of findings" }).optional(),
|
|
277
|
-
table: tableSchema("Table of related findings").optional()
|
|
278
|
-
},
|
|
279
|
-
{ description: "Detailed information" }
|
|
280
|
-
);
|
|
281
|
-
var auditOutputSchema = z6.object(
|
|
282
|
-
{
|
|
283
|
-
slug: slugSchema.describe("Reference to audit"),
|
|
284
|
-
displayValue: auditDisplayValueSchema,
|
|
285
|
-
value: auditValueSchema,
|
|
286
|
-
score: scoreSchema,
|
|
287
|
-
details: auditDetailsSchema.optional()
|
|
288
|
-
},
|
|
289
|
-
{ description: "Audit information" }
|
|
290
|
-
);
|
|
291
|
-
var auditOutputsSchema = z6.array(auditOutputSchema, {
|
|
292
|
-
description: "List of JSON formatted audit output emitted by the runner process of a plugin"
|
|
293
|
-
}).refine(
|
|
294
|
-
(audits) => !getDuplicateSlugsInAudits2(audits),
|
|
295
|
-
(audits) => ({ message: duplicateSlugsInAuditsErrorMsg2(audits) })
|
|
296
|
-
);
|
|
297
|
-
function duplicateSlugsInAuditsErrorMsg2(audits) {
|
|
298
|
-
const duplicateRefs = getDuplicateSlugsInAudits2(audits);
|
|
299
|
-
return `In plugin audits the slugs are not unique: ${errorItems(
|
|
300
|
-
duplicateRefs
|
|
301
|
-
)}`;
|
|
302
|
-
}
|
|
303
|
-
function getDuplicateSlugsInAudits2(audits) {
|
|
304
|
-
return hasDuplicateStrings(audits.map(({ slug }) => slug));
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
// packages/models/src/lib/category-config.ts
|
|
308
|
-
import { z as z7 } from "zod";
|
|
309
|
-
var categoryRefSchema = weightedRefSchema(
|
|
310
|
-
"Weighted references to audits and/or groups for the category",
|
|
311
|
-
"Slug of an audit or group (depending on `type`)"
|
|
312
|
-
).merge(
|
|
313
|
-
z7.object({
|
|
314
|
-
type: z7.enum(["audit", "group"], {
|
|
315
|
-
description: "Discriminant for reference kind, affects where `slug` is looked up"
|
|
316
|
-
}),
|
|
317
|
-
plugin: slugSchema.describe(
|
|
318
|
-
"Plugin slug (plugin should contain referenced audit or group)"
|
|
319
|
-
)
|
|
320
|
-
})
|
|
321
|
-
);
|
|
322
|
-
var categoryConfigSchema = scorableSchema(
|
|
323
|
-
"Category with a score calculated from audits and groups from various plugins",
|
|
324
|
-
categoryRefSchema,
|
|
325
|
-
getDuplicateRefsInCategoryMetrics,
|
|
326
|
-
duplicateRefsInCategoryMetricsErrorMsg
|
|
327
|
-
).merge(
|
|
328
|
-
metaSchema({
|
|
329
|
-
titleDescription: "Category Title",
|
|
330
|
-
docsUrlDescription: "Category docs URL",
|
|
331
|
-
descriptionDescription: "Category description",
|
|
332
|
-
description: "Meta info for category"
|
|
333
|
-
})
|
|
334
|
-
).merge(
|
|
335
|
-
z7.object({
|
|
336
|
-
isBinary: z7.boolean({
|
|
337
|
-
description: 'Is this a binary category (i.e. only a perfect score considered a "pass")?'
|
|
338
|
-
}).optional()
|
|
339
|
-
})
|
|
340
|
-
);
|
|
341
|
-
function duplicateRefsInCategoryMetricsErrorMsg(metrics) {
|
|
342
|
-
const duplicateRefs = getDuplicateRefsInCategoryMetrics(metrics);
|
|
343
|
-
return `In the categories, the following audit or group refs are duplicates: ${errorItems(
|
|
344
|
-
duplicateRefs
|
|
345
|
-
)}`;
|
|
346
|
-
}
|
|
347
|
-
function getDuplicateRefsInCategoryMetrics(metrics) {
|
|
348
|
-
return hasDuplicateStrings(
|
|
349
|
-
metrics.map(({ slug, type, plugin }) => `${type} :: ${plugin} / ${slug}`)
|
|
350
|
-
);
|
|
351
|
-
}
|
|
352
|
-
var categoriesSchema = z7.array(categoryConfigSchema, {
|
|
353
|
-
description: "Categorization of individual audits"
|
|
354
|
-
}).refine(
|
|
355
|
-
(categoryCfg) => !getDuplicateSlugCategories(categoryCfg),
|
|
356
|
-
(categoryCfg) => ({
|
|
357
|
-
message: duplicateSlugCategoriesErrorMsg(categoryCfg)
|
|
358
|
-
})
|
|
359
|
-
);
|
|
360
|
-
function duplicateSlugCategoriesErrorMsg(categories) {
|
|
361
|
-
const duplicateStringSlugs = getDuplicateSlugCategories(categories);
|
|
362
|
-
return `In the categories, the following slugs are duplicated: ${errorItems(
|
|
363
|
-
duplicateStringSlugs
|
|
364
|
-
)}`;
|
|
365
|
-
}
|
|
366
|
-
function getDuplicateSlugCategories(categories) {
|
|
367
|
-
return hasDuplicateStrings(categories.map(({ slug }) => slug));
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
// packages/models/src/lib/commit.ts
|
|
371
|
-
import { z as z8 } from "zod";
|
|
372
|
-
var commitSchema = z8.object(
|
|
373
|
-
{
|
|
374
|
-
hash: z8.string({ description: "Commit SHA (full)" }).regex(
|
|
375
|
-
/^[\da-f]{40}$/,
|
|
376
|
-
"Commit SHA should be a 40-character hexadecimal string"
|
|
377
|
-
),
|
|
378
|
-
message: z8.string({ description: "Commit message" }),
|
|
379
|
-
date: z8.coerce.date({
|
|
380
|
-
description: "Date and time when commit was authored"
|
|
381
|
-
}),
|
|
382
|
-
author: z8.string({
|
|
383
|
-
description: "Commit author name"
|
|
384
|
-
}).trim()
|
|
385
|
-
},
|
|
386
|
-
{ description: "Git commit" }
|
|
387
|
-
);
|
|
388
|
-
|
|
389
|
-
// packages/models/src/lib/core-config.ts
|
|
390
|
-
import { z as z14 } from "zod";
|
|
391
|
-
|
|
392
|
-
// packages/models/src/lib/persist-config.ts
|
|
393
|
-
import { z as z9 } from "zod";
|
|
394
|
-
var formatSchema = z9.enum(["json", "md"]);
|
|
395
|
-
var persistConfigSchema = z9.object({
|
|
396
|
-
outputDir: filePathSchema.describe("Artifacts folder").optional(),
|
|
397
|
-
filename: fileNameSchema.describe("Artifacts file name (without extension)").optional(),
|
|
398
|
-
format: z9.array(formatSchema).optional()
|
|
399
|
-
});
|
|
400
|
-
|
|
401
|
-
// packages/models/src/lib/plugin-config.ts
|
|
402
|
-
import { z as z12 } from "zod";
|
|
403
|
-
|
|
404
|
-
// packages/models/src/lib/group.ts
|
|
405
|
-
import { z as z10 } from "zod";
|
|
406
|
-
var groupRefSchema = weightedRefSchema(
|
|
407
|
-
"Weighted reference to a group",
|
|
408
|
-
"Reference slug to a group within this plugin (e.g. 'max-lines')"
|
|
409
|
-
);
|
|
410
|
-
var groupMetaSchema = metaSchema({
|
|
411
|
-
titleDescription: "Descriptive name for the group",
|
|
412
|
-
descriptionDescription: "Description of the group (markdown)",
|
|
413
|
-
docsUrlDescription: "Group documentation site",
|
|
414
|
-
description: "Group metadata"
|
|
415
|
-
});
|
|
416
|
-
var groupSchema = scorableSchema(
|
|
417
|
-
'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',
|
|
418
|
-
groupRefSchema,
|
|
419
|
-
getDuplicateRefsInGroups,
|
|
420
|
-
duplicateRefsInGroupsErrorMsg
|
|
421
|
-
).merge(groupMetaSchema);
|
|
422
|
-
var groupsSchema = z10.array(groupSchema, {
|
|
423
|
-
description: "List of groups"
|
|
424
|
-
}).optional().refine(
|
|
425
|
-
(groups) => !getDuplicateSlugsInGroups(groups),
|
|
426
|
-
(groups) => ({
|
|
427
|
-
message: duplicateSlugsInGroupsErrorMsg(groups)
|
|
428
|
-
})
|
|
429
|
-
);
|
|
430
|
-
function duplicateRefsInGroupsErrorMsg(groups) {
|
|
431
|
-
const duplicateRefs = getDuplicateRefsInGroups(groups);
|
|
432
|
-
return `In plugin groups the following references are not unique: ${errorItems(
|
|
433
|
-
duplicateRefs
|
|
434
|
-
)}`;
|
|
435
|
-
}
|
|
436
|
-
function getDuplicateRefsInGroups(groups) {
|
|
437
|
-
return hasDuplicateStrings(groups.map(({ slug: ref }) => ref).filter(exists));
|
|
438
|
-
}
|
|
439
|
-
function duplicateSlugsInGroupsErrorMsg(groups) {
|
|
440
|
-
const duplicateRefs = getDuplicateSlugsInGroups(groups);
|
|
441
|
-
return `In groups the following slugs are not unique: ${errorItems(
|
|
442
|
-
duplicateRefs
|
|
443
|
-
)}`;
|
|
444
|
-
}
|
|
445
|
-
function getDuplicateSlugsInGroups(groups) {
|
|
446
|
-
return Array.isArray(groups) ? hasDuplicateStrings(groups.map(({ slug }) => slug)) : false;
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
// packages/models/src/lib/runner-config.ts
|
|
450
|
-
import { z as z11 } from "zod";
|
|
451
|
-
var outputTransformSchema = z11.function().args(z11.unknown()).returns(z11.union([auditOutputsSchema, z11.promise(auditOutputsSchema)]));
|
|
452
|
-
var runnerConfigSchema = z11.object(
|
|
453
|
-
{
|
|
454
|
-
command: z11.string({
|
|
455
|
-
description: "Shell command to execute"
|
|
456
|
-
}),
|
|
457
|
-
args: z11.array(z11.string({ description: "Command arguments" })).optional(),
|
|
458
|
-
outputFile: filePathSchema.describe("Output path"),
|
|
459
|
-
outputTransform: outputTransformSchema.optional()
|
|
460
|
-
},
|
|
461
|
-
{
|
|
462
|
-
description: "How to execute runner"
|
|
463
|
-
}
|
|
464
|
-
);
|
|
465
|
-
var onProgressSchema = z11.function().args(z11.unknown()).returns(z11.void());
|
|
466
|
-
var runnerFunctionSchema = z11.function().args(onProgressSchema.optional()).returns(z11.union([auditOutputsSchema, z11.promise(auditOutputsSchema)]));
|
|
467
|
-
|
|
468
|
-
// packages/models/src/lib/plugin-config.ts
|
|
469
|
-
var pluginMetaSchema = packageVersionSchema().merge(
|
|
470
|
-
metaSchema({
|
|
471
|
-
titleDescription: "Descriptive name",
|
|
472
|
-
descriptionDescription: "Description (markdown)",
|
|
473
|
-
docsUrlDescription: "Plugin documentation site",
|
|
474
|
-
description: "Plugin metadata"
|
|
475
|
-
})
|
|
476
|
-
).merge(
|
|
477
|
-
z12.object({
|
|
478
|
-
slug: slugSchema.describe("Unique plugin slug within core config"),
|
|
479
|
-
icon: materialIconSchema
|
|
480
|
-
})
|
|
481
|
-
);
|
|
482
|
-
var pluginDataSchema = z12.object({
|
|
483
|
-
runner: z12.union([runnerConfigSchema, runnerFunctionSchema]),
|
|
484
|
-
audits: pluginAuditsSchema,
|
|
485
|
-
groups: groupsSchema
|
|
486
|
-
});
|
|
487
|
-
var pluginConfigSchema = pluginMetaSchema.merge(pluginDataSchema).refine(
|
|
488
|
-
(pluginCfg) => !getMissingRefsFromGroups(pluginCfg),
|
|
489
|
-
(pluginCfg) => ({
|
|
490
|
-
message: missingRefsFromGroupsErrorMsg(pluginCfg)
|
|
491
|
-
})
|
|
492
|
-
);
|
|
493
|
-
function missingRefsFromGroupsErrorMsg(pluginCfg) {
|
|
494
|
-
const missingRefs = getMissingRefsFromGroups(pluginCfg);
|
|
495
|
-
return `The following group references need to point to an existing audit in this plugin config: ${errorItems(
|
|
496
|
-
missingRefs
|
|
497
|
-
)}`;
|
|
498
|
-
}
|
|
499
|
-
function getMissingRefsFromGroups(pluginCfg) {
|
|
500
|
-
return hasMissingStrings(
|
|
501
|
-
pluginCfg.groups?.flatMap(
|
|
502
|
-
({ refs: audits }) => audits.map(({ slug: ref }) => ref)
|
|
503
|
-
) ?? [],
|
|
504
|
-
pluginCfg.audits.map(({ slug }) => slug)
|
|
505
|
-
);
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
// packages/models/src/lib/upload-config.ts
|
|
509
|
-
import { z as z13 } from "zod";
|
|
510
|
-
var uploadConfigSchema = z13.object({
|
|
511
|
-
server: urlSchema.describe("URL of deployed portal API"),
|
|
512
|
-
apiKey: z13.string({
|
|
513
|
-
description: "API key with write access to portal (use `process.env` for security)"
|
|
514
|
-
}),
|
|
515
|
-
organization: slugSchema.describe(
|
|
516
|
-
"Organization slug from Code PushUp portal"
|
|
517
|
-
),
|
|
518
|
-
project: slugSchema.describe("Project slug from Code PushUp portal"),
|
|
519
|
-
timeout: z13.number({ description: "Request timeout in minutes (default is 5)" }).positive().int().optional()
|
|
520
|
-
});
|
|
521
|
-
|
|
522
|
-
// packages/models/src/lib/core-config.ts
|
|
523
|
-
var unrefinedCoreConfigSchema = z14.object({
|
|
524
|
-
plugins: z14.array(pluginConfigSchema, {
|
|
525
|
-
description: "List of plugins to be used (official, community-provided, or custom)"
|
|
526
|
-
}).min(1),
|
|
527
|
-
/** portal configuration for persisting results */
|
|
528
|
-
persist: persistConfigSchema.optional(),
|
|
529
|
-
/** portal configuration for uploading results */
|
|
530
|
-
upload: uploadConfigSchema.optional(),
|
|
531
|
-
categories: categoriesSchema.optional()
|
|
532
|
-
});
|
|
533
|
-
var coreConfigSchema = refineCoreConfig(unrefinedCoreConfigSchema);
|
|
534
|
-
function refineCoreConfig(schema) {
|
|
535
|
-
return schema.refine(
|
|
536
|
-
({ categories, plugins }) => !getMissingRefsForCategories(categories, plugins),
|
|
537
|
-
({ categories, plugins }) => ({
|
|
538
|
-
message: missingRefsForCategoriesErrorMsg(categories, plugins)
|
|
539
|
-
})
|
|
540
|
-
);
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
// packages/models/src/lib/report.ts
|
|
544
|
-
import { z as z15 } from "zod";
|
|
545
|
-
var auditReportSchema = auditSchema.merge(auditOutputSchema);
|
|
546
|
-
var pluginReportSchema = pluginMetaSchema.merge(
|
|
547
|
-
executionMetaSchema({
|
|
548
|
-
descriptionDate: "Start date and time of plugin run",
|
|
549
|
-
descriptionDuration: "Duration of the plugin run in ms"
|
|
550
|
-
})
|
|
551
|
-
).merge(
|
|
552
|
-
z15.object({
|
|
553
|
-
audits: z15.array(auditReportSchema).min(1),
|
|
554
|
-
groups: z15.array(groupSchema).optional()
|
|
555
|
-
})
|
|
556
|
-
).refine(
|
|
557
|
-
(pluginReport) => !getMissingRefsFromGroups2(pluginReport.audits, pluginReport.groups ?? []),
|
|
558
|
-
(pluginReport) => ({
|
|
559
|
-
message: missingRefsFromGroupsErrorMsg2(
|
|
560
|
-
pluginReport.audits,
|
|
561
|
-
pluginReport.groups ?? []
|
|
562
|
-
)
|
|
563
|
-
})
|
|
564
|
-
);
|
|
565
|
-
function missingRefsFromGroupsErrorMsg2(audits, groups) {
|
|
566
|
-
const missingRefs = getMissingRefsFromGroups2(audits, groups);
|
|
567
|
-
return `group references need to point to an existing audit in this plugin report: ${errorItems(
|
|
568
|
-
missingRefs
|
|
569
|
-
)}`;
|
|
570
|
-
}
|
|
571
|
-
function getMissingRefsFromGroups2(audits, groups) {
|
|
572
|
-
return hasMissingStrings(
|
|
573
|
-
groups.flatMap(
|
|
574
|
-
({ refs: auditRefs }) => auditRefs.map(({ slug: ref }) => ref)
|
|
575
|
-
),
|
|
576
|
-
audits.map(({ slug }) => slug)
|
|
577
|
-
);
|
|
578
|
-
}
|
|
579
|
-
var reportSchema = packageVersionSchema({
|
|
580
|
-
versionDescription: "NPM version of the CLI",
|
|
581
|
-
required: true
|
|
582
|
-
}).merge(
|
|
583
|
-
executionMetaSchema({
|
|
584
|
-
descriptionDate: "Start date and time of the collect run",
|
|
585
|
-
descriptionDuration: "Duration of the collect run in ms"
|
|
586
|
-
})
|
|
587
|
-
).merge(
|
|
588
|
-
z15.object(
|
|
589
|
-
{
|
|
590
|
-
plugins: z15.array(pluginReportSchema).min(1),
|
|
591
|
-
categories: z15.array(categoryConfigSchema).optional(),
|
|
592
|
-
commit: commitSchema.describe("Git commit for which report was collected").nullable()
|
|
593
|
-
},
|
|
594
|
-
{ description: "Collect output data" }
|
|
595
|
-
)
|
|
596
|
-
).refine(
|
|
597
|
-
({ categories, plugins }) => !getMissingRefsForCategories(categories, plugins),
|
|
598
|
-
({ categories, plugins }) => ({
|
|
599
|
-
message: missingRefsForCategoriesErrorMsg(categories, plugins)
|
|
600
|
-
})
|
|
601
|
-
);
|
|
602
|
-
|
|
603
|
-
// packages/models/src/lib/reports-diff.ts
|
|
604
|
-
import { z as z16 } from "zod";
|
|
605
|
-
function makeComparisonSchema(schema) {
|
|
606
|
-
const sharedDescription = schema.description || "Result";
|
|
607
|
-
return z16.object({
|
|
608
|
-
before: schema.describe(`${sharedDescription} (source commit)`),
|
|
609
|
-
after: schema.describe(`${sharedDescription} (target commit)`)
|
|
610
|
-
});
|
|
611
|
-
}
|
|
612
|
-
function makeArraysComparisonSchema(diffSchema, resultSchema, description) {
|
|
613
|
-
return z16.object(
|
|
614
|
-
{
|
|
615
|
-
changed: z16.array(diffSchema),
|
|
616
|
-
unchanged: z16.array(resultSchema),
|
|
617
|
-
added: z16.array(resultSchema),
|
|
618
|
-
removed: z16.array(resultSchema)
|
|
619
|
-
},
|
|
620
|
-
{ description }
|
|
621
|
-
);
|
|
622
|
-
}
|
|
623
|
-
var scorableMetaSchema = z16.object({
|
|
624
|
-
slug: slugSchema,
|
|
625
|
-
title: titleSchema,
|
|
626
|
-
docsUrl: docsUrlSchema
|
|
627
|
-
});
|
|
628
|
-
var scorableWithPluginMetaSchema = scorableMetaSchema.merge(
|
|
629
|
-
z16.object({
|
|
630
|
-
plugin: pluginMetaSchema.pick({ slug: true, title: true, docsUrl: true }).describe("Plugin which defines it")
|
|
631
|
-
})
|
|
632
|
-
);
|
|
633
|
-
var scorableDiffSchema = scorableMetaSchema.merge(
|
|
634
|
-
z16.object({
|
|
635
|
-
scores: makeComparisonSchema(scoreSchema).merge(
|
|
636
|
-
z16.object({
|
|
637
|
-
diff: z16.number().min(-1).max(1).describe("Score change (`scores.after - scores.before`)")
|
|
638
|
-
})
|
|
639
|
-
).describe("Score comparison")
|
|
640
|
-
})
|
|
641
|
-
);
|
|
642
|
-
var scorableWithPluginDiffSchema = scorableDiffSchema.merge(
|
|
643
|
-
scorableWithPluginMetaSchema
|
|
644
|
-
);
|
|
645
|
-
var categoryDiffSchema = scorableDiffSchema;
|
|
646
|
-
var groupDiffSchema = scorableWithPluginDiffSchema;
|
|
647
|
-
var auditDiffSchema = scorableWithPluginDiffSchema.merge(
|
|
648
|
-
z16.object({
|
|
649
|
-
values: makeComparisonSchema(auditValueSchema).merge(
|
|
650
|
-
z16.object({
|
|
651
|
-
diff: z16.number().describe("Value change (`values.after - values.before`)")
|
|
652
|
-
})
|
|
653
|
-
).describe("Audit `value` comparison"),
|
|
654
|
-
displayValues: makeComparisonSchema(auditDisplayValueSchema).describe(
|
|
655
|
-
"Audit `displayValue` comparison"
|
|
656
|
-
)
|
|
657
|
-
})
|
|
658
|
-
);
|
|
659
|
-
var categoryResultSchema = scorableMetaSchema.merge(
|
|
660
|
-
z16.object({ score: scoreSchema })
|
|
661
|
-
);
|
|
662
|
-
var groupResultSchema = scorableWithPluginMetaSchema.merge(
|
|
663
|
-
z16.object({ score: scoreSchema })
|
|
664
|
-
);
|
|
665
|
-
var auditResultSchema = scorableWithPluginMetaSchema.merge(
|
|
666
|
-
auditOutputSchema.pick({ score: true, value: true, displayValue: true })
|
|
667
|
-
);
|
|
668
|
-
var reportsDiffSchema = z16.object({
|
|
669
|
-
commits: makeComparisonSchema(commitSchema).nullable().describe("Commits identifying compared reports"),
|
|
670
|
-
portalUrl: urlSchema.optional().describe("Link to comparison page in Code PushUp portal"),
|
|
671
|
-
label: z16.string().optional().describe("Label (e.g. project name)"),
|
|
672
|
-
categories: makeArraysComparisonSchema(
|
|
673
|
-
categoryDiffSchema,
|
|
674
|
-
categoryResultSchema,
|
|
675
|
-
"Changes affecting categories"
|
|
676
|
-
),
|
|
677
|
-
groups: makeArraysComparisonSchema(
|
|
678
|
-
groupDiffSchema,
|
|
679
|
-
groupResultSchema,
|
|
680
|
-
"Changes affecting groups"
|
|
681
|
-
),
|
|
682
|
-
audits: makeArraysComparisonSchema(
|
|
683
|
-
auditDiffSchema,
|
|
684
|
-
auditResultSchema,
|
|
685
|
-
"Changes affecting audits"
|
|
686
|
-
)
|
|
687
|
-
}).merge(
|
|
688
|
-
packageVersionSchema({
|
|
689
|
-
versionDescription: "NPM version of the CLI (when `compare` was run)",
|
|
690
|
-
required: true
|
|
691
|
-
})
|
|
692
|
-
).merge(
|
|
693
|
-
executionMetaSchema({
|
|
694
|
-
descriptionDate: "Start date and time of the compare run",
|
|
695
|
-
descriptionDuration: "Duration of the compare run in ms"
|
|
696
|
-
})
|
|
697
|
-
);
|
|
698
|
-
|
|
699
|
-
// packages/utils/src/lib/execute-process.ts
|
|
700
|
-
import {
|
|
701
|
-
spawn
|
|
702
|
-
} from "node:child_process";
|
|
703
|
-
|
|
704
|
-
// packages/utils/src/lib/reports/utils.ts
|
|
705
|
-
import ansis from "ansis";
|
|
706
|
-
import { md } from "build-md";
|
|
707
|
-
|
|
708
|
-
// packages/utils/src/lib/reports/constants.ts
|
|
709
|
-
var TERMINAL_WIDTH = 80;
|
|
710
|
-
|
|
711
|
-
// packages/utils/src/lib/reports/utils.ts
|
|
712
|
-
function calcDuration(start, stop) {
|
|
713
|
-
return Math.round((stop ?? performance.now()) - start);
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
// packages/utils/src/lib/execute-process.ts
|
|
717
|
-
var ProcessError = class extends Error {
|
|
718
|
-
code;
|
|
719
|
-
stderr;
|
|
720
|
-
stdout;
|
|
721
|
-
constructor(result) {
|
|
722
|
-
super(result.stderr);
|
|
723
|
-
this.code = result.code;
|
|
724
|
-
this.stderr = result.stderr;
|
|
725
|
-
this.stdout = result.stdout;
|
|
726
|
-
}
|
|
727
|
-
};
|
|
728
|
-
function executeProcess(cfg) {
|
|
729
|
-
const { command, args, observer, ignoreExitCode = false, ...options } = cfg;
|
|
730
|
-
const { onStdout, onStderr, onError, onComplete } = observer ?? {};
|
|
731
|
-
const date = (/* @__PURE__ */ new Date()).toISOString();
|
|
732
|
-
const start = performance.now();
|
|
733
|
-
return new Promise((resolve, reject) => {
|
|
734
|
-
const spawnedProcess = spawn(command, args ?? [], {
|
|
735
|
-
shell: true,
|
|
736
|
-
windowsHide: true,
|
|
737
|
-
...options
|
|
738
|
-
});
|
|
739
|
-
let stdout = "";
|
|
740
|
-
let stderr = "";
|
|
741
|
-
spawnedProcess.stdout.on("data", (data) => {
|
|
742
|
-
stdout += String(data);
|
|
743
|
-
onStdout?.(String(data), spawnedProcess);
|
|
744
|
-
});
|
|
745
|
-
spawnedProcess.stderr.on("data", (data) => {
|
|
746
|
-
stderr += String(data);
|
|
747
|
-
onStderr?.(String(data), spawnedProcess);
|
|
748
|
-
});
|
|
749
|
-
spawnedProcess.on("error", (err) => {
|
|
750
|
-
stderr += err.toString();
|
|
751
|
-
});
|
|
752
|
-
spawnedProcess.on("close", (code2) => {
|
|
753
|
-
const timings = { date, duration: calcDuration(start) };
|
|
754
|
-
if (code2 === 0 || ignoreExitCode) {
|
|
755
|
-
onComplete?.();
|
|
756
|
-
resolve({ code: code2, stdout, stderr, ...timings });
|
|
757
|
-
} else {
|
|
758
|
-
const errorMsg = new ProcessError({ code: code2, stdout, stderr, ...timings });
|
|
759
|
-
onError?.(errorMsg);
|
|
760
|
-
reject(errorMsg);
|
|
761
|
-
}
|
|
762
|
-
});
|
|
763
|
-
});
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
// packages/utils/src/lib/file-system.ts
|
|
767
|
-
import { bold, gray } from "ansis";
|
|
768
|
-
import { bundleRequire } from "bundle-require";
|
|
769
|
-
import { mkdir, readFile, readdir, rm, stat } from "node:fs/promises";
|
|
770
|
-
import { dirname, join } from "node:path";
|
|
771
|
-
|
|
772
|
-
// packages/utils/src/lib/logging.ts
|
|
773
|
-
import isaacs_cliui from "@isaacs/cliui";
|
|
774
|
-
import { cliui } from "@poppinss/cliui";
|
|
775
|
-
import { underline } from "ansis";
|
|
776
|
-
var singletonUiInstance;
|
|
777
|
-
function ui() {
|
|
778
|
-
if (singletonUiInstance === void 0) {
|
|
779
|
-
singletonUiInstance = cliui();
|
|
780
|
-
}
|
|
781
|
-
return {
|
|
782
|
-
...singletonUiInstance,
|
|
783
|
-
row: (args) => {
|
|
784
|
-
logListItem(args);
|
|
785
|
-
}
|
|
786
|
-
};
|
|
787
|
-
}
|
|
788
|
-
var singletonisaacUi;
|
|
789
|
-
function logListItem(args) {
|
|
790
|
-
if (singletonisaacUi === void 0) {
|
|
791
|
-
singletonisaacUi = isaacs_cliui({ width: TERMINAL_WIDTH });
|
|
792
|
-
}
|
|
793
|
-
singletonisaacUi.div(...args);
|
|
794
|
-
const content = singletonisaacUi.toString();
|
|
795
|
-
singletonisaacUi.rows = [];
|
|
796
|
-
singletonUiInstance?.logger.log(content);
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
// packages/utils/src/lib/file-system.ts
|
|
800
|
-
async function readTextFile(path) {
|
|
801
|
-
const buffer = await readFile(path);
|
|
802
|
-
return buffer.toString();
|
|
803
|
-
}
|
|
804
|
-
async function readJsonFile(path) {
|
|
805
|
-
const text = await readTextFile(path);
|
|
806
|
-
return JSON.parse(text);
|
|
807
|
-
}
|
|
808
|
-
async function ensureDirectoryExists(baseDir) {
|
|
809
|
-
try {
|
|
810
|
-
await mkdir(baseDir, { recursive: true });
|
|
811
|
-
return;
|
|
812
|
-
} catch (error) {
|
|
813
|
-
ui().logger.info(error.message);
|
|
814
|
-
if (error.code !== "EEXIST") {
|
|
815
|
-
throw error;
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
function pluginWorkDir(slug) {
|
|
820
|
-
return join("node_modules", ".code-pushup", slug);
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
// packages/utils/src/lib/git/git.ts
|
|
824
|
-
import { simpleGit } from "simple-git";
|
|
825
|
-
|
|
826
|
-
// packages/utils/src/lib/transform.ts
|
|
827
|
-
import { platform } from "node:os";
|
|
828
|
-
function toUnixNewlines(text) {
|
|
829
|
-
return platform() === "win32" ? text.replace(/\r\n/g, "\n") : text;
|
|
830
|
-
}
|
|
831
|
-
function toNumberPrecision(value, decimalPlaces) {
|
|
832
|
-
return Number(
|
|
833
|
-
`${Math.round(
|
|
834
|
-
Number.parseFloat(`${value}e${decimalPlaces}`)
|
|
835
|
-
)}e-${decimalPlaces}`
|
|
836
|
-
);
|
|
837
|
-
}
|
|
838
|
-
function toOrdinal(value) {
|
|
839
|
-
if (value % 10 === 1 && value % 100 !== 11) {
|
|
840
|
-
return `${value}st`;
|
|
841
|
-
}
|
|
842
|
-
if (value % 10 === 2 && value % 100 !== 12) {
|
|
843
|
-
return `${value}nd`;
|
|
844
|
-
}
|
|
845
|
-
if (value % 10 === 3 && value % 100 !== 13) {
|
|
846
|
-
return `${value}rd`;
|
|
847
|
-
}
|
|
848
|
-
return `${value}th`;
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
// packages/utils/src/lib/git/git.commits-and-tags.ts
|
|
852
|
-
import { simpleGit as simpleGit2 } from "simple-git";
|
|
853
|
-
|
|
854
|
-
// packages/utils/src/lib/semver.ts
|
|
855
|
-
import { rcompare, valid } from "semver";
|
|
856
|
-
|
|
857
|
-
// packages/utils/src/lib/progress.ts
|
|
858
|
-
import { black, bold as bold2, gray as gray2, green } from "ansis";
|
|
859
|
-
import { MultiProgressBars } from "multi-progress-bars";
|
|
860
|
-
|
|
861
|
-
// packages/utils/src/lib/reports/generate-md-report.ts
|
|
862
|
-
import { MarkdownDocument as MarkdownDocument3, md as md4 } from "build-md";
|
|
863
|
-
|
|
864
|
-
// packages/utils/src/lib/reports/formatting.ts
|
|
865
|
-
import {
|
|
866
|
-
MarkdownDocument,
|
|
867
|
-
md as md2
|
|
868
|
-
} from "build-md";
|
|
869
|
-
|
|
870
|
-
// packages/utils/src/lib/reports/generate-md-report-categoy-section.ts
|
|
871
|
-
import { MarkdownDocument as MarkdownDocument2, md as md3 } from "build-md";
|
|
872
|
-
|
|
873
|
-
// packages/utils/src/lib/reports/generate-md-reports-diff.ts
|
|
874
|
-
import {
|
|
875
|
-
MarkdownDocument as MarkdownDocument5,
|
|
876
|
-
md as md6
|
|
877
|
-
} from "build-md";
|
|
878
|
-
|
|
879
|
-
// packages/utils/src/lib/reports/generate-md-reports-diff-utils.ts
|
|
880
|
-
import { MarkdownDocument as MarkdownDocument4, md as md5 } from "build-md";
|
|
881
|
-
|
|
882
|
-
// packages/utils/src/lib/reports/log-stdout-summary.ts
|
|
883
|
-
import { bold as bold4, cyan, cyanBright, green as green2, red } from "ansis";
|
|
884
|
-
|
|
885
|
-
// packages/plugin-coverage/src/lib/runner/constants.ts
|
|
886
|
-
import { join as join2 } from "node:path";
|
|
887
|
-
var WORKDIR = pluginWorkDir("coverage");
|
|
888
|
-
var RUNNER_OUTPUT_PATH = join2(WORKDIR, "runner-output.json");
|
|
889
|
-
var PLUGIN_CONFIG_PATH = join2(
|
|
890
|
-
process.cwd(),
|
|
891
|
-
WORKDIR,
|
|
892
|
-
"plugin-config.json"
|
|
893
|
-
);
|
|
894
|
-
var INVALID_FUNCTION_NAME = "(empty-report)";
|
|
895
|
-
|
|
896
|
-
// packages/plugin-coverage/src/lib/runner/lcov/lcov-runner.ts
|
|
897
|
-
import { join as join3 } from "node:path";
|
|
898
|
-
|
|
899
|
-
// packages/plugin-coverage/src/lib/runner/lcov/merge-lcov.ts
|
|
900
|
-
function mergeLcovResults(records) {
|
|
901
|
-
const allFilenames = records.map((record) => record.file);
|
|
902
|
-
if (allFilenames.length === new Set(allFilenames).size) {
|
|
903
|
-
return records;
|
|
904
|
-
}
|
|
905
|
-
return records.reduce((accMerged, currRecord, currIndex) => {
|
|
906
|
-
const filePath = currRecord.file;
|
|
907
|
-
const lines = currRecord.lines.found;
|
|
908
|
-
const duplicates = records.reduce(
|
|
909
|
-
(acc, candidateRecord, candidateIndex) => {
|
|
910
|
-
if (candidateRecord.file === filePath && candidateRecord.lines.found === lines && candidateIndex !== currIndex) {
|
|
911
|
-
return [...acc, [candidateRecord, candidateIndex]];
|
|
912
|
-
}
|
|
913
|
-
return acc;
|
|
914
|
-
},
|
|
915
|
-
[]
|
|
916
|
-
);
|
|
917
|
-
if (duplicates.map((duplicate) => duplicate[1]).some((index) => index < currIndex)) {
|
|
918
|
-
return accMerged;
|
|
919
|
-
}
|
|
920
|
-
if (duplicates.length === 0) {
|
|
921
|
-
return [...accMerged, currRecord];
|
|
922
|
-
}
|
|
923
|
-
return [
|
|
924
|
-
...accMerged,
|
|
925
|
-
mergeDuplicateLcovRecords([
|
|
926
|
-
currRecord,
|
|
927
|
-
...duplicates.map((duplicate) => duplicate[0])
|
|
928
|
-
])
|
|
929
|
-
];
|
|
930
|
-
}, []);
|
|
931
|
-
}
|
|
932
|
-
function mergeDuplicateLcovRecords(records) {
|
|
933
|
-
const linesDetails = mergeLcovLineDetails(
|
|
934
|
-
records.map((record) => record.lines.details)
|
|
935
|
-
);
|
|
936
|
-
const linesHit = linesDetails.reduce(
|
|
937
|
-
(acc, line) => acc + (line.hit > 0 ? 1 : 0),
|
|
938
|
-
0
|
|
939
|
-
);
|
|
940
|
-
const branchesDetails = mergeLcovBranchesDetails(
|
|
941
|
-
records.map((record) => record.branches.details)
|
|
942
|
-
);
|
|
943
|
-
const branchesHit = branchesDetails.reduce(
|
|
944
|
-
(acc, branch) => acc + (branch.taken > 0 ? 1 : 0),
|
|
945
|
-
0
|
|
946
|
-
);
|
|
947
|
-
const functionsDetails = mergeLcovFunctionsDetails(
|
|
948
|
-
records.map((record) => record.functions.details)
|
|
949
|
-
);
|
|
950
|
-
const functionsHit = functionsDetails.reduce(
|
|
951
|
-
(acc, func) => acc + (func.hit != null && func.hit > 0 ? 1 : 0),
|
|
952
|
-
0
|
|
953
|
-
);
|
|
954
|
-
const mergedRecord = {
|
|
955
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
956
|
-
file: records[0].file,
|
|
957
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
958
|
-
title: records[0].title,
|
|
959
|
-
lines: {
|
|
960
|
-
found: linesDetails.length,
|
|
961
|
-
hit: linesHit,
|
|
962
|
-
details: linesDetails
|
|
963
|
-
},
|
|
964
|
-
branches: {
|
|
965
|
-
found: branchesDetails.length,
|
|
966
|
-
hit: branchesHit,
|
|
967
|
-
details: branchesDetails
|
|
968
|
-
},
|
|
969
|
-
functions: {
|
|
970
|
-
found: functionsDetails.length,
|
|
971
|
-
hit: functionsHit,
|
|
972
|
-
details: functionsDetails
|
|
973
|
-
}
|
|
974
|
-
};
|
|
975
|
-
return mergedRecord;
|
|
976
|
-
}
|
|
977
|
-
function mergeLcovLineDetails(details2) {
|
|
978
|
-
const flatDetails = details2.flat();
|
|
979
|
-
const uniqueLines = [
|
|
980
|
-
...new Set(flatDetails.map((flatDetail) => flatDetail.line))
|
|
981
|
-
];
|
|
982
|
-
return uniqueLines.map((line) => {
|
|
983
|
-
const hitSum = flatDetails.filter((lineDetail) => lineDetail.line === line).reduce((acc, lineDetail) => acc + lineDetail.hit, 0);
|
|
984
|
-
return { line, hit: hitSum };
|
|
985
|
-
});
|
|
986
|
-
}
|
|
987
|
-
function mergeLcovBranchesDetails(details2) {
|
|
988
|
-
const flatDetails = details2.flat();
|
|
989
|
-
const uniqueBranches = [
|
|
990
|
-
...new Set(
|
|
991
|
-
flatDetails.map(
|
|
992
|
-
({ line, block, branch }) => JSON.stringify({ line, block, branch })
|
|
993
|
-
)
|
|
994
|
-
)
|
|
995
|
-
].map(
|
|
996
|
-
(functionJSON) => JSON.parse(functionJSON)
|
|
997
|
-
);
|
|
998
|
-
return uniqueBranches.map(({ line, block, branch }) => {
|
|
999
|
-
const takenSum = flatDetails.filter(
|
|
1000
|
-
(branchDetail) => branchDetail.line === line && branchDetail.block === block && branchDetail.branch === branch
|
|
1001
|
-
).reduce((acc, branchDetail) => acc + branchDetail.taken, 0);
|
|
1002
|
-
return { line, block, branch, taken: takenSum };
|
|
1003
|
-
});
|
|
1004
|
-
}
|
|
1005
|
-
function mergeLcovFunctionsDetails(details2) {
|
|
1006
|
-
const flatDetails = details2.flat();
|
|
1007
|
-
const uniqueFunctions = [
|
|
1008
|
-
...new Set(
|
|
1009
|
-
flatDetails.map(({ line, name }) => JSON.stringify({ line, name }))
|
|
1010
|
-
)
|
|
1011
|
-
].map(
|
|
1012
|
-
(functionJSON) => JSON.parse(functionJSON)
|
|
1013
|
-
);
|
|
1014
|
-
return uniqueFunctions.map(({ line, name }) => {
|
|
1015
|
-
const hitSum = flatDetails.filter(
|
|
1016
|
-
(functionDetail) => functionDetail.line === line && functionDetail.name === name
|
|
1017
|
-
).reduce((acc, functionDetail) => acc + (functionDetail.hit ?? 0), 0);
|
|
1018
|
-
return { line, name, hit: hitSum };
|
|
1019
|
-
});
|
|
1020
|
-
}
|
|
1021
|
-
|
|
1022
|
-
// packages/plugin-coverage/src/lib/runner/lcov/parse-lcov.ts
|
|
1023
|
-
import parseLcovExport from "parse-lcov";
|
|
1024
|
-
var godKnows = parseLcovExport;
|
|
1025
|
-
var parseLcov = "default" in godKnows ? godKnows.default : godKnows;
|
|
1026
|
-
|
|
1027
|
-
// packages/plugin-coverage/src/lib/runner/lcov/utils.ts
|
|
1028
|
-
function calculateCoverage(hit, found) {
|
|
1029
|
-
return found > 0 ? hit / found : 1;
|
|
1030
|
-
}
|
|
1031
|
-
function mergeConsecutiveNumbers(numberArr) {
|
|
1032
|
-
return numberArr.toSorted((a, b) => a - b).reduce((acc, currValue) => {
|
|
1033
|
-
const prevValue = acc.at(-1);
|
|
1034
|
-
if (prevValue != null && (prevValue.start === currValue - 1 || prevValue.end === currValue - 1)) {
|
|
1035
|
-
return [
|
|
1036
|
-
...acc.slice(0, -1),
|
|
1037
|
-
{ start: prevValue.start, end: currValue }
|
|
1038
|
-
];
|
|
1039
|
-
}
|
|
1040
|
-
return [...acc, { start: currValue }];
|
|
1041
|
-
}, []);
|
|
1042
|
-
}
|
|
1043
|
-
|
|
1044
|
-
// packages/plugin-coverage/src/lib/runner/lcov/transform.ts
|
|
1045
|
-
function lcovReportToFunctionStat(record) {
|
|
1046
|
-
const validRecord = removeEmptyReport(record);
|
|
1047
|
-
return {
|
|
1048
|
-
totalFound: validRecord.functions.found,
|
|
1049
|
-
totalHit: validRecord.functions.hit,
|
|
1050
|
-
issues: validRecord.functions.hit < validRecord.functions.found ? validRecord.functions.details.filter((detail) => !detail.hit).map(
|
|
1051
|
-
(detail) => ({
|
|
1052
|
-
message: `Function ${detail.name} is not called in any test case.`,
|
|
1053
|
-
severity: "error",
|
|
1054
|
-
source: {
|
|
1055
|
-
file: validRecord.file,
|
|
1056
|
-
position: { startLine: detail.line }
|
|
1057
|
-
}
|
|
1058
|
-
})
|
|
1059
|
-
) : []
|
|
1060
|
-
};
|
|
1061
|
-
}
|
|
1062
|
-
function removeEmptyReport(record) {
|
|
1063
|
-
const validFunctions = record.functions.details.filter(
|
|
1064
|
-
(detail) => detail.name !== INVALID_FUNCTION_NAME
|
|
1065
|
-
);
|
|
1066
|
-
if (validFunctions.length === record.functions.found) {
|
|
1067
|
-
return record;
|
|
1068
|
-
}
|
|
1069
|
-
return {
|
|
1070
|
-
...record,
|
|
1071
|
-
functions: {
|
|
1072
|
-
details: validFunctions,
|
|
1073
|
-
found: validFunctions.length,
|
|
1074
|
-
hit: validFunctions.reduce(
|
|
1075
|
-
(acc, fn) => acc + (fn.hit != null && fn.hit > 0 ? 1 : 0),
|
|
1076
|
-
0
|
|
1077
|
-
)
|
|
1078
|
-
}
|
|
1079
|
-
};
|
|
1080
|
-
}
|
|
1081
|
-
function lcovReportToLineStat(record) {
|
|
1082
|
-
const missingCoverage = record.lines.hit < record.lines.found;
|
|
1083
|
-
const lines = missingCoverage ? record.lines.details.filter((detail) => !detail.hit).map((detail) => detail.line) : [];
|
|
1084
|
-
const linePositions = mergeConsecutiveNumbers(lines);
|
|
1085
|
-
return {
|
|
1086
|
-
totalFound: record.lines.found,
|
|
1087
|
-
totalHit: record.lines.hit,
|
|
1088
|
-
issues: missingCoverage ? linePositions.map((linePosition) => {
|
|
1089
|
-
const lineReference = linePosition.end == null ? `Line ${linePosition.start} is` : `Lines ${linePosition.start}-${linePosition.end} are`;
|
|
1090
|
-
return {
|
|
1091
|
-
message: `${lineReference} not covered in any test case.`,
|
|
1092
|
-
severity: "warning",
|
|
1093
|
-
source: {
|
|
1094
|
-
file: record.file,
|
|
1095
|
-
position: {
|
|
1096
|
-
startLine: linePosition.start,
|
|
1097
|
-
endLine: linePosition.end
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
};
|
|
1101
|
-
}) : []
|
|
1102
|
-
};
|
|
1103
|
-
}
|
|
1104
|
-
function lcovReportToBranchStat(record) {
|
|
1105
|
-
return {
|
|
1106
|
-
totalFound: record.branches.found,
|
|
1107
|
-
totalHit: record.branches.hit,
|
|
1108
|
-
issues: record.branches.hit < record.branches.found ? record.branches.details.filter((detail) => !detail.taken).map(
|
|
1109
|
-
(detail) => ({
|
|
1110
|
-
message: `${toOrdinal(
|
|
1111
|
-
detail.branch + 1
|
|
1112
|
-
)} branch is not taken in any test case.`,
|
|
1113
|
-
severity: "error",
|
|
1114
|
-
source: {
|
|
1115
|
-
file: record.file,
|
|
1116
|
-
position: { startLine: detail.line }
|
|
1117
|
-
}
|
|
1118
|
-
})
|
|
1119
|
-
) : []
|
|
1120
|
-
};
|
|
1121
|
-
}
|
|
1122
|
-
var recordToStatFunctionMapper = {
|
|
1123
|
-
branch: lcovReportToBranchStat,
|
|
1124
|
-
line: lcovReportToLineStat,
|
|
1125
|
-
function: lcovReportToFunctionStat
|
|
1126
|
-
};
|
|
1127
|
-
function lcovCoverageToAuditOutput(stat2, coverageType) {
|
|
1128
|
-
const coverage = calculateCoverage(stat2.totalHit, stat2.totalFound);
|
|
1129
|
-
const MAX_DECIMAL_PLACES = 4;
|
|
1130
|
-
const coveragePercentage = coverage * 100;
|
|
1131
|
-
return {
|
|
1132
|
-
slug: `${coverageType}-coverage`,
|
|
1133
|
-
score: toNumberPrecision(coverage, MAX_DECIMAL_PLACES),
|
|
1134
|
-
value: coveragePercentage,
|
|
1135
|
-
displayValue: `${toNumberPrecision(coveragePercentage, 1)} %`,
|
|
1136
|
-
details: {
|
|
1137
|
-
issues: stat2.issues
|
|
1138
|
-
}
|
|
1139
|
-
};
|
|
1140
|
-
}
|
|
1141
|
-
|
|
1142
|
-
// packages/plugin-coverage/src/lib/runner/lcov/lcov-runner.ts
|
|
1143
|
-
async function lcovResultsToAuditOutputs(results, coverageTypes) {
|
|
1144
|
-
const lcovResults = await parseLcovFiles(results);
|
|
1145
|
-
const mergedResults = mergeLcovResults(lcovResults);
|
|
1146
|
-
const totalCoverageStats = getTotalCoverageFromLcovRecords(
|
|
1147
|
-
mergedResults,
|
|
1148
|
-
coverageTypes
|
|
1149
|
-
);
|
|
1150
|
-
return coverageTypes.map((coverageType) => {
|
|
1151
|
-
const stats = totalCoverageStats[coverageType];
|
|
1152
|
-
if (!stats) {
|
|
1153
|
-
return null;
|
|
1154
|
-
}
|
|
1155
|
-
return lcovCoverageToAuditOutput(stats, coverageType);
|
|
1156
|
-
}).filter(exists);
|
|
1157
|
-
}
|
|
1158
|
-
async function parseLcovFiles(results) {
|
|
1159
|
-
const parsedResults = await Promise.all(
|
|
1160
|
-
results.map(async (result) => {
|
|
1161
|
-
const resultsPath = typeof result === "string" ? result : result.resultsPath;
|
|
1162
|
-
const lcovFileContent = await readTextFile(resultsPath);
|
|
1163
|
-
if (lcovFileContent.trim() === "") {
|
|
1164
|
-
ui().logger.warning(
|
|
1165
|
-
`Coverage plugin: Empty lcov report file detected at ${resultsPath}.`
|
|
1166
|
-
);
|
|
1167
|
-
}
|
|
1168
|
-
const parsedRecords = parseLcov(toUnixNewlines(lcovFileContent));
|
|
1169
|
-
return parsedRecords.map((record) => ({
|
|
1170
|
-
...record,
|
|
1171
|
-
file: typeof result === "string" || result.pathToProject == null ? record.file : join3(result.pathToProject, record.file)
|
|
1172
|
-
}));
|
|
1173
|
-
})
|
|
1174
|
-
);
|
|
1175
|
-
if (parsedResults.length !== results.length) {
|
|
1176
|
-
throw new Error("Some provided LCOV results were not valid.");
|
|
1177
|
-
}
|
|
1178
|
-
const flatResults = parsedResults.flat();
|
|
1179
|
-
if (flatResults.length === 0) {
|
|
1180
|
-
throw new Error("All provided results are empty.");
|
|
1181
|
-
}
|
|
1182
|
-
return flatResults;
|
|
1183
|
-
}
|
|
1184
|
-
function getTotalCoverageFromLcovRecords(records, coverageTypes) {
|
|
1185
|
-
return records.reduce(
|
|
1186
|
-
(acc, report) => Object.fromEntries([
|
|
1187
|
-
...Object.entries(acc),
|
|
1188
|
-
...Object.entries(
|
|
1189
|
-
getCoverageStatsFromLcovRecord(report, coverageTypes)
|
|
1190
|
-
).map(([type, stats]) => [
|
|
1191
|
-
type,
|
|
1192
|
-
{
|
|
1193
|
-
totalFound: (acc[type]?.totalFound ?? 0) + stats.totalFound,
|
|
1194
|
-
totalHit: (acc[type]?.totalHit ?? 0) + stats.totalHit,
|
|
1195
|
-
issues: [...acc[type]?.issues ?? [], ...stats.issues]
|
|
1196
|
-
}
|
|
1197
|
-
])
|
|
1198
|
-
]),
|
|
1199
|
-
{}
|
|
1200
|
-
);
|
|
1201
|
-
}
|
|
1202
|
-
function getCoverageStatsFromLcovRecord(record, coverageTypes) {
|
|
1203
|
-
return Object.fromEntries(
|
|
1204
|
-
coverageTypes.map((coverageType) => [
|
|
1205
|
-
coverageType,
|
|
1206
|
-
recordToStatFunctionMapper[coverageType](record)
|
|
1207
|
-
])
|
|
1208
|
-
);
|
|
1209
|
-
}
|
|
1210
|
-
|
|
1211
|
-
// packages/plugin-coverage/src/lib/runner/index.ts
|
|
1212
|
-
async function executeRunner() {
|
|
1213
|
-
const { reports, coverageToolCommand, coverageTypes } = await readJsonFile(PLUGIN_CONFIG_PATH);
|
|
1214
|
-
if (coverageToolCommand != null) {
|
|
1215
|
-
const { command, args } = coverageToolCommand;
|
|
1216
|
-
try {
|
|
1217
|
-
await executeProcess({ command, args });
|
|
1218
|
-
} catch (error) {
|
|
1219
|
-
if (error instanceof ProcessError) {
|
|
1220
|
-
ui().logger.error(bold5("stdout from failed coverage tool process:"));
|
|
1221
|
-
ui().logger.error(error.stdout);
|
|
1222
|
-
ui().logger.error(bold5("stderr from failed coverage tool process:"));
|
|
1223
|
-
ui().logger.error(error.stderr);
|
|
1224
|
-
}
|
|
1225
|
-
throw new Error(
|
|
1226
|
-
"Coverage plugin: Running coverage tool failed. Make sure all your provided tests are passing."
|
|
1227
|
-
);
|
|
1228
|
-
}
|
|
1229
|
-
}
|
|
1230
|
-
const auditOutputs = await lcovResultsToAuditOutputs(reports, coverageTypes);
|
|
1231
|
-
await ensureDirectoryExists(dirname2(RUNNER_OUTPUT_PATH));
|
|
1232
|
-
await writeFile(RUNNER_OUTPUT_PATH, JSON.stringify(auditOutputs));
|
|
1233
|
-
}
|
|
1234
|
-
|
|
1235
|
-
// packages/plugin-coverage/src/bin.ts
|
|
1236
|
-
await executeRunner();
|