@code-pushup/core 0.23.1 → 0.25.6
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 +84 -63
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -693,8 +693,6 @@ var SCORE_COLOR_RANGE = {
|
|
|
693
693
|
GREEN_MIN: 0.9,
|
|
694
694
|
YELLOW_MIN: 0.5
|
|
695
695
|
};
|
|
696
|
-
|
|
697
|
-
// packages/utils/src/lib/reports/utils.ts
|
|
698
696
|
var FOOTER_PREFIX = "Made with \u2764 by";
|
|
699
697
|
var CODE_PUSHUP_DOMAIN = "code-pushup.dev";
|
|
700
698
|
var README_LINK = "https://github.com/flowup/quality-metrics-cli#readme";
|
|
@@ -725,6 +723,8 @@ var detailsTableHeaders = [
|
|
|
725
723
|
"Source file",
|
|
726
724
|
"Line(s)"
|
|
727
725
|
];
|
|
726
|
+
|
|
727
|
+
// packages/utils/src/lib/reports/utils.ts
|
|
728
728
|
function formatReportScore(score) {
|
|
729
729
|
return Math.round(score * 100).toString();
|
|
730
730
|
}
|
|
@@ -761,7 +761,7 @@ function calcDuration(start, stop) {
|
|
|
761
761
|
function countCategoryAudits(refs, plugins) {
|
|
762
762
|
const groupLookup = plugins.reduce(
|
|
763
763
|
(lookup, plugin) => {
|
|
764
|
-
if (plugin.groups.length === 0) {
|
|
764
|
+
if (plugin.groups == null || plugin.groups.length === 0) {
|
|
765
765
|
return lookup;
|
|
766
766
|
}
|
|
767
767
|
return {
|
|
@@ -781,7 +781,7 @@ function countCategoryAudits(refs, plugins) {
|
|
|
781
781
|
return acc + 1;
|
|
782
782
|
}, 0);
|
|
783
783
|
}
|
|
784
|
-
function
|
|
784
|
+
function getSortableAuditByRef({ slug, weight, plugin }, plugins) {
|
|
785
785
|
const auditPlugin = plugins.find((p) => p.slug === plugin);
|
|
786
786
|
if (!auditPlugin) {
|
|
787
787
|
throwIsNotPresentError(`Plugin ${plugin}`, "report");
|
|
@@ -798,39 +798,51 @@ function getAuditByRef({ slug, weight, plugin }, plugins) {
|
|
|
798
798
|
plugin
|
|
799
799
|
};
|
|
800
800
|
}
|
|
801
|
-
function
|
|
802
|
-
const
|
|
803
|
-
if (!
|
|
804
|
-
throwIsNotPresentError(`Plugin ${
|
|
805
|
-
}
|
|
806
|
-
const groupWithAudits = plugin.groups?.find(({ slug }) => slug === refSlug);
|
|
807
|
-
if (!groupWithAudits) {
|
|
808
|
-
throwIsNotPresentError(`Group ${refSlug}`, plugin.slug);
|
|
801
|
+
function getSortableGroupByRef({ plugin, slug, weight }, plugins) {
|
|
802
|
+
const groupPlugin = plugins.find((p) => p.slug === plugin);
|
|
803
|
+
if (!groupPlugin) {
|
|
804
|
+
throwIsNotPresentError(`Plugin ${plugin}`, "report");
|
|
809
805
|
}
|
|
810
|
-
const
|
|
811
|
-
(
|
|
812
|
-
const audit = getAuditByRef(
|
|
813
|
-
{ ...ref, plugin: refPlugin, type: "audit" },
|
|
814
|
-
plugins
|
|
815
|
-
);
|
|
816
|
-
return [...acc, audit];
|
|
817
|
-
},
|
|
818
|
-
[]
|
|
806
|
+
const group = groupPlugin.groups?.find(
|
|
807
|
+
({ slug: groupSlug }) => groupSlug === slug
|
|
819
808
|
);
|
|
820
|
-
|
|
809
|
+
if (!group) {
|
|
810
|
+
throwIsNotPresentError(`Group ${slug}`, groupPlugin.slug);
|
|
811
|
+
}
|
|
812
|
+
const sortedAudits = getSortedGroupAudits(group, groupPlugin.slug, plugins);
|
|
813
|
+
const sortedAuditRefs = [...group.refs].sort((a, b) => {
|
|
814
|
+
const aIndex = sortedAudits.findIndex((ref) => ref.slug === a.slug);
|
|
815
|
+
const bIndex = sortedAudits.findIndex((ref) => ref.slug === b.slug);
|
|
816
|
+
return aIndex - bIndex;
|
|
817
|
+
});
|
|
821
818
|
return {
|
|
822
|
-
...
|
|
823
|
-
|
|
819
|
+
...group,
|
|
820
|
+
refs: sortedAuditRefs,
|
|
821
|
+
plugin,
|
|
822
|
+
weight
|
|
824
823
|
};
|
|
825
824
|
}
|
|
826
|
-
function
|
|
825
|
+
function getSortedGroupAudits(group, plugin, plugins) {
|
|
826
|
+
return group.refs.map(
|
|
827
|
+
(ref) => getSortableAuditByRef(
|
|
828
|
+
{
|
|
829
|
+
plugin,
|
|
830
|
+
slug: ref.slug,
|
|
831
|
+
weight: ref.weight,
|
|
832
|
+
type: "audit"
|
|
833
|
+
},
|
|
834
|
+
plugins
|
|
835
|
+
)
|
|
836
|
+
).sort(compareCategoryAuditsAndGroups);
|
|
837
|
+
}
|
|
838
|
+
function compareCategoryAuditsAndGroups(a, b) {
|
|
827
839
|
if (a.weight !== b.weight) {
|
|
828
840
|
return b.weight - a.weight;
|
|
829
841
|
}
|
|
830
842
|
if (a.score !== b.score) {
|
|
831
843
|
return a.score - b.score;
|
|
832
844
|
}
|
|
833
|
-
if (a.value !== b.value) {
|
|
845
|
+
if ("value" in a && "value" in b && a.value !== b.value) {
|
|
834
846
|
return b.value - a.value;
|
|
835
847
|
}
|
|
836
848
|
return a.title.localeCompare(b.title);
|
|
@@ -939,6 +951,10 @@ function executeProcess(cfg) {
|
|
|
939
951
|
});
|
|
940
952
|
}
|
|
941
953
|
|
|
954
|
+
// packages/utils/src/lib/git.ts
|
|
955
|
+
import { isAbsolute, join as join2, relative } from "node:path";
|
|
956
|
+
import { simpleGit } from "simple-git";
|
|
957
|
+
|
|
942
958
|
// packages/utils/src/lib/transform.ts
|
|
943
959
|
function deepClone(obj) {
|
|
944
960
|
return obj == null || typeof obj !== "object" ? obj : structuredClone(obj);
|
|
@@ -948,8 +964,6 @@ function toUnixPath(path) {
|
|
|
948
964
|
}
|
|
949
965
|
|
|
950
966
|
// packages/utils/src/lib/git.ts
|
|
951
|
-
import { isAbsolute, join as join2, relative } from "node:path";
|
|
952
|
-
import { simpleGit } from "simple-git";
|
|
953
967
|
async function getLatestCommit(git = simpleGit()) {
|
|
954
968
|
const log = await git.log({
|
|
955
969
|
maxCount: 1,
|
|
@@ -968,7 +982,7 @@ function formatGitPath(path, gitRoot) {
|
|
|
968
982
|
function validateCommitData(commitData, options = {}) {
|
|
969
983
|
if (!commitData) {
|
|
970
984
|
const msg = "no commit data available";
|
|
971
|
-
if (options
|
|
985
|
+
if (options.throwError) {
|
|
972
986
|
throw new Error(msg);
|
|
973
987
|
} else {
|
|
974
988
|
console.warn(msg);
|
|
@@ -1159,12 +1173,24 @@ function reportToCategoriesSection(report) {
|
|
|
1159
1173
|
const categoryDocs = getDocsAndDescription(category);
|
|
1160
1174
|
const categoryMDItems = category.refs.reduce((refAcc, ref) => {
|
|
1161
1175
|
if (ref.type === "group") {
|
|
1162
|
-
const group =
|
|
1163
|
-
const
|
|
1176
|
+
const group = getSortableGroupByRef(ref, plugins);
|
|
1177
|
+
const groupAudits = group.refs.map(
|
|
1178
|
+
(groupRef) => getSortableAuditByRef(
|
|
1179
|
+
{ ...groupRef, plugin: group.plugin, type: "audit" },
|
|
1180
|
+
plugins
|
|
1181
|
+
)
|
|
1182
|
+
);
|
|
1183
|
+
const pluginTitle = getPluginNameFromSlug(ref.plugin, plugins);
|
|
1184
|
+
const mdGroupItem = groupItemToCategorySection(
|
|
1185
|
+
group,
|
|
1186
|
+
groupAudits,
|
|
1187
|
+
pluginTitle
|
|
1188
|
+
);
|
|
1164
1189
|
return refAcc + mdGroupItem + NEW_LINE;
|
|
1165
1190
|
} else {
|
|
1166
|
-
const audit =
|
|
1167
|
-
const
|
|
1191
|
+
const audit = getSortableAuditByRef(ref, plugins);
|
|
1192
|
+
const pluginTitle = getPluginNameFromSlug(ref.plugin, plugins);
|
|
1193
|
+
const mdAuditItem = auditItemToCategorySection(audit, pluginTitle);
|
|
1168
1194
|
return refAcc + mdAuditItem + NEW_LINE;
|
|
1169
1195
|
}
|
|
1170
1196
|
}, "");
|
|
@@ -1172,8 +1198,7 @@ function reportToCategoriesSection(report) {
|
|
|
1172
1198
|
}, "");
|
|
1173
1199
|
return h2("\u{1F3F7} Categories") + NEW_LINE + categoryDetails;
|
|
1174
1200
|
}
|
|
1175
|
-
function auditItemToCategorySection(audit,
|
|
1176
|
-
const pluginTitle = getPluginNameFromSlug(audit.plugin, plugins);
|
|
1201
|
+
function auditItemToCategorySection(audit, pluginTitle) {
|
|
1177
1202
|
const auditTitle = link(
|
|
1178
1203
|
`#${slugify(audit.title)}-${slugify(pluginTitle)}`,
|
|
1179
1204
|
audit.title
|
|
@@ -1184,13 +1209,12 @@ function auditItemToCategorySection(audit, plugins) {
|
|
|
1184
1209
|
)} ${auditTitle} (_${pluginTitle}_) - ${getAuditResult(audit)}`
|
|
1185
1210
|
);
|
|
1186
1211
|
}
|
|
1187
|
-
function groupItemToCategorySection(group,
|
|
1188
|
-
const
|
|
1189
|
-
const groupScore = Number(formatReportScore(group?.score || 0));
|
|
1212
|
+
function groupItemToCategorySection(group, groupAudits, pluginTitle) {
|
|
1213
|
+
const groupScore = Number(formatReportScore(group.score || 0));
|
|
1190
1214
|
const groupTitle = li(
|
|
1191
1215
|
`${getRoundScoreMarker(groupScore)} ${group.title} (_${pluginTitle}_)`
|
|
1192
1216
|
);
|
|
1193
|
-
const
|
|
1217
|
+
const auditTitles = groupAudits.reduce((acc, audit) => {
|
|
1194
1218
|
const auditTitle = link(
|
|
1195
1219
|
`#${slugify(audit.title)}-${slugify(pluginTitle)}`,
|
|
1196
1220
|
audit.title
|
|
@@ -1201,13 +1225,13 @@ function groupItemToCategorySection(group, plugins) {
|
|
|
1201
1225
|
)}`
|
|
1202
1226
|
)}${NEW_LINE}`;
|
|
1203
1227
|
}, "");
|
|
1204
|
-
return groupTitle + NEW_LINE +
|
|
1228
|
+
return groupTitle + NEW_LINE + auditTitles;
|
|
1205
1229
|
}
|
|
1206
1230
|
function reportToAuditsSection(report) {
|
|
1207
1231
|
const auditsSection = report.plugins.reduce((pluginAcc, plugin) => {
|
|
1208
1232
|
const auditsData = plugin.audits.reduce((auditAcc, audit) => {
|
|
1209
1233
|
const auditTitle = `${audit.title} (${getPluginNameFromSlug(
|
|
1210
|
-
|
|
1234
|
+
plugin.slug,
|
|
1211
1235
|
report.plugins
|
|
1212
1236
|
)})`;
|
|
1213
1237
|
return auditAcc + h3(auditTitle) + NEW_LINE + NEW_LINE + reportToDetailsSection(audit) + NEW_LINE + NEW_LINE + getDocsAndDescription(audit);
|
|
@@ -1384,29 +1408,30 @@ var GroupRefInvalidError = class extends Error {
|
|
|
1384
1408
|
function scoreReport(report) {
|
|
1385
1409
|
const allScoredAuditsAndGroups = /* @__PURE__ */ new Map();
|
|
1386
1410
|
const scoredPlugins = report.plugins.map((plugin) => {
|
|
1387
|
-
const {
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
allScoredAuditsAndGroups.set(`${slug}-${audit.slug}-audit`, audit);
|
|
1411
|
+
const { groups, ...pluginProps } = plugin;
|
|
1412
|
+
plugin.audits.forEach((audit) => {
|
|
1413
|
+
allScoredAuditsAndGroups.set(`${plugin.slug}-${audit.slug}-audit`, audit);
|
|
1391
1414
|
});
|
|
1392
1415
|
function groupScoreFn(ref) {
|
|
1393
1416
|
const score = allScoredAuditsAndGroups.get(
|
|
1394
|
-
`${slug}-${ref.slug}-audit`
|
|
1417
|
+
`${plugin.slug}-${ref.slug}-audit`
|
|
1395
1418
|
)?.score;
|
|
1396
1419
|
if (score == null) {
|
|
1397
|
-
throw new GroupRefInvalidError(ref.slug, slug);
|
|
1420
|
+
throw new GroupRefInvalidError(ref.slug, plugin.slug);
|
|
1398
1421
|
}
|
|
1399
1422
|
return score;
|
|
1400
1423
|
}
|
|
1401
1424
|
const scoredGroups = groups?.map((group) => ({
|
|
1402
1425
|
...group,
|
|
1403
|
-
score: calculateScore(group.refs, groupScoreFn)
|
|
1404
|
-
plugin: slug
|
|
1426
|
+
score: calculateScore(group.refs, groupScoreFn)
|
|
1405
1427
|
})) ?? [];
|
|
1406
1428
|
scoredGroups.forEach((group) => {
|
|
1407
|
-
allScoredAuditsAndGroups.set(`${slug}-${group.slug}-group`, group);
|
|
1429
|
+
allScoredAuditsAndGroups.set(`${plugin.slug}-${group.slug}-group`, group);
|
|
1408
1430
|
});
|
|
1409
|
-
return {
|
|
1431
|
+
return {
|
|
1432
|
+
...pluginProps,
|
|
1433
|
+
...scoredGroups.length > 0 && { groups: scoredGroups }
|
|
1434
|
+
};
|
|
1410
1435
|
});
|
|
1411
1436
|
function catScoreFn(ref) {
|
|
1412
1437
|
const key = `${ref.plugin}-${ref.slug}-${ref.type}`;
|
|
@@ -1467,26 +1492,22 @@ function sortReport(report) {
|
|
|
1467
1492
|
(acc, ref) => ({
|
|
1468
1493
|
...acc,
|
|
1469
1494
|
...ref.type === "group" ? {
|
|
1470
|
-
groups: [
|
|
1471
|
-
...acc.groups,
|
|
1472
|
-
getGroupWithAudits(ref.slug, ref.plugin, plugins)
|
|
1473
|
-
]
|
|
1495
|
+
groups: [...acc.groups, getSortableGroupByRef(ref, plugins)]
|
|
1474
1496
|
} : {
|
|
1475
|
-
audits: [...acc.audits,
|
|
1497
|
+
audits: [...acc.audits, getSortableAuditByRef(ref, plugins)]
|
|
1476
1498
|
}
|
|
1477
1499
|
}),
|
|
1478
1500
|
{ groups: [], audits: [] }
|
|
1479
1501
|
);
|
|
1480
|
-
const sortedAuditsAndGroups = [
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
];
|
|
1502
|
+
const sortedAuditsAndGroups = [...audits, ...groups].sort(
|
|
1503
|
+
compareCategoryAuditsAndGroups
|
|
1504
|
+
);
|
|
1484
1505
|
const sortedRefs = [...category.refs].sort((a, b) => {
|
|
1485
1506
|
const aIndex = sortedAuditsAndGroups.findIndex(
|
|
1486
|
-
(ref) => ref.slug === a.slug
|
|
1507
|
+
(ref) => ref.slug === a.slug && ref.plugin === a.plugin
|
|
1487
1508
|
);
|
|
1488
1509
|
const bIndex = sortedAuditsAndGroups.findIndex(
|
|
1489
|
-
(ref) => ref.slug === b.slug
|
|
1510
|
+
(ref) => ref.slug === b.slug && ref.plugin === b.plugin
|
|
1490
1511
|
);
|
|
1491
1512
|
return aIndex - bIndex;
|
|
1492
1513
|
});
|
|
@@ -1535,7 +1556,7 @@ var verboseUtils = (verbose = false) => ({
|
|
|
1535
1556
|
|
|
1536
1557
|
// packages/core/package.json
|
|
1537
1558
|
var name = "@code-pushup/core";
|
|
1538
|
-
var version = "0.
|
|
1559
|
+
var version = "0.25.6";
|
|
1539
1560
|
|
|
1540
1561
|
// packages/core/src/lib/implementation/execute-plugin.ts
|
|
1541
1562
|
import chalk5 from "chalk";
|