@code-pushup/cli 0.23.0 → 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.
Files changed (2) hide show
  1. package/index.js +85 -66
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -706,8 +706,6 @@ var SCORE_COLOR_RANGE = {
706
706
  GREEN_MIN: 0.9,
707
707
  YELLOW_MIN: 0.5
708
708
  };
709
-
710
- // packages/utils/src/lib/reports/utils.ts
711
709
  var FOOTER_PREFIX = "Made with \u2764 by";
712
710
  var CODE_PUSHUP_DOMAIN = "code-pushup.dev";
713
711
  var README_LINK = "https://github.com/flowup/quality-metrics-cli#readme";
@@ -738,6 +736,8 @@ var detailsTableHeaders = [
738
736
  "Source file",
739
737
  "Line(s)"
740
738
  ];
739
+
740
+ // packages/utils/src/lib/reports/utils.ts
741
741
  function formatReportScore(score) {
742
742
  return Math.round(score * 100).toString();
743
743
  }
@@ -774,7 +774,7 @@ function calcDuration(start, stop) {
774
774
  function countCategoryAudits(refs, plugins) {
775
775
  const groupLookup = plugins.reduce(
776
776
  (lookup, plugin) => {
777
- if (plugin.groups.length === 0) {
777
+ if (plugin.groups == null || plugin.groups.length === 0) {
778
778
  return lookup;
779
779
  }
780
780
  return {
@@ -794,7 +794,7 @@ function countCategoryAudits(refs, plugins) {
794
794
  return acc + 1;
795
795
  }, 0);
796
796
  }
797
- function getAuditByRef({ slug, weight, plugin }, plugins) {
797
+ function getSortableAuditByRef({ slug, weight, plugin }, plugins) {
798
798
  const auditPlugin = plugins.find((p) => p.slug === plugin);
799
799
  if (!auditPlugin) {
800
800
  throwIsNotPresentError(`Plugin ${plugin}`, "report");
@@ -811,39 +811,51 @@ function getAuditByRef({ slug, weight, plugin }, plugins) {
811
811
  plugin
812
812
  };
813
813
  }
814
- function getGroupWithAudits(refSlug, refPlugin, plugins) {
815
- const plugin = plugins.find(({ slug }) => slug === refPlugin);
816
- if (!plugin) {
817
- throwIsNotPresentError(`Plugin ${refPlugin}`, "report");
818
- }
819
- const groupWithAudits = plugin.groups?.find(({ slug }) => slug === refSlug);
820
- if (!groupWithAudits) {
821
- throwIsNotPresentError(`Group ${refSlug}`, plugin.slug);
814
+ function getSortableGroupByRef({ plugin, slug, weight }, plugins) {
815
+ const groupPlugin = plugins.find((p) => p.slug === plugin);
816
+ if (!groupPlugin) {
817
+ throwIsNotPresentError(`Plugin ${plugin}`, "report");
822
818
  }
823
- const groupAudits = groupWithAudits.refs.reduce(
824
- (acc, ref) => {
825
- const audit = getAuditByRef(
826
- { ...ref, plugin: refPlugin, type: "audit" },
827
- plugins
828
- );
829
- return [...acc, audit];
830
- },
831
- []
819
+ const group = groupPlugin.groups?.find(
820
+ ({ slug: groupSlug }) => groupSlug === slug
832
821
  );
833
- const audits = [...groupAudits].sort(compareCategoryAudits);
822
+ if (!group) {
823
+ throwIsNotPresentError(`Group ${slug}`, groupPlugin.slug);
824
+ }
825
+ const sortedAudits = getSortedGroupAudits(group, groupPlugin.slug, plugins);
826
+ const sortedAuditRefs = [...group.refs].sort((a, b) => {
827
+ const aIndex = sortedAudits.findIndex((ref) => ref.slug === a.slug);
828
+ const bIndex = sortedAudits.findIndex((ref) => ref.slug === b.slug);
829
+ return aIndex - bIndex;
830
+ });
834
831
  return {
835
- ...groupWithAudits,
836
- audits
832
+ ...group,
833
+ refs: sortedAuditRefs,
834
+ plugin,
835
+ weight
837
836
  };
838
837
  }
839
- function compareCategoryAudits(a, b) {
838
+ function getSortedGroupAudits(group, plugin, plugins) {
839
+ return group.refs.map(
840
+ (ref) => getSortableAuditByRef(
841
+ {
842
+ plugin,
843
+ slug: ref.slug,
844
+ weight: ref.weight,
845
+ type: "audit"
846
+ },
847
+ plugins
848
+ )
849
+ ).sort(compareCategoryAuditsAndGroups);
850
+ }
851
+ function compareCategoryAuditsAndGroups(a, b) {
840
852
  if (a.weight !== b.weight) {
841
853
  return b.weight - a.weight;
842
854
  }
843
855
  if (a.score !== b.score) {
844
856
  return a.score - b.score;
845
857
  }
846
- if (a.value !== b.value) {
858
+ if ("value" in a && "value" in b && a.value !== b.value) {
847
859
  return b.value - a.value;
848
860
  }
849
861
  return a.title.localeCompare(b.title);
@@ -952,6 +964,10 @@ function executeProcess(cfg) {
952
964
  });
953
965
  }
954
966
 
967
+ // packages/utils/src/lib/git.ts
968
+ import { isAbsolute, join as join2, relative } from "node:path";
969
+ import { simpleGit } from "simple-git";
970
+
955
971
  // packages/utils/src/lib/transform.ts
956
972
  function toArray(val) {
957
973
  return Array.isArray(val) ? val : [val];
@@ -964,8 +980,6 @@ function toUnixPath(path) {
964
980
  }
965
981
 
966
982
  // packages/utils/src/lib/git.ts
967
- import { isAbsolute, join as join2, relative } from "node:path";
968
- import { simpleGit } from "simple-git";
969
983
  async function getLatestCommit(git = simpleGit()) {
970
984
  const log = await git.log({
971
985
  maxCount: 1,
@@ -984,7 +998,7 @@ function formatGitPath(path, gitRoot) {
984
998
  function validateCommitData(commitData, options2 = {}) {
985
999
  if (!commitData) {
986
1000
  const msg = "no commit data available";
987
- if (options2?.throwError) {
1001
+ if (options2.throwError) {
988
1002
  throw new Error(msg);
989
1003
  } else {
990
1004
  console.warn(msg);
@@ -1178,12 +1192,24 @@ function reportToCategoriesSection(report) {
1178
1192
  const categoryDocs = getDocsAndDescription(category);
1179
1193
  const categoryMDItems = category.refs.reduce((refAcc, ref) => {
1180
1194
  if (ref.type === "group") {
1181
- const group = getGroupWithAudits(ref.slug, ref.plugin, plugins);
1182
- const mdGroupItem = groupItemToCategorySection(group, plugins);
1195
+ const group = getSortableGroupByRef(ref, plugins);
1196
+ const groupAudits = group.refs.map(
1197
+ (groupRef) => getSortableAuditByRef(
1198
+ { ...groupRef, plugin: group.plugin, type: "audit" },
1199
+ plugins
1200
+ )
1201
+ );
1202
+ const pluginTitle = getPluginNameFromSlug(ref.plugin, plugins);
1203
+ const mdGroupItem = groupItemToCategorySection(
1204
+ group,
1205
+ groupAudits,
1206
+ pluginTitle
1207
+ );
1183
1208
  return refAcc + mdGroupItem + NEW_LINE;
1184
1209
  } else {
1185
- const audit = getAuditByRef(ref, plugins);
1186
- const mdAuditItem = auditItemToCategorySection(audit, plugins);
1210
+ const audit = getSortableAuditByRef(ref, plugins);
1211
+ const pluginTitle = getPluginNameFromSlug(ref.plugin, plugins);
1212
+ const mdAuditItem = auditItemToCategorySection(audit, pluginTitle);
1187
1213
  return refAcc + mdAuditItem + NEW_LINE;
1188
1214
  }
1189
1215
  }, "");
@@ -1191,8 +1217,7 @@ function reportToCategoriesSection(report) {
1191
1217
  }, "");
1192
1218
  return h2("\u{1F3F7} Categories") + NEW_LINE + categoryDetails;
1193
1219
  }
1194
- function auditItemToCategorySection(audit, plugins) {
1195
- const pluginTitle = getPluginNameFromSlug(audit.plugin, plugins);
1220
+ function auditItemToCategorySection(audit, pluginTitle) {
1196
1221
  const auditTitle = link2(
1197
1222
  `#${slugify(audit.title)}-${slugify(pluginTitle)}`,
1198
1223
  audit.title
@@ -1203,13 +1228,12 @@ function auditItemToCategorySection(audit, plugins) {
1203
1228
  )} ${auditTitle} (_${pluginTitle}_) - ${getAuditResult(audit)}`
1204
1229
  );
1205
1230
  }
1206
- function groupItemToCategorySection(group, plugins) {
1207
- const pluginTitle = getPluginNameFromSlug(group.plugin, plugins);
1208
- const groupScore = Number(formatReportScore(group?.score || 0));
1231
+ function groupItemToCategorySection(group, groupAudits, pluginTitle) {
1232
+ const groupScore = Number(formatReportScore(group.score || 0));
1209
1233
  const groupTitle = li(
1210
1234
  `${getRoundScoreMarker(groupScore)} ${group.title} (_${pluginTitle}_)`
1211
1235
  );
1212
- const groupAudits = group.audits.reduce((acc, audit) => {
1236
+ const auditTitles = groupAudits.reduce((acc, audit) => {
1213
1237
  const auditTitle = link2(
1214
1238
  `#${slugify(audit.title)}-${slugify(pluginTitle)}`,
1215
1239
  audit.title
@@ -1220,13 +1244,13 @@ function groupItemToCategorySection(group, plugins) {
1220
1244
  )}`
1221
1245
  )}${NEW_LINE}`;
1222
1246
  }, "");
1223
- return groupTitle + NEW_LINE + groupAudits;
1247
+ return groupTitle + NEW_LINE + auditTitles;
1224
1248
  }
1225
1249
  function reportToAuditsSection(report) {
1226
1250
  const auditsSection = report.plugins.reduce((pluginAcc, plugin) => {
1227
1251
  const auditsData = plugin.audits.reduce((auditAcc, audit) => {
1228
1252
  const auditTitle = `${audit.title} (${getPluginNameFromSlug(
1229
- audit.plugin,
1253
+ plugin.slug,
1230
1254
  report.plugins
1231
1255
  )})`;
1232
1256
  return auditAcc + h3(auditTitle) + NEW_LINE + NEW_LINE + reportToDetailsSection(audit) + NEW_LINE + NEW_LINE + getDocsAndDescription(audit);
@@ -1403,29 +1427,30 @@ var GroupRefInvalidError = class extends Error {
1403
1427
  function scoreReport(report) {
1404
1428
  const allScoredAuditsAndGroups = /* @__PURE__ */ new Map();
1405
1429
  const scoredPlugins = report.plugins.map((plugin) => {
1406
- const { slug, audits, groups } = plugin;
1407
- const updatedAudits = audits.map((audit) => ({ ...audit, plugin: slug }));
1408
- updatedAudits.forEach((audit) => {
1409
- allScoredAuditsAndGroups.set(`${slug}-${audit.slug}-audit`, audit);
1430
+ const { groups, ...pluginProps } = plugin;
1431
+ plugin.audits.forEach((audit) => {
1432
+ allScoredAuditsAndGroups.set(`${plugin.slug}-${audit.slug}-audit`, audit);
1410
1433
  });
1411
1434
  function groupScoreFn(ref) {
1412
1435
  const score = allScoredAuditsAndGroups.get(
1413
- `${slug}-${ref.slug}-audit`
1436
+ `${plugin.slug}-${ref.slug}-audit`
1414
1437
  )?.score;
1415
1438
  if (score == null) {
1416
- throw new GroupRefInvalidError(ref.slug, slug);
1439
+ throw new GroupRefInvalidError(ref.slug, plugin.slug);
1417
1440
  }
1418
1441
  return score;
1419
1442
  }
1420
1443
  const scoredGroups = groups?.map((group) => ({
1421
1444
  ...group,
1422
- score: calculateScore(group.refs, groupScoreFn),
1423
- plugin: slug
1445
+ score: calculateScore(group.refs, groupScoreFn)
1424
1446
  })) ?? [];
1425
1447
  scoredGroups.forEach((group) => {
1426
- allScoredAuditsAndGroups.set(`${slug}-${group.slug}-group`, group);
1448
+ allScoredAuditsAndGroups.set(`${plugin.slug}-${group.slug}-group`, group);
1427
1449
  });
1428
- return { ...plugin, audits: updatedAudits, groups: scoredGroups };
1450
+ return {
1451
+ ...pluginProps,
1452
+ ...scoredGroups.length > 0 && { groups: scoredGroups }
1453
+ };
1429
1454
  });
1430
1455
  function catScoreFn(ref) {
1431
1456
  const key = `${ref.plugin}-${ref.slug}-${ref.type}`;
@@ -1486,26 +1511,22 @@ function sortReport(report) {
1486
1511
  (acc, ref) => ({
1487
1512
  ...acc,
1488
1513
  ...ref.type === "group" ? {
1489
- groups: [
1490
- ...acc.groups,
1491
- getGroupWithAudits(ref.slug, ref.plugin, plugins)
1492
- ]
1514
+ groups: [...acc.groups, getSortableGroupByRef(ref, plugins)]
1493
1515
  } : {
1494
- audits: [...acc.audits, getAuditByRef(ref, plugins)]
1516
+ audits: [...acc.audits, getSortableAuditByRef(ref, plugins)]
1495
1517
  }
1496
1518
  }),
1497
1519
  { groups: [], audits: [] }
1498
1520
  );
1499
- const sortedAuditsAndGroups = [
1500
- ...groups,
1501
- ...[...audits].sort(compareCategoryAudits)
1502
- ];
1521
+ const sortedAuditsAndGroups = [...audits, ...groups].sort(
1522
+ compareCategoryAuditsAndGroups
1523
+ );
1503
1524
  const sortedRefs = [...category.refs].sort((a, b) => {
1504
1525
  const aIndex = sortedAuditsAndGroups.findIndex(
1505
- (ref) => ref.slug === a.slug
1526
+ (ref) => ref.slug === a.slug && ref.plugin === a.plugin
1506
1527
  );
1507
1528
  const bIndex = sortedAuditsAndGroups.findIndex(
1508
- (ref) => ref.slug === b.slug
1529
+ (ref) => ref.slug === b.slug && ref.plugin === b.plugin
1509
1530
  );
1510
1531
  return aIndex - bIndex;
1511
1532
  });
@@ -1554,7 +1575,7 @@ var verboseUtils = (verbose = false) => ({
1554
1575
 
1555
1576
  // packages/core/package.json
1556
1577
  var name = "@code-pushup/core";
1557
- var version = "0.23.0";
1578
+ var version = "0.25.6";
1558
1579
 
1559
1580
  // packages/core/src/lib/implementation/execute-plugin.ts
1560
1581
  import chalk5 from "chalk";
@@ -1878,9 +1899,7 @@ function auditToGQL(audit) {
1878
1899
  formattedValue: audit.displayValue,
1879
1900
  ...audit.details && {
1880
1901
  details: {
1881
- ...audit.details.issues && {
1882
- issues: audit.details.issues.map(issueToGQL)
1883
- }
1902
+ issues: audit.details.issues.map(issueToGQL)
1884
1903
  }
1885
1904
  }
1886
1905
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-pushup/cli",
3
- "version": "0.23.0",
3
+ "version": "0.25.6",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "code-pushup": "index.js"