@code-pushup/cli 0.4.5 → 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.
Files changed (3) hide show
  1. package/README.md +1 -0
  2. package/index.js +17 -7
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -144,6 +144,7 @@ Each example is fully tested to give demonstrate best practices for plugin testi
144
144
  **Example for custom plugins:**
145
145
 
146
146
  - [File Size](../../examples/plugins/src/file-size)
147
+ - [Package Json](../../examples/plugins/src/package-json)
147
148
 
148
149
  ## CLI commands and options
149
150
 
package/index.js CHANGED
@@ -137,12 +137,14 @@ function scorableSchema(description, refSchema, duplicateCheckFn, duplicateMessa
137
137
  return z.object(
138
138
  {
139
139
  slug: slugSchema('Human-readable unique ID, e.g. "performance"'),
140
- refs: z.array(refSchema).refine(
140
+ refs: z.array(refSchema).min(1).refine(
141
141
  (refs) => !duplicateCheckFn(refs),
142
142
  (refs) => ({
143
143
  message: duplicateMessageFn(refs)
144
144
  })
145
- )
145
+ ).refine(hasWeightedRefsInCategories, () => ({
146
+ message: `In a category there has to be at least one ref with weight > 0`
147
+ }))
146
148
  },
147
149
  { description }
148
150
  );
@@ -151,6 +153,9 @@ var materialIconSchema = z.enum(
151
153
  MATERIAL_ICONS,
152
154
  { description: "Icon from VSCode Material Icons extension" }
153
155
  );
156
+ function hasWeightedRefsInCategories(categoryRefs) {
157
+ return categoryRefs.reduce((acc, { weight }) => weight + acc, 0) !== 0;
158
+ }
154
159
 
155
160
  // packages/models/src/lib/category-config.ts
156
161
  var categoryRefSchema = weightedRefSchema(
@@ -448,10 +453,10 @@ var unrefinedCoreConfigSchema = z11.object({
448
453
  upload: uploadConfigSchema.optional(),
449
454
  categories: z11.array(categoryConfigSchema, {
450
455
  description: "Categorization of individual audits"
451
- }).refine(
452
- (categoryCfg) => !getDuplicateSlugCategories(categoryCfg),
453
- (categoryCfg) => ({
454
- message: duplicateSlugCategoriesErrorMsg(categoryCfg)
456
+ }).min(1).refine(
457
+ (categories) => !getDuplicateSlugCategories(categories),
458
+ (categories) => ({
459
+ message: duplicateSlugCategoriesErrorMsg(categories)
455
460
  })
456
461
  )
457
462
  });
@@ -1399,6 +1404,11 @@ function calculateScore(refs, scoreFn) {
1399
1404
  },
1400
1405
  { numerator: 0, denominator: 0 }
1401
1406
  );
1407
+ if (!numerator && !denominator) {
1408
+ throw new Error(
1409
+ "0 division for score. This can be caused by refs only weighted with 0 or empty refs"
1410
+ );
1411
+ }
1402
1412
  return numerator / denominator;
1403
1413
  }
1404
1414
  function scoreReport(report) {
@@ -1640,7 +1650,7 @@ function auditOutputsCorrelateWithPluginOutput(auditOutputs, pluginConfigAudits)
1640
1650
 
1641
1651
  // packages/core/package.json
1642
1652
  var name = "@code-pushup/core";
1643
- var version = "0.4.5";
1653
+ var version = "0.5.0";
1644
1654
 
1645
1655
  // packages/core/src/lib/implementation/collect.ts
1646
1656
  async function collect(options2) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-pushup/cli",
3
- "version": "0.4.5",
3
+ "version": "0.5.0",
4
4
  "bin": {
5
5
  "code-pushup": "index.js"
6
6
  },