@code-pushup/core 0.8.8 → 0.8.10

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 (2) hide show
  1. package/index.js +72 -27
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -808,13 +808,13 @@ function getGroupWithAudits(refSlug, refPlugin, plugins) {
808
808
  },
809
809
  []
810
810
  );
811
- const audits = groupAudits.sort(sortCategoryAudits);
811
+ const audits = groupAudits.sort(compareCategoryAudits);
812
812
  return {
813
813
  ...groupWithAudits,
814
814
  audits
815
815
  };
816
816
  }
817
- function sortCategoryAudits(a, b) {
817
+ function compareCategoryAudits(a, b) {
818
818
  if (a.weight !== b.weight) {
819
819
  return b.weight - a.weight;
820
820
  }
@@ -826,7 +826,7 @@ function sortCategoryAudits(a, b) {
826
826
  }
827
827
  return a.title.localeCompare(b.title);
828
828
  }
829
- function sortAudits(a, b) {
829
+ function compareAudits(a, b) {
830
830
  if (a.score !== b.score) {
831
831
  return a.score - b.score;
832
832
  }
@@ -1120,23 +1120,18 @@ function reportToCategoriesSection(report) {
1120
1120
  category.score
1121
1121
  )} Score: ${style(formatReportScore(category.score))}`;
1122
1122
  const categoryDocs = getDocsAndDescription(category);
1123
- const auditsAndGroups = category.refs.reduce(
1124
- (acc2, ref) => ({
1125
- ...acc2,
1126
- ...ref.type === "group" ? {
1127
- groups: [
1128
- ...acc2.groups,
1129
- getGroupWithAudits(ref.slug, ref.plugin, plugins)
1130
- ]
1131
- } : {
1132
- audits: [...acc2.audits, getAuditByRef(ref, plugins)]
1133
- }
1134
- }),
1135
- { groups: [], audits: [] }
1136
- );
1137
- const audits = auditsAndGroups.audits.sort(sortCategoryAudits).map((audit) => auditItemToCategorySection(audit, plugins)).join(NEW_LINE);
1138
- const groups = auditsAndGroups.groups.map((group) => groupItemToCategorySection(group, plugins)).join("");
1139
- return acc + NEW_LINE + categoryTitle + NEW_LINE + NEW_LINE + categoryDocs + categoryScore + NEW_LINE + groups + NEW_LINE + audits;
1123
+ const categoryMDItems = category.refs.reduce((acc2, ref) => {
1124
+ if (ref.type === "group") {
1125
+ const group = getGroupWithAudits(ref.slug, ref.plugin, plugins);
1126
+ const mdGroupItem = groupItemToCategorySection(group, plugins);
1127
+ return acc2 + mdGroupItem + NEW_LINE;
1128
+ } else {
1129
+ const audit = getAuditByRef(ref, plugins);
1130
+ const mdAuditItem = auditItemToCategorySection(audit, plugins);
1131
+ return acc2 + mdAuditItem + NEW_LINE;
1132
+ }
1133
+ }, "");
1134
+ return acc + NEW_LINE + categoryTitle + NEW_LINE + NEW_LINE + categoryDocs + categoryScore + NEW_LINE + categoryMDItems;
1140
1135
  }, "");
1141
1136
  return h2("\u{1F3F7} Categories") + NEW_LINE + categoryDetails;
1142
1137
  }
@@ -1175,7 +1170,7 @@ function groupItemToCategorySection(group, plugins) {
1175
1170
  }
1176
1171
  function reportToAuditsSection(report) {
1177
1172
  const auditsSection = report.plugins.reduce((acc, plugin) => {
1178
- const auditsData = plugin.audits.sort(sortAudits).reduce((acc2, audit) => {
1173
+ const auditsData = plugin.audits.reduce((acc2, audit) => {
1179
1174
  const auditTitle = `${audit.title} (${getPluginNameFromSlug(
1180
1175
  audit.plugin,
1181
1176
  report.plugins
@@ -1198,7 +1193,7 @@ function reportToAuditsSection(report) {
1198
1193
  }
1199
1194
  const detailsTableData = [
1200
1195
  detailsTableHeaders,
1201
- ...audit.details.issues.sort(compareIssues).map((issue) => {
1196
+ ...audit.details.issues.map((issue) => {
1202
1197
  const severity = `${getSeverityIcon(issue.severity)} <i>${issue.severity}</i>`;
1203
1198
  const message = issue.message;
1204
1199
  if (!issue.source) {
@@ -1302,7 +1297,7 @@ function reportToDetailSection(report) {
1302
1297
  output += addLine(chalk3.magentaBright.bold(`${title} audits`));
1303
1298
  output += addLine();
1304
1299
  const ui = cliui({ width: 80 });
1305
- audits.sort(sortAudits).forEach(({ score, title: title2, displayValue, value }) => {
1300
+ audits.forEach(({ score, title: title2, displayValue, value }) => {
1306
1301
  ui.div(
1307
1302
  {
1308
1303
  text: withColor({ score, text: "\u25CF" }),
@@ -1462,6 +1457,56 @@ var verboseUtils = (verbose) => ({
1462
1457
  exec: getExecVerbose(verbose)
1463
1458
  });
1464
1459
 
1460
+ // packages/utils/src/lib/sort-report.ts
1461
+ function sortReport(report) {
1462
+ const { categories, plugins } = report;
1463
+ const sortedCategories = categories.map((category) => {
1464
+ const { audits, groups } = category.refs.reduce(
1465
+ (acc, ref) => ({
1466
+ ...acc,
1467
+ ...ref.type === "group" ? {
1468
+ groups: [
1469
+ ...acc.groups,
1470
+ getGroupWithAudits(ref.slug, ref.plugin, plugins)
1471
+ ]
1472
+ } : {
1473
+ audits: [...acc.audits, getAuditByRef(ref, plugins)]
1474
+ }
1475
+ }),
1476
+ { groups: [], audits: [] }
1477
+ );
1478
+ const sortedAuditsAndGroups = [
1479
+ ...groups,
1480
+ ...audits.sort(compareCategoryAudits)
1481
+ ];
1482
+ const sortedRefs = category.refs.slice().sort((a, b) => {
1483
+ const aIndex = sortedAuditsAndGroups.findIndex(
1484
+ (ref) => ref.slug === a.slug
1485
+ );
1486
+ const bIndex = sortedAuditsAndGroups.findIndex(
1487
+ (ref) => ref.slug === b.slug
1488
+ );
1489
+ return aIndex - bIndex;
1490
+ });
1491
+ return { ...category, refs: sortedRefs };
1492
+ });
1493
+ const sortedPlugins = plugins.map((plugin) => ({
1494
+ ...plugin,
1495
+ audits: plugin.audits.sort(compareAudits).map((audit) => ({
1496
+ ...audit,
1497
+ details: {
1498
+ ...audit.details,
1499
+ issues: audit?.details?.issues.slice().sort(compareIssues) || []
1500
+ }
1501
+ }))
1502
+ }));
1503
+ return {
1504
+ ...report,
1505
+ categories: sortedCategories,
1506
+ plugins: sortedPlugins
1507
+ };
1508
+ }
1509
+
1465
1510
  // packages/core/src/lib/implementation/persist.ts
1466
1511
  var PersistDirError = class extends Error {
1467
1512
  constructor(outputDir) {
@@ -1475,8 +1520,8 @@ var PersistError = class extends Error {
1475
1520
  };
1476
1521
  async function persistReport(report, options) {
1477
1522
  const { outputDir, filename, format } = options;
1478
- const scoredReport = scoreReport(report);
1479
- console.info(reportToStdout(scoredReport));
1523
+ const sortedScoredReport = sortReport(scoreReport(report));
1524
+ console.info(reportToStdout(sortedScoredReport));
1480
1525
  const results = [];
1481
1526
  if (format.includes("json")) {
1482
1527
  results.push({
@@ -1489,7 +1534,7 @@ async function persistReport(report, options) {
1489
1534
  validateCommitData(commitData);
1490
1535
  results.push({
1491
1536
  format: "md",
1492
- content: reportToMd(scoredReport, commitData)
1537
+ content: reportToMd(sortedScoredReport, commitData)
1493
1538
  });
1494
1539
  }
1495
1540
  if (!existsSync(outputDir)) {
@@ -1634,7 +1679,7 @@ function auditOutputsCorrelateWithPluginOutput(auditOutputs, pluginConfigAudits)
1634
1679
 
1635
1680
  // packages/core/package.json
1636
1681
  var name = "@code-pushup/core";
1637
- var version = "0.8.8";
1682
+ var version = "0.8.10";
1638
1683
 
1639
1684
  // packages/core/src/lib/implementation/collect.ts
1640
1685
  async function collect(options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-pushup/core",
3
- "version": "0.8.8",
3
+ "version": "0.8.10",
4
4
  "dependencies": {
5
5
  "@code-pushup/models": "*",
6
6
  "@code-pushup/utils": "*",