@code-pushup/utils 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 +12 -7
- package/src/index.d.ts +30 -29
- package/src/index.js +30 -0
- package/src/index.js.map +1 -0
- package/src/lib/diff.js +38 -0
- package/src/lib/diff.js.map +1 -0
- package/src/lib/errors.js +14 -0
- package/src/lib/errors.js.map +1 -0
- package/src/lib/execute-process.d.ts +0 -1
- package/src/lib/execute-process.js +101 -0
- package/src/lib/execute-process.js.map +1 -0
- package/src/lib/file-system.d.ts +5 -5
- package/src/lib/file-system.js +113 -0
- package/src/lib/file-system.js.map +1 -0
- package/src/lib/filter.js +10 -0
- package/src/lib/filter.js.map +1 -0
- package/src/lib/formatting.js +83 -0
- package/src/lib/formatting.js.map +1 -0
- package/src/lib/git/git.commits-and-tags.js +148 -0
- package/src/lib/git/git.commits-and-tags.js.map +1 -0
- package/src/lib/git/git.d.ts +2 -2
- package/src/lib/git/git.js +58 -0
- package/src/lib/git/git.js.map +1 -0
- package/src/lib/group-by-status.js +6 -0
- package/src/lib/group-by-status.js.map +1 -0
- package/src/lib/guards.d.ts +2 -0
- package/src/lib/guards.js +10 -0
- package/src/lib/guards.js.map +1 -0
- package/src/lib/log-results.js +28 -0
- package/src/lib/log-results.js.map +1 -0
- package/src/lib/logging.js +33 -0
- package/src/lib/logging.js.map +1 -0
- package/src/lib/merge-configs.js +104 -0
- package/src/lib/merge-configs.js.map +1 -0
- package/src/lib/progress.js +57 -0
- package/src/lib/progress.js.map +1 -0
- package/src/lib/reports/constants.js +19 -0
- package/src/lib/reports/constants.js.map +1 -0
- package/src/lib/reports/environment-type.d.ts +1 -1
- package/src/lib/reports/environment-type.js +17 -0
- package/src/lib/reports/environment-type.js.map +1 -0
- package/src/lib/reports/flatten-plugins.js +8 -0
- package/src/lib/reports/flatten-plugins.js.map +1 -0
- package/src/lib/reports/formatting.d.ts +1 -1
- package/src/lib/reports/formatting.js +105 -0
- package/src/lib/reports/formatting.js.map +1 -0
- package/src/lib/reports/generate-md-report-categoy-section.d.ts +1 -1
- package/src/lib/reports/generate-md-report-categoy-section.js +63 -0
- package/src/lib/reports/generate-md-report-categoy-section.js.map +1 -0
- package/src/lib/reports/generate-md-report.d.ts +1 -1
- package/src/lib/reports/generate-md-report.js +116 -0
- package/src/lib/reports/generate-md-report.js.map +1 -0
- package/src/lib/reports/generate-md-reports-diff-utils.d.ts +1 -1
- package/src/lib/reports/generate-md-reports-diff-utils.js +117 -0
- package/src/lib/reports/generate-md-reports-diff-utils.js.map +1 -0
- package/src/lib/reports/generate-md-reports-diff.d.ts +1 -1
- package/src/lib/reports/generate-md-reports-diff.js +158 -0
- package/src/lib/reports/generate-md-reports-diff.js.map +1 -0
- package/src/lib/reports/load-report.js +15 -0
- package/src/lib/reports/load-report.js.map +1 -0
- package/src/lib/reports/log-stdout-summary.d.ts +1 -1
- package/src/lib/reports/log-stdout-summary.js +102 -0
- package/src/lib/reports/log-stdout-summary.js.map +1 -0
- package/src/lib/reports/scoring.d.ts +1 -1
- package/src/lib/reports/scoring.js +78 -0
- package/src/lib/reports/scoring.js.map +1 -0
- package/src/lib/reports/sorting.d.ts +1 -1
- package/src/lib/reports/sorting.js +91 -0
- package/src/lib/reports/sorting.js.map +1 -0
- package/src/lib/reports/types.js +7 -0
- package/src/lib/reports/types.js.map +1 -0
- package/src/lib/reports/utils.d.ts +1 -1
- package/src/lib/reports/utils.js +209 -0
- package/src/lib/reports/utils.js.map +1 -0
- package/src/lib/semver.js +17 -0
- package/src/lib/semver.js.map +1 -0
- package/src/lib/text-formats/constants.js +14 -0
- package/src/lib/text-formats/constants.js.map +1 -0
- package/src/lib/text-formats/html/details.js +20 -0
- package/src/lib/text-formats/html/details.js.map +1 -0
- package/src/lib/text-formats/html/font-style.js +13 -0
- package/src/lib/text-formats/html/font-style.js.map +1 -0
- package/src/lib/text-formats/html/link.js +4 -0
- package/src/lib/text-formats/html/link.js.map +1 -0
- package/src/lib/text-formats/html/table.js +27 -0
- package/src/lib/text-formats/html/table.js.map +1 -0
- package/src/lib/text-formats/index.d.ts +5 -5
- package/src/lib/text-formats/index.js +14 -0
- package/src/lib/text-formats/index.js.map +1 -0
- package/src/lib/text-formats/table.js +92 -0
- package/src/lib/text-formats/table.js.map +1 -0
- package/src/lib/transform.d.ts +1 -2
- package/src/lib/transform.js +111 -0
- package/src/lib/transform.js.map +1 -0
- package/src/lib/types.d.ts +3 -3
- package/src/lib/types.js +2 -0
- package/src/lib/types.js.map +1 -0
- package/src/lib/verbose-utils.js +20 -0
- package/src/lib/verbose-utils.js.map +1 -0
- package/src/lib/zod-validation.d.ts +3 -0
- package/src/lib/zod-validation.js +22 -0
- package/src/lib/zod-validation.js.map +1 -0
- package/index.js +0 -2980
package/index.js
DELETED
|
@@ -1,2980 +0,0 @@
|
|
|
1
|
-
// packages/models/src/lib/implementation/schemas.ts
|
|
2
|
-
import { MATERIAL_ICONS } from "vscode-material-icons";
|
|
3
|
-
import { z } from "zod";
|
|
4
|
-
|
|
5
|
-
// packages/models/src/lib/implementation/limits.ts
|
|
6
|
-
var MAX_SLUG_LENGTH = 128;
|
|
7
|
-
var MAX_TITLE_LENGTH = 256;
|
|
8
|
-
var MAX_DESCRIPTION_LENGTH = 65536;
|
|
9
|
-
var MAX_ISSUE_MESSAGE_LENGTH = 1024;
|
|
10
|
-
|
|
11
|
-
// packages/models/src/lib/implementation/utils.ts
|
|
12
|
-
var slugRegex = /^[a-z\d]+(?:-[a-z\d]+)*$/;
|
|
13
|
-
var filenameRegex = /^(?!.*[ \\/:*?"<>|]).+$/;
|
|
14
|
-
function hasDuplicateStrings(strings) {
|
|
15
|
-
const sortedStrings = strings.toSorted();
|
|
16
|
-
const duplStrings = sortedStrings.filter(
|
|
17
|
-
(item, index) => index !== 0 && item === sortedStrings[index - 1]
|
|
18
|
-
);
|
|
19
|
-
return duplStrings.length === 0 ? false : [...new Set(duplStrings)];
|
|
20
|
-
}
|
|
21
|
-
function hasMissingStrings(toCheck, existing) {
|
|
22
|
-
const nonExisting = toCheck.filter((s) => !existing.includes(s));
|
|
23
|
-
return nonExisting.length === 0 ? false : nonExisting;
|
|
24
|
-
}
|
|
25
|
-
function errorItems(items, transform = (itemArr) => itemArr.join(", ")) {
|
|
26
|
-
return transform(items || []);
|
|
27
|
-
}
|
|
28
|
-
function exists(value) {
|
|
29
|
-
return value != null;
|
|
30
|
-
}
|
|
31
|
-
function getMissingRefsForCategories(categories, plugins) {
|
|
32
|
-
if (!categories || categories.length === 0) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
const auditRefsFromCategory = categories.flatMap(
|
|
36
|
-
({ refs }) => refs.filter(({ type }) => type === "audit").map(({ plugin, slug }) => `${plugin}/${slug}`)
|
|
37
|
-
);
|
|
38
|
-
const auditRefsFromPlugins = plugins.flatMap(
|
|
39
|
-
({ audits, slug: pluginSlug }) => audits.map(({ slug }) => `${pluginSlug}/${slug}`)
|
|
40
|
-
);
|
|
41
|
-
const missingAuditRefs = hasMissingStrings(
|
|
42
|
-
auditRefsFromCategory,
|
|
43
|
-
auditRefsFromPlugins
|
|
44
|
-
);
|
|
45
|
-
const groupRefsFromCategory = categories.flatMap(
|
|
46
|
-
({ refs }) => refs.filter(({ type }) => type === "group").map(({ plugin, slug }) => `${plugin}#${slug} (group)`)
|
|
47
|
-
);
|
|
48
|
-
const groupRefsFromPlugins = plugins.flatMap(
|
|
49
|
-
({ groups, slug: pluginSlug }) => Array.isArray(groups) ? groups.map(({ slug }) => `${pluginSlug}#${slug} (group)`) : []
|
|
50
|
-
);
|
|
51
|
-
const missingGroupRefs = hasMissingStrings(
|
|
52
|
-
groupRefsFromCategory,
|
|
53
|
-
groupRefsFromPlugins
|
|
54
|
-
);
|
|
55
|
-
const missingRefs = [missingAuditRefs, missingGroupRefs].filter((refs) => Array.isArray(refs) && refs.length > 0).flat();
|
|
56
|
-
return missingRefs.length > 0 ? missingRefs : false;
|
|
57
|
-
}
|
|
58
|
-
function missingRefsForCategoriesErrorMsg(categories, plugins) {
|
|
59
|
-
const missingRefs = getMissingRefsForCategories(categories, plugins);
|
|
60
|
-
return `The following category references need to point to an audit or group: ${errorItems(
|
|
61
|
-
missingRefs
|
|
62
|
-
)}`;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// packages/models/src/lib/implementation/schemas.ts
|
|
66
|
-
var tableCellValueSchema = z.union([z.string(), z.number(), z.boolean(), z.null()]).default(null);
|
|
67
|
-
function executionMetaSchema(options = {
|
|
68
|
-
descriptionDate: "Execution start date and time",
|
|
69
|
-
descriptionDuration: "Execution duration in ms"
|
|
70
|
-
}) {
|
|
71
|
-
return z.object({
|
|
72
|
-
date: z.string({ description: options.descriptionDate }),
|
|
73
|
-
duration: z.number({ description: options.descriptionDuration })
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
var slugSchema = z.string({ description: "Unique ID (human-readable, URL-safe)" }).regex(slugRegex, {
|
|
77
|
-
message: "The slug has to follow the pattern [0-9a-z] followed by multiple optional groups of -[0-9a-z]. e.g. my-slug"
|
|
78
|
-
}).max(MAX_SLUG_LENGTH, {
|
|
79
|
-
message: `slug can be max ${MAX_SLUG_LENGTH} characters long`
|
|
80
|
-
});
|
|
81
|
-
var descriptionSchema = z.string({ description: "Description (markdown)" }).max(MAX_DESCRIPTION_LENGTH).optional();
|
|
82
|
-
var urlSchema = z.string().url();
|
|
83
|
-
var docsUrlSchema = urlSchema.optional().or(z.literal("")).describe("Documentation site");
|
|
84
|
-
var titleSchema = z.string({ description: "Descriptive name" }).max(MAX_TITLE_LENGTH);
|
|
85
|
-
var scoreSchema = z.number({
|
|
86
|
-
description: "Value between 0 and 1"
|
|
87
|
-
}).min(0).max(1);
|
|
88
|
-
function metaSchema(options) {
|
|
89
|
-
const {
|
|
90
|
-
descriptionDescription,
|
|
91
|
-
titleDescription,
|
|
92
|
-
docsUrlDescription,
|
|
93
|
-
description
|
|
94
|
-
} = options ?? {};
|
|
95
|
-
return z.object(
|
|
96
|
-
{
|
|
97
|
-
title: titleDescription ? titleSchema.describe(titleDescription) : titleSchema,
|
|
98
|
-
description: descriptionDescription ? descriptionSchema.describe(descriptionDescription) : descriptionSchema,
|
|
99
|
-
docsUrl: docsUrlDescription ? docsUrlSchema.describe(docsUrlDescription) : docsUrlSchema
|
|
100
|
-
},
|
|
101
|
-
{ description }
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
var filePathSchema = z.string().trim().min(1, { message: "path is invalid" });
|
|
105
|
-
var fileNameSchema = z.string().trim().regex(filenameRegex, {
|
|
106
|
-
message: `The filename has to be valid`
|
|
107
|
-
}).min(1, { message: "file name is invalid" });
|
|
108
|
-
var positiveIntSchema = z.number().int().positive();
|
|
109
|
-
var nonnegativeNumberSchema = z.number().nonnegative();
|
|
110
|
-
function packageVersionSchema(options) {
|
|
111
|
-
const { versionDescription = "NPM version of the package", required } = options ?? {};
|
|
112
|
-
const packageSchema = z.string({ description: "NPM package name" });
|
|
113
|
-
const versionSchema = z.string({ description: versionDescription });
|
|
114
|
-
return z.object(
|
|
115
|
-
{
|
|
116
|
-
packageName: required ? packageSchema : packageSchema.optional(),
|
|
117
|
-
version: required ? versionSchema : versionSchema.optional()
|
|
118
|
-
},
|
|
119
|
-
{ description: "NPM package name and version of a published package" }
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
var weightSchema = nonnegativeNumberSchema.describe(
|
|
123
|
-
"Coefficient for the given score (use weight 0 if only for display)"
|
|
124
|
-
);
|
|
125
|
-
function weightedRefSchema(description, slugDescription) {
|
|
126
|
-
return z.object(
|
|
127
|
-
{
|
|
128
|
-
slug: slugSchema.describe(slugDescription),
|
|
129
|
-
weight: weightSchema.describe("Weight used to calculate score")
|
|
130
|
-
},
|
|
131
|
-
{ description }
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
function scorableSchema(description, refSchema, duplicateCheckFn, duplicateMessageFn) {
|
|
135
|
-
return z.object(
|
|
136
|
-
{
|
|
137
|
-
slug: slugSchema.describe('Human-readable unique ID, e.g. "performance"'),
|
|
138
|
-
refs: z.array(refSchema).min(1).refine(
|
|
139
|
-
(refs) => !duplicateCheckFn(refs),
|
|
140
|
-
(refs) => ({
|
|
141
|
-
message: duplicateMessageFn(refs)
|
|
142
|
-
})
|
|
143
|
-
).refine(hasNonZeroWeightedRef, () => ({
|
|
144
|
-
message: "In a category there has to be at least one ref with weight > 0"
|
|
145
|
-
}))
|
|
146
|
-
},
|
|
147
|
-
{ description }
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
var materialIconSchema = z.enum(MATERIAL_ICONS, {
|
|
151
|
-
description: "Icon from VSCode Material Icons extension"
|
|
152
|
-
});
|
|
153
|
-
function hasNonZeroWeightedRef(refs) {
|
|
154
|
-
return refs.reduce((acc, { weight }) => weight + acc, 0) !== 0;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// packages/models/src/lib/source.ts
|
|
158
|
-
import { z as z2 } from "zod";
|
|
159
|
-
var sourceFileLocationSchema = z2.object(
|
|
160
|
-
{
|
|
161
|
-
file: filePathSchema.describe("Relative path to source file in Git repo"),
|
|
162
|
-
position: z2.object(
|
|
163
|
-
{
|
|
164
|
-
startLine: positiveIntSchema.describe("Start line"),
|
|
165
|
-
startColumn: positiveIntSchema.describe("Start column").optional(),
|
|
166
|
-
endLine: positiveIntSchema.describe("End line").optional(),
|
|
167
|
-
endColumn: positiveIntSchema.describe("End column").optional()
|
|
168
|
-
},
|
|
169
|
-
{ description: "Location in file" }
|
|
170
|
-
).optional()
|
|
171
|
-
},
|
|
172
|
-
{ description: "Source file location" }
|
|
173
|
-
);
|
|
174
|
-
|
|
175
|
-
// packages/models/src/lib/audit.ts
|
|
176
|
-
import { z as z3 } from "zod";
|
|
177
|
-
var auditSchema = z3.object({
|
|
178
|
-
slug: slugSchema.describe("ID (unique within plugin)")
|
|
179
|
-
}).merge(
|
|
180
|
-
metaSchema({
|
|
181
|
-
titleDescription: "Descriptive name",
|
|
182
|
-
descriptionDescription: "Description (markdown)",
|
|
183
|
-
docsUrlDescription: "Link to documentation (rationale)",
|
|
184
|
-
description: "List of scorable metrics for the given plugin"
|
|
185
|
-
})
|
|
186
|
-
);
|
|
187
|
-
var pluginAuditsSchema = z3.array(auditSchema, {
|
|
188
|
-
description: "List of audits maintained in a plugin"
|
|
189
|
-
}).min(1).refine(
|
|
190
|
-
(auditMetadata) => !getDuplicateSlugsInAudits(auditMetadata),
|
|
191
|
-
(auditMetadata) => ({
|
|
192
|
-
message: duplicateSlugsInAuditsErrorMsg(auditMetadata)
|
|
193
|
-
})
|
|
194
|
-
);
|
|
195
|
-
function duplicateSlugsInAuditsErrorMsg(audits) {
|
|
196
|
-
const duplicateRefs = getDuplicateSlugsInAudits(audits);
|
|
197
|
-
return `In plugin audits the following slugs are not unique: ${errorItems(
|
|
198
|
-
duplicateRefs
|
|
199
|
-
)}`;
|
|
200
|
-
}
|
|
201
|
-
function getDuplicateSlugsInAudits(audits) {
|
|
202
|
-
return hasDuplicateStrings(audits.map(({ slug }) => slug));
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// packages/models/src/lib/audit-output.ts
|
|
206
|
-
import { z as z6 } from "zod";
|
|
207
|
-
|
|
208
|
-
// packages/models/src/lib/issue.ts
|
|
209
|
-
import { z as z4 } from "zod";
|
|
210
|
-
var issueSeveritySchema = z4.enum(["info", "warning", "error"], {
|
|
211
|
-
description: "Severity level"
|
|
212
|
-
});
|
|
213
|
-
var issueSchema = z4.object(
|
|
214
|
-
{
|
|
215
|
-
message: z4.string({ description: "Descriptive error message" }).max(MAX_ISSUE_MESSAGE_LENGTH),
|
|
216
|
-
severity: issueSeveritySchema,
|
|
217
|
-
source: sourceFileLocationSchema.optional()
|
|
218
|
-
},
|
|
219
|
-
{ description: "Issue information" }
|
|
220
|
-
);
|
|
221
|
-
|
|
222
|
-
// packages/models/src/lib/table.ts
|
|
223
|
-
import { z as z5 } from "zod";
|
|
224
|
-
var tableAlignmentSchema = z5.enum(["left", "center", "right"], {
|
|
225
|
-
description: "Cell alignment"
|
|
226
|
-
});
|
|
227
|
-
var tableColumnObjectSchema = z5.object({
|
|
228
|
-
key: z5.string(),
|
|
229
|
-
label: z5.string().optional(),
|
|
230
|
-
align: tableAlignmentSchema.optional()
|
|
231
|
-
});
|
|
232
|
-
var tableRowObjectSchema = z5.record(tableCellValueSchema, {
|
|
233
|
-
description: "Object row"
|
|
234
|
-
});
|
|
235
|
-
var tableRowPrimitiveSchema = z5.array(tableCellValueSchema, {
|
|
236
|
-
description: "Primitive row"
|
|
237
|
-
});
|
|
238
|
-
var tableSharedSchema = z5.object({
|
|
239
|
-
title: z5.string().optional().describe("Display title for table")
|
|
240
|
-
});
|
|
241
|
-
var tablePrimitiveSchema = tableSharedSchema.merge(
|
|
242
|
-
z5.object(
|
|
243
|
-
{
|
|
244
|
-
columns: z5.array(tableAlignmentSchema).optional(),
|
|
245
|
-
rows: z5.array(tableRowPrimitiveSchema)
|
|
246
|
-
},
|
|
247
|
-
{ description: "Table with primitive rows and optional alignment columns" }
|
|
248
|
-
)
|
|
249
|
-
);
|
|
250
|
-
var tableObjectSchema = tableSharedSchema.merge(
|
|
251
|
-
z5.object(
|
|
252
|
-
{
|
|
253
|
-
columns: z5.union([
|
|
254
|
-
z5.array(tableAlignmentSchema),
|
|
255
|
-
z5.array(tableColumnObjectSchema)
|
|
256
|
-
]).optional(),
|
|
257
|
-
rows: z5.array(tableRowObjectSchema)
|
|
258
|
-
},
|
|
259
|
-
{
|
|
260
|
-
description: "Table with object rows and optional alignment or object columns"
|
|
261
|
-
}
|
|
262
|
-
)
|
|
263
|
-
);
|
|
264
|
-
var tableSchema = (description = "Table information") => z5.union([tablePrimitiveSchema, tableObjectSchema], { description });
|
|
265
|
-
|
|
266
|
-
// packages/models/src/lib/audit-output.ts
|
|
267
|
-
var auditValueSchema = nonnegativeNumberSchema.describe("Raw numeric value");
|
|
268
|
-
var auditDisplayValueSchema = z6.string({ description: "Formatted value (e.g. '0.9 s', '2.1 MB')" }).optional();
|
|
269
|
-
var auditDetailsSchema = z6.object(
|
|
270
|
-
{
|
|
271
|
-
issues: z6.array(issueSchema, { description: "List of findings" }).optional(),
|
|
272
|
-
table: tableSchema("Table of related findings").optional()
|
|
273
|
-
},
|
|
274
|
-
{ description: "Detailed information" }
|
|
275
|
-
);
|
|
276
|
-
var auditOutputSchema = z6.object(
|
|
277
|
-
{
|
|
278
|
-
slug: slugSchema.describe("Reference to audit"),
|
|
279
|
-
displayValue: auditDisplayValueSchema,
|
|
280
|
-
value: auditValueSchema,
|
|
281
|
-
score: scoreSchema,
|
|
282
|
-
details: auditDetailsSchema.optional()
|
|
283
|
-
},
|
|
284
|
-
{ description: "Audit information" }
|
|
285
|
-
);
|
|
286
|
-
var auditOutputsSchema = z6.array(auditOutputSchema, {
|
|
287
|
-
description: "List of JSON formatted audit output emitted by the runner process of a plugin"
|
|
288
|
-
}).refine(
|
|
289
|
-
(audits) => !getDuplicateSlugsInAudits2(audits),
|
|
290
|
-
(audits) => ({ message: duplicateSlugsInAuditsErrorMsg2(audits) })
|
|
291
|
-
);
|
|
292
|
-
function duplicateSlugsInAuditsErrorMsg2(audits) {
|
|
293
|
-
const duplicateRefs = getDuplicateSlugsInAudits2(audits);
|
|
294
|
-
return `In plugin audits the slugs are not unique: ${errorItems(
|
|
295
|
-
duplicateRefs
|
|
296
|
-
)}`;
|
|
297
|
-
}
|
|
298
|
-
function getDuplicateSlugsInAudits2(audits) {
|
|
299
|
-
return hasDuplicateStrings(audits.map(({ slug }) => slug));
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
// packages/models/src/lib/category-config.ts
|
|
303
|
-
import { z as z7 } from "zod";
|
|
304
|
-
var categoryRefSchema = weightedRefSchema(
|
|
305
|
-
"Weighted references to audits and/or groups for the category",
|
|
306
|
-
"Slug of an audit or group (depending on `type`)"
|
|
307
|
-
).merge(
|
|
308
|
-
z7.object({
|
|
309
|
-
type: z7.enum(["audit", "group"], {
|
|
310
|
-
description: "Discriminant for reference kind, affects where `slug` is looked up"
|
|
311
|
-
}),
|
|
312
|
-
plugin: slugSchema.describe(
|
|
313
|
-
"Plugin slug (plugin should contain referenced audit or group)"
|
|
314
|
-
)
|
|
315
|
-
})
|
|
316
|
-
);
|
|
317
|
-
var categoryConfigSchema = scorableSchema(
|
|
318
|
-
"Category with a score calculated from audits and groups from various plugins",
|
|
319
|
-
categoryRefSchema,
|
|
320
|
-
getDuplicateRefsInCategoryMetrics,
|
|
321
|
-
duplicateRefsInCategoryMetricsErrorMsg
|
|
322
|
-
).merge(
|
|
323
|
-
metaSchema({
|
|
324
|
-
titleDescription: "Category Title",
|
|
325
|
-
docsUrlDescription: "Category docs URL",
|
|
326
|
-
descriptionDescription: "Category description",
|
|
327
|
-
description: "Meta info for category"
|
|
328
|
-
})
|
|
329
|
-
).merge(
|
|
330
|
-
z7.object({
|
|
331
|
-
isBinary: z7.boolean({
|
|
332
|
-
description: 'Is this a binary category (i.e. only a perfect score considered a "pass")?'
|
|
333
|
-
}).optional()
|
|
334
|
-
})
|
|
335
|
-
);
|
|
336
|
-
function duplicateRefsInCategoryMetricsErrorMsg(metrics) {
|
|
337
|
-
const duplicateRefs = getDuplicateRefsInCategoryMetrics(metrics);
|
|
338
|
-
return `In the categories, the following audit or group refs are duplicates: ${errorItems(
|
|
339
|
-
duplicateRefs
|
|
340
|
-
)}`;
|
|
341
|
-
}
|
|
342
|
-
function getDuplicateRefsInCategoryMetrics(metrics) {
|
|
343
|
-
return hasDuplicateStrings(
|
|
344
|
-
metrics.map(({ slug, type, plugin }) => `${type} :: ${plugin} / ${slug}`)
|
|
345
|
-
);
|
|
346
|
-
}
|
|
347
|
-
var categoriesSchema = z7.array(categoryConfigSchema, {
|
|
348
|
-
description: "Categorization of individual audits"
|
|
349
|
-
}).refine(
|
|
350
|
-
(categoryCfg) => !getDuplicateSlugCategories(categoryCfg),
|
|
351
|
-
(categoryCfg) => ({
|
|
352
|
-
message: duplicateSlugCategoriesErrorMsg(categoryCfg)
|
|
353
|
-
})
|
|
354
|
-
);
|
|
355
|
-
function duplicateSlugCategoriesErrorMsg(categories) {
|
|
356
|
-
const duplicateStringSlugs = getDuplicateSlugCategories(categories);
|
|
357
|
-
return `In the categories, the following slugs are duplicated: ${errorItems(
|
|
358
|
-
duplicateStringSlugs
|
|
359
|
-
)}`;
|
|
360
|
-
}
|
|
361
|
-
function getDuplicateSlugCategories(categories) {
|
|
362
|
-
return hasDuplicateStrings(categories.map(({ slug }) => slug));
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
// packages/models/src/lib/commit.ts
|
|
366
|
-
import { z as z8 } from "zod";
|
|
367
|
-
var commitSchema = z8.object(
|
|
368
|
-
{
|
|
369
|
-
hash: z8.string({ description: "Commit SHA (full)" }).regex(
|
|
370
|
-
/^[\da-f]{40}$/,
|
|
371
|
-
"Commit SHA should be a 40-character hexadecimal string"
|
|
372
|
-
),
|
|
373
|
-
message: z8.string({ description: "Commit message" }),
|
|
374
|
-
date: z8.coerce.date({
|
|
375
|
-
description: "Date and time when commit was authored"
|
|
376
|
-
}),
|
|
377
|
-
author: z8.string({
|
|
378
|
-
description: "Commit author name"
|
|
379
|
-
}).trim()
|
|
380
|
-
},
|
|
381
|
-
{ description: "Git commit" }
|
|
382
|
-
);
|
|
383
|
-
|
|
384
|
-
// packages/models/src/lib/core-config.ts
|
|
385
|
-
import { z as z14 } from "zod";
|
|
386
|
-
|
|
387
|
-
// packages/models/src/lib/persist-config.ts
|
|
388
|
-
import { z as z9 } from "zod";
|
|
389
|
-
var formatSchema = z9.enum(["json", "md"]);
|
|
390
|
-
var persistConfigSchema = z9.object({
|
|
391
|
-
outputDir: filePathSchema.describe("Artifacts folder").optional(),
|
|
392
|
-
filename: fileNameSchema.describe("Artifacts file name (without extension)").optional(),
|
|
393
|
-
format: z9.array(formatSchema).optional()
|
|
394
|
-
});
|
|
395
|
-
|
|
396
|
-
// packages/models/src/lib/plugin-config.ts
|
|
397
|
-
import { z as z12 } from "zod";
|
|
398
|
-
|
|
399
|
-
// packages/models/src/lib/group.ts
|
|
400
|
-
import { z as z10 } from "zod";
|
|
401
|
-
var groupRefSchema = weightedRefSchema(
|
|
402
|
-
"Weighted reference to a group",
|
|
403
|
-
"Reference slug to a group within this plugin (e.g. 'max-lines')"
|
|
404
|
-
);
|
|
405
|
-
var groupMetaSchema = metaSchema({
|
|
406
|
-
titleDescription: "Descriptive name for the group",
|
|
407
|
-
descriptionDescription: "Description of the group (markdown)",
|
|
408
|
-
docsUrlDescription: "Group documentation site",
|
|
409
|
-
description: "Group metadata"
|
|
410
|
-
});
|
|
411
|
-
var groupSchema = scorableSchema(
|
|
412
|
-
'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',
|
|
413
|
-
groupRefSchema,
|
|
414
|
-
getDuplicateRefsInGroups,
|
|
415
|
-
duplicateRefsInGroupsErrorMsg
|
|
416
|
-
).merge(groupMetaSchema);
|
|
417
|
-
var groupsSchema = z10.array(groupSchema, {
|
|
418
|
-
description: "List of groups"
|
|
419
|
-
}).optional().refine(
|
|
420
|
-
(groups) => !getDuplicateSlugsInGroups(groups),
|
|
421
|
-
(groups) => ({
|
|
422
|
-
message: duplicateSlugsInGroupsErrorMsg(groups)
|
|
423
|
-
})
|
|
424
|
-
);
|
|
425
|
-
function duplicateRefsInGroupsErrorMsg(groups) {
|
|
426
|
-
const duplicateRefs = getDuplicateRefsInGroups(groups);
|
|
427
|
-
return `In plugin groups the following references are not unique: ${errorItems(
|
|
428
|
-
duplicateRefs
|
|
429
|
-
)}`;
|
|
430
|
-
}
|
|
431
|
-
function getDuplicateRefsInGroups(groups) {
|
|
432
|
-
return hasDuplicateStrings(groups.map(({ slug: ref }) => ref).filter(exists));
|
|
433
|
-
}
|
|
434
|
-
function duplicateSlugsInGroupsErrorMsg(groups) {
|
|
435
|
-
const duplicateRefs = getDuplicateSlugsInGroups(groups);
|
|
436
|
-
return `In groups the following slugs are not unique: ${errorItems(
|
|
437
|
-
duplicateRefs
|
|
438
|
-
)}`;
|
|
439
|
-
}
|
|
440
|
-
function getDuplicateSlugsInGroups(groups) {
|
|
441
|
-
return Array.isArray(groups) ? hasDuplicateStrings(groups.map(({ slug }) => slug)) : false;
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
// packages/models/src/lib/runner-config.ts
|
|
445
|
-
import { z as z11 } from "zod";
|
|
446
|
-
var outputTransformSchema = z11.function().args(z11.unknown()).returns(z11.union([auditOutputsSchema, z11.promise(auditOutputsSchema)]));
|
|
447
|
-
var runnerConfigSchema = z11.object(
|
|
448
|
-
{
|
|
449
|
-
command: z11.string({
|
|
450
|
-
description: "Shell command to execute"
|
|
451
|
-
}),
|
|
452
|
-
args: z11.array(z11.string({ description: "Command arguments" })).optional(),
|
|
453
|
-
outputFile: filePathSchema.describe("Output path"),
|
|
454
|
-
outputTransform: outputTransformSchema.optional()
|
|
455
|
-
},
|
|
456
|
-
{
|
|
457
|
-
description: "How to execute runner"
|
|
458
|
-
}
|
|
459
|
-
);
|
|
460
|
-
var onProgressSchema = z11.function().args(z11.unknown()).returns(z11.void());
|
|
461
|
-
var runnerFunctionSchema = z11.function().args(onProgressSchema.optional()).returns(z11.union([auditOutputsSchema, z11.promise(auditOutputsSchema)]));
|
|
462
|
-
|
|
463
|
-
// packages/models/src/lib/plugin-config.ts
|
|
464
|
-
var pluginMetaSchema = packageVersionSchema().merge(
|
|
465
|
-
metaSchema({
|
|
466
|
-
titleDescription: "Descriptive name",
|
|
467
|
-
descriptionDescription: "Description (markdown)",
|
|
468
|
-
docsUrlDescription: "Plugin documentation site",
|
|
469
|
-
description: "Plugin metadata"
|
|
470
|
-
})
|
|
471
|
-
).merge(
|
|
472
|
-
z12.object({
|
|
473
|
-
slug: slugSchema.describe("Unique plugin slug within core config"),
|
|
474
|
-
icon: materialIconSchema
|
|
475
|
-
})
|
|
476
|
-
);
|
|
477
|
-
var pluginDataSchema = z12.object({
|
|
478
|
-
runner: z12.union([runnerConfigSchema, runnerFunctionSchema]),
|
|
479
|
-
audits: pluginAuditsSchema,
|
|
480
|
-
groups: groupsSchema
|
|
481
|
-
});
|
|
482
|
-
var pluginConfigSchema = pluginMetaSchema.merge(pluginDataSchema).refine(
|
|
483
|
-
(pluginCfg) => !getMissingRefsFromGroups(pluginCfg),
|
|
484
|
-
(pluginCfg) => ({
|
|
485
|
-
message: missingRefsFromGroupsErrorMsg(pluginCfg)
|
|
486
|
-
})
|
|
487
|
-
);
|
|
488
|
-
function missingRefsFromGroupsErrorMsg(pluginCfg) {
|
|
489
|
-
const missingRefs = getMissingRefsFromGroups(pluginCfg);
|
|
490
|
-
return `The following group references need to point to an existing audit in this plugin config: ${errorItems(
|
|
491
|
-
missingRefs
|
|
492
|
-
)}`;
|
|
493
|
-
}
|
|
494
|
-
function getMissingRefsFromGroups(pluginCfg) {
|
|
495
|
-
return hasMissingStrings(
|
|
496
|
-
pluginCfg.groups?.flatMap(
|
|
497
|
-
({ refs: audits }) => audits.map(({ slug: ref }) => ref)
|
|
498
|
-
) ?? [],
|
|
499
|
-
pluginCfg.audits.map(({ slug }) => slug)
|
|
500
|
-
);
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
// packages/models/src/lib/upload-config.ts
|
|
504
|
-
import { z as z13 } from "zod";
|
|
505
|
-
var uploadConfigSchema = z13.object({
|
|
506
|
-
server: urlSchema.describe("URL of deployed portal API"),
|
|
507
|
-
apiKey: z13.string({
|
|
508
|
-
description: "API key with write access to portal (use `process.env` for security)"
|
|
509
|
-
}),
|
|
510
|
-
organization: slugSchema.describe(
|
|
511
|
-
"Organization slug from Code PushUp portal"
|
|
512
|
-
),
|
|
513
|
-
project: slugSchema.describe("Project slug from Code PushUp portal"),
|
|
514
|
-
timeout: z13.number({ description: "Request timeout in minutes (default is 5)" }).positive().int().optional()
|
|
515
|
-
});
|
|
516
|
-
|
|
517
|
-
// packages/models/src/lib/core-config.ts
|
|
518
|
-
var unrefinedCoreConfigSchema = z14.object({
|
|
519
|
-
plugins: z14.array(pluginConfigSchema, {
|
|
520
|
-
description: "List of plugins to be used (official, community-provided, or custom)"
|
|
521
|
-
}).min(1),
|
|
522
|
-
/** portal configuration for persisting results */
|
|
523
|
-
persist: persistConfigSchema.optional(),
|
|
524
|
-
/** portal configuration for uploading results */
|
|
525
|
-
upload: uploadConfigSchema.optional(),
|
|
526
|
-
categories: categoriesSchema.optional()
|
|
527
|
-
});
|
|
528
|
-
var coreConfigSchema = refineCoreConfig(unrefinedCoreConfigSchema);
|
|
529
|
-
function refineCoreConfig(schema) {
|
|
530
|
-
return schema.refine(
|
|
531
|
-
({ categories, plugins }) => !getMissingRefsForCategories(categories, plugins),
|
|
532
|
-
({ categories, plugins }) => ({
|
|
533
|
-
message: missingRefsForCategoriesErrorMsg(categories, plugins)
|
|
534
|
-
})
|
|
535
|
-
);
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
// packages/models/src/lib/report.ts
|
|
539
|
-
import { z as z15 } from "zod";
|
|
540
|
-
var auditReportSchema = auditSchema.merge(auditOutputSchema);
|
|
541
|
-
var pluginReportSchema = pluginMetaSchema.merge(
|
|
542
|
-
executionMetaSchema({
|
|
543
|
-
descriptionDate: "Start date and time of plugin run",
|
|
544
|
-
descriptionDuration: "Duration of the plugin run in ms"
|
|
545
|
-
})
|
|
546
|
-
).merge(
|
|
547
|
-
z15.object({
|
|
548
|
-
audits: z15.array(auditReportSchema).min(1),
|
|
549
|
-
groups: z15.array(groupSchema).optional()
|
|
550
|
-
})
|
|
551
|
-
).refine(
|
|
552
|
-
(pluginReport) => !getMissingRefsFromGroups2(pluginReport.audits, pluginReport.groups ?? []),
|
|
553
|
-
(pluginReport) => ({
|
|
554
|
-
message: missingRefsFromGroupsErrorMsg2(
|
|
555
|
-
pluginReport.audits,
|
|
556
|
-
pluginReport.groups ?? []
|
|
557
|
-
)
|
|
558
|
-
})
|
|
559
|
-
);
|
|
560
|
-
function missingRefsFromGroupsErrorMsg2(audits, groups) {
|
|
561
|
-
const missingRefs = getMissingRefsFromGroups2(audits, groups);
|
|
562
|
-
return `group references need to point to an existing audit in this plugin report: ${errorItems(
|
|
563
|
-
missingRefs
|
|
564
|
-
)}`;
|
|
565
|
-
}
|
|
566
|
-
function getMissingRefsFromGroups2(audits, groups) {
|
|
567
|
-
return hasMissingStrings(
|
|
568
|
-
groups.flatMap(
|
|
569
|
-
({ refs: auditRefs }) => auditRefs.map(({ slug: ref }) => ref)
|
|
570
|
-
),
|
|
571
|
-
audits.map(({ slug }) => slug)
|
|
572
|
-
);
|
|
573
|
-
}
|
|
574
|
-
var reportSchema = packageVersionSchema({
|
|
575
|
-
versionDescription: "NPM version of the CLI",
|
|
576
|
-
required: true
|
|
577
|
-
}).merge(
|
|
578
|
-
executionMetaSchema({
|
|
579
|
-
descriptionDate: "Start date and time of the collect run",
|
|
580
|
-
descriptionDuration: "Duration of the collect run in ms"
|
|
581
|
-
})
|
|
582
|
-
).merge(
|
|
583
|
-
z15.object(
|
|
584
|
-
{
|
|
585
|
-
plugins: z15.array(pluginReportSchema).min(1),
|
|
586
|
-
categories: z15.array(categoryConfigSchema).optional(),
|
|
587
|
-
commit: commitSchema.describe("Git commit for which report was collected").nullable()
|
|
588
|
-
},
|
|
589
|
-
{ description: "Collect output data" }
|
|
590
|
-
)
|
|
591
|
-
).refine(
|
|
592
|
-
({ categories, plugins }) => !getMissingRefsForCategories(categories, plugins),
|
|
593
|
-
({ categories, plugins }) => ({
|
|
594
|
-
message: missingRefsForCategoriesErrorMsg(categories, plugins)
|
|
595
|
-
})
|
|
596
|
-
);
|
|
597
|
-
|
|
598
|
-
// packages/models/src/lib/reports-diff.ts
|
|
599
|
-
import { z as z16 } from "zod";
|
|
600
|
-
function makeComparisonSchema(schema) {
|
|
601
|
-
const sharedDescription = schema.description || "Result";
|
|
602
|
-
return z16.object({
|
|
603
|
-
before: schema.describe(`${sharedDescription} (source commit)`),
|
|
604
|
-
after: schema.describe(`${sharedDescription} (target commit)`)
|
|
605
|
-
});
|
|
606
|
-
}
|
|
607
|
-
function makeArraysComparisonSchema(diffSchema, resultSchema, description) {
|
|
608
|
-
return z16.object(
|
|
609
|
-
{
|
|
610
|
-
changed: z16.array(diffSchema),
|
|
611
|
-
unchanged: z16.array(resultSchema),
|
|
612
|
-
added: z16.array(resultSchema),
|
|
613
|
-
removed: z16.array(resultSchema)
|
|
614
|
-
},
|
|
615
|
-
{ description }
|
|
616
|
-
);
|
|
617
|
-
}
|
|
618
|
-
var scorableMetaSchema = z16.object({
|
|
619
|
-
slug: slugSchema,
|
|
620
|
-
title: titleSchema,
|
|
621
|
-
docsUrl: docsUrlSchema
|
|
622
|
-
});
|
|
623
|
-
var scorableWithPluginMetaSchema = scorableMetaSchema.merge(
|
|
624
|
-
z16.object({
|
|
625
|
-
plugin: pluginMetaSchema.pick({ slug: true, title: true, docsUrl: true }).describe("Plugin which defines it")
|
|
626
|
-
})
|
|
627
|
-
);
|
|
628
|
-
var scorableDiffSchema = scorableMetaSchema.merge(
|
|
629
|
-
z16.object({
|
|
630
|
-
scores: makeComparisonSchema(scoreSchema).merge(
|
|
631
|
-
z16.object({
|
|
632
|
-
diff: z16.number().min(-1).max(1).describe("Score change (`scores.after - scores.before`)")
|
|
633
|
-
})
|
|
634
|
-
).describe("Score comparison")
|
|
635
|
-
})
|
|
636
|
-
);
|
|
637
|
-
var scorableWithPluginDiffSchema = scorableDiffSchema.merge(
|
|
638
|
-
scorableWithPluginMetaSchema
|
|
639
|
-
);
|
|
640
|
-
var categoryDiffSchema = scorableDiffSchema;
|
|
641
|
-
var groupDiffSchema = scorableWithPluginDiffSchema;
|
|
642
|
-
var auditDiffSchema = scorableWithPluginDiffSchema.merge(
|
|
643
|
-
z16.object({
|
|
644
|
-
values: makeComparisonSchema(auditValueSchema).merge(
|
|
645
|
-
z16.object({
|
|
646
|
-
diff: z16.number().describe("Value change (`values.after - values.before`)")
|
|
647
|
-
})
|
|
648
|
-
).describe("Audit `value` comparison"),
|
|
649
|
-
displayValues: makeComparisonSchema(auditDisplayValueSchema).describe(
|
|
650
|
-
"Audit `displayValue` comparison"
|
|
651
|
-
)
|
|
652
|
-
})
|
|
653
|
-
);
|
|
654
|
-
var categoryResultSchema = scorableMetaSchema.merge(
|
|
655
|
-
z16.object({ score: scoreSchema })
|
|
656
|
-
);
|
|
657
|
-
var groupResultSchema = scorableWithPluginMetaSchema.merge(
|
|
658
|
-
z16.object({ score: scoreSchema })
|
|
659
|
-
);
|
|
660
|
-
var auditResultSchema = scorableWithPluginMetaSchema.merge(
|
|
661
|
-
auditOutputSchema.pick({ score: true, value: true, displayValue: true })
|
|
662
|
-
);
|
|
663
|
-
var reportsDiffSchema = z16.object({
|
|
664
|
-
commits: makeComparisonSchema(commitSchema).nullable().describe("Commits identifying compared reports"),
|
|
665
|
-
portalUrl: urlSchema.optional().describe("Link to comparison page in Code PushUp portal"),
|
|
666
|
-
label: z16.string().optional().describe("Label (e.g. project name)"),
|
|
667
|
-
categories: makeArraysComparisonSchema(
|
|
668
|
-
categoryDiffSchema,
|
|
669
|
-
categoryResultSchema,
|
|
670
|
-
"Changes affecting categories"
|
|
671
|
-
),
|
|
672
|
-
groups: makeArraysComparisonSchema(
|
|
673
|
-
groupDiffSchema,
|
|
674
|
-
groupResultSchema,
|
|
675
|
-
"Changes affecting groups"
|
|
676
|
-
),
|
|
677
|
-
audits: makeArraysComparisonSchema(
|
|
678
|
-
auditDiffSchema,
|
|
679
|
-
auditResultSchema,
|
|
680
|
-
"Changes affecting audits"
|
|
681
|
-
)
|
|
682
|
-
}).merge(
|
|
683
|
-
packageVersionSchema({
|
|
684
|
-
versionDescription: "NPM version of the CLI (when `compare` was run)",
|
|
685
|
-
required: true
|
|
686
|
-
})
|
|
687
|
-
).merge(
|
|
688
|
-
executionMetaSchema({
|
|
689
|
-
descriptionDate: "Start date and time of the compare run",
|
|
690
|
-
descriptionDuration: "Duration of the compare run in ms"
|
|
691
|
-
})
|
|
692
|
-
);
|
|
693
|
-
|
|
694
|
-
// packages/utils/src/lib/diff.ts
|
|
695
|
-
function matchArrayItemsByKey({
|
|
696
|
-
before,
|
|
697
|
-
after,
|
|
698
|
-
key
|
|
699
|
-
}) {
|
|
700
|
-
const pairs = [];
|
|
701
|
-
const added = [];
|
|
702
|
-
const afterKeys = /* @__PURE__ */ new Set();
|
|
703
|
-
const keyFn = typeof key === "function" ? key : (item) => item[key];
|
|
704
|
-
for (const afterItem of after) {
|
|
705
|
-
const afterKey = keyFn(afterItem);
|
|
706
|
-
afterKeys.add(afterKey);
|
|
707
|
-
const match = before.find((beforeItem) => keyFn(beforeItem) === afterKey);
|
|
708
|
-
if (match) {
|
|
709
|
-
pairs.push({ before: match, after: afterItem });
|
|
710
|
-
} else {
|
|
711
|
-
added.push(afterItem);
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
const removed = before.filter(
|
|
715
|
-
(beforeItem) => !afterKeys.has(keyFn(beforeItem))
|
|
716
|
-
);
|
|
717
|
-
return {
|
|
718
|
-
pairs,
|
|
719
|
-
added,
|
|
720
|
-
removed
|
|
721
|
-
};
|
|
722
|
-
}
|
|
723
|
-
function comparePairs(pairs, equalsFn) {
|
|
724
|
-
return pairs.reduce(
|
|
725
|
-
(acc, pair) => ({
|
|
726
|
-
...acc,
|
|
727
|
-
...equalsFn(pair) ? { unchanged: [...acc.unchanged, pair.after] } : { changed: [...acc.changed, pair] }
|
|
728
|
-
}),
|
|
729
|
-
{
|
|
730
|
-
changed: [],
|
|
731
|
-
unchanged: []
|
|
732
|
-
}
|
|
733
|
-
);
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
// packages/utils/src/lib/errors.ts
|
|
737
|
-
function stringifyError(error) {
|
|
738
|
-
if (error instanceof Error) {
|
|
739
|
-
if (error.name === "Error" || error.message.startsWith(error.name)) {
|
|
740
|
-
return error.message;
|
|
741
|
-
}
|
|
742
|
-
return `${error.name}: ${error.message}`;
|
|
743
|
-
}
|
|
744
|
-
if (typeof error === "string") {
|
|
745
|
-
return error;
|
|
746
|
-
}
|
|
747
|
-
return JSON.stringify(error);
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
// packages/utils/src/lib/execute-process.ts
|
|
751
|
-
import {
|
|
752
|
-
spawn
|
|
753
|
-
} from "node:child_process";
|
|
754
|
-
|
|
755
|
-
// packages/utils/src/lib/reports/utils.ts
|
|
756
|
-
import ansis from "ansis";
|
|
757
|
-
import { md } from "build-md";
|
|
758
|
-
|
|
759
|
-
// packages/utils/src/lib/reports/constants.ts
|
|
760
|
-
var TERMINAL_WIDTH = 80;
|
|
761
|
-
var SCORE_COLOR_RANGE = {
|
|
762
|
-
GREEN_MIN: 0.9,
|
|
763
|
-
YELLOW_MIN: 0.5
|
|
764
|
-
};
|
|
765
|
-
var FOOTER_PREFIX = "Made with \u2764 by";
|
|
766
|
-
var CODE_PUSHUP_DOMAIN = "code-pushup.dev";
|
|
767
|
-
var README_LINK = "https://github.com/code-pushup/cli#readme";
|
|
768
|
-
var REPORT_HEADLINE_TEXT = "Code PushUp Report";
|
|
769
|
-
var CODE_PUSHUP_UNICODE_LOGO = "<\u2713>";
|
|
770
|
-
var REPORT_RAW_OVERVIEW_TABLE_HEADERS = [
|
|
771
|
-
"Category",
|
|
772
|
-
"Score",
|
|
773
|
-
"Audits"
|
|
774
|
-
];
|
|
775
|
-
|
|
776
|
-
// packages/utils/src/lib/reports/utils.ts
|
|
777
|
-
function formatReportScore(score) {
|
|
778
|
-
const scaledScore = score * 100;
|
|
779
|
-
const roundedScore = Math.round(scaledScore);
|
|
780
|
-
return roundedScore === 100 && score !== 1 ? Math.floor(scaledScore).toString() : roundedScore.toString();
|
|
781
|
-
}
|
|
782
|
-
function formatScoreWithColor(score, options) {
|
|
783
|
-
const styledNumber = options?.skipBold ? formatReportScore(score) : md.bold(formatReportScore(score));
|
|
784
|
-
return md`${scoreMarker(score)} ${styledNumber}`;
|
|
785
|
-
}
|
|
786
|
-
var MARKERS = {
|
|
787
|
-
circle: {
|
|
788
|
-
red: "\u{1F534}",
|
|
789
|
-
yellow: "\u{1F7E1}",
|
|
790
|
-
green: "\u{1F7E2}"
|
|
791
|
-
},
|
|
792
|
-
square: {
|
|
793
|
-
red: "\u{1F7E5}",
|
|
794
|
-
yellow: "\u{1F7E8}",
|
|
795
|
-
green: "\u{1F7E9}"
|
|
796
|
-
}
|
|
797
|
-
};
|
|
798
|
-
function scoreMarker(score, markerType = "circle") {
|
|
799
|
-
if (score >= SCORE_COLOR_RANGE.GREEN_MIN) {
|
|
800
|
-
return MARKERS[markerType].green;
|
|
801
|
-
}
|
|
802
|
-
if (score >= SCORE_COLOR_RANGE.YELLOW_MIN) {
|
|
803
|
-
return MARKERS[markerType].yellow;
|
|
804
|
-
}
|
|
805
|
-
return MARKERS[markerType].red;
|
|
806
|
-
}
|
|
807
|
-
function getDiffMarker(diff) {
|
|
808
|
-
if (diff > 0) {
|
|
809
|
-
return "\u2191";
|
|
810
|
-
}
|
|
811
|
-
if (diff < 0) {
|
|
812
|
-
return "\u2193";
|
|
813
|
-
}
|
|
814
|
-
return "";
|
|
815
|
-
}
|
|
816
|
-
function colorByScoreDiff(text, diff) {
|
|
817
|
-
const color = diff > 0 ? "green" : diff < 0 ? "red" : "gray";
|
|
818
|
-
return shieldsBadge(text, color);
|
|
819
|
-
}
|
|
820
|
-
function shieldsBadge(text, color) {
|
|
821
|
-
return md.image(
|
|
822
|
-
`https://img.shields.io/badge/${encodeURIComponent(text)}-${color}`,
|
|
823
|
-
text
|
|
824
|
-
);
|
|
825
|
-
}
|
|
826
|
-
function formatDiffNumber(diff) {
|
|
827
|
-
const number = Math.abs(diff) === Number.POSITIVE_INFINITY ? "\u221E" : `${Math.abs(diff)}`;
|
|
828
|
-
const sign = diff < 0 ? "\u2212" : "+";
|
|
829
|
-
return `${sign}${number}`;
|
|
830
|
-
}
|
|
831
|
-
function severityMarker(severity) {
|
|
832
|
-
if (severity === "error") {
|
|
833
|
-
return "\u{1F6A8}";
|
|
834
|
-
}
|
|
835
|
-
if (severity === "warning") {
|
|
836
|
-
return "\u26A0\uFE0F";
|
|
837
|
-
}
|
|
838
|
-
return "\u2139\uFE0F";
|
|
839
|
-
}
|
|
840
|
-
var MIN_NON_ZERO_RESULT = 0.1;
|
|
841
|
-
function roundValue(value) {
|
|
842
|
-
const roundedValue = Math.round(value * 10) / 10;
|
|
843
|
-
if (roundedValue === 0 && value !== 0) {
|
|
844
|
-
return MIN_NON_ZERO_RESULT * Math.sign(value);
|
|
845
|
-
}
|
|
846
|
-
return roundedValue;
|
|
847
|
-
}
|
|
848
|
-
function formatScoreChange(diff) {
|
|
849
|
-
const marker = getDiffMarker(diff);
|
|
850
|
-
const text = formatDiffNumber(roundValue(diff * 100));
|
|
851
|
-
return colorByScoreDiff(`${marker} ${text}`, diff);
|
|
852
|
-
}
|
|
853
|
-
function formatValueChange({
|
|
854
|
-
values,
|
|
855
|
-
scores
|
|
856
|
-
}) {
|
|
857
|
-
const marker = getDiffMarker(values.diff);
|
|
858
|
-
const percentage = values.before === 0 ? values.diff > 0 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY : roundValue(values.diff / values.before * 100);
|
|
859
|
-
const text = `${formatDiffNumber(percentage)}\u2009%`;
|
|
860
|
-
return colorByScoreDiff(`${marker} ${text}`, scores.diff);
|
|
861
|
-
}
|
|
862
|
-
function calcDuration(start, stop) {
|
|
863
|
-
return Math.round((stop ?? performance.now()) - start);
|
|
864
|
-
}
|
|
865
|
-
function countCategoryAudits(refs, plugins) {
|
|
866
|
-
const groupLookup = plugins.reduce(
|
|
867
|
-
(lookup, plugin) => {
|
|
868
|
-
if (plugin.groups == null || plugin.groups.length === 0) {
|
|
869
|
-
return lookup;
|
|
870
|
-
}
|
|
871
|
-
return {
|
|
872
|
-
...lookup,
|
|
873
|
-
[plugin.slug]: Object.fromEntries(
|
|
874
|
-
plugin.groups.map((group) => [group.slug, group])
|
|
875
|
-
)
|
|
876
|
-
};
|
|
877
|
-
},
|
|
878
|
-
{}
|
|
879
|
-
);
|
|
880
|
-
return refs.reduce((acc, ref) => {
|
|
881
|
-
if (ref.type === "group") {
|
|
882
|
-
const groupRefs = groupLookup[ref.plugin]?.[ref.slug]?.refs;
|
|
883
|
-
return acc + (groupRefs?.length ?? 0);
|
|
884
|
-
}
|
|
885
|
-
return acc + 1;
|
|
886
|
-
}, 0);
|
|
887
|
-
}
|
|
888
|
-
function compareCategoryAuditsAndGroups(a, b) {
|
|
889
|
-
if (a.score !== b.score) {
|
|
890
|
-
return a.score - b.score;
|
|
891
|
-
}
|
|
892
|
-
if (a.weight !== b.weight) {
|
|
893
|
-
return b.weight - a.weight;
|
|
894
|
-
}
|
|
895
|
-
if ("value" in a && "value" in b && a.value !== b.value) {
|
|
896
|
-
return b.value - a.value;
|
|
897
|
-
}
|
|
898
|
-
return a.title.localeCompare(b.title);
|
|
899
|
-
}
|
|
900
|
-
function compareAudits(a, b) {
|
|
901
|
-
if (a.score !== b.score) {
|
|
902
|
-
return a.score - b.score;
|
|
903
|
-
}
|
|
904
|
-
if (a.value !== b.value) {
|
|
905
|
-
return b.value - a.value;
|
|
906
|
-
}
|
|
907
|
-
return a.title.localeCompare(b.title);
|
|
908
|
-
}
|
|
909
|
-
function compareIssueSeverity(severity1, severity2) {
|
|
910
|
-
const levels = {
|
|
911
|
-
info: 0,
|
|
912
|
-
warning: 1,
|
|
913
|
-
error: 2
|
|
914
|
-
};
|
|
915
|
-
return levels[severity1] - levels[severity2];
|
|
916
|
-
}
|
|
917
|
-
function throwIsNotPresentError(itemName, presentPlace) {
|
|
918
|
-
throw new Error(`${itemName} is not present in ${presentPlace}`);
|
|
919
|
-
}
|
|
920
|
-
function getPluginNameFromSlug(slug, plugins) {
|
|
921
|
-
return plugins.find(({ slug: pluginSlug }) => pluginSlug === slug)?.title || slug;
|
|
922
|
-
}
|
|
923
|
-
function compareIssues(a, b) {
|
|
924
|
-
if (a.severity !== b.severity) {
|
|
925
|
-
return -compareIssueSeverity(a.severity, b.severity);
|
|
926
|
-
}
|
|
927
|
-
if (!a.source && b.source) {
|
|
928
|
-
return -1;
|
|
929
|
-
}
|
|
930
|
-
if (a.source && !b.source) {
|
|
931
|
-
return 1;
|
|
932
|
-
}
|
|
933
|
-
if (a.source?.file !== b.source?.file) {
|
|
934
|
-
return a.source?.file.localeCompare(b.source?.file || "") ?? 0;
|
|
935
|
-
}
|
|
936
|
-
if (!a.source?.position && b.source?.position) {
|
|
937
|
-
return -1;
|
|
938
|
-
}
|
|
939
|
-
if (a.source?.position && !b.source?.position) {
|
|
940
|
-
return 1;
|
|
941
|
-
}
|
|
942
|
-
if (a.source?.position?.startLine !== b.source?.position?.startLine) {
|
|
943
|
-
return (a.source?.position?.startLine ?? 0) - (b.source?.position?.startLine ?? 0);
|
|
944
|
-
}
|
|
945
|
-
return 0;
|
|
946
|
-
}
|
|
947
|
-
function applyScoreColor({ score, text }, style = ansis) {
|
|
948
|
-
const formattedScore = text ?? formatReportScore(score);
|
|
949
|
-
if (score >= SCORE_COLOR_RANGE.GREEN_MIN) {
|
|
950
|
-
return text ? style.green(formattedScore) : style.bold(style.green(formattedScore));
|
|
951
|
-
}
|
|
952
|
-
if (score >= SCORE_COLOR_RANGE.YELLOW_MIN) {
|
|
953
|
-
return text ? style.yellow(formattedScore) : style.bold(style.yellow(formattedScore));
|
|
954
|
-
}
|
|
955
|
-
return text ? style.red(formattedScore) : style.bold(style.red(formattedScore));
|
|
956
|
-
}
|
|
957
|
-
function targetScoreIcon(score, targetScore, options = {}) {
|
|
958
|
-
if (targetScore != null) {
|
|
959
|
-
const {
|
|
960
|
-
passIcon = "\u2705",
|
|
961
|
-
failIcon = "\u274C",
|
|
962
|
-
prefix = "",
|
|
963
|
-
postfix = ""
|
|
964
|
-
} = options;
|
|
965
|
-
if (score >= targetScore) {
|
|
966
|
-
return `${prefix}${passIcon}${postfix}`;
|
|
967
|
-
}
|
|
968
|
-
return `${prefix}${failIcon}${postfix}`;
|
|
969
|
-
}
|
|
970
|
-
return "";
|
|
971
|
-
}
|
|
972
|
-
|
|
973
|
-
// packages/utils/src/lib/execute-process.ts
|
|
974
|
-
var ProcessError = class extends Error {
|
|
975
|
-
code;
|
|
976
|
-
stderr;
|
|
977
|
-
stdout;
|
|
978
|
-
constructor(result) {
|
|
979
|
-
super(result.stderr);
|
|
980
|
-
this.code = result.code;
|
|
981
|
-
this.stderr = result.stderr;
|
|
982
|
-
this.stdout = result.stdout;
|
|
983
|
-
}
|
|
984
|
-
};
|
|
985
|
-
function executeProcess(cfg) {
|
|
986
|
-
const { command, args, observer, ignoreExitCode = false, ...options } = cfg;
|
|
987
|
-
const { onStdout, onStderr, onError, onComplete } = observer ?? {};
|
|
988
|
-
const date = (/* @__PURE__ */ new Date()).toISOString();
|
|
989
|
-
const start = performance.now();
|
|
990
|
-
return new Promise((resolve, reject) => {
|
|
991
|
-
const spawnedProcess = spawn(command, args ?? [], {
|
|
992
|
-
shell: true,
|
|
993
|
-
windowsHide: true,
|
|
994
|
-
...options
|
|
995
|
-
});
|
|
996
|
-
let stdout = "";
|
|
997
|
-
let stderr = "";
|
|
998
|
-
spawnedProcess.stdout.on("data", (data) => {
|
|
999
|
-
stdout += String(data);
|
|
1000
|
-
onStdout?.(String(data), spawnedProcess);
|
|
1001
|
-
});
|
|
1002
|
-
spawnedProcess.stderr.on("data", (data) => {
|
|
1003
|
-
stderr += String(data);
|
|
1004
|
-
onStderr?.(String(data), spawnedProcess);
|
|
1005
|
-
});
|
|
1006
|
-
spawnedProcess.on("error", (err) => {
|
|
1007
|
-
stderr += err.toString();
|
|
1008
|
-
});
|
|
1009
|
-
spawnedProcess.on("close", (code2) => {
|
|
1010
|
-
const timings = { date, duration: calcDuration(start) };
|
|
1011
|
-
if (code2 === 0 || ignoreExitCode) {
|
|
1012
|
-
onComplete?.();
|
|
1013
|
-
resolve({ code: code2, stdout, stderr, ...timings });
|
|
1014
|
-
} else {
|
|
1015
|
-
const errorMsg = new ProcessError({ code: code2, stdout, stderr, ...timings });
|
|
1016
|
-
onError?.(errorMsg);
|
|
1017
|
-
reject(errorMsg);
|
|
1018
|
-
}
|
|
1019
|
-
});
|
|
1020
|
-
});
|
|
1021
|
-
}
|
|
1022
|
-
|
|
1023
|
-
// packages/utils/src/lib/file-system.ts
|
|
1024
|
-
import { bold, gray } from "ansis";
|
|
1025
|
-
import { bundleRequire } from "bundle-require";
|
|
1026
|
-
import { mkdir, readFile, readdir, rm, stat } from "node:fs/promises";
|
|
1027
|
-
import { dirname, join } from "node:path";
|
|
1028
|
-
|
|
1029
|
-
// packages/utils/src/lib/formatting.ts
|
|
1030
|
-
function slugify(text) {
|
|
1031
|
-
return text.trim().toLowerCase().replace(/\s+|\//g, "-").replace(/[^a-z\d-]/g, "");
|
|
1032
|
-
}
|
|
1033
|
-
function pluralize(text, amount) {
|
|
1034
|
-
if (amount != null && Math.abs(amount) === 1) {
|
|
1035
|
-
return text;
|
|
1036
|
-
}
|
|
1037
|
-
if (text.endsWith("y")) {
|
|
1038
|
-
return `${text.slice(0, -1)}ies`;
|
|
1039
|
-
}
|
|
1040
|
-
if (text.endsWith("s")) {
|
|
1041
|
-
return `${text}es`;
|
|
1042
|
-
}
|
|
1043
|
-
return `${text}s`;
|
|
1044
|
-
}
|
|
1045
|
-
function formatBytes(bytes, decimals = 2) {
|
|
1046
|
-
const positiveBytes = Math.max(bytes, 0);
|
|
1047
|
-
if (positiveBytes === 0) {
|
|
1048
|
-
return "0 B";
|
|
1049
|
-
}
|
|
1050
|
-
const k = 1024;
|
|
1051
|
-
const dm = decimals < 0 ? 0 : decimals;
|
|
1052
|
-
const sizes = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
|
1053
|
-
const i = Math.floor(Math.log(positiveBytes) / Math.log(k));
|
|
1054
|
-
return `${Number.parseFloat((positiveBytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
|
|
1055
|
-
}
|
|
1056
|
-
function pluralizeToken(token, times) {
|
|
1057
|
-
return `${times} ${Math.abs(times) === 1 ? token : pluralize(token)}`;
|
|
1058
|
-
}
|
|
1059
|
-
function formatDuration(duration, granularity = 0) {
|
|
1060
|
-
if (duration < 1e3) {
|
|
1061
|
-
return `${granularity ? duration.toFixed(granularity) : duration} ms`;
|
|
1062
|
-
}
|
|
1063
|
-
return `${(duration / 1e3).toFixed(2)} s`;
|
|
1064
|
-
}
|
|
1065
|
-
function formatDate(date) {
|
|
1066
|
-
const locale = "en-US";
|
|
1067
|
-
return date.toLocaleString(locale, {
|
|
1068
|
-
weekday: "short",
|
|
1069
|
-
month: "short",
|
|
1070
|
-
day: "numeric",
|
|
1071
|
-
year: "numeric",
|
|
1072
|
-
hour: "numeric",
|
|
1073
|
-
minute: "2-digit",
|
|
1074
|
-
timeZoneName: "short"
|
|
1075
|
-
}).replace(/\u202F/g, " ");
|
|
1076
|
-
}
|
|
1077
|
-
function truncateText(text, options) {
|
|
1078
|
-
const {
|
|
1079
|
-
maxChars,
|
|
1080
|
-
position = "end",
|
|
1081
|
-
ellipsis = "..."
|
|
1082
|
-
} = typeof options === "number" ? { maxChars: options } : options;
|
|
1083
|
-
if (text.length <= maxChars) {
|
|
1084
|
-
return text;
|
|
1085
|
-
}
|
|
1086
|
-
const maxLength = maxChars - ellipsis.length;
|
|
1087
|
-
switch (position) {
|
|
1088
|
-
case "start":
|
|
1089
|
-
return ellipsis + text.slice(-maxLength).trim();
|
|
1090
|
-
case "middle":
|
|
1091
|
-
const halfMaxChars = Math.floor(maxLength / 2);
|
|
1092
|
-
return text.slice(0, halfMaxChars).trim() + ellipsis + text.slice(-halfMaxChars).trim();
|
|
1093
|
-
case "end":
|
|
1094
|
-
return text.slice(0, maxLength).trim() + ellipsis;
|
|
1095
|
-
}
|
|
1096
|
-
}
|
|
1097
|
-
function truncateTitle(text) {
|
|
1098
|
-
return truncateText(text, MAX_TITLE_LENGTH);
|
|
1099
|
-
}
|
|
1100
|
-
function truncateDescription(text) {
|
|
1101
|
-
return truncateText(text, MAX_DESCRIPTION_LENGTH);
|
|
1102
|
-
}
|
|
1103
|
-
function truncateIssueMessage(text) {
|
|
1104
|
-
return truncateText(text, MAX_ISSUE_MESSAGE_LENGTH);
|
|
1105
|
-
}
|
|
1106
|
-
|
|
1107
|
-
// packages/utils/src/lib/guards.ts
|
|
1108
|
-
function isPromiseFulfilledResult(result) {
|
|
1109
|
-
return result.status === "fulfilled";
|
|
1110
|
-
}
|
|
1111
|
-
function isPromiseRejectedResult(result) {
|
|
1112
|
-
return result.status === "rejected";
|
|
1113
|
-
}
|
|
1114
|
-
|
|
1115
|
-
// packages/utils/src/lib/logging.ts
|
|
1116
|
-
import isaacs_cliui from "@isaacs/cliui";
|
|
1117
|
-
import { cliui } from "@poppinss/cliui";
|
|
1118
|
-
import { underline } from "ansis";
|
|
1119
|
-
var singletonUiInstance;
|
|
1120
|
-
function ui() {
|
|
1121
|
-
if (singletonUiInstance === void 0) {
|
|
1122
|
-
singletonUiInstance = cliui();
|
|
1123
|
-
}
|
|
1124
|
-
return {
|
|
1125
|
-
...singletonUiInstance,
|
|
1126
|
-
row: (args) => {
|
|
1127
|
-
logListItem(args);
|
|
1128
|
-
}
|
|
1129
|
-
};
|
|
1130
|
-
}
|
|
1131
|
-
var singletonisaacUi;
|
|
1132
|
-
function logListItem(args) {
|
|
1133
|
-
if (singletonisaacUi === void 0) {
|
|
1134
|
-
singletonisaacUi = isaacs_cliui({ width: TERMINAL_WIDTH });
|
|
1135
|
-
}
|
|
1136
|
-
singletonisaacUi.div(...args);
|
|
1137
|
-
const content = singletonisaacUi.toString();
|
|
1138
|
-
singletonisaacUi.rows = [];
|
|
1139
|
-
singletonUiInstance?.logger.log(content);
|
|
1140
|
-
}
|
|
1141
|
-
function link(text) {
|
|
1142
|
-
return underline.blueBright(text);
|
|
1143
|
-
}
|
|
1144
|
-
|
|
1145
|
-
// packages/utils/src/lib/log-results.ts
|
|
1146
|
-
function logMultipleResults(results, messagePrefix, succeededTransform, failedTransform) {
|
|
1147
|
-
if (succeededTransform) {
|
|
1148
|
-
const succeededResults = results.filter(isPromiseFulfilledResult);
|
|
1149
|
-
logPromiseResults(
|
|
1150
|
-
succeededResults,
|
|
1151
|
-
`${messagePrefix} successfully: `,
|
|
1152
|
-
succeededTransform
|
|
1153
|
-
);
|
|
1154
|
-
}
|
|
1155
|
-
if (failedTransform) {
|
|
1156
|
-
const failedResults = results.filter(isPromiseRejectedResult);
|
|
1157
|
-
logPromiseResults(
|
|
1158
|
-
failedResults,
|
|
1159
|
-
`${messagePrefix} failed: `,
|
|
1160
|
-
failedTransform
|
|
1161
|
-
);
|
|
1162
|
-
}
|
|
1163
|
-
}
|
|
1164
|
-
function logPromiseResults(results, logMessage, getMsg) {
|
|
1165
|
-
if (results.length > 0) {
|
|
1166
|
-
const log2 = results[0]?.status === "fulfilled" ? (m) => {
|
|
1167
|
-
ui().logger.success(m);
|
|
1168
|
-
} : (m) => {
|
|
1169
|
-
ui().logger.warning(m);
|
|
1170
|
-
};
|
|
1171
|
-
log2(logMessage);
|
|
1172
|
-
results.forEach((result) => {
|
|
1173
|
-
log2(getMsg(result));
|
|
1174
|
-
});
|
|
1175
|
-
}
|
|
1176
|
-
}
|
|
1177
|
-
|
|
1178
|
-
// packages/utils/src/lib/file-system.ts
|
|
1179
|
-
async function readTextFile(path) {
|
|
1180
|
-
const buffer = await readFile(path);
|
|
1181
|
-
return buffer.toString();
|
|
1182
|
-
}
|
|
1183
|
-
async function readJsonFile(path) {
|
|
1184
|
-
const text = await readTextFile(path);
|
|
1185
|
-
return JSON.parse(text);
|
|
1186
|
-
}
|
|
1187
|
-
async function fileExists(path) {
|
|
1188
|
-
try {
|
|
1189
|
-
const stats = await stat(path);
|
|
1190
|
-
return stats.isFile();
|
|
1191
|
-
} catch {
|
|
1192
|
-
return false;
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
async function directoryExists(path) {
|
|
1196
|
-
try {
|
|
1197
|
-
const stats = await stat(path);
|
|
1198
|
-
return stats.isDirectory();
|
|
1199
|
-
} catch {
|
|
1200
|
-
return false;
|
|
1201
|
-
}
|
|
1202
|
-
}
|
|
1203
|
-
async function ensureDirectoryExists(baseDir) {
|
|
1204
|
-
try {
|
|
1205
|
-
await mkdir(baseDir, { recursive: true });
|
|
1206
|
-
return;
|
|
1207
|
-
} catch (error) {
|
|
1208
|
-
ui().logger.info(error.message);
|
|
1209
|
-
if (error.code !== "EEXIST") {
|
|
1210
|
-
throw error;
|
|
1211
|
-
}
|
|
1212
|
-
}
|
|
1213
|
-
}
|
|
1214
|
-
async function removeDirectoryIfExists(dir) {
|
|
1215
|
-
if (await directoryExists(dir)) {
|
|
1216
|
-
await rm(dir, { recursive: true, force: true });
|
|
1217
|
-
}
|
|
1218
|
-
}
|
|
1219
|
-
function logMultipleFileResults(fileResults, messagePrefix) {
|
|
1220
|
-
const succeededTransform = (result) => {
|
|
1221
|
-
const [fileName, size] = result.value;
|
|
1222
|
-
const formattedSize = size ? ` (${gray(formatBytes(size))})` : "";
|
|
1223
|
-
return `- ${bold(fileName)}${formattedSize}`;
|
|
1224
|
-
};
|
|
1225
|
-
const failedTransform = (result) => `- ${bold(result.reason)}`;
|
|
1226
|
-
logMultipleResults(
|
|
1227
|
-
fileResults,
|
|
1228
|
-
messagePrefix,
|
|
1229
|
-
succeededTransform,
|
|
1230
|
-
failedTransform
|
|
1231
|
-
);
|
|
1232
|
-
}
|
|
1233
|
-
async function importModule(options) {
|
|
1234
|
-
const { mod } = await bundleRequire(options);
|
|
1235
|
-
if (typeof mod === "object" && "default" in mod) {
|
|
1236
|
-
return mod.default;
|
|
1237
|
-
}
|
|
1238
|
-
return mod;
|
|
1239
|
-
}
|
|
1240
|
-
function pluginWorkDir(slug) {
|
|
1241
|
-
return join("node_modules", ".code-pushup", slug);
|
|
1242
|
-
}
|
|
1243
|
-
async function crawlFileSystem(options) {
|
|
1244
|
-
const {
|
|
1245
|
-
directory,
|
|
1246
|
-
pattern,
|
|
1247
|
-
fileTransform = (filePath) => filePath
|
|
1248
|
-
} = options;
|
|
1249
|
-
const files = await readdir(directory);
|
|
1250
|
-
const promises = files.map(async (file) => {
|
|
1251
|
-
const filePath = join(directory, file);
|
|
1252
|
-
const stats = await stat(filePath);
|
|
1253
|
-
if (stats.isDirectory()) {
|
|
1254
|
-
return crawlFileSystem({ directory: filePath, pattern, fileTransform });
|
|
1255
|
-
}
|
|
1256
|
-
if (stats.isFile() && (!pattern || new RegExp(pattern).test(file))) {
|
|
1257
|
-
return fileTransform(filePath);
|
|
1258
|
-
}
|
|
1259
|
-
return [];
|
|
1260
|
-
});
|
|
1261
|
-
const resultsNestedArray = await Promise.all(promises);
|
|
1262
|
-
return resultsNestedArray.flat();
|
|
1263
|
-
}
|
|
1264
|
-
async function findNearestFile(fileNames, cwd = process.cwd()) {
|
|
1265
|
-
for (let directory = cwd; directory !== dirname(directory); directory = dirname(directory)) {
|
|
1266
|
-
for (const file of fileNames) {
|
|
1267
|
-
if (await fileExists(join(directory, file))) {
|
|
1268
|
-
return join(directory, file);
|
|
1269
|
-
}
|
|
1270
|
-
}
|
|
1271
|
-
}
|
|
1272
|
-
return void 0;
|
|
1273
|
-
}
|
|
1274
|
-
function findLineNumberInText(content, pattern) {
|
|
1275
|
-
const lines = content.split(/\r?\n/);
|
|
1276
|
-
const lineNumber = lines.findIndex((line) => line.includes(pattern)) + 1;
|
|
1277
|
-
return lineNumber === 0 ? null : lineNumber;
|
|
1278
|
-
}
|
|
1279
|
-
function filePathToCliArg(path) {
|
|
1280
|
-
return `"${path}"`;
|
|
1281
|
-
}
|
|
1282
|
-
function projectToFilename(project) {
|
|
1283
|
-
return project.replace(/[/\\\s]+/g, "-").replace(/@/g, "");
|
|
1284
|
-
}
|
|
1285
|
-
|
|
1286
|
-
// packages/utils/src/lib/filter.ts
|
|
1287
|
-
function filterItemRefsBy(items, refFilterFn) {
|
|
1288
|
-
return items.map((item) => ({
|
|
1289
|
-
...item,
|
|
1290
|
-
refs: item.refs.filter(refFilterFn)
|
|
1291
|
-
})).filter((item) => item.refs.length);
|
|
1292
|
-
}
|
|
1293
|
-
|
|
1294
|
-
// packages/utils/src/lib/git/git.ts
|
|
1295
|
-
import { isAbsolute, join as join2, relative } from "node:path";
|
|
1296
|
-
import { simpleGit } from "simple-git";
|
|
1297
|
-
|
|
1298
|
-
// packages/utils/src/lib/transform.ts
|
|
1299
|
-
import { platform } from "node:os";
|
|
1300
|
-
function toArray(val) {
|
|
1301
|
-
return Array.isArray(val) ? val : [val];
|
|
1302
|
-
}
|
|
1303
|
-
function objectToKeys(obj) {
|
|
1304
|
-
return Object.keys(obj);
|
|
1305
|
-
}
|
|
1306
|
-
function objectToEntries(obj) {
|
|
1307
|
-
return Object.entries(obj);
|
|
1308
|
-
}
|
|
1309
|
-
function objectFromEntries(entries) {
|
|
1310
|
-
return Object.fromEntries(entries);
|
|
1311
|
-
}
|
|
1312
|
-
function countOccurrences(values) {
|
|
1313
|
-
return values.reduce(
|
|
1314
|
-
(acc, value) => ({ ...acc, [value]: (acc[value] ?? 0) + 1 }),
|
|
1315
|
-
{}
|
|
1316
|
-
);
|
|
1317
|
-
}
|
|
1318
|
-
function distinct(array) {
|
|
1319
|
-
return [...new Set(array)];
|
|
1320
|
-
}
|
|
1321
|
-
function deepClone(obj) {
|
|
1322
|
-
return obj == null || typeof obj !== "object" ? obj : structuredClone(obj);
|
|
1323
|
-
}
|
|
1324
|
-
function factorOf(items, filterFn) {
|
|
1325
|
-
const itemCount = items.length;
|
|
1326
|
-
if (!itemCount) {
|
|
1327
|
-
return 1;
|
|
1328
|
-
}
|
|
1329
|
-
const filterCount = items.filter(filterFn).length;
|
|
1330
|
-
return filterCount === 0 ? 1 : (itemCount - filterCount) / itemCount;
|
|
1331
|
-
}
|
|
1332
|
-
function objectToCliArgs(params) {
|
|
1333
|
-
if (!params) {
|
|
1334
|
-
return [];
|
|
1335
|
-
}
|
|
1336
|
-
return Object.entries(params).flatMap(([key, value]) => {
|
|
1337
|
-
if (key === "_") {
|
|
1338
|
-
return Array.isArray(value) ? value : [`${value}`];
|
|
1339
|
-
}
|
|
1340
|
-
const prefix = key.length === 1 ? "-" : "--";
|
|
1341
|
-
if (Array.isArray(value)) {
|
|
1342
|
-
return value.map((v) => `${prefix}${key}="${v}"`);
|
|
1343
|
-
}
|
|
1344
|
-
if (Array.isArray(value)) {
|
|
1345
|
-
return value.map((v) => `${prefix}${key}="${v}"`);
|
|
1346
|
-
}
|
|
1347
|
-
if (typeof value === "object") {
|
|
1348
|
-
return Object.entries(value).flatMap(
|
|
1349
|
-
// transform nested objects to the dot notation `key.subkey`
|
|
1350
|
-
([k, v]) => objectToCliArgs({ [`${key}.${k}`]: v })
|
|
1351
|
-
);
|
|
1352
|
-
}
|
|
1353
|
-
if (typeof value === "string") {
|
|
1354
|
-
return [`${prefix}${key}="${value}"`];
|
|
1355
|
-
}
|
|
1356
|
-
if (typeof value === "number") {
|
|
1357
|
-
return [`${prefix}${key}=${value}`];
|
|
1358
|
-
}
|
|
1359
|
-
if (typeof value === "boolean") {
|
|
1360
|
-
return [`${prefix}${value ? "" : "no-"}${key}`];
|
|
1361
|
-
}
|
|
1362
|
-
throw new Error(`Unsupported type ${typeof value} for key ${key}`);
|
|
1363
|
-
});
|
|
1364
|
-
}
|
|
1365
|
-
function toUnixPath(path) {
|
|
1366
|
-
return path.replace(/\\/g, "/");
|
|
1367
|
-
}
|
|
1368
|
-
function toUnixNewlines(text) {
|
|
1369
|
-
return platform() === "win32" ? text.replace(/\r\n/g, "\n") : text;
|
|
1370
|
-
}
|
|
1371
|
-
function fromJsonLines(jsonLines) {
|
|
1372
|
-
const unifiedNewLines = toUnixNewlines(jsonLines).trim();
|
|
1373
|
-
return JSON.parse(`[${unifiedNewLines.split("\n").join(",")}]`);
|
|
1374
|
-
}
|
|
1375
|
-
function toJsonLines(json) {
|
|
1376
|
-
return json.map((item) => JSON.stringify(item)).join("\n");
|
|
1377
|
-
}
|
|
1378
|
-
function capitalize(text) {
|
|
1379
|
-
return `${text.charAt(0).toLocaleUpperCase()}${text.slice(
|
|
1380
|
-
1
|
|
1381
|
-
)}`;
|
|
1382
|
-
}
|
|
1383
|
-
function toNumberPrecision(value, decimalPlaces) {
|
|
1384
|
-
return Number(
|
|
1385
|
-
`${Math.round(
|
|
1386
|
-
Number.parseFloat(`${value}e${decimalPlaces}`)
|
|
1387
|
-
)}e-${decimalPlaces}`
|
|
1388
|
-
);
|
|
1389
|
-
}
|
|
1390
|
-
function toOrdinal(value) {
|
|
1391
|
-
if (value % 10 === 1 && value % 100 !== 11) {
|
|
1392
|
-
return `${value}st`;
|
|
1393
|
-
}
|
|
1394
|
-
if (value % 10 === 2 && value % 100 !== 12) {
|
|
1395
|
-
return `${value}nd`;
|
|
1396
|
-
}
|
|
1397
|
-
if (value % 10 === 3 && value % 100 !== 13) {
|
|
1398
|
-
return `${value}rd`;
|
|
1399
|
-
}
|
|
1400
|
-
return `${value}th`;
|
|
1401
|
-
}
|
|
1402
|
-
|
|
1403
|
-
// packages/utils/src/lib/git/git.ts
|
|
1404
|
-
function getGitRoot(git = simpleGit()) {
|
|
1405
|
-
return git.revparse("--show-toplevel");
|
|
1406
|
-
}
|
|
1407
|
-
function formatGitPath(path, gitRoot) {
|
|
1408
|
-
const absolutePath = isAbsolute(path) ? path : join2(process.cwd(), path);
|
|
1409
|
-
const relativePath = relative(gitRoot, absolutePath);
|
|
1410
|
-
return toUnixPath(relativePath);
|
|
1411
|
-
}
|
|
1412
|
-
async function toGitPath(path, git = simpleGit()) {
|
|
1413
|
-
const gitRoot = await getGitRoot(git);
|
|
1414
|
-
return formatGitPath(path, gitRoot);
|
|
1415
|
-
}
|
|
1416
|
-
var GitStatusError = class _GitStatusError extends Error {
|
|
1417
|
-
static ignoredProps = /* @__PURE__ */ new Set(["current", "tracking"]);
|
|
1418
|
-
static getReducedStatus(status) {
|
|
1419
|
-
return Object.fromEntries(
|
|
1420
|
-
Object.entries(status).filter(([key]) => !this.ignoredProps.has(key)).filter(
|
|
1421
|
-
(entry) => {
|
|
1422
|
-
const value = entry[1];
|
|
1423
|
-
if (value == null) {
|
|
1424
|
-
return false;
|
|
1425
|
-
}
|
|
1426
|
-
if (Array.isArray(value) && value.length === 0) {
|
|
1427
|
-
return false;
|
|
1428
|
-
}
|
|
1429
|
-
if (typeof value === "number" && value === 0) {
|
|
1430
|
-
return false;
|
|
1431
|
-
}
|
|
1432
|
-
return !(typeof value === "boolean" && !value);
|
|
1433
|
-
}
|
|
1434
|
-
)
|
|
1435
|
-
);
|
|
1436
|
-
}
|
|
1437
|
-
constructor(status) {
|
|
1438
|
-
super(
|
|
1439
|
-
`Working directory needs to be clean before we you can proceed. Commit your local changes or stash them:
|
|
1440
|
-
${JSON.stringify(
|
|
1441
|
-
_GitStatusError.getReducedStatus(status),
|
|
1442
|
-
null,
|
|
1443
|
-
2
|
|
1444
|
-
)}`
|
|
1445
|
-
);
|
|
1446
|
-
}
|
|
1447
|
-
};
|
|
1448
|
-
async function guardAgainstLocalChanges(git = simpleGit()) {
|
|
1449
|
-
const status = await git.status(["-s"]);
|
|
1450
|
-
if (status.files.length > 0) {
|
|
1451
|
-
throw new GitStatusError(status);
|
|
1452
|
-
}
|
|
1453
|
-
}
|
|
1454
|
-
async function safeCheckout(branchOrHash, forceCleanStatus = false, git = simpleGit()) {
|
|
1455
|
-
if (forceCleanStatus) {
|
|
1456
|
-
await git.raw(["reset", "--hard"]);
|
|
1457
|
-
await git.clean(["f", "d"]);
|
|
1458
|
-
ui().logger.info(`git status cleaned`);
|
|
1459
|
-
}
|
|
1460
|
-
await guardAgainstLocalChanges(git);
|
|
1461
|
-
await git.checkout(branchOrHash);
|
|
1462
|
-
}
|
|
1463
|
-
|
|
1464
|
-
// packages/utils/src/lib/git/git.commits-and-tags.ts
|
|
1465
|
-
import { simpleGit as simpleGit2 } from "simple-git";
|
|
1466
|
-
|
|
1467
|
-
// packages/utils/src/lib/semver.ts
|
|
1468
|
-
import { rcompare, valid } from "semver";
|
|
1469
|
-
function normalizeSemver(semverString) {
|
|
1470
|
-
if (semverString.startsWith("v") || semverString.startsWith("V")) {
|
|
1471
|
-
return semverString.slice(1);
|
|
1472
|
-
}
|
|
1473
|
-
if (semverString.includes("@")) {
|
|
1474
|
-
return semverString.split("@").at(-1) ?? "";
|
|
1475
|
-
}
|
|
1476
|
-
return semverString;
|
|
1477
|
-
}
|
|
1478
|
-
function isSemver(semverString = "") {
|
|
1479
|
-
return valid(normalizeSemver(semverString)) != null;
|
|
1480
|
-
}
|
|
1481
|
-
function sortSemvers(semverStrings) {
|
|
1482
|
-
return semverStrings.map(normalizeSemver).filter(isSemver).sort(rcompare);
|
|
1483
|
-
}
|
|
1484
|
-
|
|
1485
|
-
// packages/utils/src/lib/git/git.commits-and-tags.ts
|
|
1486
|
-
async function getLatestCommit(git = simpleGit2()) {
|
|
1487
|
-
const log2 = await git.log({
|
|
1488
|
-
maxCount: 1,
|
|
1489
|
-
// git log -1 --pretty=format:"%H %s %an %aI" - See: https://git-scm.com/docs/pretty-formats
|
|
1490
|
-
format: { hash: "%H", message: "%s", author: "%an", date: "%aI" }
|
|
1491
|
-
});
|
|
1492
|
-
return commitSchema.parse(log2.latest);
|
|
1493
|
-
}
|
|
1494
|
-
async function getCurrentBranchOrTag(git = simpleGit2()) {
|
|
1495
|
-
return await git.branch().then((r) => r.current) || // If no current branch, try to get the tag
|
|
1496
|
-
// @TODO use simple git
|
|
1497
|
-
await git.raw(["describe", "--tags", "--exact-match"]).then((out) => out.trim());
|
|
1498
|
-
}
|
|
1499
|
-
function validateFilter({ from, to }) {
|
|
1500
|
-
if (to && !from) {
|
|
1501
|
-
throw new Error(
|
|
1502
|
-
`filter needs the "from" option defined to accept the "to" option.
|
|
1503
|
-
`
|
|
1504
|
-
);
|
|
1505
|
-
}
|
|
1506
|
-
}
|
|
1507
|
-
function filterLogs(allTags, opt) {
|
|
1508
|
-
if (!opt) {
|
|
1509
|
-
return allTags;
|
|
1510
|
-
}
|
|
1511
|
-
validateFilter(opt);
|
|
1512
|
-
const { from, to, maxCount } = opt;
|
|
1513
|
-
const finIndex = (tagName, fallback) => {
|
|
1514
|
-
const idx = allTags.indexOf(tagName ?? "");
|
|
1515
|
-
if (idx > -1) {
|
|
1516
|
-
return idx;
|
|
1517
|
-
}
|
|
1518
|
-
return fallback;
|
|
1519
|
-
};
|
|
1520
|
-
const fromIndex = finIndex(from, 0);
|
|
1521
|
-
const toIndex = finIndex(to, void 0);
|
|
1522
|
-
return allTags.slice(fromIndex, toIndex ? toIndex + 1 : toIndex).slice(0, maxCount ?? void 0);
|
|
1523
|
-
}
|
|
1524
|
-
async function getHashFromTag(tag, git = simpleGit2()) {
|
|
1525
|
-
const tagDetails = await git.show(["--no-patch", "--format=%H", tag]);
|
|
1526
|
-
const hash = tagDetails.trim();
|
|
1527
|
-
return {
|
|
1528
|
-
hash: hash.split("\n").at(-1) ?? "",
|
|
1529
|
-
message: tag
|
|
1530
|
-
};
|
|
1531
|
-
}
|
|
1532
|
-
async function getSemverTags(opt = {}, git = simpleGit2()) {
|
|
1533
|
-
validateFilter(opt);
|
|
1534
|
-
const { targetBranch, ...options } = opt;
|
|
1535
|
-
let currentBranch;
|
|
1536
|
-
if (targetBranch) {
|
|
1537
|
-
currentBranch = await getCurrentBranchOrTag(git);
|
|
1538
|
-
await git.checkout(targetBranch);
|
|
1539
|
-
}
|
|
1540
|
-
const tagsRaw = await git.tag([
|
|
1541
|
-
"--merged",
|
|
1542
|
-
targetBranch ?? await getCurrentBranchOrTag(git)
|
|
1543
|
-
]);
|
|
1544
|
-
const allTags = tagsRaw.split(/\n/).map((tag) => tag.trim()).filter(Boolean).filter(isSemver);
|
|
1545
|
-
const relevantTags = filterLogs(allTags, options);
|
|
1546
|
-
const tagsWithHashes = await Promise.all(
|
|
1547
|
-
relevantTags.map((tag) => getHashFromTag(tag, git))
|
|
1548
|
-
);
|
|
1549
|
-
if (currentBranch) {
|
|
1550
|
-
await git.checkout(currentBranch);
|
|
1551
|
-
}
|
|
1552
|
-
return tagsWithHashes;
|
|
1553
|
-
}
|
|
1554
|
-
async function getHashes(options = {}, git = simpleGit2()) {
|
|
1555
|
-
const { targetBranch, from, to, maxCount, ...opt } = options;
|
|
1556
|
-
validateFilter({ from, to });
|
|
1557
|
-
let currentBranch;
|
|
1558
|
-
if (targetBranch) {
|
|
1559
|
-
currentBranch = await getCurrentBranchOrTag(git);
|
|
1560
|
-
await git.checkout(targetBranch);
|
|
1561
|
-
}
|
|
1562
|
-
const logs = await git.log({
|
|
1563
|
-
...opt,
|
|
1564
|
-
format: {
|
|
1565
|
-
hash: "%H",
|
|
1566
|
-
message: "%s"
|
|
1567
|
-
},
|
|
1568
|
-
from,
|
|
1569
|
-
to,
|
|
1570
|
-
maxCount
|
|
1571
|
-
});
|
|
1572
|
-
if (targetBranch) {
|
|
1573
|
-
await git.checkout(currentBranch);
|
|
1574
|
-
}
|
|
1575
|
-
return [...logs.all];
|
|
1576
|
-
}
|
|
1577
|
-
|
|
1578
|
-
// packages/utils/src/lib/group-by-status.ts
|
|
1579
|
-
function groupByStatus(results) {
|
|
1580
|
-
return results.reduce(
|
|
1581
|
-
(acc, result) => result.status === "fulfilled" ? { ...acc, fulfilled: [...acc.fulfilled, result] } : { ...acc, rejected: [...acc.rejected, result] },
|
|
1582
|
-
{ fulfilled: [], rejected: [] }
|
|
1583
|
-
);
|
|
1584
|
-
}
|
|
1585
|
-
|
|
1586
|
-
// packages/utils/src/lib/merge-configs.ts
|
|
1587
|
-
function mergeConfigs(config, ...configs) {
|
|
1588
|
-
return configs.reduce(
|
|
1589
|
-
(acc, obj) => ({
|
|
1590
|
-
...acc,
|
|
1591
|
-
...mergeCategories(acc.categories, obj.categories),
|
|
1592
|
-
...mergePlugins(acc.plugins, obj.plugins),
|
|
1593
|
-
...mergePersist(acc.persist, obj.persist),
|
|
1594
|
-
...mergeUpload(acc.upload, obj.upload)
|
|
1595
|
-
}),
|
|
1596
|
-
config
|
|
1597
|
-
);
|
|
1598
|
-
}
|
|
1599
|
-
function mergeCategories(a, b) {
|
|
1600
|
-
if (!a && !b) {
|
|
1601
|
-
return {};
|
|
1602
|
-
}
|
|
1603
|
-
const mergedMap = /* @__PURE__ */ new Map();
|
|
1604
|
-
const addToMap = (categories) => {
|
|
1605
|
-
categories.forEach((newObject) => {
|
|
1606
|
-
if (mergedMap.has(newObject.slug)) {
|
|
1607
|
-
const existingObject = mergedMap.get(
|
|
1608
|
-
newObject.slug
|
|
1609
|
-
);
|
|
1610
|
-
mergedMap.set(newObject.slug, {
|
|
1611
|
-
...existingObject,
|
|
1612
|
-
...newObject,
|
|
1613
|
-
refs: mergeByUniqueCategoryRefCombination(
|
|
1614
|
-
existingObject?.refs,
|
|
1615
|
-
newObject.refs
|
|
1616
|
-
)
|
|
1617
|
-
});
|
|
1618
|
-
} else {
|
|
1619
|
-
mergedMap.set(newObject.slug, newObject);
|
|
1620
|
-
}
|
|
1621
|
-
});
|
|
1622
|
-
};
|
|
1623
|
-
if (a) {
|
|
1624
|
-
addToMap(a);
|
|
1625
|
-
}
|
|
1626
|
-
if (b) {
|
|
1627
|
-
addToMap(b);
|
|
1628
|
-
}
|
|
1629
|
-
return { categories: [...mergedMap.values()] };
|
|
1630
|
-
}
|
|
1631
|
-
function mergePlugins(a, b) {
|
|
1632
|
-
if (!a && !b) {
|
|
1633
|
-
return { plugins: [] };
|
|
1634
|
-
}
|
|
1635
|
-
const mergedMap = /* @__PURE__ */ new Map();
|
|
1636
|
-
const addToMap = (plugins) => {
|
|
1637
|
-
plugins.forEach((newObject) => {
|
|
1638
|
-
mergedMap.set(newObject.slug, newObject);
|
|
1639
|
-
});
|
|
1640
|
-
};
|
|
1641
|
-
if (a) {
|
|
1642
|
-
addToMap(a);
|
|
1643
|
-
}
|
|
1644
|
-
if (b) {
|
|
1645
|
-
addToMap(b);
|
|
1646
|
-
}
|
|
1647
|
-
return { plugins: [...mergedMap.values()] };
|
|
1648
|
-
}
|
|
1649
|
-
function mergePersist(a, b) {
|
|
1650
|
-
if (!a && !b) {
|
|
1651
|
-
return {};
|
|
1652
|
-
}
|
|
1653
|
-
if (a) {
|
|
1654
|
-
return b ? { persist: { ...a, ...b } } : {};
|
|
1655
|
-
} else {
|
|
1656
|
-
return { persist: b };
|
|
1657
|
-
}
|
|
1658
|
-
}
|
|
1659
|
-
function mergeByUniqueCategoryRefCombination(a, b) {
|
|
1660
|
-
const map = /* @__PURE__ */ new Map();
|
|
1661
|
-
const addToMap = (refs) => {
|
|
1662
|
-
refs.forEach((ref) => {
|
|
1663
|
-
const uniqueIdentification = `${ref.type}:${ref.plugin}:${ref.slug}`;
|
|
1664
|
-
if (map.has(uniqueIdentification)) {
|
|
1665
|
-
map.set(uniqueIdentification, {
|
|
1666
|
-
...map.get(uniqueIdentification),
|
|
1667
|
-
...ref
|
|
1668
|
-
});
|
|
1669
|
-
} else {
|
|
1670
|
-
map.set(uniqueIdentification, ref);
|
|
1671
|
-
}
|
|
1672
|
-
});
|
|
1673
|
-
};
|
|
1674
|
-
if (a) {
|
|
1675
|
-
addToMap(a);
|
|
1676
|
-
}
|
|
1677
|
-
if (b) {
|
|
1678
|
-
addToMap(b);
|
|
1679
|
-
}
|
|
1680
|
-
return [...map.values()];
|
|
1681
|
-
}
|
|
1682
|
-
function mergeUpload(a, b) {
|
|
1683
|
-
if (!a && !b) {
|
|
1684
|
-
return {};
|
|
1685
|
-
}
|
|
1686
|
-
if (a) {
|
|
1687
|
-
return b ? { upload: { ...a, ...b } } : {};
|
|
1688
|
-
} else {
|
|
1689
|
-
return { upload: b };
|
|
1690
|
-
}
|
|
1691
|
-
}
|
|
1692
|
-
|
|
1693
|
-
// packages/utils/src/lib/progress.ts
|
|
1694
|
-
import { black, bold as bold2, gray as gray2, green } from "ansis";
|
|
1695
|
-
import { MultiProgressBars } from "multi-progress-bars";
|
|
1696
|
-
var barStyles = {
|
|
1697
|
-
active: (s) => green(s),
|
|
1698
|
-
done: (s) => gray2(s),
|
|
1699
|
-
idle: (s) => gray2(s)
|
|
1700
|
-
};
|
|
1701
|
-
var messageStyles = {
|
|
1702
|
-
active: (s) => black(s),
|
|
1703
|
-
done: (s) => bold2.green(s),
|
|
1704
|
-
idle: (s) => gray2(s)
|
|
1705
|
-
};
|
|
1706
|
-
var mpb;
|
|
1707
|
-
function getSingletonProgressBars(options) {
|
|
1708
|
-
if (!mpb) {
|
|
1709
|
-
mpb = new MultiProgressBars({
|
|
1710
|
-
progressWidth: TERMINAL_WIDTH,
|
|
1711
|
-
initMessage: "",
|
|
1712
|
-
border: true,
|
|
1713
|
-
...options
|
|
1714
|
-
});
|
|
1715
|
-
}
|
|
1716
|
-
return mpb;
|
|
1717
|
-
}
|
|
1718
|
-
function getProgressBar(taskName) {
|
|
1719
|
-
const tasks = getSingletonProgressBars();
|
|
1720
|
-
tasks.addTask(taskName, {
|
|
1721
|
-
type: "percentage",
|
|
1722
|
-
percentage: 0,
|
|
1723
|
-
message: "",
|
|
1724
|
-
barTransformFn: barStyles.idle
|
|
1725
|
-
});
|
|
1726
|
-
return {
|
|
1727
|
-
incrementInSteps: (numPlugins) => {
|
|
1728
|
-
tasks.incrementTask(taskName, {
|
|
1729
|
-
percentage: 1 / numPlugins,
|
|
1730
|
-
barTransformFn: barStyles.active
|
|
1731
|
-
});
|
|
1732
|
-
},
|
|
1733
|
-
updateTitle: (title) => {
|
|
1734
|
-
tasks.updateTask(taskName, {
|
|
1735
|
-
message: title,
|
|
1736
|
-
barTransformFn: barStyles.active
|
|
1737
|
-
});
|
|
1738
|
-
},
|
|
1739
|
-
endProgress: (message = "") => {
|
|
1740
|
-
tasks.done(taskName, {
|
|
1741
|
-
message: messageStyles.done(message),
|
|
1742
|
-
barTransformFn: barStyles.done
|
|
1743
|
-
});
|
|
1744
|
-
}
|
|
1745
|
-
};
|
|
1746
|
-
}
|
|
1747
|
-
|
|
1748
|
-
// packages/utils/src/lib/reports/flatten-plugins.ts
|
|
1749
|
-
function listGroupsFromAllPlugins(report) {
|
|
1750
|
-
return report.plugins.flatMap(
|
|
1751
|
-
(plugin) => plugin.groups?.map((group) => ({ plugin, group })) ?? []
|
|
1752
|
-
);
|
|
1753
|
-
}
|
|
1754
|
-
function listAuditsFromAllPlugins(report) {
|
|
1755
|
-
return report.plugins.flatMap(
|
|
1756
|
-
(plugin) => plugin.audits.map((audit) => ({ plugin, audit }))
|
|
1757
|
-
);
|
|
1758
|
-
}
|
|
1759
|
-
|
|
1760
|
-
// packages/utils/src/lib/reports/generate-md-report.ts
|
|
1761
|
-
import { MarkdownDocument as MarkdownDocument3, md as md4 } from "build-md";
|
|
1762
|
-
|
|
1763
|
-
// packages/utils/src/lib/text-formats/constants.ts
|
|
1764
|
-
var NEW_LINE = "\n";
|
|
1765
|
-
var TAB = " ";
|
|
1766
|
-
var SPACE = " ";
|
|
1767
|
-
var HIERARCHY = {
|
|
1768
|
-
level_1: 1,
|
|
1769
|
-
level_2: 2,
|
|
1770
|
-
level_3: 3,
|
|
1771
|
-
level_4: 4,
|
|
1772
|
-
level_5: 5,
|
|
1773
|
-
level_6: 6
|
|
1774
|
-
};
|
|
1775
|
-
|
|
1776
|
-
// packages/utils/src/lib/text-formats/html/details.ts
|
|
1777
|
-
function details(title, content, cfg = { open: false }) {
|
|
1778
|
-
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.
|
|
1779
|
-
NEW_LINE}${content}${NEW_LINE}${// @TODO in the future we could consider adding it only if the content ends with a code block
|
|
1780
|
-
// ⚠️ The blank line ensure Markdown in content is rendered correctly.
|
|
1781
|
-
NEW_LINE}</details>${// ⚠️ The blank line is needed to ensure Markdown after details is rendered correctly.
|
|
1782
|
-
NEW_LINE}`;
|
|
1783
|
-
}
|
|
1784
|
-
|
|
1785
|
-
// packages/utils/src/lib/text-formats/html/font-style.ts
|
|
1786
|
-
var boldElement = "b";
|
|
1787
|
-
function bold3(text) {
|
|
1788
|
-
return `<${boldElement}>${text}</${boldElement}>`;
|
|
1789
|
-
}
|
|
1790
|
-
var italicElement = "i";
|
|
1791
|
-
function italic(text) {
|
|
1792
|
-
return `<${italicElement}>${text}</${italicElement}>`;
|
|
1793
|
-
}
|
|
1794
|
-
var codeElement = "code";
|
|
1795
|
-
function code(text) {
|
|
1796
|
-
return `<${codeElement}>${text}</${codeElement}>`;
|
|
1797
|
-
}
|
|
1798
|
-
|
|
1799
|
-
// packages/utils/src/lib/text-formats/html/link.ts
|
|
1800
|
-
function link2(href, text) {
|
|
1801
|
-
return `<a href="${href}">${text || href}</a>`;
|
|
1802
|
-
}
|
|
1803
|
-
|
|
1804
|
-
// packages/utils/src/lib/text-formats/table.ts
|
|
1805
|
-
function rowToStringArray({ rows, columns = [] }) {
|
|
1806
|
-
if (Array.isArray(rows.at(0)) && typeof columns.at(0) === "object") {
|
|
1807
|
-
throw new TypeError(
|
|
1808
|
-
"Column can`t be object when rows are primitive values"
|
|
1809
|
-
);
|
|
1810
|
-
}
|
|
1811
|
-
return rows.map((row) => {
|
|
1812
|
-
if (Array.isArray(row)) {
|
|
1813
|
-
return row.map(String);
|
|
1814
|
-
}
|
|
1815
|
-
const objectRow = row;
|
|
1816
|
-
if (columns.length === 0 || typeof columns.at(0) === "string") {
|
|
1817
|
-
return Object.values(objectRow).map(
|
|
1818
|
-
(value) => value == null ? "" : String(value)
|
|
1819
|
-
);
|
|
1820
|
-
}
|
|
1821
|
-
return columns.map(
|
|
1822
|
-
({ key }) => objectRow[key] == null ? "" : String(objectRow[key])
|
|
1823
|
-
);
|
|
1824
|
-
});
|
|
1825
|
-
}
|
|
1826
|
-
function columnsToStringArray({
|
|
1827
|
-
rows,
|
|
1828
|
-
columns = []
|
|
1829
|
-
}) {
|
|
1830
|
-
const firstRow = rows.at(0);
|
|
1831
|
-
const primitiveRows = Array.isArray(firstRow);
|
|
1832
|
-
if (typeof columns.at(0) === "string" && !primitiveRows) {
|
|
1833
|
-
throw new Error("invalid union type. Caught by model parsing.");
|
|
1834
|
-
}
|
|
1835
|
-
if (columns.length === 0) {
|
|
1836
|
-
if (Array.isArray(firstRow)) {
|
|
1837
|
-
return firstRow.map((_, idx) => String(idx));
|
|
1838
|
-
}
|
|
1839
|
-
return Object.keys(firstRow);
|
|
1840
|
-
}
|
|
1841
|
-
if (typeof columns.at(0) === "string") {
|
|
1842
|
-
return columns.map(String);
|
|
1843
|
-
}
|
|
1844
|
-
const cols = columns;
|
|
1845
|
-
return cols.map(({ label, key }) => label ?? capitalize(key));
|
|
1846
|
-
}
|
|
1847
|
-
function getColumnAlignmentForKeyAndIndex(targetKey, targetIdx, columns = []) {
|
|
1848
|
-
const column = columns.at(targetIdx) ?? columns.find((col) => col.key === targetKey);
|
|
1849
|
-
if (typeof column === "string") {
|
|
1850
|
-
return column;
|
|
1851
|
-
} else if (typeof column === "object") {
|
|
1852
|
-
return column.align ?? "center";
|
|
1853
|
-
} else {
|
|
1854
|
-
return "center";
|
|
1855
|
-
}
|
|
1856
|
-
}
|
|
1857
|
-
function getColumnAlignmentForIndex(targetIdx, columns = []) {
|
|
1858
|
-
const column = columns.at(targetIdx);
|
|
1859
|
-
if (column == null) {
|
|
1860
|
-
return "center";
|
|
1861
|
-
} else if (typeof column === "string") {
|
|
1862
|
-
return column;
|
|
1863
|
-
} else if (typeof column === "object") {
|
|
1864
|
-
return column.align ?? "center";
|
|
1865
|
-
} else {
|
|
1866
|
-
return "center";
|
|
1867
|
-
}
|
|
1868
|
-
}
|
|
1869
|
-
function getColumnAlignments(tableData) {
|
|
1870
|
-
const { rows, columns = [] } = tableData;
|
|
1871
|
-
if (rows.at(0) == null) {
|
|
1872
|
-
throw new Error("first row can`t be undefined.");
|
|
1873
|
-
}
|
|
1874
|
-
if (Array.isArray(rows.at(0))) {
|
|
1875
|
-
const firstPrimitiveRow = rows.at(0);
|
|
1876
|
-
return Array.from({ length: firstPrimitiveRow.length }).map(
|
|
1877
|
-
(_, idx) => getColumnAlignmentForIndex(idx, columns)
|
|
1878
|
-
);
|
|
1879
|
-
}
|
|
1880
|
-
const biggestRow = rows.toSorted((a, b) => Object.keys(a).length - Object.keys(b).length).at(-1);
|
|
1881
|
-
if (columns.length > 0) {
|
|
1882
|
-
return columns.map(
|
|
1883
|
-
(column, idx) => typeof column === "string" ? column : getColumnAlignmentForKeyAndIndex(
|
|
1884
|
-
column.key,
|
|
1885
|
-
idx,
|
|
1886
|
-
columns
|
|
1887
|
-
)
|
|
1888
|
-
);
|
|
1889
|
-
}
|
|
1890
|
-
return Object.keys(biggestRow ?? {}).map((_) => "center");
|
|
1891
|
-
}
|
|
1892
|
-
|
|
1893
|
-
// packages/utils/src/lib/text-formats/html/table.ts
|
|
1894
|
-
function wrap(elem, content) {
|
|
1895
|
-
return `<${elem}>${content}</${elem}>${NEW_LINE}`;
|
|
1896
|
-
}
|
|
1897
|
-
function wrapRow(content) {
|
|
1898
|
-
const elem = "tr";
|
|
1899
|
-
return `<${elem}>${NEW_LINE}${content}</${elem}>${NEW_LINE}`;
|
|
1900
|
-
}
|
|
1901
|
-
function table(tableData) {
|
|
1902
|
-
if (tableData.rows.length === 0) {
|
|
1903
|
-
throw new Error("Data can't be empty");
|
|
1904
|
-
}
|
|
1905
|
-
const tableHeaderCols = columnsToStringArray(tableData).map((s) => wrap("th", s)).join("");
|
|
1906
|
-
const tableHeaderRow = wrapRow(tableHeaderCols);
|
|
1907
|
-
const tableBody = rowToStringArray(tableData).map((arr) => {
|
|
1908
|
-
const columns = arr.map((s) => wrap("td", s)).join("");
|
|
1909
|
-
return wrapRow(columns);
|
|
1910
|
-
}).join("");
|
|
1911
|
-
return wrap("table", `${NEW_LINE}${tableHeaderRow}${tableBody}`);
|
|
1912
|
-
}
|
|
1913
|
-
|
|
1914
|
-
// packages/utils/src/lib/text-formats/index.ts
|
|
1915
|
-
var html = {
|
|
1916
|
-
bold: bold3,
|
|
1917
|
-
italic,
|
|
1918
|
-
code,
|
|
1919
|
-
link: link2,
|
|
1920
|
-
details,
|
|
1921
|
-
table
|
|
1922
|
-
};
|
|
1923
|
-
|
|
1924
|
-
// packages/utils/src/lib/reports/formatting.ts
|
|
1925
|
-
import {
|
|
1926
|
-
MarkdownDocument,
|
|
1927
|
-
md as md2
|
|
1928
|
-
} from "build-md";
|
|
1929
|
-
import { posix as pathPosix } from "node:path";
|
|
1930
|
-
|
|
1931
|
-
// packages/utils/src/lib/reports/types.ts
|
|
1932
|
-
var SUPPORTED_ENVIRONMENTS = [
|
|
1933
|
-
"vscode",
|
|
1934
|
-
"github",
|
|
1935
|
-
"gitlab",
|
|
1936
|
-
"other"
|
|
1937
|
-
];
|
|
1938
|
-
|
|
1939
|
-
// packages/utils/src/lib/reports/environment-type.ts
|
|
1940
|
-
var environmentChecks = {
|
|
1941
|
-
vscode: () => process.env["TERM_PROGRAM"] === "vscode",
|
|
1942
|
-
github: () => process.env["GITHUB_ACTIONS"] === "true",
|
|
1943
|
-
gitlab: () => process.env["GITLAB_CI"] === "true",
|
|
1944
|
-
other: () => true
|
|
1945
|
-
};
|
|
1946
|
-
function getEnvironmentType() {
|
|
1947
|
-
return SUPPORTED_ENVIRONMENTS.find((env) => environmentChecks[env]()) ?? "other";
|
|
1948
|
-
}
|
|
1949
|
-
function getGitHubBaseUrl() {
|
|
1950
|
-
return `${process.env["GITHUB_SERVER_URL"]}/${process.env["GITHUB_REPOSITORY"]}/blob/${process.env["GITHUB_SHA"]}`;
|
|
1951
|
-
}
|
|
1952
|
-
function getGitLabBaseUrl() {
|
|
1953
|
-
return `${process.env["CI_SERVER_URL"]}/${process.env["CI_PROJECT_PATH"]}/-/blob/${process.env["CI_COMMIT_SHA"]}`;
|
|
1954
|
-
}
|
|
1955
|
-
|
|
1956
|
-
// packages/utils/src/lib/reports/formatting.ts
|
|
1957
|
-
function tableSection(tableData, options) {
|
|
1958
|
-
if (tableData.rows.length === 0) {
|
|
1959
|
-
return null;
|
|
1960
|
-
}
|
|
1961
|
-
const { level = HIERARCHY.level_4 } = options ?? {};
|
|
1962
|
-
const columns = columnsToStringArray(tableData);
|
|
1963
|
-
const alignments = getColumnAlignments(tableData);
|
|
1964
|
-
const rows = rowToStringArray(tableData);
|
|
1965
|
-
return new MarkdownDocument().heading(level, tableData.title).table(
|
|
1966
|
-
columns.map((heading, i) => {
|
|
1967
|
-
const alignment = alignments[i];
|
|
1968
|
-
if (alignment) {
|
|
1969
|
-
return { heading, alignment };
|
|
1970
|
-
}
|
|
1971
|
-
return heading;
|
|
1972
|
-
}),
|
|
1973
|
-
rows
|
|
1974
|
-
);
|
|
1975
|
-
}
|
|
1976
|
-
function metaDescription(audit) {
|
|
1977
|
-
const docsUrl = audit.docsUrl;
|
|
1978
|
-
const description = audit.description?.trim();
|
|
1979
|
-
if (docsUrl) {
|
|
1980
|
-
const docsLink = md2.link(docsUrl, "\u{1F4D6} Docs");
|
|
1981
|
-
if (!description) {
|
|
1982
|
-
return docsLink;
|
|
1983
|
-
}
|
|
1984
|
-
const parsedDescription = description.endsWith("```") ? `${description}
|
|
1985
|
-
|
|
1986
|
-
` : `${description} `;
|
|
1987
|
-
return md2`${parsedDescription}${docsLink}`;
|
|
1988
|
-
}
|
|
1989
|
-
if (description && description.trim().length > 0) {
|
|
1990
|
-
return description;
|
|
1991
|
-
}
|
|
1992
|
-
return "";
|
|
1993
|
-
}
|
|
1994
|
-
function linkToLocalSourceForIde(source, options) {
|
|
1995
|
-
const { file, position } = source;
|
|
1996
|
-
const { outputDir } = options ?? {};
|
|
1997
|
-
if (!outputDir) {
|
|
1998
|
-
return md2.code(file);
|
|
1999
|
-
}
|
|
2000
|
-
return md2.link(formatFileLink(file, position, outputDir), md2.code(file));
|
|
2001
|
-
}
|
|
2002
|
-
function formatSourceLine(position) {
|
|
2003
|
-
if (!position) {
|
|
2004
|
-
return "";
|
|
2005
|
-
}
|
|
2006
|
-
const { startLine, endLine } = position;
|
|
2007
|
-
return endLine && startLine !== endLine ? `${startLine}-${endLine}` : `${startLine}`;
|
|
2008
|
-
}
|
|
2009
|
-
function formatGitHubLink(file, position) {
|
|
2010
|
-
const baseUrl = getGitHubBaseUrl();
|
|
2011
|
-
if (!position) {
|
|
2012
|
-
return `${baseUrl}/${file}`;
|
|
2013
|
-
}
|
|
2014
|
-
const { startLine, endLine, startColumn, endColumn } = position;
|
|
2015
|
-
const start = startColumn ? `L${startLine}C${startColumn}` : `L${startLine}`;
|
|
2016
|
-
const end = endLine ? endColumn ? `L${endLine}C${endColumn}` : `L${endLine}` : "";
|
|
2017
|
-
const lineRange = end && start !== end ? `${start}-${end}` : start;
|
|
2018
|
-
return `${baseUrl}/${file}#${lineRange}`;
|
|
2019
|
-
}
|
|
2020
|
-
function formatGitLabLink(file, position) {
|
|
2021
|
-
const baseUrl = getGitLabBaseUrl();
|
|
2022
|
-
if (!position) {
|
|
2023
|
-
return `${baseUrl}/${file}`;
|
|
2024
|
-
}
|
|
2025
|
-
const { startLine, endLine } = position;
|
|
2026
|
-
const lineRange = endLine && startLine !== endLine ? `${startLine}-${endLine}` : startLine;
|
|
2027
|
-
return `${baseUrl}/${file}#L${lineRange}`;
|
|
2028
|
-
}
|
|
2029
|
-
function formatFileLink(file, position, outputDir) {
|
|
2030
|
-
const relativePath = pathPosix.relative(outputDir, file);
|
|
2031
|
-
const env = getEnvironmentType();
|
|
2032
|
-
switch (env) {
|
|
2033
|
-
case "vscode":
|
|
2034
|
-
return position ? `${relativePath}#L${position.startLine}` : relativePath;
|
|
2035
|
-
case "github":
|
|
2036
|
-
return formatGitHubLink(file, position);
|
|
2037
|
-
case "gitlab":
|
|
2038
|
-
return formatGitLabLink(file, position);
|
|
2039
|
-
default:
|
|
2040
|
-
return relativePath;
|
|
2041
|
-
}
|
|
2042
|
-
}
|
|
2043
|
-
|
|
2044
|
-
// packages/utils/src/lib/reports/generate-md-report-categoy-section.ts
|
|
2045
|
-
import { MarkdownDocument as MarkdownDocument2, md as md3 } from "build-md";
|
|
2046
|
-
|
|
2047
|
-
// packages/utils/src/lib/reports/sorting.ts
|
|
2048
|
-
function getSortableAuditByRef({ slug, weight, plugin }, plugins) {
|
|
2049
|
-
const auditPlugin = plugins.find((p) => p.slug === plugin);
|
|
2050
|
-
if (!auditPlugin) {
|
|
2051
|
-
throwIsNotPresentError(`Plugin ${plugin}`, "report");
|
|
2052
|
-
}
|
|
2053
|
-
const audit = auditPlugin.audits.find(
|
|
2054
|
-
({ slug: auditSlug }) => auditSlug === slug
|
|
2055
|
-
);
|
|
2056
|
-
if (!audit) {
|
|
2057
|
-
throwIsNotPresentError(`Audit ${slug}`, auditPlugin.slug);
|
|
2058
|
-
}
|
|
2059
|
-
return {
|
|
2060
|
-
...audit,
|
|
2061
|
-
weight,
|
|
2062
|
-
plugin
|
|
2063
|
-
};
|
|
2064
|
-
}
|
|
2065
|
-
function getSortedGroupAudits(group, plugin, plugins) {
|
|
2066
|
-
return group.refs.map(
|
|
2067
|
-
(ref) => getSortableAuditByRef(
|
|
2068
|
-
{
|
|
2069
|
-
plugin,
|
|
2070
|
-
slug: ref.slug,
|
|
2071
|
-
weight: ref.weight,
|
|
2072
|
-
type: "audit"
|
|
2073
|
-
},
|
|
2074
|
-
plugins
|
|
2075
|
-
)
|
|
2076
|
-
).sort(compareCategoryAuditsAndGroups);
|
|
2077
|
-
}
|
|
2078
|
-
function getSortableGroupByRef({ plugin, slug, weight }, plugins) {
|
|
2079
|
-
const groupPlugin = plugins.find((p) => p.slug === plugin);
|
|
2080
|
-
if (!groupPlugin) {
|
|
2081
|
-
throwIsNotPresentError(`Plugin ${plugin}`, "report");
|
|
2082
|
-
}
|
|
2083
|
-
const group = groupPlugin.groups?.find(
|
|
2084
|
-
({ slug: groupSlug }) => groupSlug === slug
|
|
2085
|
-
);
|
|
2086
|
-
if (!group) {
|
|
2087
|
-
throwIsNotPresentError(`Group ${slug}`, groupPlugin.slug);
|
|
2088
|
-
}
|
|
2089
|
-
const sortedAudits = getSortedGroupAudits(group, groupPlugin.slug, plugins);
|
|
2090
|
-
const sortedAuditRefs = group.refs.toSorted((a, b) => {
|
|
2091
|
-
const aIndex = sortedAudits.findIndex((ref) => ref.slug === a.slug);
|
|
2092
|
-
const bIndex = sortedAudits.findIndex((ref) => ref.slug === b.slug);
|
|
2093
|
-
return aIndex - bIndex;
|
|
2094
|
-
});
|
|
2095
|
-
return {
|
|
2096
|
-
...group,
|
|
2097
|
-
refs: sortedAuditRefs,
|
|
2098
|
-
plugin,
|
|
2099
|
-
weight
|
|
2100
|
-
};
|
|
2101
|
-
}
|
|
2102
|
-
function sortReport(report) {
|
|
2103
|
-
const { categories, plugins } = report;
|
|
2104
|
-
const sortedCategories = categories?.map((category) => {
|
|
2105
|
-
const { audits, groups } = category.refs.reduce(
|
|
2106
|
-
(acc, ref) => ({
|
|
2107
|
-
...acc,
|
|
2108
|
-
...ref.type === "group" ? {
|
|
2109
|
-
groups: [...acc.groups, getSortableGroupByRef(ref, plugins)]
|
|
2110
|
-
} : {
|
|
2111
|
-
audits: [...acc.audits, getSortableAuditByRef(ref, plugins)]
|
|
2112
|
-
}
|
|
2113
|
-
}),
|
|
2114
|
-
{ groups: [], audits: [] }
|
|
2115
|
-
);
|
|
2116
|
-
const sortedAuditsAndGroups = [...audits, ...groups].sort(
|
|
2117
|
-
compareCategoryAuditsAndGroups
|
|
2118
|
-
);
|
|
2119
|
-
const sortedRefs = category.refs.toSorted((a, b) => {
|
|
2120
|
-
const aIndex = sortedAuditsAndGroups.findIndex(
|
|
2121
|
-
(ref) => ref.slug === a.slug && ref.plugin === a.plugin
|
|
2122
|
-
);
|
|
2123
|
-
const bIndex = sortedAuditsAndGroups.findIndex(
|
|
2124
|
-
(ref) => ref.slug === b.slug && ref.plugin === b.plugin
|
|
2125
|
-
);
|
|
2126
|
-
return aIndex - bIndex;
|
|
2127
|
-
});
|
|
2128
|
-
return { ...category, refs: sortedRefs };
|
|
2129
|
-
});
|
|
2130
|
-
return {
|
|
2131
|
-
...report,
|
|
2132
|
-
categories: sortedCategories,
|
|
2133
|
-
plugins: sortPlugins(plugins)
|
|
2134
|
-
};
|
|
2135
|
-
}
|
|
2136
|
-
function sortPlugins(plugins) {
|
|
2137
|
-
return plugins.map((plugin) => ({
|
|
2138
|
-
...plugin,
|
|
2139
|
-
audits: plugin.audits.toSorted(compareAudits).map(
|
|
2140
|
-
(audit) => audit.details?.issues ? {
|
|
2141
|
-
...audit,
|
|
2142
|
-
details: {
|
|
2143
|
-
...audit.details,
|
|
2144
|
-
issues: audit.details.issues.toSorted(compareIssues)
|
|
2145
|
-
}
|
|
2146
|
-
} : audit
|
|
2147
|
-
)
|
|
2148
|
-
}));
|
|
2149
|
-
}
|
|
2150
|
-
|
|
2151
|
-
// packages/utils/src/lib/reports/generate-md-report-categoy-section.ts
|
|
2152
|
-
function categoriesOverviewSection(report) {
|
|
2153
|
-
const { categories, plugins } = report;
|
|
2154
|
-
return new MarkdownDocument2().table(
|
|
2155
|
-
[
|
|
2156
|
-
{ heading: "\u{1F3F7} Category", alignment: "left" },
|
|
2157
|
-
{ heading: "\u2B50 Score", alignment: "center" },
|
|
2158
|
-
{ heading: "\u{1F6E1} Audits", alignment: "center" }
|
|
2159
|
-
],
|
|
2160
|
-
categories.map(({ title, refs, score, isBinary }) => [
|
|
2161
|
-
// @TODO refactor `isBinary: boolean` to `targetScore: number` #713
|
|
2162
|
-
// The heading "ID" is inferred from the heading text in Markdown.
|
|
2163
|
-
md3.link(`#${slugify(title)}`, title),
|
|
2164
|
-
md3`${scoreMarker(score)} ${md3.bold(
|
|
2165
|
-
formatReportScore(score)
|
|
2166
|
-
)}${binaryIconSuffix(score, isBinary)}`,
|
|
2167
|
-
countCategoryAudits(refs, plugins).toString()
|
|
2168
|
-
])
|
|
2169
|
-
);
|
|
2170
|
-
}
|
|
2171
|
-
function categoriesDetailsSection(report) {
|
|
2172
|
-
const { categories, plugins } = report;
|
|
2173
|
-
return new MarkdownDocument2().heading(HIERARCHY.level_2, "\u{1F3F7} Categories").$foreach(
|
|
2174
|
-
categories,
|
|
2175
|
-
(doc, category) => doc.heading(HIERARCHY.level_3, category.title).paragraph(metaDescription(category)).paragraph(
|
|
2176
|
-
md3`${scoreMarker(category.score)} Score: ${md3.bold(
|
|
2177
|
-
formatReportScore(category.score)
|
|
2178
|
-
)}${binaryIconSuffix(category.score, category.isBinary)}`
|
|
2179
|
-
).list(
|
|
2180
|
-
category.refs.map((ref) => {
|
|
2181
|
-
if (ref.type === "group") {
|
|
2182
|
-
const group = getSortableGroupByRef(ref, plugins);
|
|
2183
|
-
const groupAudits = group.refs.map(
|
|
2184
|
-
(groupRef) => getSortableAuditByRef(
|
|
2185
|
-
{ ...groupRef, plugin: group.plugin, type: "audit" },
|
|
2186
|
-
plugins
|
|
2187
|
-
)
|
|
2188
|
-
);
|
|
2189
|
-
const pluginTitle = getPluginNameFromSlug(ref.plugin, plugins);
|
|
2190
|
-
return categoryGroupItem(group, groupAudits, pluginTitle);
|
|
2191
|
-
} else {
|
|
2192
|
-
const audit = getSortableAuditByRef(ref, plugins);
|
|
2193
|
-
const pluginTitle = getPluginNameFromSlug(ref.plugin, plugins);
|
|
2194
|
-
return categoryRef(audit, pluginTitle);
|
|
2195
|
-
}
|
|
2196
|
-
})
|
|
2197
|
-
)
|
|
2198
|
-
);
|
|
2199
|
-
}
|
|
2200
|
-
function categoryRef({ title, score, value, displayValue }, pluginTitle) {
|
|
2201
|
-
const auditTitleAsLink = md3.link(
|
|
2202
|
-
`#${slugify(title)}-${slugify(pluginTitle)}`,
|
|
2203
|
-
title
|
|
2204
|
-
);
|
|
2205
|
-
const marker = scoreMarker(score, "square");
|
|
2206
|
-
return md3`${marker} ${auditTitleAsLink} (${md3.italic(
|
|
2207
|
-
pluginTitle
|
|
2208
|
-
)}) - ${md3.bold((displayValue || value).toString())}`;
|
|
2209
|
-
}
|
|
2210
|
-
function categoryGroupItem({ score = 0, title }, groupAudits, pluginTitle) {
|
|
2211
|
-
const groupTitle = md3`${scoreMarker(score)} ${title} (${md3.italic(
|
|
2212
|
-
pluginTitle
|
|
2213
|
-
)})`;
|
|
2214
|
-
const auditsList = md3.list(
|
|
2215
|
-
groupAudits.map(
|
|
2216
|
-
({ title: auditTitle, score: auditScore, value, displayValue }) => {
|
|
2217
|
-
const auditTitleLink = md3.link(
|
|
2218
|
-
`#${slugify(auditTitle)}-${slugify(pluginTitle)}`,
|
|
2219
|
-
auditTitle
|
|
2220
|
-
);
|
|
2221
|
-
const marker = scoreMarker(auditScore, "square");
|
|
2222
|
-
return md3`${marker} ${auditTitleLink} - ${md3.bold(
|
|
2223
|
-
String(displayValue ?? value)
|
|
2224
|
-
)}`;
|
|
2225
|
-
}
|
|
2226
|
-
)
|
|
2227
|
-
);
|
|
2228
|
-
return md3`${groupTitle}${auditsList}`;
|
|
2229
|
-
}
|
|
2230
|
-
function binaryIconSuffix(score, isBinary) {
|
|
2231
|
-
return targetScoreIcon(score, isBinary ? 1 : void 0, { prefix: " " });
|
|
2232
|
-
}
|
|
2233
|
-
|
|
2234
|
-
// packages/utils/src/lib/reports/generate-md-report.ts
|
|
2235
|
-
function auditDetailsAuditValue({
|
|
2236
|
-
score,
|
|
2237
|
-
value,
|
|
2238
|
-
displayValue
|
|
2239
|
-
}) {
|
|
2240
|
-
return md4`${scoreMarker(score, "square")} ${md4.bold(
|
|
2241
|
-
String(displayValue ?? value)
|
|
2242
|
-
)} (score: ${formatReportScore(score)})`;
|
|
2243
|
-
}
|
|
2244
|
-
function hasCategories(report) {
|
|
2245
|
-
return !!report.categories && report.categories.length > 0;
|
|
2246
|
-
}
|
|
2247
|
-
function generateMdReport(report, options) {
|
|
2248
|
-
return new MarkdownDocument3().heading(HIERARCHY.level_1, REPORT_HEADLINE_TEXT).$concat(
|
|
2249
|
-
...hasCategories(report) ? [categoriesOverviewSection(report), categoriesDetailsSection(report)] : [],
|
|
2250
|
-
auditsSection(report, options),
|
|
2251
|
-
aboutSection(report)
|
|
2252
|
-
).rule().paragraph(md4`${FOOTER_PREFIX} ${md4.link(README_LINK, "Code PushUp")}`).toString();
|
|
2253
|
-
}
|
|
2254
|
-
function auditDetailsIssues(issues = [], options) {
|
|
2255
|
-
if (issues.length === 0) {
|
|
2256
|
-
return null;
|
|
2257
|
-
}
|
|
2258
|
-
return new MarkdownDocument3().heading(HIERARCHY.level_4, "Issues").table(
|
|
2259
|
-
[
|
|
2260
|
-
{ heading: "Severity", alignment: "center" },
|
|
2261
|
-
{ heading: "Message", alignment: "left" },
|
|
2262
|
-
{ heading: "Source file", alignment: "left" },
|
|
2263
|
-
{ heading: "Line(s)", alignment: "center" }
|
|
2264
|
-
],
|
|
2265
|
-
issues.map(({ severity: level, message, source }) => {
|
|
2266
|
-
const severity = md4`${severityMarker(level)} ${md4.italic(level)}`;
|
|
2267
|
-
if (!source) {
|
|
2268
|
-
return [severity, message];
|
|
2269
|
-
}
|
|
2270
|
-
const file = linkToLocalSourceForIde(source, options);
|
|
2271
|
-
if (!source.position) {
|
|
2272
|
-
return [severity, message, file];
|
|
2273
|
-
}
|
|
2274
|
-
const line = formatSourceLine(source.position);
|
|
2275
|
-
return [severity, message, file, line];
|
|
2276
|
-
})
|
|
2277
|
-
);
|
|
2278
|
-
}
|
|
2279
|
-
function auditDetails(audit, options) {
|
|
2280
|
-
const { table: table2, issues = [] } = audit.details ?? {};
|
|
2281
|
-
const detailsValue = auditDetailsAuditValue(audit);
|
|
2282
|
-
if (issues.length === 0 && !table2?.rows.length) {
|
|
2283
|
-
return new MarkdownDocument3().paragraph(detailsValue);
|
|
2284
|
-
}
|
|
2285
|
-
const tableSectionContent = table2 && tableSection(table2);
|
|
2286
|
-
const issuesSectionContent = issues.length > 0 && auditDetailsIssues(issues, options);
|
|
2287
|
-
return new MarkdownDocument3().details(
|
|
2288
|
-
detailsValue,
|
|
2289
|
-
new MarkdownDocument3().$concat(tableSectionContent, issuesSectionContent)
|
|
2290
|
-
);
|
|
2291
|
-
}
|
|
2292
|
-
function auditsSection({ plugins }, options) {
|
|
2293
|
-
return new MarkdownDocument3().heading(HIERARCHY.level_2, "\u{1F6E1}\uFE0F Audits").$foreach(
|
|
2294
|
-
plugins.flatMap(
|
|
2295
|
-
(plugin) => plugin.audits.map((audit) => ({ ...audit, plugin }))
|
|
2296
|
-
),
|
|
2297
|
-
(doc, { plugin, ...audit }) => {
|
|
2298
|
-
const auditTitle = `${audit.title} (${plugin.title})`;
|
|
2299
|
-
const detailsContent = auditDetails(audit, options);
|
|
2300
|
-
const descriptionContent = metaDescription(audit);
|
|
2301
|
-
return doc.heading(HIERARCHY.level_3, auditTitle).$concat(detailsContent).paragraph(descriptionContent);
|
|
2302
|
-
}
|
|
2303
|
-
);
|
|
2304
|
-
}
|
|
2305
|
-
function aboutSection(report) {
|
|
2306
|
-
const { date, plugins } = report;
|
|
2307
|
-
return new MarkdownDocument3().heading(HIERARCHY.level_2, "About").paragraph(
|
|
2308
|
-
md4`Report was created by ${md4.link(
|
|
2309
|
-
README_LINK,
|
|
2310
|
-
"Code PushUp"
|
|
2311
|
-
)} on ${formatDate(new Date(date))}.`
|
|
2312
|
-
).table(...pluginMetaTable({ plugins })).table(...reportMetaTable(report));
|
|
2313
|
-
}
|
|
2314
|
-
function pluginMetaTable({
|
|
2315
|
-
plugins
|
|
2316
|
-
}) {
|
|
2317
|
-
return [
|
|
2318
|
-
[
|
|
2319
|
-
{ heading: "Plugin", alignment: "left" },
|
|
2320
|
-
{ heading: "Audits", alignment: "center" },
|
|
2321
|
-
{ heading: "Version", alignment: "center" },
|
|
2322
|
-
{ heading: "Duration", alignment: "right" }
|
|
2323
|
-
],
|
|
2324
|
-
plugins.map(({ title, audits, version = "", duration }) => [
|
|
2325
|
-
title,
|
|
2326
|
-
audits.length.toString(),
|
|
2327
|
-
version && md4.code(version),
|
|
2328
|
-
formatDuration(duration)
|
|
2329
|
-
])
|
|
2330
|
-
];
|
|
2331
|
-
}
|
|
2332
|
-
function reportMetaTable({
|
|
2333
|
-
commit,
|
|
2334
|
-
version,
|
|
2335
|
-
duration,
|
|
2336
|
-
plugins,
|
|
2337
|
-
categories
|
|
2338
|
-
}) {
|
|
2339
|
-
return [
|
|
2340
|
-
[
|
|
2341
|
-
{ heading: "Commit", alignment: "left" },
|
|
2342
|
-
{ heading: "Version", alignment: "center" },
|
|
2343
|
-
{ heading: "Duration", alignment: "right" },
|
|
2344
|
-
{ heading: "Plugins", alignment: "center" },
|
|
2345
|
-
{ heading: "Categories", alignment: "center" },
|
|
2346
|
-
{ heading: "Audits", alignment: "center" }
|
|
2347
|
-
],
|
|
2348
|
-
[
|
|
2349
|
-
[
|
|
2350
|
-
commit ? `${commit.message} (${commit.hash})` : "N/A",
|
|
2351
|
-
md4.code(version),
|
|
2352
|
-
formatDuration(duration),
|
|
2353
|
-
plugins.length.toString(),
|
|
2354
|
-
(categories?.length ?? 0).toString(),
|
|
2355
|
-
plugins.reduce((acc, { audits }) => acc + audits.length, 0).toString()
|
|
2356
|
-
]
|
|
2357
|
-
]
|
|
2358
|
-
];
|
|
2359
|
-
}
|
|
2360
|
-
|
|
2361
|
-
// packages/utils/src/lib/reports/generate-md-reports-diff.ts
|
|
2362
|
-
import {
|
|
2363
|
-
MarkdownDocument as MarkdownDocument5,
|
|
2364
|
-
md as md6
|
|
2365
|
-
} from "build-md";
|
|
2366
|
-
|
|
2367
|
-
// packages/utils/src/lib/reports/generate-md-reports-diff-utils.ts
|
|
2368
|
-
import { MarkdownDocument as MarkdownDocument4, md as md5 } from "build-md";
|
|
2369
|
-
var MAX_ROWS = 100;
|
|
2370
|
-
function summarizeUnchanged(token, { changed, unchanged }) {
|
|
2371
|
-
const pluralizedCount = changed.length > 0 ? pluralizeToken(`other ${token}`, unchanged.length) : `All of ${pluralizeToken(token, unchanged.length)}`;
|
|
2372
|
-
const pluralizedVerb = unchanged.length === 1 ? "is" : "are";
|
|
2373
|
-
return `${pluralizedCount} ${pluralizedVerb} unchanged.`;
|
|
2374
|
-
}
|
|
2375
|
-
function summarizeDiffOutcomes(outcomes, token) {
|
|
2376
|
-
return objectToEntries(countDiffOutcomes(outcomes)).filter(
|
|
2377
|
-
(entry) => entry[0] !== "unchanged" && entry[1] > 0
|
|
2378
|
-
).map(([outcome, count]) => {
|
|
2379
|
-
const formattedCount = `<strong>${count}</strong> ${pluralize(
|
|
2380
|
-
token,
|
|
2381
|
-
count
|
|
2382
|
-
)}`;
|
|
2383
|
-
switch (outcome) {
|
|
2384
|
-
case "positive":
|
|
2385
|
-
return `\u{1F44D} ${formattedCount} improved`;
|
|
2386
|
-
case "negative":
|
|
2387
|
-
return `\u{1F44E} ${formattedCount} regressed`;
|
|
2388
|
-
case "mixed":
|
|
2389
|
-
return `${formattedCount} changed without impacting score`;
|
|
2390
|
-
}
|
|
2391
|
-
}).join(", ");
|
|
2392
|
-
}
|
|
2393
|
-
function createGroupsOrAuditsDetails(token, { changed, unchanged }, ...[columns, rows]) {
|
|
2394
|
-
if (changed.length === 0) {
|
|
2395
|
-
return new MarkdownDocument4().paragraph(
|
|
2396
|
-
summarizeUnchanged(token, { changed, unchanged })
|
|
2397
|
-
);
|
|
2398
|
-
}
|
|
2399
|
-
return new MarkdownDocument4().table(columns, rows.slice(0, MAX_ROWS)).paragraph(
|
|
2400
|
-
changed.length > MAX_ROWS && md5.italic(
|
|
2401
|
-
`Only the ${MAX_ROWS} most affected ${pluralize(
|
|
2402
|
-
token
|
|
2403
|
-
)} are listed above for brevity.`
|
|
2404
|
-
)
|
|
2405
|
-
).paragraph(
|
|
2406
|
-
unchanged.length > 0 && summarizeUnchanged(token, { changed, unchanged })
|
|
2407
|
-
);
|
|
2408
|
-
}
|
|
2409
|
-
function formatTitle({
|
|
2410
|
-
title,
|
|
2411
|
-
docsUrl
|
|
2412
|
-
}) {
|
|
2413
|
-
if (docsUrl) {
|
|
2414
|
-
return md5.link(docsUrl, title);
|
|
2415
|
-
}
|
|
2416
|
-
return title;
|
|
2417
|
-
}
|
|
2418
|
-
function formatPortalLink(portalUrl) {
|
|
2419
|
-
return portalUrl && md5.link(portalUrl, "\u{1F575}\uFE0F See full comparison in Code PushUp portal \u{1F50D}");
|
|
2420
|
-
}
|
|
2421
|
-
function sortChanges(changes) {
|
|
2422
|
-
return changes.toSorted(
|
|
2423
|
-
(a, b) => Math.abs(b.scores.diff) - Math.abs(a.scores.diff) || Math.abs(b.values?.diff ?? 0) - Math.abs(a.values?.diff ?? 0)
|
|
2424
|
-
);
|
|
2425
|
-
}
|
|
2426
|
-
function getDiffChanges(diff) {
|
|
2427
|
-
return [
|
|
2428
|
-
...diff.categories.changed,
|
|
2429
|
-
...diff.groups.changed,
|
|
2430
|
-
...diff.audits.changed
|
|
2431
|
-
];
|
|
2432
|
-
}
|
|
2433
|
-
function changesToDiffOutcomes(changes) {
|
|
2434
|
-
return changes.map((change) => {
|
|
2435
|
-
if (change.scores.diff > 0) {
|
|
2436
|
-
return "positive";
|
|
2437
|
-
}
|
|
2438
|
-
if (change.scores.diff < 0) {
|
|
2439
|
-
return "negative";
|
|
2440
|
-
}
|
|
2441
|
-
if (change.values != null && change.values.diff !== 0) {
|
|
2442
|
-
return "mixed";
|
|
2443
|
-
}
|
|
2444
|
-
return "unchanged";
|
|
2445
|
-
});
|
|
2446
|
-
}
|
|
2447
|
-
function mergeDiffOutcomes(outcomes) {
|
|
2448
|
-
if (outcomes.every((outcome) => outcome === "unchanged")) {
|
|
2449
|
-
return "unchanged";
|
|
2450
|
-
}
|
|
2451
|
-
if (outcomes.includes("positive") && !outcomes.includes("negative")) {
|
|
2452
|
-
return "positive";
|
|
2453
|
-
}
|
|
2454
|
-
if (outcomes.includes("negative") && !outcomes.includes("positive")) {
|
|
2455
|
-
return "negative";
|
|
2456
|
-
}
|
|
2457
|
-
return "mixed";
|
|
2458
|
-
}
|
|
2459
|
-
function countDiffOutcomes(outcomes) {
|
|
2460
|
-
return {
|
|
2461
|
-
positive: outcomes.filter((outcome) => outcome === "positive").length,
|
|
2462
|
-
negative: outcomes.filter((outcome) => outcome === "negative").length,
|
|
2463
|
-
mixed: outcomes.filter((outcome) => outcome === "mixed").length,
|
|
2464
|
-
unchanged: outcomes.filter((outcome) => outcome === "unchanged").length
|
|
2465
|
-
};
|
|
2466
|
-
}
|
|
2467
|
-
function formatReportOutcome(outcome, commits) {
|
|
2468
|
-
const outcomeTexts = {
|
|
2469
|
-
positive: md5`🥳 Code PushUp report has ${md5.bold("improved")}`,
|
|
2470
|
-
negative: md5`😟 Code PushUp report has ${md5.bold("regressed")}`,
|
|
2471
|
-
mixed: md5`🤨 Code PushUp report has both ${md5.bold(
|
|
2472
|
-
"improvements and regressions"
|
|
2473
|
-
)}`,
|
|
2474
|
-
unchanged: md5`😐 Code PushUp report is ${md5.bold("unchanged")}`
|
|
2475
|
-
};
|
|
2476
|
-
if (commits) {
|
|
2477
|
-
const commitsText = `compared target commit ${commits.after.hash} with source commit ${commits.before.hash}`;
|
|
2478
|
-
return md5`${outcomeTexts[outcome]} – ${commitsText}.`;
|
|
2479
|
-
}
|
|
2480
|
-
return md5`${outcomeTexts[outcome]}.`;
|
|
2481
|
-
}
|
|
2482
|
-
function compareDiffsBy(type, a, b) {
|
|
2483
|
-
return sumScoreChanges(b[type].changed) - sumScoreChanges(a[type].changed) || sumConfigChanges(b[type]) - sumConfigChanges(a[type]);
|
|
2484
|
-
}
|
|
2485
|
-
function sumScoreChanges(changes) {
|
|
2486
|
-
return changes.reduce(
|
|
2487
|
-
(acc, { scores }) => acc + Math.abs(scores.diff),
|
|
2488
|
-
0
|
|
2489
|
-
);
|
|
2490
|
-
}
|
|
2491
|
-
function sumConfigChanges({
|
|
2492
|
-
added,
|
|
2493
|
-
removed
|
|
2494
|
-
}) {
|
|
2495
|
-
return added.length + removed.length;
|
|
2496
|
-
}
|
|
2497
|
-
|
|
2498
|
-
// packages/utils/src/lib/reports/generate-md-reports-diff.ts
|
|
2499
|
-
function generateMdReportsDiff(diff) {
|
|
2500
|
-
return new MarkdownDocument5().$concat(
|
|
2501
|
-
createDiffHeaderSection(diff),
|
|
2502
|
-
createDiffCategoriesSection(diff),
|
|
2503
|
-
createDiffDetailsSection(diff)
|
|
2504
|
-
).toString();
|
|
2505
|
-
}
|
|
2506
|
-
function generateMdReportsDiffForMonorepo(diffs) {
|
|
2507
|
-
const diffsWithOutcomes = diffs.map((diff) => ({
|
|
2508
|
-
...diff,
|
|
2509
|
-
outcome: mergeDiffOutcomes(changesToDiffOutcomes(getDiffChanges(diff)))
|
|
2510
|
-
})).sort(
|
|
2511
|
-
(a, b) => compareDiffsBy("categories", a, b) || compareDiffsBy("groups", a, b) || compareDiffsBy("audits", a, b) || a.label.localeCompare(b.label)
|
|
2512
|
-
);
|
|
2513
|
-
const unchanged = diffsWithOutcomes.filter(
|
|
2514
|
-
({ outcome }) => outcome === "unchanged"
|
|
2515
|
-
);
|
|
2516
|
-
const changed = diffsWithOutcomes.filter((diff) => !unchanged.includes(diff));
|
|
2517
|
-
return new MarkdownDocument5().$concat(
|
|
2518
|
-
createDiffHeaderSection(diffs),
|
|
2519
|
-
...changed.map(createDiffProjectSection)
|
|
2520
|
-
).$if(
|
|
2521
|
-
unchanged.length > 0,
|
|
2522
|
-
(doc) => doc.rule().paragraph(summarizeUnchanged("project", { unchanged, changed }))
|
|
2523
|
-
).toString();
|
|
2524
|
-
}
|
|
2525
|
-
function createDiffHeaderSection(diff) {
|
|
2526
|
-
const outcome = mergeDiffOutcomes(
|
|
2527
|
-
changesToDiffOutcomes(toArray(diff).flatMap(getDiffChanges))
|
|
2528
|
-
);
|
|
2529
|
-
const commits = Array.isArray(diff) ? diff[0]?.commits : diff.commits;
|
|
2530
|
-
const portalUrl = Array.isArray(diff) ? void 0 : diff.portalUrl;
|
|
2531
|
-
return new MarkdownDocument5().heading(HIERARCHY.level_1, "Code PushUp").paragraph(formatReportOutcome(outcome, commits)).paragraph(formatPortalLink(portalUrl));
|
|
2532
|
-
}
|
|
2533
|
-
function createDiffProjectSection(diff) {
|
|
2534
|
-
return new MarkdownDocument5().heading(HIERARCHY.level_2, md6`💼 Project ${md6.code(diff.label)}`).paragraph(formatReportOutcome(diff.outcome)).paragraph(formatPortalLink(diff.portalUrl)).$concat(
|
|
2535
|
-
createDiffCategoriesSection(diff, {
|
|
2536
|
-
skipHeading: true,
|
|
2537
|
-
skipUnchanged: true
|
|
2538
|
-
}),
|
|
2539
|
-
createDiffDetailsSection(diff, HIERARCHY.level_3)
|
|
2540
|
-
);
|
|
2541
|
-
}
|
|
2542
|
-
function createDiffCategoriesSection(diff, options) {
|
|
2543
|
-
const { changed, unchanged, added } = diff.categories;
|
|
2544
|
-
const { skipHeading, skipUnchanged } = options ?? {};
|
|
2545
|
-
const categoriesCount = changed.length + unchanged.length + added.length;
|
|
2546
|
-
const hasChanges = unchanged.length < categoriesCount;
|
|
2547
|
-
if (categoriesCount === 0) {
|
|
2548
|
-
return null;
|
|
2549
|
-
}
|
|
2550
|
-
const [columns, rows] = createCategoriesTable(diff, {
|
|
2551
|
-
hasChanges,
|
|
2552
|
-
skipUnchanged
|
|
2553
|
-
});
|
|
2554
|
-
return new MarkdownDocument5().heading(HIERARCHY.level_2, !skipHeading && "\u{1F3F7}\uFE0F Categories").table(columns, rows).paragraph(added.length > 0 && md6.italic("(\\*) New category.")).paragraph(
|
|
2555
|
-
skipUnchanged && unchanged.length > 0 && summarizeUnchanged("category", { changed, unchanged })
|
|
2556
|
-
);
|
|
2557
|
-
}
|
|
2558
|
-
function createCategoriesTable(diff, options) {
|
|
2559
|
-
const { changed, unchanged, added } = diff.categories;
|
|
2560
|
-
const { hasChanges, skipUnchanged } = options;
|
|
2561
|
-
const rows = [
|
|
2562
|
-
...sortChanges(changed).map((category) => [
|
|
2563
|
-
formatTitle(category),
|
|
2564
|
-
formatScoreWithColor(category.scores.before, {
|
|
2565
|
-
skipBold: true
|
|
2566
|
-
}),
|
|
2567
|
-
formatScoreWithColor(category.scores.after),
|
|
2568
|
-
formatScoreChange(category.scores.diff)
|
|
2569
|
-
]),
|
|
2570
|
-
...added.map((category) => [
|
|
2571
|
-
formatTitle(category),
|
|
2572
|
-
md6.italic("n/a (\\*)"),
|
|
2573
|
-
formatScoreWithColor(category.score),
|
|
2574
|
-
md6.italic("n/a (\\*)")
|
|
2575
|
-
]),
|
|
2576
|
-
...skipUnchanged ? [] : unchanged.map((category) => [
|
|
2577
|
-
formatTitle(category),
|
|
2578
|
-
formatScoreWithColor(category.score, { skipBold: true }),
|
|
2579
|
-
formatScoreWithColor(category.score),
|
|
2580
|
-
"\u2013"
|
|
2581
|
-
])
|
|
2582
|
-
];
|
|
2583
|
-
if (rows.length === 0) {
|
|
2584
|
-
return [[], []];
|
|
2585
|
-
}
|
|
2586
|
-
const columns = [
|
|
2587
|
-
{ heading: "\u{1F3F7}\uFE0F Category", alignment: "left" },
|
|
2588
|
-
{
|
|
2589
|
-
heading: hasChanges ? "\u2B50 Previous score" : "\u2B50 Score",
|
|
2590
|
-
alignment: "center"
|
|
2591
|
-
},
|
|
2592
|
-
{ heading: "\u2B50 Current score", alignment: "center" },
|
|
2593
|
-
{ heading: "\u{1F504} Score change", alignment: "center" }
|
|
2594
|
-
];
|
|
2595
|
-
return [
|
|
2596
|
-
hasChanges ? columns : columns.slice(0, 2),
|
|
2597
|
-
rows.map((row) => hasChanges ? row : row.slice(0, 2))
|
|
2598
|
-
];
|
|
2599
|
-
}
|
|
2600
|
-
function createDiffDetailsSection(diff, level = HIERARCHY.level_2) {
|
|
2601
|
-
if (diff.groups.changed.length + diff.audits.changed.length === 0) {
|
|
2602
|
-
return null;
|
|
2603
|
-
}
|
|
2604
|
-
const summary = ["group", "audit"].map(
|
|
2605
|
-
(token) => summarizeDiffOutcomes(
|
|
2606
|
-
changesToDiffOutcomes(diff[`${token}s`].changed),
|
|
2607
|
-
token
|
|
2608
|
-
)
|
|
2609
|
-
).filter(Boolean).join(", ");
|
|
2610
|
-
const details2 = new MarkdownDocument5().$concat(
|
|
2611
|
-
createDiffGroupsSection(diff, level),
|
|
2612
|
-
createDiffAuditsSection(diff, level)
|
|
2613
|
-
);
|
|
2614
|
-
return new MarkdownDocument5().details(summary, details2);
|
|
2615
|
-
}
|
|
2616
|
-
function createDiffGroupsSection(diff, level) {
|
|
2617
|
-
if (diff.groups.changed.length + diff.groups.unchanged.length === 0) {
|
|
2618
|
-
return null;
|
|
2619
|
-
}
|
|
2620
|
-
return new MarkdownDocument5().heading(level, "\u{1F5C3}\uFE0F Groups").$concat(
|
|
2621
|
-
createGroupsOrAuditsDetails(
|
|
2622
|
-
"group",
|
|
2623
|
-
diff.groups,
|
|
2624
|
-
[
|
|
2625
|
-
{ heading: "\u{1F50C} Plugin", alignment: "left" },
|
|
2626
|
-
{ heading: "\u{1F5C3}\uFE0F Group", alignment: "left" },
|
|
2627
|
-
{ heading: "\u2B50 Previous score", alignment: "center" },
|
|
2628
|
-
{ heading: "\u2B50 Current score", alignment: "center" },
|
|
2629
|
-
{ heading: "\u{1F504} Score change", alignment: "center" }
|
|
2630
|
-
],
|
|
2631
|
-
sortChanges(diff.groups.changed).map((group) => [
|
|
2632
|
-
formatTitle(group.plugin),
|
|
2633
|
-
formatTitle(group),
|
|
2634
|
-
formatScoreWithColor(group.scores.before, { skipBold: true }),
|
|
2635
|
-
formatScoreWithColor(group.scores.after),
|
|
2636
|
-
formatScoreChange(group.scores.diff)
|
|
2637
|
-
])
|
|
2638
|
-
)
|
|
2639
|
-
);
|
|
2640
|
-
}
|
|
2641
|
-
function createDiffAuditsSection(diff, level) {
|
|
2642
|
-
return new MarkdownDocument5().heading(level, "\u{1F6E1}\uFE0F Audits").$concat(
|
|
2643
|
-
createGroupsOrAuditsDetails(
|
|
2644
|
-
"audit",
|
|
2645
|
-
diff.audits,
|
|
2646
|
-
[
|
|
2647
|
-
{ heading: "\u{1F50C} Plugin", alignment: "left" },
|
|
2648
|
-
{ heading: "\u{1F6E1}\uFE0F Audit", alignment: "left" },
|
|
2649
|
-
{ heading: "\u{1F4CF} Previous value", alignment: "center" },
|
|
2650
|
-
{ heading: "\u{1F4CF} Current value", alignment: "center" },
|
|
2651
|
-
{ heading: "\u{1F504} Value change", alignment: "center" }
|
|
2652
|
-
],
|
|
2653
|
-
sortChanges(diff.audits.changed).map((audit) => [
|
|
2654
|
-
formatTitle(audit.plugin),
|
|
2655
|
-
formatTitle(audit),
|
|
2656
|
-
`${scoreMarker(audit.scores.before, "square")} ${audit.displayValues.before || audit.values.before.toString()}`,
|
|
2657
|
-
md6`${scoreMarker(audit.scores.after, "square")} ${md6.bold(
|
|
2658
|
-
audit.displayValues.after || audit.values.after.toString()
|
|
2659
|
-
)}`,
|
|
2660
|
-
formatValueChange(audit)
|
|
2661
|
-
])
|
|
2662
|
-
)
|
|
2663
|
-
);
|
|
2664
|
-
}
|
|
2665
|
-
|
|
2666
|
-
// packages/utils/src/lib/reports/load-report.ts
|
|
2667
|
-
import { join as join3 } from "node:path";
|
|
2668
|
-
async function loadReport(options) {
|
|
2669
|
-
const { outputDir, filename, format } = options;
|
|
2670
|
-
await ensureDirectoryExists(outputDir);
|
|
2671
|
-
const filePath = join3(outputDir, `${filename}.${format}`);
|
|
2672
|
-
if (format === "json") {
|
|
2673
|
-
const content = await readJsonFile(filePath);
|
|
2674
|
-
return reportSchema.parse(content);
|
|
2675
|
-
}
|
|
2676
|
-
const text = await readTextFile(filePath);
|
|
2677
|
-
return text;
|
|
2678
|
-
}
|
|
2679
|
-
|
|
2680
|
-
// packages/utils/src/lib/reports/log-stdout-summary.ts
|
|
2681
|
-
import { bold as bold4, cyan, cyanBright, green as green2, red } from "ansis";
|
|
2682
|
-
function log(msg = "") {
|
|
2683
|
-
ui().logger.log(msg);
|
|
2684
|
-
}
|
|
2685
|
-
function logStdoutSummary(report, verbose = false) {
|
|
2686
|
-
const { plugins, categories, packageName, version } = report;
|
|
2687
|
-
log(reportToHeaderSection({ packageName, version }));
|
|
2688
|
-
log();
|
|
2689
|
-
logPlugins(plugins, verbose);
|
|
2690
|
-
if (categories && categories.length > 0) {
|
|
2691
|
-
logCategories({ plugins, categories });
|
|
2692
|
-
}
|
|
2693
|
-
log(`${FOOTER_PREFIX} ${CODE_PUSHUP_DOMAIN}`);
|
|
2694
|
-
log();
|
|
2695
|
-
}
|
|
2696
|
-
function reportToHeaderSection({
|
|
2697
|
-
packageName,
|
|
2698
|
-
version
|
|
2699
|
-
}) {
|
|
2700
|
-
return `${bold4(REPORT_HEADLINE_TEXT)} - ${packageName}@${version}`;
|
|
2701
|
-
}
|
|
2702
|
-
function logPlugins(plugins, verbose) {
|
|
2703
|
-
plugins.forEach((plugin) => {
|
|
2704
|
-
const { title, audits } = plugin;
|
|
2705
|
-
const filteredAudits = verbose || audits.length === 1 ? audits : audits.filter(({ score }) => score !== 1);
|
|
2706
|
-
const diff = audits.length - filteredAudits.length;
|
|
2707
|
-
logAudits(title, filteredAudits);
|
|
2708
|
-
if (diff > 0) {
|
|
2709
|
-
const notice = filteredAudits.length === 0 ? `... All ${diff} audits have perfect scores ...` : `... ${diff} audits with perfect scores omitted for brevity ...`;
|
|
2710
|
-
logRow(1, notice);
|
|
2711
|
-
}
|
|
2712
|
-
log();
|
|
2713
|
-
});
|
|
2714
|
-
}
|
|
2715
|
-
function logAudits(pluginTitle, audits) {
|
|
2716
|
-
log();
|
|
2717
|
-
log(bold4.magentaBright(`${pluginTitle} audits`));
|
|
2718
|
-
log();
|
|
2719
|
-
audits.forEach(({ score, title, displayValue, value }) => {
|
|
2720
|
-
logRow(score, title, displayValue || `${value}`);
|
|
2721
|
-
});
|
|
2722
|
-
}
|
|
2723
|
-
function logRow(score, title, value) {
|
|
2724
|
-
ui().row([
|
|
2725
|
-
{
|
|
2726
|
-
text: applyScoreColor({ score, text: "\u25CF" }),
|
|
2727
|
-
width: 2,
|
|
2728
|
-
padding: [0, 1, 0, 0]
|
|
2729
|
-
},
|
|
2730
|
-
{
|
|
2731
|
-
text: title,
|
|
2732
|
-
// eslint-disable-next-line no-magic-numbers
|
|
2733
|
-
padding: [0, 3, 0, 0]
|
|
2734
|
-
},
|
|
2735
|
-
...value ? [
|
|
2736
|
-
{
|
|
2737
|
-
text: cyanBright(value),
|
|
2738
|
-
// eslint-disable-next-line no-magic-numbers
|
|
2739
|
-
width: 20,
|
|
2740
|
-
padding: [0, 0, 0, 0]
|
|
2741
|
-
}
|
|
2742
|
-
] : []
|
|
2743
|
-
]);
|
|
2744
|
-
}
|
|
2745
|
-
function logCategories({
|
|
2746
|
-
plugins,
|
|
2747
|
-
categories
|
|
2748
|
-
}) {
|
|
2749
|
-
const hAlign = (idx) => idx === 0 ? "left" : "right";
|
|
2750
|
-
const rows = categories.map(({ title, score, refs, isBinary }) => [
|
|
2751
|
-
title,
|
|
2752
|
-
`${binaryIconPrefix(score, isBinary)}${applyScoreColor({ score })}`,
|
|
2753
|
-
countCategoryAudits(refs, plugins)
|
|
2754
|
-
]);
|
|
2755
|
-
const table2 = ui().table();
|
|
2756
|
-
table2.columnWidths([TERMINAL_WIDTH - 9 - 10 - 4, 9, 10]);
|
|
2757
|
-
table2.head(
|
|
2758
|
-
REPORT_RAW_OVERVIEW_TABLE_HEADERS.map((heading, idx) => ({
|
|
2759
|
-
content: cyan(heading),
|
|
2760
|
-
hAlign: hAlign(idx)
|
|
2761
|
-
}))
|
|
2762
|
-
);
|
|
2763
|
-
rows.forEach(
|
|
2764
|
-
(row) => table2.row(
|
|
2765
|
-
row.map((content, idx) => ({
|
|
2766
|
-
content: content.toString(),
|
|
2767
|
-
hAlign: hAlign(idx)
|
|
2768
|
-
}))
|
|
2769
|
-
)
|
|
2770
|
-
);
|
|
2771
|
-
log(bold4.magentaBright("Categories"));
|
|
2772
|
-
log();
|
|
2773
|
-
table2.render();
|
|
2774
|
-
log();
|
|
2775
|
-
}
|
|
2776
|
-
function binaryIconPrefix(score, isBinary) {
|
|
2777
|
-
return targetScoreIcon(score, isBinary ? 1 : void 0, {
|
|
2778
|
-
passIcon: bold4(green2("\u2713")),
|
|
2779
|
-
failIcon: bold4(red("\u2717")),
|
|
2780
|
-
postfix: " "
|
|
2781
|
-
});
|
|
2782
|
-
}
|
|
2783
|
-
|
|
2784
|
-
// packages/utils/src/lib/reports/scoring.ts
|
|
2785
|
-
var GroupRefInvalidError = class extends Error {
|
|
2786
|
-
constructor(auditSlug, pluginSlug) {
|
|
2787
|
-
super(
|
|
2788
|
-
`Group has invalid ref - audit with slug ${auditSlug} from plugin ${pluginSlug} not found`
|
|
2789
|
-
);
|
|
2790
|
-
}
|
|
2791
|
-
};
|
|
2792
|
-
function scoreReport(report) {
|
|
2793
|
-
const allScoredAuditsAndGroups = /* @__PURE__ */ new Map();
|
|
2794
|
-
const scoredPlugins = report.plugins.map((plugin) => {
|
|
2795
|
-
const { groups, ...pluginProps } = plugin;
|
|
2796
|
-
plugin.audits.forEach((audit) => {
|
|
2797
|
-
allScoredAuditsAndGroups.set(`${plugin.slug}-${audit.slug}-audit`, audit);
|
|
2798
|
-
});
|
|
2799
|
-
function groupScoreFn(ref) {
|
|
2800
|
-
const score = allScoredAuditsAndGroups.get(
|
|
2801
|
-
`${plugin.slug}-${ref.slug}-audit`
|
|
2802
|
-
)?.score;
|
|
2803
|
-
if (score == null) {
|
|
2804
|
-
throw new GroupRefInvalidError(ref.slug, plugin.slug);
|
|
2805
|
-
}
|
|
2806
|
-
return score;
|
|
2807
|
-
}
|
|
2808
|
-
const scoredGroups = groups?.map((group) => ({
|
|
2809
|
-
...group,
|
|
2810
|
-
score: calculateScore(group.refs, groupScoreFn)
|
|
2811
|
-
})) ?? [];
|
|
2812
|
-
scoredGroups.forEach((group) => {
|
|
2813
|
-
allScoredAuditsAndGroups.set(`${plugin.slug}-${group.slug}-group`, group);
|
|
2814
|
-
});
|
|
2815
|
-
return {
|
|
2816
|
-
...pluginProps,
|
|
2817
|
-
...scoredGroups.length > 0 && { groups: scoredGroups }
|
|
2818
|
-
};
|
|
2819
|
-
});
|
|
2820
|
-
function catScoreFn(ref) {
|
|
2821
|
-
const key = `${ref.plugin}-${ref.slug}-${ref.type}`;
|
|
2822
|
-
const item = allScoredAuditsAndGroups.get(key);
|
|
2823
|
-
if (!item) {
|
|
2824
|
-
throw new Error(
|
|
2825
|
-
`Category has invalid ref - ${ref.type} with slug ${key} not found in ${ref.plugin} plugin`
|
|
2826
|
-
);
|
|
2827
|
-
}
|
|
2828
|
-
return item.score;
|
|
2829
|
-
}
|
|
2830
|
-
const scoredCategories = report.categories?.map((category) => ({
|
|
2831
|
-
...category,
|
|
2832
|
-
score: calculateScore(category.refs, catScoreFn)
|
|
2833
|
-
}));
|
|
2834
|
-
return {
|
|
2835
|
-
...deepClone(report),
|
|
2836
|
-
plugins: scoredPlugins,
|
|
2837
|
-
categories: scoredCategories
|
|
2838
|
-
};
|
|
2839
|
-
}
|
|
2840
|
-
function calculateScore(refs, scoreFn) {
|
|
2841
|
-
const validatedRefs = parseScoringParameters(refs, scoreFn);
|
|
2842
|
-
const { numerator, denominator } = validatedRefs.reduce(
|
|
2843
|
-
(acc, ref) => ({
|
|
2844
|
-
numerator: acc.numerator + ref.score * ref.weight,
|
|
2845
|
-
denominator: acc.denominator + ref.weight
|
|
2846
|
-
}),
|
|
2847
|
-
{ numerator: 0, denominator: 0 }
|
|
2848
|
-
);
|
|
2849
|
-
return numerator / denominator;
|
|
2850
|
-
}
|
|
2851
|
-
function parseScoringParameters(refs, scoreFn) {
|
|
2852
|
-
if (refs.length === 0) {
|
|
2853
|
-
throw new Error("Reference array cannot be empty.");
|
|
2854
|
-
}
|
|
2855
|
-
if (refs.some((ref) => ref.weight < 0)) {
|
|
2856
|
-
throw new Error("Weight cannot be negative.");
|
|
2857
|
-
}
|
|
2858
|
-
if (refs.every((ref) => ref.weight === 0)) {
|
|
2859
|
-
throw new Error("All references cannot have zero weight.");
|
|
2860
|
-
}
|
|
2861
|
-
const scoredRefs = refs.map((ref) => ({
|
|
2862
|
-
weight: ref.weight,
|
|
2863
|
-
score: scoreFn(ref)
|
|
2864
|
-
}));
|
|
2865
|
-
if (scoredRefs.some((ref) => ref.score < 0 || ref.score > 1)) {
|
|
2866
|
-
throw new Error("All scores must be in range 0-1.");
|
|
2867
|
-
}
|
|
2868
|
-
return scoredRefs;
|
|
2869
|
-
}
|
|
2870
|
-
|
|
2871
|
-
// packages/utils/src/lib/verbose-utils.ts
|
|
2872
|
-
function getLogVerbose(verbose = false) {
|
|
2873
|
-
return (msg) => {
|
|
2874
|
-
if (verbose) {
|
|
2875
|
-
ui().logger.info(msg);
|
|
2876
|
-
}
|
|
2877
|
-
};
|
|
2878
|
-
}
|
|
2879
|
-
function getExecVerbose(verbose = false) {
|
|
2880
|
-
return (fn) => {
|
|
2881
|
-
if (verbose) {
|
|
2882
|
-
fn();
|
|
2883
|
-
}
|
|
2884
|
-
};
|
|
2885
|
-
}
|
|
2886
|
-
var verboseUtils = (verbose = false) => ({
|
|
2887
|
-
log: getLogVerbose(verbose),
|
|
2888
|
-
exec: getExecVerbose(verbose)
|
|
2889
|
-
});
|
|
2890
|
-
export {
|
|
2891
|
-
CODE_PUSHUP_DOMAIN,
|
|
2892
|
-
CODE_PUSHUP_UNICODE_LOGO,
|
|
2893
|
-
FOOTER_PREFIX,
|
|
2894
|
-
HIERARCHY,
|
|
2895
|
-
NEW_LINE,
|
|
2896
|
-
ProcessError,
|
|
2897
|
-
README_LINK,
|
|
2898
|
-
SPACE,
|
|
2899
|
-
TAB,
|
|
2900
|
-
TERMINAL_WIDTH,
|
|
2901
|
-
calcDuration,
|
|
2902
|
-
capitalize,
|
|
2903
|
-
compareIssueSeverity,
|
|
2904
|
-
comparePairs,
|
|
2905
|
-
countOccurrences,
|
|
2906
|
-
crawlFileSystem,
|
|
2907
|
-
directoryExists,
|
|
2908
|
-
distinct,
|
|
2909
|
-
ensureDirectoryExists,
|
|
2910
|
-
executeProcess,
|
|
2911
|
-
exists,
|
|
2912
|
-
factorOf,
|
|
2913
|
-
fileExists,
|
|
2914
|
-
filePathToCliArg,
|
|
2915
|
-
filterItemRefsBy,
|
|
2916
|
-
findLineNumberInText,
|
|
2917
|
-
findNearestFile,
|
|
2918
|
-
formatBytes,
|
|
2919
|
-
formatDuration,
|
|
2920
|
-
formatGitPath,
|
|
2921
|
-
formatReportScore,
|
|
2922
|
-
fromJsonLines,
|
|
2923
|
-
generateMdReport,
|
|
2924
|
-
generateMdReportsDiff,
|
|
2925
|
-
generateMdReportsDiffForMonorepo,
|
|
2926
|
-
getCurrentBranchOrTag,
|
|
2927
|
-
getGitRoot,
|
|
2928
|
-
getHashFromTag,
|
|
2929
|
-
getHashes,
|
|
2930
|
-
getLatestCommit,
|
|
2931
|
-
getProgressBar,
|
|
2932
|
-
getSemverTags,
|
|
2933
|
-
groupByStatus,
|
|
2934
|
-
guardAgainstLocalChanges,
|
|
2935
|
-
html,
|
|
2936
|
-
importModule,
|
|
2937
|
-
isPromiseFulfilledResult,
|
|
2938
|
-
isPromiseRejectedResult,
|
|
2939
|
-
isSemver,
|
|
2940
|
-
link,
|
|
2941
|
-
listAuditsFromAllPlugins,
|
|
2942
|
-
listGroupsFromAllPlugins,
|
|
2943
|
-
loadReport,
|
|
2944
|
-
logMultipleFileResults,
|
|
2945
|
-
logMultipleResults,
|
|
2946
|
-
logStdoutSummary,
|
|
2947
|
-
matchArrayItemsByKey,
|
|
2948
|
-
mergeConfigs,
|
|
2949
|
-
normalizeSemver,
|
|
2950
|
-
objectFromEntries,
|
|
2951
|
-
objectToCliArgs,
|
|
2952
|
-
objectToEntries,
|
|
2953
|
-
objectToKeys,
|
|
2954
|
-
pluginWorkDir,
|
|
2955
|
-
pluralize,
|
|
2956
|
-
pluralizeToken,
|
|
2957
|
-
projectToFilename,
|
|
2958
|
-
readJsonFile,
|
|
2959
|
-
readTextFile,
|
|
2960
|
-
removeDirectoryIfExists,
|
|
2961
|
-
safeCheckout,
|
|
2962
|
-
scoreReport,
|
|
2963
|
-
slugify,
|
|
2964
|
-
sortReport,
|
|
2965
|
-
sortSemvers,
|
|
2966
|
-
stringifyError,
|
|
2967
|
-
toArray,
|
|
2968
|
-
toGitPath,
|
|
2969
|
-
toJsonLines,
|
|
2970
|
-
toNumberPrecision,
|
|
2971
|
-
toOrdinal,
|
|
2972
|
-
toUnixNewlines,
|
|
2973
|
-
toUnixPath,
|
|
2974
|
-
truncateDescription,
|
|
2975
|
-
truncateIssueMessage,
|
|
2976
|
-
truncateText,
|
|
2977
|
-
truncateTitle,
|
|
2978
|
-
ui,
|
|
2979
|
-
verboseUtils
|
|
2980
|
-
};
|