@code-pushup/core 0.4.4 → 0.5.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/index.js +17 -7
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -129,12 +129,14 @@ function scorableSchema(description, refSchema, duplicateCheckFn, duplicateMessa
|
|
|
129
129
|
return z.object(
|
|
130
130
|
{
|
|
131
131
|
slug: slugSchema('Human-readable unique ID, e.g. "performance"'),
|
|
132
|
-
refs: z.array(refSchema).refine(
|
|
132
|
+
refs: z.array(refSchema).min(1).refine(
|
|
133
133
|
(refs) => !duplicateCheckFn(refs),
|
|
134
134
|
(refs) => ({
|
|
135
135
|
message: duplicateMessageFn(refs)
|
|
136
136
|
})
|
|
137
|
-
)
|
|
137
|
+
).refine(hasWeightedRefsInCategories, () => ({
|
|
138
|
+
message: `In a category there has to be at least one ref with weight > 0`
|
|
139
|
+
}))
|
|
138
140
|
},
|
|
139
141
|
{ description }
|
|
140
142
|
);
|
|
@@ -143,6 +145,9 @@ var materialIconSchema = z.enum(
|
|
|
143
145
|
MATERIAL_ICONS,
|
|
144
146
|
{ description: "Icon from VSCode Material Icons extension" }
|
|
145
147
|
);
|
|
148
|
+
function hasWeightedRefsInCategories(categoryRefs) {
|
|
149
|
+
return categoryRefs.reduce((acc, { weight }) => weight + acc, 0) !== 0;
|
|
150
|
+
}
|
|
146
151
|
|
|
147
152
|
// packages/models/src/lib/category-config.ts
|
|
148
153
|
var categoryRefSchema = weightedRefSchema(
|
|
@@ -440,10 +445,10 @@ var unrefinedCoreConfigSchema = z11.object({
|
|
|
440
445
|
upload: uploadConfigSchema.optional(),
|
|
441
446
|
categories: z11.array(categoryConfigSchema, {
|
|
442
447
|
description: "Categorization of individual audits"
|
|
443
|
-
}).refine(
|
|
444
|
-
(
|
|
445
|
-
(
|
|
446
|
-
message: duplicateSlugCategoriesErrorMsg(
|
|
448
|
+
}).min(1).refine(
|
|
449
|
+
(categories) => !getDuplicateSlugCategories(categories),
|
|
450
|
+
(categories) => ({
|
|
451
|
+
message: duplicateSlugCategoriesErrorMsg(categories)
|
|
447
452
|
})
|
|
448
453
|
)
|
|
449
454
|
});
|
|
@@ -1391,6 +1396,11 @@ function calculateScore(refs, scoreFn) {
|
|
|
1391
1396
|
},
|
|
1392
1397
|
{ numerator: 0, denominator: 0 }
|
|
1393
1398
|
);
|
|
1399
|
+
if (!numerator && !denominator) {
|
|
1400
|
+
throw new Error(
|
|
1401
|
+
"0 division for score. This can be caused by refs only weighted with 0 or empty refs"
|
|
1402
|
+
);
|
|
1403
|
+
}
|
|
1394
1404
|
return numerator / denominator;
|
|
1395
1405
|
}
|
|
1396
1406
|
function scoreReport(report) {
|
|
@@ -1632,7 +1642,7 @@ function auditOutputsCorrelateWithPluginOutput(auditOutputs, pluginConfigAudits)
|
|
|
1632
1642
|
|
|
1633
1643
|
// packages/core/package.json
|
|
1634
1644
|
var name = "@code-pushup/core";
|
|
1635
|
-
var version = "0.
|
|
1645
|
+
var version = "0.5.0";
|
|
1636
1646
|
|
|
1637
1647
|
// packages/core/src/lib/implementation/collect.ts
|
|
1638
1648
|
async function collect(options) {
|