@code-pushup/cli 0.10.6 → 0.10.7
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 +31 -19
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1372,24 +1372,6 @@ function deepClone(obj) {
|
|
|
1372
1372
|
}
|
|
1373
1373
|
|
|
1374
1374
|
// packages/utils/src/lib/reports/scoring.ts
|
|
1375
|
-
function calculateScore(refs, scoreFn) {
|
|
1376
|
-
const { numerator, denominator } = refs.reduce(
|
|
1377
|
-
(acc, ref) => {
|
|
1378
|
-
const score = scoreFn(ref);
|
|
1379
|
-
return {
|
|
1380
|
-
numerator: acc.numerator + score * ref.weight,
|
|
1381
|
-
denominator: acc.denominator + ref.weight
|
|
1382
|
-
};
|
|
1383
|
-
},
|
|
1384
|
-
{ numerator: 0, denominator: 0 }
|
|
1385
|
-
);
|
|
1386
|
-
if (!numerator && !denominator) {
|
|
1387
|
-
throw new Error(
|
|
1388
|
-
"0 division for score. This can be caused by refs only weighted with 0 or empty refs"
|
|
1389
|
-
);
|
|
1390
|
-
}
|
|
1391
|
-
return numerator / denominator;
|
|
1392
|
-
}
|
|
1393
1375
|
function scoreReport(report) {
|
|
1394
1376
|
const allScoredAuditsAndGroups = /* @__PURE__ */ new Map();
|
|
1395
1377
|
const scoredPlugins = report.plugins.map((plugin) => {
|
|
@@ -1439,6 +1421,36 @@ function scoreReport(report) {
|
|
|
1439
1421
|
categories: scoredCategories
|
|
1440
1422
|
};
|
|
1441
1423
|
}
|
|
1424
|
+
function calculateScore(refs, scoreFn) {
|
|
1425
|
+
const validatedRefs = parseScoringParameters(refs, scoreFn);
|
|
1426
|
+
const { numerator, denominator } = validatedRefs.reduce(
|
|
1427
|
+
(acc, ref) => ({
|
|
1428
|
+
numerator: acc.numerator + ref.score * ref.weight,
|
|
1429
|
+
denominator: acc.denominator + ref.weight
|
|
1430
|
+
}),
|
|
1431
|
+
{ numerator: 0, denominator: 0 }
|
|
1432
|
+
);
|
|
1433
|
+
return numerator / denominator;
|
|
1434
|
+
}
|
|
1435
|
+
function parseScoringParameters(refs, scoreFn) {
|
|
1436
|
+
if (refs.length === 0) {
|
|
1437
|
+
throw new Error("Reference array cannot be empty.");
|
|
1438
|
+
}
|
|
1439
|
+
if (refs.some((ref) => ref.weight < 0)) {
|
|
1440
|
+
throw new Error("Weight cannot be negative.");
|
|
1441
|
+
}
|
|
1442
|
+
if (refs.every((ref) => ref.weight === 0)) {
|
|
1443
|
+
throw new Error("All references cannot have zero weight.");
|
|
1444
|
+
}
|
|
1445
|
+
const scoredRefs = refs.map((ref) => ({
|
|
1446
|
+
weight: ref.weight,
|
|
1447
|
+
score: scoreFn(ref)
|
|
1448
|
+
}));
|
|
1449
|
+
if (scoredRefs.some((ref) => ref.score < 0 || ref.score > 1)) {
|
|
1450
|
+
throw new Error("All scores must be in range 0-1.");
|
|
1451
|
+
}
|
|
1452
|
+
return scoredRefs;
|
|
1453
|
+
}
|
|
1442
1454
|
|
|
1443
1455
|
// packages/utils/src/lib/reports/sorting.ts
|
|
1444
1456
|
function sortReport(report) {
|
|
@@ -1691,7 +1703,7 @@ function auditOutputsCorrelateWithPluginOutput(auditOutputs, pluginConfigAudits)
|
|
|
1691
1703
|
|
|
1692
1704
|
// packages/core/package.json
|
|
1693
1705
|
var name = "@code-pushup/core";
|
|
1694
|
-
var version = "0.10.
|
|
1706
|
+
var version = "0.10.7";
|
|
1695
1707
|
|
|
1696
1708
|
// packages/core/src/lib/implementation/collect.ts
|
|
1697
1709
|
async function collect(options2) {
|