@code-pushup/cli 0.8.20 → 0.8.22

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 +84 -105
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -30,59 +30,48 @@ var MAX_DESCRIPTION_LENGTH = 65536;
30
30
  var MAX_ISSUE_MESSAGE_LENGTH = 1024;
31
31
 
32
32
  // packages/models/src/lib/implementation/utils.ts
33
- var slugRegex = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
33
+ var slugRegex = /^[a-z\d]+(?:-[a-z\d]+)*$/;
34
34
  var filenameRegex = /^(?!.*[ \\/:*?"<>|]).+$/;
35
35
  function hasDuplicateStrings(strings) {
36
- const uniqueStrings = Array.from(new Set(strings));
37
- const duplicatedStrings = strings.filter(
38
- /* @__PURE__ */ ((i) => (v) => uniqueStrings[i] !== v || !++i)(0)
36
+ const sortedStrings = [...strings].sort();
37
+ const duplStrings = sortedStrings.filter(
38
+ (item, index) => index !== 0 && item === sortedStrings[index - 1]
39
39
  );
40
- return duplicatedStrings.length === 0 ? false : duplicatedStrings;
40
+ return duplStrings.length === 0 ? false : [...new Set(duplStrings)];
41
41
  }
42
42
  function hasMissingStrings(toCheck, existing) {
43
43
  const nonExisting = toCheck.filter((s) => !existing.includes(s));
44
44
  return nonExisting.length === 0 ? false : nonExisting;
45
45
  }
46
- function errorItems(items, transform = (items2) => items2.join(", ")) {
47
- const paredItems = items ? items : [];
48
- return transform(paredItems);
46
+ function errorItems(items, transform = (itemArr) => itemArr.join(", ")) {
47
+ return transform(items || []);
49
48
  }
50
49
  function exists(value) {
51
50
  return value != null;
52
51
  }
53
52
  function getMissingRefsForCategories(categories, plugins) {
54
- const missingRefs = [];
55
53
  const auditRefsFromCategory = categories.flatMap(
56
54
  ({ refs }) => refs.filter(({ type }) => type === "audit").map(({ plugin, slug }) => `${plugin}/${slug}`)
57
55
  );
58
56
  const auditRefsFromPlugins = plugins.flatMap(
59
- ({ audits, slug: pluginSlug }) => {
60
- return audits.map(({ slug }) => `${pluginSlug}/${slug}`);
61
- }
57
+ ({ audits, slug: pluginSlug }) => audits.map(({ slug }) => `${pluginSlug}/${slug}`)
62
58
  );
63
59
  const missingAuditRefs = hasMissingStrings(
64
60
  auditRefsFromCategory,
65
61
  auditRefsFromPlugins
66
62
  );
67
- if (Array.isArray(missingAuditRefs) && missingAuditRefs.length > 0) {
68
- missingRefs.push(...missingAuditRefs);
69
- }
70
63
  const groupRefsFromCategory = categories.flatMap(
71
64
  ({ refs }) => refs.filter(({ type }) => type === "group").map(({ plugin, slug }) => `${plugin}#${slug} (group)`)
72
65
  );
73
66
  const groupRefsFromPlugins = plugins.flatMap(
74
- ({ groups, slug: pluginSlug }) => {
75
- return Array.isArray(groups) ? groups.map(({ slug }) => `${pluginSlug}#${slug} (group)`) : [];
76
- }
67
+ ({ groups, slug: pluginSlug }) => Array.isArray(groups) ? groups.map(({ slug }) => `${pluginSlug}#${slug} (group)`) : []
77
68
  );
78
69
  const missingGroupRefs = hasMissingStrings(
79
70
  groupRefsFromCategory,
80
71
  groupRefsFromPlugins
81
72
  );
82
- if (Array.isArray(missingGroupRefs) && missingGroupRefs.length > 0) {
83
- missingRefs.push(...missingGroupRefs);
84
- }
85
- return missingRefs.length ? missingRefs : false;
73
+ const missingRefs = [missingAuditRefs, missingGroupRefs].filter((refs) => Array.isArray(refs) && refs.length > 0).flat();
74
+ return missingRefs.length > 0 ? missingRefs : false;
86
75
  }
87
76
  function missingRefsForCategoriesErrorMsg(categories, plugins) {
88
77
  const missingRefs = getMissingRefsForCategories(categories, plugins);
@@ -126,7 +115,7 @@ function metaSchema(options2) {
126
115
  titleDescription,
127
116
  docsUrlDescription,
128
117
  description
129
- } = options2 || {};
118
+ } = options2 ?? {};
130
119
  return z.object(
131
120
  {
132
121
  title: titleSchema(titleDescription),
@@ -585,13 +574,14 @@ function slugify(text) {
585
574
  }
586
575
  function formatBytes(bytes, decimals = 2) {
587
576
  bytes = Math.max(bytes, 0);
588
- if (!bytes)
577
+ if (!bytes) {
589
578
  return "0 B";
579
+ }
590
580
  const k = 1024;
591
581
  const dm = decimals < 0 ? 0 : decimals;
592
582
  const sizes = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
593
583
  const i = Math.floor(Math.log(bytes) / Math.log(k));
594
- return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
584
+ return `${Number.parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
595
585
  }
596
586
  function formatDuration(duration) {
597
587
  if (duration < 1e3) {
@@ -628,7 +618,7 @@ function logMultipleResults(results, messagePrefix, succeededCallback, failedCal
628
618
  }
629
619
  }
630
620
  function logPromiseResults(results, logMessage, callback) {
631
- if (results.length) {
621
+ if (results.length > 0) {
632
622
  if (results[0]?.status === "fulfilled") {
633
623
  console.info(logMessage);
634
624
  } else {
@@ -677,9 +667,8 @@ async function ensureDirectoryExists(baseDir) {
677
667
  function logMultipleFileResults(fileResults, messagePrefix) {
678
668
  const succeededCallback = (result) => {
679
669
  const [fileName, size] = result.value;
680
- console.info(
681
- `- ${chalk.bold(fileName)}` + (size ? ` (${chalk.gray(formatBytes(size))})` : "")
682
- );
670
+ const formattedSize = size ? ` (${chalk.gray(formatBytes(size))})` : "";
671
+ console.info(`- ${chalk.bold(fileName)}${formattedSize}`);
683
672
  };
684
673
  const failedCallback = (result) => {
685
674
  console.warn(`- ${chalk.bold(result.reason)}`);
@@ -708,6 +697,7 @@ async function importEsmModule(options2) {
708
697
  }
709
698
 
710
699
  // packages/utils/src/lib/reports/constants.ts
700
+ var TERMINAL_WIDTH = 80;
711
701
  var NEW_LINE = "\n";
712
702
  var SCORE_COLOR_RANGE = {
713
703
  GREEN_MIN: 0.9,
@@ -776,28 +766,20 @@ function getSeverityIcon(severity) {
776
766
  return "\u2139\uFE0F";
777
767
  }
778
768
  function calcDuration(start, stop) {
779
- stop = stop !== void 0 ? stop : performance.now();
769
+ stop ??= performance.now();
780
770
  return Math.floor(stop - start);
781
771
  }
782
772
  function countCategoryAudits(refs, plugins) {
783
773
  const groupLookup = plugins.reduce(
784
774
  (lookup, plugin) => {
785
- if (!plugin.groups.length) {
775
+ if (plugin.groups.length === 0) {
786
776
  return lookup;
787
777
  }
788
778
  return {
789
779
  ...lookup,
790
- [plugin.slug]: {
791
- ...plugin.groups.reduce(
792
- (groupLookup2, group) => {
793
- return {
794
- ...groupLookup2,
795
- [group.slug]: group
796
- };
797
- },
798
- {}
799
- )
800
- }
780
+ [plugin.slug]: Object.fromEntries(
781
+ plugin.groups.map((group) => [group.slug, group])
782
+ )
801
783
  };
802
784
  },
803
785
  {}
@@ -805,7 +787,7 @@ function countCategoryAudits(refs, plugins) {
805
787
  return refs.reduce((acc, ref) => {
806
788
  if (ref.type === "group") {
807
789
  const groupRefs = groupLookup[ref.plugin]?.[ref.slug]?.refs;
808
- return acc + (groupRefs?.length || 0);
790
+ return acc + (groupRefs?.length ?? 0);
809
791
  }
810
792
  return acc + 1;
811
793
  }, 0);
@@ -911,7 +893,7 @@ function compareIssues(a, b) {
911
893
  return 1;
912
894
  }
913
895
  if (a.source?.file !== b.source?.file) {
914
- return a.source?.file.localeCompare(b.source?.file || "") || 0;
896
+ return a.source?.file.localeCompare(b.source?.file || "") ?? 0;
915
897
  }
916
898
  if (!a.source?.position && b.source?.position) {
917
899
  return -1;
@@ -920,7 +902,7 @@ function compareIssues(a, b) {
920
902
  return 1;
921
903
  }
922
904
  if (a.source?.position?.startLine !== b.source?.position?.startLine) {
923
- return (a.source?.position?.startLine || 0) - (b.source?.position?.startLine || 0);
905
+ return (a.source?.position?.startLine ?? 0) - (b.source?.position?.startLine ?? 0);
924
906
  }
925
907
  return 0;
926
908
  }
@@ -938,12 +920,12 @@ var ProcessError = class extends Error {
938
920
  }
939
921
  };
940
922
  function executeProcess(cfg) {
941
- const { observer, cwd } = cfg;
942
- const { onStdout, onError, onComplete } = observer || {};
923
+ const { observer, cwd, command, args } = cfg;
924
+ const { onStdout, onError, onComplete } = observer ?? {};
943
925
  const date = (/* @__PURE__ */ new Date()).toISOString();
944
926
  const start = performance.now();
945
927
  return new Promise((resolve, reject) => {
946
- const process2 = spawn(cfg.command, cfg.args, { cwd, shell: true });
928
+ const process2 = spawn(command, args, { cwd, shell: true });
947
929
  let stdout = "";
948
930
  let stderr = "";
949
931
  process2.stdout.on("data", (data) => {
@@ -1077,7 +1059,7 @@ function style(text, styles = ["b"]) {
1077
1059
 
1078
1060
  // packages/utils/src/lib/reports/md/headline.ts
1079
1061
  function headline(text, hierarchy = 1) {
1080
- return `${new Array(hierarchy).fill("#").join("")} ${text}`;
1062
+ return `${"#".repeat(hierarchy)} ${text}`;
1081
1063
  }
1082
1064
  function h2(text) {
1083
1065
  return headline(text, 2);
@@ -1107,45 +1089,50 @@ function tableMd(data, align) {
1107
1089
  if (data.length === 0) {
1108
1090
  throw new Error("Data can't be empty");
1109
1091
  }
1110
- align = align || data[0]?.map(() => "c");
1111
- const _data = data.map((arr) => "|" + arr.join("|") + "|");
1112
- const secondRow = "|" + align?.map((s) => alignString.get(s)).join("|") + "|";
1113
- return _data.shift() + NEW_LINE + secondRow + NEW_LINE + _data.join(NEW_LINE);
1092
+ align ??= data[0]?.map(() => "c");
1093
+ const tableContent = data.map((arr) => `|${arr.join("|")}|`);
1094
+ const secondRow = `|${align?.map((s) => alignString.get(s)).join("|")}|`;
1095
+ return tableContent.shift() + NEW_LINE + secondRow + NEW_LINE + tableContent.join(NEW_LINE);
1114
1096
  }
1115
1097
  function tableHtml(data) {
1116
1098
  if (data.length === 0) {
1117
1099
  throw new Error("Data can't be empty");
1118
1100
  }
1119
- const _data = data.map((arr, index) => {
1101
+ const tableContent = data.map((arr, index) => {
1120
1102
  if (index === 0) {
1121
- return "<tr>" + arr.map((s) => `<th>${s}</th>`).join("") + "</tr>";
1103
+ const headerRow = arr.map((s) => `<th>${s}</th>`).join("");
1104
+ return `<tr>${headerRow}</tr>`;
1122
1105
  }
1123
- return "<tr>" + arr.map((s) => `<td>${s}</td>`).join("") + "</tr>";
1106
+ const row = arr.map((s) => `<td>${s}</td>`).join("");
1107
+ return `<tr>${row}</tr>`;
1124
1108
  });
1125
- return "<table>" + _data.join("") + "</table>";
1109
+ return `<table>${tableContent.join("")}</table>`;
1126
1110
  }
1127
1111
 
1128
1112
  // packages/utils/src/lib/reports/generate-md-report.ts
1129
1113
  function generateMdReport(report, commitData) {
1130
- let md = reportToHeaderSection() + NEW_LINE;
1131
- md += reportToOverviewSection(report) + NEW_LINE + NEW_LINE;
1132
- md += reportToCategoriesSection(report) + NEW_LINE + NEW_LINE;
1133
- md += reportToAuditsSection(report) + NEW_LINE + NEW_LINE;
1134
- md += reportToAboutSection(report, commitData) + NEW_LINE + NEW_LINE;
1135
- md += `${FOOTER_PREFIX} ${link(README_LINK, "Code PushUp")}`;
1136
- return md;
1114
+ return (
1115
+ // header section
1116
+ // eslint-disable-next-line prefer-template
1117
+ reportToHeaderSection() + NEW_LINE + // overview section
1118
+ reportToOverviewSection(report) + NEW_LINE + NEW_LINE + // categories section
1119
+ reportToCategoriesSection(report) + NEW_LINE + NEW_LINE + // audits section
1120
+ reportToAuditsSection(report) + NEW_LINE + NEW_LINE + // about section
1121
+ reportToAboutSection(report, commitData) + NEW_LINE + NEW_LINE + // footer section
1122
+ `${FOOTER_PREFIX} ${link(README_LINK, "Code PushUp")}`
1123
+ );
1137
1124
  }
1138
1125
  function reportToHeaderSection() {
1139
1126
  return headline(reportHeadlineText) + NEW_LINE;
1140
1127
  }
1141
1128
  function reportToOverviewSection(report) {
1142
- const { categories } = report;
1129
+ const { categories, plugins } = report;
1143
1130
  const tableContent = [
1144
1131
  reportOverviewTableHeaders,
1145
1132
  ...categories.map(({ title, refs, score }) => [
1146
1133
  link(`#${slugify(title)}`, title),
1147
1134
  `${getRoundScoreMarker(score)} ${style(formatReportScore(score))}`,
1148
- countCategoryAudits(refs, report.plugins).toString()
1135
+ countCategoryAudits(refs, plugins).toString()
1149
1136
  ])
1150
1137
  ];
1151
1138
  return tableMd(tableContent, ["l", "c", "c"]);
@@ -1281,7 +1268,10 @@ function reportToAboutSection(report, commitData) {
1281
1268
  formatDuration(duration2)
1282
1269
  ])
1283
1270
  ];
1284
- return h2("About") + NEW_LINE + NEW_LINE + `Report was created by [Code PushUp](${README_LINK}) on ${date}.` + NEW_LINE + NEW_LINE + tableMd(reportMetaTable, ["l", "c", "c", "c", "c", "c"]) + NEW_LINE + NEW_LINE + "The following plugins were run:" + NEW_LINE + NEW_LINE + tableMd(pluginMetaTable, ["l", "c", "c", "c"]);
1271
+ return (
1272
+ // eslint-disable-next-line prefer-template
1273
+ h2("About") + NEW_LINE + NEW_LINE + `Report was created by [Code PushUp](${README_LINK}) on ${date}.` + NEW_LINE + NEW_LINE + tableMd(reportMetaTable, ["l", "c", "c", "c", "c", "c"]) + NEW_LINE + NEW_LINE + "The following plugins were run:" + NEW_LINE + NEW_LINE + tableMd(pluginMetaTable, ["l", "c", "c", "c"])
1274
+ );
1285
1275
  }
1286
1276
  function getDocsAndDescription({
1287
1277
  docsUrl,
@@ -1315,13 +1305,7 @@ function addLine(line = "") {
1315
1305
  return line + NEW_LINE;
1316
1306
  }
1317
1307
  function generateStdoutSummary(report) {
1318
- let output = "";
1319
- output += addLine(reportToHeaderSection2(report));
1320
- output += addLine();
1321
- output += addLine(reportToDetailSection(report));
1322
- output += addLine(reportToOverviewSection2(report));
1323
- output += addLine(`${FOOTER_PREFIX} ${CODE_PUSHUP_DOMAIN}`);
1324
- return output;
1308
+ return addLine(reportToHeaderSection2(report)) + addLine() + addLine(reportToDetailSection(report)) + addLine(reportToOverviewSection2(report)) + addLine(`${FOOTER_PREFIX} ${CODE_PUSHUP_DOMAIN}`);
1325
1309
  }
1326
1310
  function reportToHeaderSection2(report) {
1327
1311
  const { packageName, version: version2 } = report;
@@ -1329,12 +1313,9 @@ function reportToHeaderSection2(report) {
1329
1313
  }
1330
1314
  function reportToDetailSection(report) {
1331
1315
  const { plugins } = report;
1332
- let output = "";
1333
- plugins.forEach(({ title, audits }) => {
1334
- output += addLine();
1335
- output += addLine(chalk3.magentaBright.bold(`${title} audits`));
1336
- output += addLine();
1337
- const ui = cliui({ width: 80 });
1316
+ return plugins.reduce((acc, plugin) => {
1317
+ const { title, audits } = plugin;
1318
+ const ui = cliui({ width: TERMINAL_WIDTH });
1338
1319
  audits.forEach(({ score, title: title2, displayValue, value }) => {
1339
1320
  ui.div(
1340
1321
  {
@@ -1344,6 +1325,7 @@ function reportToDetailSection(report) {
1344
1325
  },
1345
1326
  {
1346
1327
  text: title2,
1328
+ // eslint-disable-next-line no-magic-numbers
1347
1329
  padding: [0, 3, 0, 0]
1348
1330
  },
1349
1331
  {
@@ -1353,17 +1335,13 @@ function reportToDetailSection(report) {
1353
1335
  }
1354
1336
  );
1355
1337
  });
1356
- output += addLine(ui.toString());
1357
- output += addLine();
1358
- });
1359
- return output;
1338
+ return acc + addLine() + addLine(chalk3.magentaBright.bold(`${title} audits`)) + addLine() + addLine(ui.toString()) + addLine();
1339
+ }, "");
1360
1340
  }
1361
1341
  function reportToOverviewSection2({
1362
1342
  categories,
1363
1343
  plugins
1364
1344
  }) {
1365
- let output = addLine(chalk3.magentaBright.bold("Categories"));
1366
- output += addLine();
1367
1345
  const table = new Table({
1368
1346
  head: reportRawOverviewTableHeaders,
1369
1347
  colAligns: ["left", "right", "right"],
@@ -1378,8 +1356,7 @@ function reportToOverviewSection2({
1378
1356
  countCategoryAudits(refs, plugins)
1379
1357
  ])
1380
1358
  );
1381
- output += addLine(table.toString());
1382
- return output;
1359
+ return addLine(chalk3.magentaBright.bold("Categories")) + addLine() + addLine(table.toString());
1383
1360
  }
1384
1361
  function withColor({ score, text }) {
1385
1362
  const formattedScore = text ?? formatReportScore(score);
@@ -1433,28 +1410,28 @@ function scoreReport(report) {
1433
1410
  const scoredReport = deepClone(report);
1434
1411
  const allScoredAuditsAndGroups = /* @__PURE__ */ new Map();
1435
1412
  scoredReport.plugins?.forEach((plugin) => {
1436
- const { audits } = plugin;
1413
+ const { slug, audits } = plugin;
1437
1414
  const groups = plugin.groups || [];
1438
1415
  audits.forEach((audit) => {
1439
- const key = `${plugin.slug}-${audit.slug}-audit`;
1440
- audit.plugin = plugin.slug;
1416
+ const key = `${slug}-${audit.slug}-audit`;
1417
+ audit.plugin = slug;
1441
1418
  allScoredAuditsAndGroups.set(key, audit);
1442
1419
  });
1443
1420
  function groupScoreFn(ref) {
1444
1421
  const score = allScoredAuditsAndGroups.get(
1445
- `${plugin.slug}-${ref.slug}-audit`
1422
+ `${slug}-${ref.slug}-audit`
1446
1423
  )?.score;
1447
1424
  if (score == null) {
1448
1425
  throw new Error(
1449
- `Group has invalid ref - audit with slug ${plugin.slug}-${ref.slug}-audit not found`
1426
+ `Group has invalid ref - audit with slug ${slug}-${ref.slug}-audit not found`
1450
1427
  );
1451
1428
  }
1452
1429
  return score;
1453
1430
  }
1454
1431
  groups.forEach((group) => {
1455
- const key = `${plugin.slug}-${group.slug}-group`;
1432
+ const key = `${slug}-${group.slug}-group`;
1456
1433
  group.score = calculateScore(group.refs, groupScoreFn);
1457
- group.plugin = plugin.slug;
1434
+ group.plugin = slug;
1458
1435
  allScoredAuditsAndGroups.set(key, group);
1459
1436
  });
1460
1437
  plugin.groups = groups;
@@ -1474,7 +1451,7 @@ function scoreReport(report) {
1474
1451
  category.score = calculateScore(category.refs, catScoreFn);
1475
1452
  scoredCategoriesMap.set(category.slug, category);
1476
1453
  }
1477
- scoredReport.categories = Array.from(scoredCategoriesMap.values());
1454
+ scoredReport.categories = [...scoredCategoriesMap.values()];
1478
1455
  return scoredReport;
1479
1456
  }
1480
1457
 
@@ -1500,7 +1477,7 @@ function sortReport(report) {
1500
1477
  ...groups,
1501
1478
  ...audits.sort(compareCategoryAudits)
1502
1479
  ];
1503
- const sortedRefs = category.refs.slice().sort((a, b) => {
1480
+ const sortedRefs = [...category.refs].sort((a, b) => {
1504
1481
  const aIndex = sortedAuditsAndGroups.findIndex(
1505
1482
  (ref) => ref.slug === a.slug
1506
1483
  );
@@ -1513,13 +1490,15 @@ function sortReport(report) {
1513
1490
  });
1514
1491
  const sortedPlugins = plugins.map((plugin) => ({
1515
1492
  ...plugin,
1516
- audits: plugin.audits.sort(compareAudits).map((audit) => ({
1517
- ...audit,
1518
- details: {
1519
- ...audit.details,
1520
- issues: audit?.details?.issues.slice().sort(compareIssues) || []
1521
- }
1522
- }))
1493
+ audits: [...plugin.audits].sort(compareAudits).map(
1494
+ (audit) => audit.details?.issues ? {
1495
+ ...audit,
1496
+ details: {
1497
+ ...audit.details,
1498
+ issues: [...audit.details.issues].sort(compareIssues)
1499
+ }
1500
+ } : audit
1501
+ )
1523
1502
  }));
1524
1503
  return {
1525
1504
  ...report,
@@ -1725,7 +1704,7 @@ function auditOutputsCorrelateWithPluginOutput(auditOutputs, pluginConfigAudits)
1725
1704
 
1726
1705
  // packages/core/package.json
1727
1706
  var name = "@code-pushup/core";
1728
- var version = "0.8.20";
1707
+ var version = "0.8.22";
1729
1708
 
1730
1709
  // packages/core/src/lib/implementation/collect.ts
1731
1710
  async function collect(options2) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-pushup/cli",
3
- "version": "0.8.20",
3
+ "version": "0.8.22",
4
4
  "bin": {
5
5
  "code-pushup": "index.js"
6
6
  },