@code-pushup/utils 0.8.10 → 0.8.11
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/index.js +97 -72
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -38,6 +38,46 @@ function errorItems(items, transform = (items2) => items2.join(", ")) {
|
|
|
38
38
|
function exists(value) {
|
|
39
39
|
return value != null;
|
|
40
40
|
}
|
|
41
|
+
function getMissingRefsForCategories(categories, plugins) {
|
|
42
|
+
const missingRefs = [];
|
|
43
|
+
const auditRefsFromCategory = categories.flatMap(
|
|
44
|
+
({ refs }) => refs.filter(({ type }) => type === "audit").map(({ plugin, slug }) => `${plugin}/${slug}`)
|
|
45
|
+
);
|
|
46
|
+
const auditRefsFromPlugins = plugins.flatMap(
|
|
47
|
+
({ audits, slug: pluginSlug }) => {
|
|
48
|
+
return audits.map(({ slug }) => `${pluginSlug}/${slug}`);
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
const missingAuditRefs = hasMissingStrings(
|
|
52
|
+
auditRefsFromCategory,
|
|
53
|
+
auditRefsFromPlugins
|
|
54
|
+
);
|
|
55
|
+
if (Array.isArray(missingAuditRefs) && missingAuditRefs.length > 0) {
|
|
56
|
+
missingRefs.push(...missingAuditRefs);
|
|
57
|
+
}
|
|
58
|
+
const groupRefsFromCategory = categories.flatMap(
|
|
59
|
+
({ refs }) => refs.filter(({ type }) => type === "group").map(({ plugin, slug }) => `${plugin}#${slug} (group)`)
|
|
60
|
+
);
|
|
61
|
+
const groupRefsFromPlugins = plugins.flatMap(
|
|
62
|
+
({ groups, slug: pluginSlug }) => {
|
|
63
|
+
return Array.isArray(groups) ? groups.map(({ slug }) => `${pluginSlug}#${slug} (group)`) : [];
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
const missingGroupRefs = hasMissingStrings(
|
|
67
|
+
groupRefsFromCategory,
|
|
68
|
+
groupRefsFromPlugins
|
|
69
|
+
);
|
|
70
|
+
if (Array.isArray(missingGroupRefs) && missingGroupRefs.length > 0) {
|
|
71
|
+
missingRefs.push(...missingGroupRefs);
|
|
72
|
+
}
|
|
73
|
+
return missingRefs.length ? missingRefs : false;
|
|
74
|
+
}
|
|
75
|
+
function missingRefsForCategoriesErrorMsg(categories, plugins) {
|
|
76
|
+
const missingRefs = getMissingRefsForCategories(categories, plugins);
|
|
77
|
+
return `The following category references need to point to an audit or group: ${errorItems(
|
|
78
|
+
missingRefs
|
|
79
|
+
)}`;
|
|
80
|
+
}
|
|
41
81
|
|
|
42
82
|
// packages/models/src/lib/implementation/schemas.ts
|
|
43
83
|
function executionMetaSchema(options = {
|
|
@@ -96,15 +136,13 @@ function positiveIntSchema(description) {
|
|
|
96
136
|
return z.number({ description }).int().nonnegative();
|
|
97
137
|
}
|
|
98
138
|
function packageVersionSchema(options) {
|
|
99
|
-
|
|
100
|
-
versionDescription = versionDescription || "NPM version of the package";
|
|
101
|
-
optional = !!optional;
|
|
139
|
+
const { versionDescription = "NPM version of the package", required } = options ?? {};
|
|
102
140
|
const packageSchema = z.string({ description: "NPM package name" });
|
|
103
141
|
const versionSchema = z.string({ description: versionDescription });
|
|
104
142
|
return z.object(
|
|
105
143
|
{
|
|
106
|
-
packageName:
|
|
107
|
-
version:
|
|
144
|
+
packageName: required ? packageSchema : packageSchema.optional(),
|
|
145
|
+
version: required ? versionSchema : versionSchema.optional()
|
|
108
146
|
},
|
|
109
147
|
{ description: "NPM package name and version of a published package" }
|
|
110
148
|
);
|
|
@@ -166,7 +204,7 @@ var pluginAuditsSchema = z2.array(auditSchema, {
|
|
|
166
204
|
);
|
|
167
205
|
function duplicateSlugsInAuditsErrorMsg(audits) {
|
|
168
206
|
const duplicateRefs = getDuplicateSlugsInAudits(audits);
|
|
169
|
-
return `In plugin audits the slugs are not unique: ${errorItems(
|
|
207
|
+
return `In plugin audits the following slugs are not unique: ${errorItems(
|
|
170
208
|
duplicateRefs
|
|
171
209
|
)}`;
|
|
172
210
|
}
|
|
@@ -355,7 +393,9 @@ function getDuplicateRefsInGroups(groups) {
|
|
|
355
393
|
}
|
|
356
394
|
function duplicateSlugsInGroupsErrorMsg(groups) {
|
|
357
395
|
const duplicateRefs = getDuplicateSlugsInGroups(groups);
|
|
358
|
-
return `In groups the slugs are not unique: ${errorItems(
|
|
396
|
+
return `In groups the following slugs are not unique: ${errorItems(
|
|
397
|
+
duplicateRefs
|
|
398
|
+
)}`;
|
|
359
399
|
}
|
|
360
400
|
function getDuplicateSlugsInGroups(groups) {
|
|
361
401
|
return Array.isArray(groups) ? hasDuplicateStrings(groups.map(({ slug }) => slug)) : false;
|
|
@@ -381,9 +421,7 @@ var onProgressSchema = z8.function().args(z8.unknown()).returns(z8.void());
|
|
|
381
421
|
var runnerFunctionSchema = z8.function().args(onProgressSchema.optional()).returns(z8.union([auditOutputsSchema, z8.promise(auditOutputsSchema)]));
|
|
382
422
|
|
|
383
423
|
// packages/models/src/lib/plugin-config.ts
|
|
384
|
-
var pluginMetaSchema = packageVersionSchema(
|
|
385
|
-
optional: true
|
|
386
|
-
}).merge(
|
|
424
|
+
var pluginMetaSchema = packageVersionSchema().merge(
|
|
387
425
|
metaSchema({
|
|
388
426
|
titleDescription: "Descriptive name",
|
|
389
427
|
descriptionDescription: "Description (markdown)",
|
|
@@ -392,7 +430,7 @@ var pluginMetaSchema = packageVersionSchema({
|
|
|
392
430
|
})
|
|
393
431
|
).merge(
|
|
394
432
|
z9.object({
|
|
395
|
-
slug: slugSchema("
|
|
433
|
+
slug: slugSchema("Unique plugin slug within core config"),
|
|
396
434
|
icon: materialIconSchema
|
|
397
435
|
})
|
|
398
436
|
);
|
|
@@ -409,20 +447,17 @@ var pluginConfigSchema = pluginMetaSchema.merge(pluginDataSchema).refine(
|
|
|
409
447
|
);
|
|
410
448
|
function missingRefsFromGroupsErrorMsg(pluginCfg) {
|
|
411
449
|
const missingRefs = getMissingRefsFromGroups(pluginCfg);
|
|
412
|
-
return `
|
|
450
|
+
return `The following group references need to point to an existing audit in this plugin config: ${errorItems(
|
|
413
451
|
missingRefs
|
|
414
452
|
)}`;
|
|
415
453
|
}
|
|
416
454
|
function getMissingRefsFromGroups(pluginCfg) {
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
);
|
|
424
|
-
}
|
|
425
|
-
return false;
|
|
455
|
+
return hasMissingStrings(
|
|
456
|
+
pluginCfg.groups?.flatMap(
|
|
457
|
+
({ refs: audits }) => audits.map(({ slug: ref }) => ref)
|
|
458
|
+
) ?? [],
|
|
459
|
+
pluginCfg.audits.map(({ slug }) => slug)
|
|
460
|
+
);
|
|
426
461
|
}
|
|
427
462
|
|
|
428
463
|
// packages/models/src/lib/upload-config.ts
|
|
@@ -432,19 +467,15 @@ var uploadConfigSchema = z10.object({
|
|
|
432
467
|
apiKey: z10.string({
|
|
433
468
|
description: "API key with write access to portal (use `process.env` for security)"
|
|
434
469
|
}),
|
|
435
|
-
organization:
|
|
436
|
-
|
|
437
|
-
}),
|
|
438
|
-
project: z10.string({
|
|
439
|
-
description: "Project in code versioning system"
|
|
440
|
-
})
|
|
470
|
+
organization: slugSchema("Organization slug from Code PushUp portal"),
|
|
471
|
+
project: slugSchema("Project slug from Code PushUp portal")
|
|
441
472
|
});
|
|
442
473
|
|
|
443
474
|
// packages/models/src/lib/core-config.ts
|
|
444
475
|
var unrefinedCoreConfigSchema = z11.object({
|
|
445
476
|
plugins: z11.array(pluginConfigSchema, {
|
|
446
477
|
description: "List of plugins to be used (official, community-provided, or custom)"
|
|
447
|
-
}),
|
|
478
|
+
}).min(1),
|
|
448
479
|
/** portal configuration for persisting results */
|
|
449
480
|
persist: persistConfigSchema.optional(),
|
|
450
481
|
/** portal configuration for uploading results */
|
|
@@ -454,52 +485,15 @@ var unrefinedCoreConfigSchema = z11.object({
|
|
|
454
485
|
var coreConfigSchema = refineCoreConfig(unrefinedCoreConfigSchema);
|
|
455
486
|
function refineCoreConfig(schema) {
|
|
456
487
|
return schema.refine(
|
|
457
|
-
(coreCfg) => !getMissingRefsForCategories(coreCfg),
|
|
488
|
+
(coreCfg) => !getMissingRefsForCategories(coreCfg.categories, coreCfg.plugins),
|
|
458
489
|
(coreCfg) => ({
|
|
459
|
-
message: missingRefsForCategoriesErrorMsg(
|
|
490
|
+
message: missingRefsForCategoriesErrorMsg(
|
|
491
|
+
coreCfg.categories,
|
|
492
|
+
coreCfg.plugins
|
|
493
|
+
)
|
|
460
494
|
})
|
|
461
495
|
);
|
|
462
496
|
}
|
|
463
|
-
function missingRefsForCategoriesErrorMsg(coreCfg) {
|
|
464
|
-
const missingRefs = getMissingRefsForCategories(coreCfg);
|
|
465
|
-
return `In the categories, the following plugin refs do not exist in the provided plugins: ${errorItems(
|
|
466
|
-
missingRefs
|
|
467
|
-
)}`;
|
|
468
|
-
}
|
|
469
|
-
function getMissingRefsForCategories(coreCfg) {
|
|
470
|
-
const missingRefs = [];
|
|
471
|
-
const auditRefsFromCategory = coreCfg.categories.flatMap(
|
|
472
|
-
({ refs }) => refs.filter(({ type }) => type === "audit").map(({ plugin, slug }) => `${plugin}/${slug}`)
|
|
473
|
-
);
|
|
474
|
-
const auditRefsFromPlugins = coreCfg.plugins.flatMap(
|
|
475
|
-
({ audits, slug: pluginSlug }) => {
|
|
476
|
-
return audits.map(({ slug }) => `${pluginSlug}/${slug}`);
|
|
477
|
-
}
|
|
478
|
-
);
|
|
479
|
-
const missingAuditRefs = hasMissingStrings(
|
|
480
|
-
auditRefsFromCategory,
|
|
481
|
-
auditRefsFromPlugins
|
|
482
|
-
);
|
|
483
|
-
if (Array.isArray(missingAuditRefs) && missingAuditRefs.length > 0) {
|
|
484
|
-
missingRefs.push(...missingAuditRefs);
|
|
485
|
-
}
|
|
486
|
-
const groupRefsFromCategory = coreCfg.categories.flatMap(
|
|
487
|
-
({ refs }) => refs.filter(({ type }) => type === "group").map(({ plugin, slug }) => `${plugin}#${slug} (group)`)
|
|
488
|
-
);
|
|
489
|
-
const groupRefsFromPlugins = coreCfg.plugins.flatMap(
|
|
490
|
-
({ groups, slug: pluginSlug }) => {
|
|
491
|
-
return Array.isArray(groups) ? groups.map(({ slug }) => `${pluginSlug}#${slug} (group)`) : [];
|
|
492
|
-
}
|
|
493
|
-
);
|
|
494
|
-
const missingGroupRefs = hasMissingStrings(
|
|
495
|
-
groupRefsFromCategory,
|
|
496
|
-
groupRefsFromPlugins
|
|
497
|
-
);
|
|
498
|
-
if (Array.isArray(missingGroupRefs) && missingGroupRefs.length > 0) {
|
|
499
|
-
missingRefs.push(...missingGroupRefs);
|
|
500
|
-
}
|
|
501
|
-
return missingRefs.length ? missingRefs : false;
|
|
502
|
-
}
|
|
503
497
|
|
|
504
498
|
// packages/models/src/lib/report.ts
|
|
505
499
|
import { z as z12 } from "zod";
|
|
@@ -514,9 +508,32 @@ var pluginReportSchema = pluginMetaSchema.merge(
|
|
|
514
508
|
audits: z12.array(auditReportSchema),
|
|
515
509
|
groups: z12.array(groupSchema).optional()
|
|
516
510
|
})
|
|
511
|
+
).refine(
|
|
512
|
+
(pluginReport) => !getMissingRefsFromGroups2(pluginReport.audits, pluginReport.groups ?? []),
|
|
513
|
+
(pluginReport) => ({
|
|
514
|
+
message: missingRefsFromGroupsErrorMsg2(
|
|
515
|
+
pluginReport.audits,
|
|
516
|
+
pluginReport.groups ?? []
|
|
517
|
+
)
|
|
518
|
+
})
|
|
517
519
|
);
|
|
520
|
+
function missingRefsFromGroupsErrorMsg2(audits, groups) {
|
|
521
|
+
const missingRefs = getMissingRefsFromGroups2(audits, groups);
|
|
522
|
+
return `group references need to point to an existing audit in this plugin report: ${errorItems(
|
|
523
|
+
missingRefs
|
|
524
|
+
)}`;
|
|
525
|
+
}
|
|
526
|
+
function getMissingRefsFromGroups2(audits, groups) {
|
|
527
|
+
return hasMissingStrings(
|
|
528
|
+
groups.flatMap(
|
|
529
|
+
({ refs: auditRefs }) => auditRefs.map(({ slug: ref }) => ref)
|
|
530
|
+
),
|
|
531
|
+
audits.map(({ slug }) => slug)
|
|
532
|
+
);
|
|
533
|
+
}
|
|
518
534
|
var reportSchema = packageVersionSchema({
|
|
519
|
-
versionDescription: "NPM version of the CLI"
|
|
535
|
+
versionDescription: "NPM version of the CLI",
|
|
536
|
+
required: true
|
|
520
537
|
}).merge(
|
|
521
538
|
executionMetaSchema({
|
|
522
539
|
descriptionDate: "Start date and time of the collect run",
|
|
@@ -526,10 +543,18 @@ var reportSchema = packageVersionSchema({
|
|
|
526
543
|
z12.object(
|
|
527
544
|
{
|
|
528
545
|
categories: z12.array(categoryConfigSchema),
|
|
529
|
-
plugins: z12.array(pluginReportSchema)
|
|
546
|
+
plugins: z12.array(pluginReportSchema).min(1)
|
|
530
547
|
},
|
|
531
548
|
{ description: "Collect output data" }
|
|
532
549
|
)
|
|
550
|
+
).refine(
|
|
551
|
+
(report) => !getMissingRefsForCategories(report.categories, report.plugins),
|
|
552
|
+
(report) => ({
|
|
553
|
+
message: missingRefsForCategoriesErrorMsg(
|
|
554
|
+
report.categories,
|
|
555
|
+
report.plugins
|
|
556
|
+
)
|
|
557
|
+
})
|
|
533
558
|
);
|
|
534
559
|
|
|
535
560
|
// packages/utils/src/lib/constants.ts
|