@code-pushup/cli 0.8.21 → 0.8.23
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 +72 -82
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -574,13 +574,14 @@ function slugify(text) {
|
|
|
574
574
|
}
|
|
575
575
|
function formatBytes(bytes, decimals = 2) {
|
|
576
576
|
bytes = Math.max(bytes, 0);
|
|
577
|
-
if (!bytes)
|
|
577
|
+
if (!bytes) {
|
|
578
578
|
return "0 B";
|
|
579
|
+
}
|
|
579
580
|
const k = 1024;
|
|
580
581
|
const dm = decimals < 0 ? 0 : decimals;
|
|
581
582
|
const sizes = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
|
582
583
|
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
583
|
-
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
|
|
584
|
+
return `${Number.parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
|
|
584
585
|
}
|
|
585
586
|
function formatDuration(duration) {
|
|
586
587
|
if (duration < 1e3) {
|
|
@@ -617,7 +618,7 @@ function logMultipleResults(results, messagePrefix, succeededCallback, failedCal
|
|
|
617
618
|
}
|
|
618
619
|
}
|
|
619
620
|
function logPromiseResults(results, logMessage, callback) {
|
|
620
|
-
if (results.length) {
|
|
621
|
+
if (results.length > 0) {
|
|
621
622
|
if (results[0]?.status === "fulfilled") {
|
|
622
623
|
console.info(logMessage);
|
|
623
624
|
} else {
|
|
@@ -666,9 +667,8 @@ async function ensureDirectoryExists(baseDir) {
|
|
|
666
667
|
function logMultipleFileResults(fileResults, messagePrefix) {
|
|
667
668
|
const succeededCallback = (result) => {
|
|
668
669
|
const [fileName, size] = result.value;
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
);
|
|
670
|
+
const formattedSize = size ? ` (${chalk.gray(formatBytes(size))})` : "";
|
|
671
|
+
console.info(`- ${chalk.bold(fileName)}${formattedSize}`);
|
|
672
672
|
};
|
|
673
673
|
const failedCallback = (result) => {
|
|
674
674
|
console.warn(`- ${chalk.bold(result.reason)}`);
|
|
@@ -697,6 +697,7 @@ async function importEsmModule(options2) {
|
|
|
697
697
|
}
|
|
698
698
|
|
|
699
699
|
// packages/utils/src/lib/reports/constants.ts
|
|
700
|
+
var TERMINAL_WIDTH = 80;
|
|
700
701
|
var NEW_LINE = "\n";
|
|
701
702
|
var SCORE_COLOR_RANGE = {
|
|
702
703
|
GREEN_MIN: 0.9,
|
|
@@ -765,28 +766,20 @@ function getSeverityIcon(severity) {
|
|
|
765
766
|
return "\u2139\uFE0F";
|
|
766
767
|
}
|
|
767
768
|
function calcDuration(start, stop) {
|
|
768
|
-
stop
|
|
769
|
+
stop ??= performance.now();
|
|
769
770
|
return Math.floor(stop - start);
|
|
770
771
|
}
|
|
771
772
|
function countCategoryAudits(refs, plugins) {
|
|
772
773
|
const groupLookup = plugins.reduce(
|
|
773
774
|
(lookup, plugin) => {
|
|
774
|
-
if (
|
|
775
|
+
if (plugin.groups.length === 0) {
|
|
775
776
|
return lookup;
|
|
776
777
|
}
|
|
777
778
|
return {
|
|
778
779
|
...lookup,
|
|
779
|
-
[plugin.slug]:
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
return {
|
|
783
|
-
...groupLookup2,
|
|
784
|
-
[group.slug]: group
|
|
785
|
-
};
|
|
786
|
-
},
|
|
787
|
-
{}
|
|
788
|
-
)
|
|
789
|
-
}
|
|
780
|
+
[plugin.slug]: Object.fromEntries(
|
|
781
|
+
plugin.groups.map((group) => [group.slug, group])
|
|
782
|
+
)
|
|
790
783
|
};
|
|
791
784
|
},
|
|
792
785
|
{}
|
|
@@ -794,7 +787,7 @@ function countCategoryAudits(refs, plugins) {
|
|
|
794
787
|
return refs.reduce((acc, ref) => {
|
|
795
788
|
if (ref.type === "group") {
|
|
796
789
|
const groupRefs = groupLookup[ref.plugin]?.[ref.slug]?.refs;
|
|
797
|
-
return acc + (groupRefs?.length
|
|
790
|
+
return acc + (groupRefs?.length ?? 0);
|
|
798
791
|
}
|
|
799
792
|
return acc + 1;
|
|
800
793
|
}, 0);
|
|
@@ -900,7 +893,7 @@ function compareIssues(a, b) {
|
|
|
900
893
|
return 1;
|
|
901
894
|
}
|
|
902
895
|
if (a.source?.file !== b.source?.file) {
|
|
903
|
-
return a.source?.file.localeCompare(b.source?.file || "")
|
|
896
|
+
return a.source?.file.localeCompare(b.source?.file || "") ?? 0;
|
|
904
897
|
}
|
|
905
898
|
if (!a.source?.position && b.source?.position) {
|
|
906
899
|
return -1;
|
|
@@ -909,7 +902,7 @@ function compareIssues(a, b) {
|
|
|
909
902
|
return 1;
|
|
910
903
|
}
|
|
911
904
|
if (a.source?.position?.startLine !== b.source?.position?.startLine) {
|
|
912
|
-
return (a.source?.position?.startLine
|
|
905
|
+
return (a.source?.position?.startLine ?? 0) - (b.source?.position?.startLine ?? 0);
|
|
913
906
|
}
|
|
914
907
|
return 0;
|
|
915
908
|
}
|
|
@@ -927,12 +920,12 @@ var ProcessError = class extends Error {
|
|
|
927
920
|
}
|
|
928
921
|
};
|
|
929
922
|
function executeProcess(cfg) {
|
|
930
|
-
const { observer, cwd } = cfg;
|
|
931
|
-
const { onStdout, onError, onComplete } = observer
|
|
923
|
+
const { observer, cwd, command, args } = cfg;
|
|
924
|
+
const { onStdout, onError, onComplete } = observer ?? {};
|
|
932
925
|
const date = (/* @__PURE__ */ new Date()).toISOString();
|
|
933
926
|
const start = performance.now();
|
|
934
927
|
return new Promise((resolve, reject) => {
|
|
935
|
-
const process2 = spawn(
|
|
928
|
+
const process2 = spawn(command, args, { cwd, shell: true });
|
|
936
929
|
let stdout = "";
|
|
937
930
|
let stderr = "";
|
|
938
931
|
process2.stdout.on("data", (data) => {
|
|
@@ -1066,7 +1059,7 @@ function style(text, styles = ["b"]) {
|
|
|
1066
1059
|
|
|
1067
1060
|
// packages/utils/src/lib/reports/md/headline.ts
|
|
1068
1061
|
function headline(text, hierarchy = 1) {
|
|
1069
|
-
return `${
|
|
1062
|
+
return `${"#".repeat(hierarchy)} ${text}`;
|
|
1070
1063
|
}
|
|
1071
1064
|
function h2(text) {
|
|
1072
1065
|
return headline(text, 2);
|
|
@@ -1096,45 +1089,50 @@ function tableMd(data, align) {
|
|
|
1096
1089
|
if (data.length === 0) {
|
|
1097
1090
|
throw new Error("Data can't be empty");
|
|
1098
1091
|
}
|
|
1099
|
-
align
|
|
1100
|
-
const
|
|
1101
|
-
const secondRow =
|
|
1102
|
-
return
|
|
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);
|
|
1103
1096
|
}
|
|
1104
1097
|
function tableHtml(data) {
|
|
1105
1098
|
if (data.length === 0) {
|
|
1106
1099
|
throw new Error("Data can't be empty");
|
|
1107
1100
|
}
|
|
1108
|
-
const
|
|
1101
|
+
const tableContent = data.map((arr, index) => {
|
|
1109
1102
|
if (index === 0) {
|
|
1110
|
-
|
|
1103
|
+
const headerRow = arr.map((s) => `<th>${s}</th>`).join("");
|
|
1104
|
+
return `<tr>${headerRow}</tr>`;
|
|
1111
1105
|
}
|
|
1112
|
-
|
|
1106
|
+
const row = arr.map((s) => `<td>${s}</td>`).join("");
|
|
1107
|
+
return `<tr>${row}</tr>`;
|
|
1113
1108
|
});
|
|
1114
|
-
return
|
|
1109
|
+
return `<table>${tableContent.join("")}</table>`;
|
|
1115
1110
|
}
|
|
1116
1111
|
|
|
1117
1112
|
// packages/utils/src/lib/reports/generate-md-report.ts
|
|
1118
1113
|
function generateMdReport(report, commitData) {
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
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
|
+
);
|
|
1126
1124
|
}
|
|
1127
1125
|
function reportToHeaderSection() {
|
|
1128
1126
|
return headline(reportHeadlineText) + NEW_LINE;
|
|
1129
1127
|
}
|
|
1130
1128
|
function reportToOverviewSection(report) {
|
|
1131
|
-
const { categories } = report;
|
|
1129
|
+
const { categories, plugins } = report;
|
|
1132
1130
|
const tableContent = [
|
|
1133
1131
|
reportOverviewTableHeaders,
|
|
1134
1132
|
...categories.map(({ title, refs, score }) => [
|
|
1135
1133
|
link(`#${slugify(title)}`, title),
|
|
1136
1134
|
`${getRoundScoreMarker(score)} ${style(formatReportScore(score))}`,
|
|
1137
|
-
countCategoryAudits(refs,
|
|
1135
|
+
countCategoryAudits(refs, plugins).toString()
|
|
1138
1136
|
])
|
|
1139
1137
|
];
|
|
1140
1138
|
return tableMd(tableContent, ["l", "c", "c"]);
|
|
@@ -1270,7 +1268,10 @@ function reportToAboutSection(report, commitData) {
|
|
|
1270
1268
|
formatDuration(duration2)
|
|
1271
1269
|
])
|
|
1272
1270
|
];
|
|
1273
|
-
return
|
|
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
|
+
);
|
|
1274
1275
|
}
|
|
1275
1276
|
function getDocsAndDescription({
|
|
1276
1277
|
docsUrl,
|
|
@@ -1304,13 +1305,7 @@ function addLine(line = "") {
|
|
|
1304
1305
|
return line + NEW_LINE;
|
|
1305
1306
|
}
|
|
1306
1307
|
function generateStdoutSummary(report) {
|
|
1307
|
-
|
|
1308
|
-
output += addLine(reportToHeaderSection2(report));
|
|
1309
|
-
output += addLine();
|
|
1310
|
-
output += addLine(reportToDetailSection(report));
|
|
1311
|
-
output += addLine(reportToOverviewSection2(report));
|
|
1312
|
-
output += addLine(`${FOOTER_PREFIX} ${CODE_PUSHUP_DOMAIN}`);
|
|
1313
|
-
return output;
|
|
1308
|
+
return addLine(reportToHeaderSection2(report)) + addLine() + addLine(reportToDetailSection(report)) + addLine(reportToOverviewSection2(report)) + addLine(`${FOOTER_PREFIX} ${CODE_PUSHUP_DOMAIN}`);
|
|
1314
1309
|
}
|
|
1315
1310
|
function reportToHeaderSection2(report) {
|
|
1316
1311
|
const { packageName, version: version2 } = report;
|
|
@@ -1318,12 +1313,9 @@ function reportToHeaderSection2(report) {
|
|
|
1318
1313
|
}
|
|
1319
1314
|
function reportToDetailSection(report) {
|
|
1320
1315
|
const { plugins } = report;
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
output += addLine(chalk3.magentaBright.bold(`${title} audits`));
|
|
1325
|
-
output += addLine();
|
|
1326
|
-
const ui = cliui({ width: 80 });
|
|
1316
|
+
return plugins.reduce((acc, plugin) => {
|
|
1317
|
+
const { title, audits } = plugin;
|
|
1318
|
+
const ui = cliui({ width: TERMINAL_WIDTH });
|
|
1327
1319
|
audits.forEach(({ score, title: title2, displayValue, value }) => {
|
|
1328
1320
|
ui.div(
|
|
1329
1321
|
{
|
|
@@ -1333,6 +1325,7 @@ function reportToDetailSection(report) {
|
|
|
1333
1325
|
},
|
|
1334
1326
|
{
|
|
1335
1327
|
text: title2,
|
|
1328
|
+
// eslint-disable-next-line no-magic-numbers
|
|
1336
1329
|
padding: [0, 3, 0, 0]
|
|
1337
1330
|
},
|
|
1338
1331
|
{
|
|
@@ -1342,17 +1335,13 @@ function reportToDetailSection(report) {
|
|
|
1342
1335
|
}
|
|
1343
1336
|
);
|
|
1344
1337
|
});
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
});
|
|
1348
|
-
return output;
|
|
1338
|
+
return acc + addLine() + addLine(chalk3.magentaBright.bold(`${title} audits`)) + addLine() + addLine(ui.toString()) + addLine();
|
|
1339
|
+
}, "");
|
|
1349
1340
|
}
|
|
1350
1341
|
function reportToOverviewSection2({
|
|
1351
1342
|
categories,
|
|
1352
1343
|
plugins
|
|
1353
1344
|
}) {
|
|
1354
|
-
let output = addLine(chalk3.magentaBright.bold("Categories"));
|
|
1355
|
-
output += addLine();
|
|
1356
1345
|
const table = new Table({
|
|
1357
1346
|
head: reportRawOverviewTableHeaders,
|
|
1358
1347
|
colAligns: ["left", "right", "right"],
|
|
@@ -1367,8 +1356,7 @@ function reportToOverviewSection2({
|
|
|
1367
1356
|
countCategoryAudits(refs, plugins)
|
|
1368
1357
|
])
|
|
1369
1358
|
);
|
|
1370
|
-
|
|
1371
|
-
return output;
|
|
1359
|
+
return addLine(chalk3.magentaBright.bold("Categories")) + addLine() + addLine(table.toString());
|
|
1372
1360
|
}
|
|
1373
1361
|
function withColor({ score, text }) {
|
|
1374
1362
|
const formattedScore = text ?? formatReportScore(score);
|
|
@@ -1422,28 +1410,28 @@ function scoreReport(report) {
|
|
|
1422
1410
|
const scoredReport = deepClone(report);
|
|
1423
1411
|
const allScoredAuditsAndGroups = /* @__PURE__ */ new Map();
|
|
1424
1412
|
scoredReport.plugins?.forEach((plugin) => {
|
|
1425
|
-
const { audits } = plugin;
|
|
1413
|
+
const { slug, audits } = plugin;
|
|
1426
1414
|
const groups = plugin.groups || [];
|
|
1427
1415
|
audits.forEach((audit) => {
|
|
1428
|
-
const key = `${
|
|
1429
|
-
audit.plugin =
|
|
1416
|
+
const key = `${slug}-${audit.slug}-audit`;
|
|
1417
|
+
audit.plugin = slug;
|
|
1430
1418
|
allScoredAuditsAndGroups.set(key, audit);
|
|
1431
1419
|
});
|
|
1432
1420
|
function groupScoreFn(ref) {
|
|
1433
1421
|
const score = allScoredAuditsAndGroups.get(
|
|
1434
|
-
`${
|
|
1422
|
+
`${slug}-${ref.slug}-audit`
|
|
1435
1423
|
)?.score;
|
|
1436
1424
|
if (score == null) {
|
|
1437
1425
|
throw new Error(
|
|
1438
|
-
`Group has invalid ref - audit with slug ${
|
|
1426
|
+
`Group has invalid ref - audit with slug ${slug}-${ref.slug}-audit not found`
|
|
1439
1427
|
);
|
|
1440
1428
|
}
|
|
1441
1429
|
return score;
|
|
1442
1430
|
}
|
|
1443
1431
|
groups.forEach((group) => {
|
|
1444
|
-
const key = `${
|
|
1432
|
+
const key = `${slug}-${group.slug}-group`;
|
|
1445
1433
|
group.score = calculateScore(group.refs, groupScoreFn);
|
|
1446
|
-
group.plugin =
|
|
1434
|
+
group.plugin = slug;
|
|
1447
1435
|
allScoredAuditsAndGroups.set(key, group);
|
|
1448
1436
|
});
|
|
1449
1437
|
plugin.groups = groups;
|
|
@@ -1463,7 +1451,7 @@ function scoreReport(report) {
|
|
|
1463
1451
|
category.score = calculateScore(category.refs, catScoreFn);
|
|
1464
1452
|
scoredCategoriesMap.set(category.slug, category);
|
|
1465
1453
|
}
|
|
1466
|
-
scoredReport.categories =
|
|
1454
|
+
scoredReport.categories = [...scoredCategoriesMap.values()];
|
|
1467
1455
|
return scoredReport;
|
|
1468
1456
|
}
|
|
1469
1457
|
|
|
@@ -1489,7 +1477,7 @@ function sortReport(report) {
|
|
|
1489
1477
|
...groups,
|
|
1490
1478
|
...audits.sort(compareCategoryAudits)
|
|
1491
1479
|
];
|
|
1492
|
-
const sortedRefs = category.refs.
|
|
1480
|
+
const sortedRefs = [...category.refs].sort((a, b) => {
|
|
1493
1481
|
const aIndex = sortedAuditsAndGroups.findIndex(
|
|
1494
1482
|
(ref) => ref.slug === a.slug
|
|
1495
1483
|
);
|
|
@@ -1502,13 +1490,15 @@ function sortReport(report) {
|
|
|
1502
1490
|
});
|
|
1503
1491
|
const sortedPlugins = plugins.map((plugin) => ({
|
|
1504
1492
|
...plugin,
|
|
1505
|
-
audits: plugin.audits.sort(compareAudits).map(
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
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
|
+
)
|
|
1512
1502
|
}));
|
|
1513
1503
|
return {
|
|
1514
1504
|
...report,
|
|
@@ -1714,7 +1704,7 @@ function auditOutputsCorrelateWithPluginOutput(auditOutputs, pluginConfigAudits)
|
|
|
1714
1704
|
|
|
1715
1705
|
// packages/core/package.json
|
|
1716
1706
|
var name = "@code-pushup/core";
|
|
1717
|
-
var version = "0.8.
|
|
1707
|
+
var version = "0.8.23";
|
|
1718
1708
|
|
|
1719
1709
|
// packages/core/src/lib/implementation/collect.ts
|
|
1720
1710
|
async function collect(options2) {
|