@code-pushup/eslint-plugin 0.8.9 → 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/bin.js +97 -72
- package/index.js +98 -73
- package/package.json +1 -1
package/bin.js
CHANGED
|
@@ -36,6 +36,46 @@ function errorItems(items, transform = (items2) => items2.join(", ")) {
|
|
|
36
36
|
function exists(value) {
|
|
37
37
|
return value != null;
|
|
38
38
|
}
|
|
39
|
+
function getMissingRefsForCategories(categories, plugins) {
|
|
40
|
+
const missingRefs = [];
|
|
41
|
+
const auditRefsFromCategory = categories.flatMap(
|
|
42
|
+
({ refs }) => refs.filter(({ type }) => type === "audit").map(({ plugin, slug }) => `${plugin}/${slug}`)
|
|
43
|
+
);
|
|
44
|
+
const auditRefsFromPlugins = plugins.flatMap(
|
|
45
|
+
({ audits, slug: pluginSlug }) => {
|
|
46
|
+
return audits.map(({ slug }) => `${pluginSlug}/${slug}`);
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
const missingAuditRefs = hasMissingStrings(
|
|
50
|
+
auditRefsFromCategory,
|
|
51
|
+
auditRefsFromPlugins
|
|
52
|
+
);
|
|
53
|
+
if (Array.isArray(missingAuditRefs) && missingAuditRefs.length > 0) {
|
|
54
|
+
missingRefs.push(...missingAuditRefs);
|
|
55
|
+
}
|
|
56
|
+
const groupRefsFromCategory = categories.flatMap(
|
|
57
|
+
({ refs }) => refs.filter(({ type }) => type === "group").map(({ plugin, slug }) => `${plugin}#${slug} (group)`)
|
|
58
|
+
);
|
|
59
|
+
const groupRefsFromPlugins = plugins.flatMap(
|
|
60
|
+
({ groups, slug: pluginSlug }) => {
|
|
61
|
+
return Array.isArray(groups) ? groups.map(({ slug }) => `${pluginSlug}#${slug} (group)`) : [];
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
const missingGroupRefs = hasMissingStrings(
|
|
65
|
+
groupRefsFromCategory,
|
|
66
|
+
groupRefsFromPlugins
|
|
67
|
+
);
|
|
68
|
+
if (Array.isArray(missingGroupRefs) && missingGroupRefs.length > 0) {
|
|
69
|
+
missingRefs.push(...missingGroupRefs);
|
|
70
|
+
}
|
|
71
|
+
return missingRefs.length ? missingRefs : false;
|
|
72
|
+
}
|
|
73
|
+
function missingRefsForCategoriesErrorMsg(categories, plugins) {
|
|
74
|
+
const missingRefs = getMissingRefsForCategories(categories, plugins);
|
|
75
|
+
return `The following category references need to point to an audit or group: ${errorItems(
|
|
76
|
+
missingRefs
|
|
77
|
+
)}`;
|
|
78
|
+
}
|
|
39
79
|
|
|
40
80
|
// packages/models/src/lib/implementation/schemas.ts
|
|
41
81
|
function executionMetaSchema(options = {
|
|
@@ -94,15 +134,13 @@ function positiveIntSchema(description) {
|
|
|
94
134
|
return z.number({ description }).int().nonnegative();
|
|
95
135
|
}
|
|
96
136
|
function packageVersionSchema(options) {
|
|
97
|
-
|
|
98
|
-
versionDescription = versionDescription || "NPM version of the package";
|
|
99
|
-
optional = !!optional;
|
|
137
|
+
const { versionDescription = "NPM version of the package", required } = options ?? {};
|
|
100
138
|
const packageSchema = z.string({ description: "NPM package name" });
|
|
101
139
|
const versionSchema = z.string({ description: versionDescription });
|
|
102
140
|
return z.object(
|
|
103
141
|
{
|
|
104
|
-
packageName:
|
|
105
|
-
version:
|
|
142
|
+
packageName: required ? packageSchema : packageSchema.optional(),
|
|
143
|
+
version: required ? versionSchema : versionSchema.optional()
|
|
106
144
|
},
|
|
107
145
|
{ description: "NPM package name and version of a published package" }
|
|
108
146
|
);
|
|
@@ -164,7 +202,7 @@ var pluginAuditsSchema = z2.array(auditSchema, {
|
|
|
164
202
|
);
|
|
165
203
|
function duplicateSlugsInAuditsErrorMsg(audits) {
|
|
166
204
|
const duplicateRefs = getDuplicateSlugsInAudits(audits);
|
|
167
|
-
return `In plugin audits the slugs are not unique: ${errorItems(
|
|
205
|
+
return `In plugin audits the following slugs are not unique: ${errorItems(
|
|
168
206
|
duplicateRefs
|
|
169
207
|
)}`;
|
|
170
208
|
}
|
|
@@ -353,7 +391,9 @@ function getDuplicateRefsInGroups(groups) {
|
|
|
353
391
|
}
|
|
354
392
|
function duplicateSlugsInGroupsErrorMsg(groups) {
|
|
355
393
|
const duplicateRefs = getDuplicateSlugsInGroups(groups);
|
|
356
|
-
return `In groups the slugs are not unique: ${errorItems(
|
|
394
|
+
return `In groups the following slugs are not unique: ${errorItems(
|
|
395
|
+
duplicateRefs
|
|
396
|
+
)}`;
|
|
357
397
|
}
|
|
358
398
|
function getDuplicateSlugsInGroups(groups) {
|
|
359
399
|
return Array.isArray(groups) ? hasDuplicateStrings(groups.map(({ slug }) => slug)) : false;
|
|
@@ -379,9 +419,7 @@ var onProgressSchema = z8.function().args(z8.unknown()).returns(z8.void());
|
|
|
379
419
|
var runnerFunctionSchema = z8.function().args(onProgressSchema.optional()).returns(z8.union([auditOutputsSchema, z8.promise(auditOutputsSchema)]));
|
|
380
420
|
|
|
381
421
|
// packages/models/src/lib/plugin-config.ts
|
|
382
|
-
var pluginMetaSchema = packageVersionSchema(
|
|
383
|
-
optional: true
|
|
384
|
-
}).merge(
|
|
422
|
+
var pluginMetaSchema = packageVersionSchema().merge(
|
|
385
423
|
metaSchema({
|
|
386
424
|
titleDescription: "Descriptive name",
|
|
387
425
|
descriptionDescription: "Description (markdown)",
|
|
@@ -390,7 +428,7 @@ var pluginMetaSchema = packageVersionSchema({
|
|
|
390
428
|
})
|
|
391
429
|
).merge(
|
|
392
430
|
z9.object({
|
|
393
|
-
slug: slugSchema("
|
|
431
|
+
slug: slugSchema("Unique plugin slug within core config"),
|
|
394
432
|
icon: materialIconSchema
|
|
395
433
|
})
|
|
396
434
|
);
|
|
@@ -407,20 +445,17 @@ var pluginConfigSchema = pluginMetaSchema.merge(pluginDataSchema).refine(
|
|
|
407
445
|
);
|
|
408
446
|
function missingRefsFromGroupsErrorMsg(pluginCfg) {
|
|
409
447
|
const missingRefs = getMissingRefsFromGroups(pluginCfg);
|
|
410
|
-
return `
|
|
448
|
+
return `The following group references need to point to an existing audit in this plugin config: ${errorItems(
|
|
411
449
|
missingRefs
|
|
412
450
|
)}`;
|
|
413
451
|
}
|
|
414
452
|
function getMissingRefsFromGroups(pluginCfg) {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
);
|
|
422
|
-
}
|
|
423
|
-
return false;
|
|
453
|
+
return hasMissingStrings(
|
|
454
|
+
pluginCfg.groups?.flatMap(
|
|
455
|
+
({ refs: audits }) => audits.map(({ slug: ref }) => ref)
|
|
456
|
+
) ?? [],
|
|
457
|
+
pluginCfg.audits.map(({ slug }) => slug)
|
|
458
|
+
);
|
|
424
459
|
}
|
|
425
460
|
|
|
426
461
|
// packages/models/src/lib/upload-config.ts
|
|
@@ -430,19 +465,15 @@ var uploadConfigSchema = z10.object({
|
|
|
430
465
|
apiKey: z10.string({
|
|
431
466
|
description: "API key with write access to portal (use `process.env` for security)"
|
|
432
467
|
}),
|
|
433
|
-
organization:
|
|
434
|
-
|
|
435
|
-
}),
|
|
436
|
-
project: z10.string({
|
|
437
|
-
description: "Project in code versioning system"
|
|
438
|
-
})
|
|
468
|
+
organization: slugSchema("Organization slug from Code PushUp portal"),
|
|
469
|
+
project: slugSchema("Project slug from Code PushUp portal")
|
|
439
470
|
});
|
|
440
471
|
|
|
441
472
|
// packages/models/src/lib/core-config.ts
|
|
442
473
|
var unrefinedCoreConfigSchema = z11.object({
|
|
443
474
|
plugins: z11.array(pluginConfigSchema, {
|
|
444
475
|
description: "List of plugins to be used (official, community-provided, or custom)"
|
|
445
|
-
}),
|
|
476
|
+
}).min(1),
|
|
446
477
|
/** portal configuration for persisting results */
|
|
447
478
|
persist: persistConfigSchema.optional(),
|
|
448
479
|
/** portal configuration for uploading results */
|
|
@@ -452,52 +483,15 @@ var unrefinedCoreConfigSchema = z11.object({
|
|
|
452
483
|
var coreConfigSchema = refineCoreConfig(unrefinedCoreConfigSchema);
|
|
453
484
|
function refineCoreConfig(schema) {
|
|
454
485
|
return schema.refine(
|
|
455
|
-
(coreCfg) => !getMissingRefsForCategories(coreCfg),
|
|
486
|
+
(coreCfg) => !getMissingRefsForCategories(coreCfg.categories, coreCfg.plugins),
|
|
456
487
|
(coreCfg) => ({
|
|
457
|
-
message: missingRefsForCategoriesErrorMsg(
|
|
488
|
+
message: missingRefsForCategoriesErrorMsg(
|
|
489
|
+
coreCfg.categories,
|
|
490
|
+
coreCfg.plugins
|
|
491
|
+
)
|
|
458
492
|
})
|
|
459
493
|
);
|
|
460
494
|
}
|
|
461
|
-
function missingRefsForCategoriesErrorMsg(coreCfg) {
|
|
462
|
-
const missingRefs = getMissingRefsForCategories(coreCfg);
|
|
463
|
-
return `In the categories, the following plugin refs do not exist in the provided plugins: ${errorItems(
|
|
464
|
-
missingRefs
|
|
465
|
-
)}`;
|
|
466
|
-
}
|
|
467
|
-
function getMissingRefsForCategories(coreCfg) {
|
|
468
|
-
const missingRefs = [];
|
|
469
|
-
const auditRefsFromCategory = coreCfg.categories.flatMap(
|
|
470
|
-
({ refs }) => refs.filter(({ type }) => type === "audit").map(({ plugin, slug }) => `${plugin}/${slug}`)
|
|
471
|
-
);
|
|
472
|
-
const auditRefsFromPlugins = coreCfg.plugins.flatMap(
|
|
473
|
-
({ audits, slug: pluginSlug }) => {
|
|
474
|
-
return audits.map(({ slug }) => `${pluginSlug}/${slug}`);
|
|
475
|
-
}
|
|
476
|
-
);
|
|
477
|
-
const missingAuditRefs = hasMissingStrings(
|
|
478
|
-
auditRefsFromCategory,
|
|
479
|
-
auditRefsFromPlugins
|
|
480
|
-
);
|
|
481
|
-
if (Array.isArray(missingAuditRefs) && missingAuditRefs.length > 0) {
|
|
482
|
-
missingRefs.push(...missingAuditRefs);
|
|
483
|
-
}
|
|
484
|
-
const groupRefsFromCategory = coreCfg.categories.flatMap(
|
|
485
|
-
({ refs }) => refs.filter(({ type }) => type === "group").map(({ plugin, slug }) => `${plugin}#${slug} (group)`)
|
|
486
|
-
);
|
|
487
|
-
const groupRefsFromPlugins = coreCfg.plugins.flatMap(
|
|
488
|
-
({ groups, slug: pluginSlug }) => {
|
|
489
|
-
return Array.isArray(groups) ? groups.map(({ slug }) => `${pluginSlug}#${slug} (group)`) : [];
|
|
490
|
-
}
|
|
491
|
-
);
|
|
492
|
-
const missingGroupRefs = hasMissingStrings(
|
|
493
|
-
groupRefsFromCategory,
|
|
494
|
-
groupRefsFromPlugins
|
|
495
|
-
);
|
|
496
|
-
if (Array.isArray(missingGroupRefs) && missingGroupRefs.length > 0) {
|
|
497
|
-
missingRefs.push(...missingGroupRefs);
|
|
498
|
-
}
|
|
499
|
-
return missingRefs.length ? missingRefs : false;
|
|
500
|
-
}
|
|
501
495
|
|
|
502
496
|
// packages/models/src/lib/report.ts
|
|
503
497
|
import { z as z12 } from "zod";
|
|
@@ -512,9 +506,32 @@ var pluginReportSchema = pluginMetaSchema.merge(
|
|
|
512
506
|
audits: z12.array(auditReportSchema),
|
|
513
507
|
groups: z12.array(groupSchema).optional()
|
|
514
508
|
})
|
|
509
|
+
).refine(
|
|
510
|
+
(pluginReport) => !getMissingRefsFromGroups2(pluginReport.audits, pluginReport.groups ?? []),
|
|
511
|
+
(pluginReport) => ({
|
|
512
|
+
message: missingRefsFromGroupsErrorMsg2(
|
|
513
|
+
pluginReport.audits,
|
|
514
|
+
pluginReport.groups ?? []
|
|
515
|
+
)
|
|
516
|
+
})
|
|
515
517
|
);
|
|
518
|
+
function missingRefsFromGroupsErrorMsg2(audits, groups) {
|
|
519
|
+
const missingRefs = getMissingRefsFromGroups2(audits, groups);
|
|
520
|
+
return `group references need to point to an existing audit in this plugin report: ${errorItems(
|
|
521
|
+
missingRefs
|
|
522
|
+
)}`;
|
|
523
|
+
}
|
|
524
|
+
function getMissingRefsFromGroups2(audits, groups) {
|
|
525
|
+
return hasMissingStrings(
|
|
526
|
+
groups.flatMap(
|
|
527
|
+
({ refs: auditRefs }) => auditRefs.map(({ slug: ref }) => ref)
|
|
528
|
+
),
|
|
529
|
+
audits.map(({ slug }) => slug)
|
|
530
|
+
);
|
|
531
|
+
}
|
|
516
532
|
var reportSchema = packageVersionSchema({
|
|
517
|
-
versionDescription: "NPM version of the CLI"
|
|
533
|
+
versionDescription: "NPM version of the CLI",
|
|
534
|
+
required: true
|
|
518
535
|
}).merge(
|
|
519
536
|
executionMetaSchema({
|
|
520
537
|
descriptionDate: "Start date and time of the collect run",
|
|
@@ -524,10 +541,18 @@ var reportSchema = packageVersionSchema({
|
|
|
524
541
|
z12.object(
|
|
525
542
|
{
|
|
526
543
|
categories: z12.array(categoryConfigSchema),
|
|
527
|
-
plugins: z12.array(pluginReportSchema)
|
|
544
|
+
plugins: z12.array(pluginReportSchema).min(1)
|
|
528
545
|
},
|
|
529
546
|
{ description: "Collect output data" }
|
|
530
547
|
)
|
|
548
|
+
).refine(
|
|
549
|
+
(report) => !getMissingRefsForCategories(report.categories, report.plugins),
|
|
550
|
+
(report) => ({
|
|
551
|
+
message: missingRefsForCategoriesErrorMsg(
|
|
552
|
+
report.categories,
|
|
553
|
+
report.plugins
|
|
554
|
+
)
|
|
555
|
+
})
|
|
531
556
|
);
|
|
532
557
|
|
|
533
558
|
// packages/utils/src/lib/file-system.ts
|
package/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { fileURLToPath } from "node:url";
|
|
|
5
5
|
|
|
6
6
|
// packages/plugin-eslint/package.json
|
|
7
7
|
var name = "@code-pushup/eslint-plugin";
|
|
8
|
-
var version = "0.8.
|
|
8
|
+
var version = "0.8.11";
|
|
9
9
|
|
|
10
10
|
// packages/plugin-eslint/src/lib/config.ts
|
|
11
11
|
import { z } from "zod";
|
|
@@ -58,6 +58,46 @@ function errorItems(items, transform = (items2) => items2.join(", ")) {
|
|
|
58
58
|
function exists(value) {
|
|
59
59
|
return value != null;
|
|
60
60
|
}
|
|
61
|
+
function getMissingRefsForCategories(categories, plugins) {
|
|
62
|
+
const missingRefs = [];
|
|
63
|
+
const auditRefsFromCategory = categories.flatMap(
|
|
64
|
+
({ refs }) => refs.filter(({ type }) => type === "audit").map(({ plugin, slug }) => `${plugin}/${slug}`)
|
|
65
|
+
);
|
|
66
|
+
const auditRefsFromPlugins = plugins.flatMap(
|
|
67
|
+
({ audits, slug: pluginSlug }) => {
|
|
68
|
+
return audits.map(({ slug }) => `${pluginSlug}/${slug}`);
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
const missingAuditRefs = hasMissingStrings(
|
|
72
|
+
auditRefsFromCategory,
|
|
73
|
+
auditRefsFromPlugins
|
|
74
|
+
);
|
|
75
|
+
if (Array.isArray(missingAuditRefs) && missingAuditRefs.length > 0) {
|
|
76
|
+
missingRefs.push(...missingAuditRefs);
|
|
77
|
+
}
|
|
78
|
+
const groupRefsFromCategory = categories.flatMap(
|
|
79
|
+
({ refs }) => refs.filter(({ type }) => type === "group").map(({ plugin, slug }) => `${plugin}#${slug} (group)`)
|
|
80
|
+
);
|
|
81
|
+
const groupRefsFromPlugins = plugins.flatMap(
|
|
82
|
+
({ groups, slug: pluginSlug }) => {
|
|
83
|
+
return Array.isArray(groups) ? groups.map(({ slug }) => `${pluginSlug}#${slug} (group)`) : [];
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
const missingGroupRefs = hasMissingStrings(
|
|
87
|
+
groupRefsFromCategory,
|
|
88
|
+
groupRefsFromPlugins
|
|
89
|
+
);
|
|
90
|
+
if (Array.isArray(missingGroupRefs) && missingGroupRefs.length > 0) {
|
|
91
|
+
missingRefs.push(...missingGroupRefs);
|
|
92
|
+
}
|
|
93
|
+
return missingRefs.length ? missingRefs : false;
|
|
94
|
+
}
|
|
95
|
+
function missingRefsForCategoriesErrorMsg(categories, plugins) {
|
|
96
|
+
const missingRefs = getMissingRefsForCategories(categories, plugins);
|
|
97
|
+
return `The following category references need to point to an audit or group: ${errorItems(
|
|
98
|
+
missingRefs
|
|
99
|
+
)}`;
|
|
100
|
+
}
|
|
61
101
|
|
|
62
102
|
// packages/models/src/lib/implementation/schemas.ts
|
|
63
103
|
function executionMetaSchema(options = {
|
|
@@ -116,15 +156,13 @@ function positiveIntSchema(description) {
|
|
|
116
156
|
return z2.number({ description }).int().nonnegative();
|
|
117
157
|
}
|
|
118
158
|
function packageVersionSchema(options) {
|
|
119
|
-
|
|
120
|
-
versionDescription = versionDescription || "NPM version of the package";
|
|
121
|
-
optional = !!optional;
|
|
159
|
+
const { versionDescription = "NPM version of the package", required } = options ?? {};
|
|
122
160
|
const packageSchema = z2.string({ description: "NPM package name" });
|
|
123
161
|
const versionSchema = z2.string({ description: versionDescription });
|
|
124
162
|
return z2.object(
|
|
125
163
|
{
|
|
126
|
-
packageName:
|
|
127
|
-
version:
|
|
164
|
+
packageName: required ? packageSchema : packageSchema.optional(),
|
|
165
|
+
version: required ? versionSchema : versionSchema.optional()
|
|
128
166
|
},
|
|
129
167
|
{ description: "NPM package name and version of a published package" }
|
|
130
168
|
);
|
|
@@ -186,7 +224,7 @@ var pluginAuditsSchema = z3.array(auditSchema, {
|
|
|
186
224
|
);
|
|
187
225
|
function duplicateSlugsInAuditsErrorMsg(audits) {
|
|
188
226
|
const duplicateRefs = getDuplicateSlugsInAudits(audits);
|
|
189
|
-
return `In plugin audits the slugs are not unique: ${errorItems(
|
|
227
|
+
return `In plugin audits the following slugs are not unique: ${errorItems(
|
|
190
228
|
duplicateRefs
|
|
191
229
|
)}`;
|
|
192
230
|
}
|
|
@@ -375,7 +413,9 @@ function getDuplicateRefsInGroups(groups) {
|
|
|
375
413
|
}
|
|
376
414
|
function duplicateSlugsInGroupsErrorMsg(groups) {
|
|
377
415
|
const duplicateRefs = getDuplicateSlugsInGroups(groups);
|
|
378
|
-
return `In groups the slugs are not unique: ${errorItems(
|
|
416
|
+
return `In groups the following slugs are not unique: ${errorItems(
|
|
417
|
+
duplicateRefs
|
|
418
|
+
)}`;
|
|
379
419
|
}
|
|
380
420
|
function getDuplicateSlugsInGroups(groups) {
|
|
381
421
|
return Array.isArray(groups) ? hasDuplicateStrings(groups.map(({ slug }) => slug)) : false;
|
|
@@ -401,9 +441,7 @@ var onProgressSchema = z9.function().args(z9.unknown()).returns(z9.void());
|
|
|
401
441
|
var runnerFunctionSchema = z9.function().args(onProgressSchema.optional()).returns(z9.union([auditOutputsSchema, z9.promise(auditOutputsSchema)]));
|
|
402
442
|
|
|
403
443
|
// packages/models/src/lib/plugin-config.ts
|
|
404
|
-
var pluginMetaSchema = packageVersionSchema(
|
|
405
|
-
optional: true
|
|
406
|
-
}).merge(
|
|
444
|
+
var pluginMetaSchema = packageVersionSchema().merge(
|
|
407
445
|
metaSchema({
|
|
408
446
|
titleDescription: "Descriptive name",
|
|
409
447
|
descriptionDescription: "Description (markdown)",
|
|
@@ -412,7 +450,7 @@ var pluginMetaSchema = packageVersionSchema({
|
|
|
412
450
|
})
|
|
413
451
|
).merge(
|
|
414
452
|
z10.object({
|
|
415
|
-
slug: slugSchema("
|
|
453
|
+
slug: slugSchema("Unique plugin slug within core config"),
|
|
416
454
|
icon: materialIconSchema
|
|
417
455
|
})
|
|
418
456
|
);
|
|
@@ -429,20 +467,17 @@ var pluginConfigSchema = pluginMetaSchema.merge(pluginDataSchema).refine(
|
|
|
429
467
|
);
|
|
430
468
|
function missingRefsFromGroupsErrorMsg(pluginCfg) {
|
|
431
469
|
const missingRefs = getMissingRefsFromGroups(pluginCfg);
|
|
432
|
-
return `
|
|
470
|
+
return `The following group references need to point to an existing audit in this plugin config: ${errorItems(
|
|
433
471
|
missingRefs
|
|
434
472
|
)}`;
|
|
435
473
|
}
|
|
436
474
|
function getMissingRefsFromGroups(pluginCfg) {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
);
|
|
444
|
-
}
|
|
445
|
-
return false;
|
|
475
|
+
return hasMissingStrings(
|
|
476
|
+
pluginCfg.groups?.flatMap(
|
|
477
|
+
({ refs: audits }) => audits.map(({ slug: ref }) => ref)
|
|
478
|
+
) ?? [],
|
|
479
|
+
pluginCfg.audits.map(({ slug }) => slug)
|
|
480
|
+
);
|
|
446
481
|
}
|
|
447
482
|
|
|
448
483
|
// packages/models/src/lib/upload-config.ts
|
|
@@ -452,19 +487,15 @@ var uploadConfigSchema = z11.object({
|
|
|
452
487
|
apiKey: z11.string({
|
|
453
488
|
description: "API key with write access to portal (use `process.env` for security)"
|
|
454
489
|
}),
|
|
455
|
-
organization:
|
|
456
|
-
|
|
457
|
-
}),
|
|
458
|
-
project: z11.string({
|
|
459
|
-
description: "Project in code versioning system"
|
|
460
|
-
})
|
|
490
|
+
organization: slugSchema("Organization slug from Code PushUp portal"),
|
|
491
|
+
project: slugSchema("Project slug from Code PushUp portal")
|
|
461
492
|
});
|
|
462
493
|
|
|
463
494
|
// packages/models/src/lib/core-config.ts
|
|
464
495
|
var unrefinedCoreConfigSchema = z12.object({
|
|
465
496
|
plugins: z12.array(pluginConfigSchema, {
|
|
466
497
|
description: "List of plugins to be used (official, community-provided, or custom)"
|
|
467
|
-
}),
|
|
498
|
+
}).min(1),
|
|
468
499
|
/** portal configuration for persisting results */
|
|
469
500
|
persist: persistConfigSchema.optional(),
|
|
470
501
|
/** portal configuration for uploading results */
|
|
@@ -474,52 +505,15 @@ var unrefinedCoreConfigSchema = z12.object({
|
|
|
474
505
|
var coreConfigSchema = refineCoreConfig(unrefinedCoreConfigSchema);
|
|
475
506
|
function refineCoreConfig(schema) {
|
|
476
507
|
return schema.refine(
|
|
477
|
-
(coreCfg) => !getMissingRefsForCategories(coreCfg),
|
|
508
|
+
(coreCfg) => !getMissingRefsForCategories(coreCfg.categories, coreCfg.plugins),
|
|
478
509
|
(coreCfg) => ({
|
|
479
|
-
message: missingRefsForCategoriesErrorMsg(
|
|
510
|
+
message: missingRefsForCategoriesErrorMsg(
|
|
511
|
+
coreCfg.categories,
|
|
512
|
+
coreCfg.plugins
|
|
513
|
+
)
|
|
480
514
|
})
|
|
481
515
|
);
|
|
482
516
|
}
|
|
483
|
-
function missingRefsForCategoriesErrorMsg(coreCfg) {
|
|
484
|
-
const missingRefs = getMissingRefsForCategories(coreCfg);
|
|
485
|
-
return `In the categories, the following plugin refs do not exist in the provided plugins: ${errorItems(
|
|
486
|
-
missingRefs
|
|
487
|
-
)}`;
|
|
488
|
-
}
|
|
489
|
-
function getMissingRefsForCategories(coreCfg) {
|
|
490
|
-
const missingRefs = [];
|
|
491
|
-
const auditRefsFromCategory = coreCfg.categories.flatMap(
|
|
492
|
-
({ refs }) => refs.filter(({ type }) => type === "audit").map(({ plugin, slug }) => `${plugin}/${slug}`)
|
|
493
|
-
);
|
|
494
|
-
const auditRefsFromPlugins = coreCfg.plugins.flatMap(
|
|
495
|
-
({ audits, slug: pluginSlug }) => {
|
|
496
|
-
return audits.map(({ slug }) => `${pluginSlug}/${slug}`);
|
|
497
|
-
}
|
|
498
|
-
);
|
|
499
|
-
const missingAuditRefs = hasMissingStrings(
|
|
500
|
-
auditRefsFromCategory,
|
|
501
|
-
auditRefsFromPlugins
|
|
502
|
-
);
|
|
503
|
-
if (Array.isArray(missingAuditRefs) && missingAuditRefs.length > 0) {
|
|
504
|
-
missingRefs.push(...missingAuditRefs);
|
|
505
|
-
}
|
|
506
|
-
const groupRefsFromCategory = coreCfg.categories.flatMap(
|
|
507
|
-
({ refs }) => refs.filter(({ type }) => type === "group").map(({ plugin, slug }) => `${plugin}#${slug} (group)`)
|
|
508
|
-
);
|
|
509
|
-
const groupRefsFromPlugins = coreCfg.plugins.flatMap(
|
|
510
|
-
({ groups, slug: pluginSlug }) => {
|
|
511
|
-
return Array.isArray(groups) ? groups.map(({ slug }) => `${pluginSlug}#${slug} (group)`) : [];
|
|
512
|
-
}
|
|
513
|
-
);
|
|
514
|
-
const missingGroupRefs = hasMissingStrings(
|
|
515
|
-
groupRefsFromCategory,
|
|
516
|
-
groupRefsFromPlugins
|
|
517
|
-
);
|
|
518
|
-
if (Array.isArray(missingGroupRefs) && missingGroupRefs.length > 0) {
|
|
519
|
-
missingRefs.push(...missingGroupRefs);
|
|
520
|
-
}
|
|
521
|
-
return missingRefs.length ? missingRefs : false;
|
|
522
|
-
}
|
|
523
517
|
|
|
524
518
|
// packages/models/src/lib/report.ts
|
|
525
519
|
import { z as z13 } from "zod";
|
|
@@ -534,9 +528,32 @@ var pluginReportSchema = pluginMetaSchema.merge(
|
|
|
534
528
|
audits: z13.array(auditReportSchema),
|
|
535
529
|
groups: z13.array(groupSchema).optional()
|
|
536
530
|
})
|
|
531
|
+
).refine(
|
|
532
|
+
(pluginReport) => !getMissingRefsFromGroups2(pluginReport.audits, pluginReport.groups ?? []),
|
|
533
|
+
(pluginReport) => ({
|
|
534
|
+
message: missingRefsFromGroupsErrorMsg2(
|
|
535
|
+
pluginReport.audits,
|
|
536
|
+
pluginReport.groups ?? []
|
|
537
|
+
)
|
|
538
|
+
})
|
|
537
539
|
);
|
|
540
|
+
function missingRefsFromGroupsErrorMsg2(audits, groups) {
|
|
541
|
+
const missingRefs = getMissingRefsFromGroups2(audits, groups);
|
|
542
|
+
return `group references need to point to an existing audit in this plugin report: ${errorItems(
|
|
543
|
+
missingRefs
|
|
544
|
+
)}`;
|
|
545
|
+
}
|
|
546
|
+
function getMissingRefsFromGroups2(audits, groups) {
|
|
547
|
+
return hasMissingStrings(
|
|
548
|
+
groups.flatMap(
|
|
549
|
+
({ refs: auditRefs }) => auditRefs.map(({ slug: ref }) => ref)
|
|
550
|
+
),
|
|
551
|
+
audits.map(({ slug }) => slug)
|
|
552
|
+
);
|
|
553
|
+
}
|
|
538
554
|
var reportSchema = packageVersionSchema({
|
|
539
|
-
versionDescription: "NPM version of the CLI"
|
|
555
|
+
versionDescription: "NPM version of the CLI",
|
|
556
|
+
required: true
|
|
540
557
|
}).merge(
|
|
541
558
|
executionMetaSchema({
|
|
542
559
|
descriptionDate: "Start date and time of the collect run",
|
|
@@ -546,10 +563,18 @@ var reportSchema = packageVersionSchema({
|
|
|
546
563
|
z13.object(
|
|
547
564
|
{
|
|
548
565
|
categories: z13.array(categoryConfigSchema),
|
|
549
|
-
plugins: z13.array(pluginReportSchema)
|
|
566
|
+
plugins: z13.array(pluginReportSchema).min(1)
|
|
550
567
|
},
|
|
551
568
|
{ description: "Collect output data" }
|
|
552
569
|
)
|
|
570
|
+
).refine(
|
|
571
|
+
(report) => !getMissingRefsForCategories(report.categories, report.plugins),
|
|
572
|
+
(report) => ({
|
|
573
|
+
message: missingRefsForCategoriesErrorMsg(
|
|
574
|
+
report.categories,
|
|
575
|
+
report.plugins
|
|
576
|
+
)
|
|
577
|
+
})
|
|
553
578
|
);
|
|
554
579
|
|
|
555
580
|
// packages/utils/src/lib/file-system.ts
|