@code-pushup/coverage-plugin 0.47.0 → 0.49.0

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/bin.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // packages/plugin-coverage/src/lib/runner/index.ts
2
- import chalk5 from "chalk";
2
+ import { bold as bold5 } from "ansis";
3
3
  import { writeFile } from "node:fs/promises";
4
4
  import { dirname } from "node:path";
5
5
 
@@ -701,21 +701,73 @@ var reportsDiffSchema = z15.object({
701
701
  // packages/utils/src/lib/execute-process.ts
702
702
  import { spawn } from "node:child_process";
703
703
 
704
+ // packages/utils/src/lib/reports/utils.ts
705
+ import ansis from "ansis";
706
+ import { md } from "build-md";
707
+
708
+ // packages/utils/src/lib/reports/constants.ts
709
+ var TERMINAL_WIDTH = 80;
710
+
711
+ // packages/utils/src/lib/reports/utils.ts
712
+ function calcDuration(start, stop) {
713
+ return Math.round((stop ?? performance.now()) - start);
714
+ }
715
+
716
+ // packages/utils/src/lib/execute-process.ts
717
+ var ProcessError = class extends Error {
718
+ code;
719
+ stderr;
720
+ stdout;
721
+ constructor(result) {
722
+ super(result.stderr);
723
+ this.code = result.code;
724
+ this.stderr = result.stderr;
725
+ this.stdout = result.stdout;
726
+ }
727
+ };
728
+ function executeProcess(cfg) {
729
+ const { observer, cwd, command, args, ignoreExitCode = false } = cfg;
730
+ const { onStdout, onError, onComplete } = observer ?? {};
731
+ const date = (/* @__PURE__ */ new Date()).toISOString();
732
+ const start = performance.now();
733
+ return new Promise((resolve, reject) => {
734
+ const process2 = spawn(command, args, { cwd, shell: true });
735
+ let stdout = "";
736
+ let stderr = "";
737
+ process2.stdout.on("data", (data) => {
738
+ stdout += String(data);
739
+ onStdout?.(String(data));
740
+ });
741
+ process2.stderr.on("data", (data) => {
742
+ stderr += String(data);
743
+ });
744
+ process2.on("error", (err) => {
745
+ stderr += err.toString();
746
+ });
747
+ process2.on("close", (code2) => {
748
+ const timings = { date, duration: calcDuration(start) };
749
+ if (code2 === 0 || ignoreExitCode) {
750
+ onComplete?.();
751
+ resolve({ code: code2, stdout, stderr, ...timings });
752
+ } else {
753
+ const errorMsg = new ProcessError({ code: code2, stdout, stderr, ...timings });
754
+ onError?.(errorMsg);
755
+ reject(errorMsg);
756
+ }
757
+ });
758
+ });
759
+ }
760
+
704
761
  // packages/utils/src/lib/file-system.ts
762
+ import { bold, gray } from "ansis";
705
763
  import { bundleRequire } from "bundle-require";
706
- import chalk2 from "chalk";
707
764
  import { mkdir, readFile, readdir, rm, stat } from "node:fs/promises";
708
765
  import { join } from "node:path";
709
766
 
710
767
  // packages/utils/src/lib/logging.ts
711
768
  import isaacs_cliui from "@isaacs/cliui";
712
769
  import { cliui } from "@poppinss/cliui";
713
- import chalk from "chalk";
714
-
715
- // packages/utils/src/lib/reports/constants.ts
716
- var TERMINAL_WIDTH = 80;
717
-
718
- // packages/utils/src/lib/logging.ts
770
+ import { underline } from "ansis";
719
771
  var singletonUiInstance;
720
772
  function ui() {
721
773
  if (singletonUiInstance === void 0) {
@@ -763,48 +815,14 @@ function pluginWorkDir(slug) {
763
815
  return join("node_modules", ".code-pushup", slug);
764
816
  }
765
817
 
766
- // packages/utils/src/lib/text-formats/constants.ts
767
- var NEW_LINE = "\n";
768
- var TAB = " ";
769
-
770
- // packages/utils/src/lib/text-formats/html/details.ts
771
- function details(title, content, cfg = { open: false }) {
772
- return `<details${cfg.open ? " open" : ""}>${NEW_LINE}<summary>${title}</summary>${NEW_LINE}${// ⚠️ The blank line is needed to ensure Markdown in content is rendered correctly.
773
- NEW_LINE}${content}${NEW_LINE}${// @TODO in the future we could consider adding it only if the content ends with a code block
774
- // ⚠️ The blank line ensure Markdown in content is rendered correctly.
775
- NEW_LINE}</details>${// ⚠️ The blank line is needed to ensure Markdown after details is rendered correctly.
776
- NEW_LINE}`;
777
- }
778
-
779
- // packages/utils/src/lib/text-formats/html/font-style.ts
780
- var boldElement = "b";
781
- function bold(text) {
782
- return `<${boldElement}>${text}</${boldElement}>`;
783
- }
784
- var italicElement = "i";
785
- function italic(text) {
786
- return `<${italicElement}>${text}</${italicElement}>`;
787
- }
788
- var codeElement = "code";
789
- function code(text) {
790
- return `<${codeElement}>${text}</${codeElement}>`;
791
- }
792
-
793
- // packages/utils/src/lib/text-formats/html/link.ts
794
- function link(href, text) {
795
- return `<a href="${href}">${text || href}</a>`;
796
- }
818
+ // packages/utils/src/lib/git/git.ts
819
+ import { simpleGit } from "simple-git";
797
820
 
798
821
  // packages/utils/src/lib/transform.ts
799
822
  import { platform } from "node:os";
800
823
  function toUnixNewlines(text) {
801
824
  return platform() === "win32" ? text.replace(/\r\n/g, "\n") : text;
802
825
  }
803
- function capitalize(text) {
804
- return `${text.charAt(0).toLocaleUpperCase()}${text.slice(
805
- 1
806
- )}`;
807
- }
808
826
  function toNumberPrecision(value, decimalPlaces) {
809
827
  return Number(
810
828
  `${Math.round(
@@ -825,306 +843,6 @@ function toOrdinal(value) {
825
843
  return `${value}th`;
826
844
  }
827
845
 
828
- // packages/utils/src/lib/text-formats/table.ts
829
- function rowToStringArray({ rows, columns = [] }) {
830
- if (Array.isArray(rows.at(0)) && typeof columns.at(0) === "object") {
831
- throw new TypeError(
832
- "Column can`t be object when rows are primitive values"
833
- );
834
- }
835
- return rows.map((row) => {
836
- if (Array.isArray(row)) {
837
- return row.map(String);
838
- }
839
- const objectRow = row;
840
- if (columns.length === 0 || typeof columns.at(0) === "string") {
841
- return Object.values(objectRow).map(
842
- (value) => value == null ? "" : String(value)
843
- );
844
- }
845
- return columns.map(
846
- ({ key }) => objectRow[key] == null ? "" : String(objectRow[key])
847
- );
848
- });
849
- }
850
- function columnsToStringArray({
851
- rows,
852
- columns = []
853
- }) {
854
- const firstRow = rows.at(0);
855
- const primitiveRows = Array.isArray(firstRow);
856
- if (typeof columns.at(0) === "string" && !primitiveRows) {
857
- throw new Error("invalid union type. Caught by model parsing.");
858
- }
859
- if (columns.length === 0) {
860
- if (Array.isArray(firstRow)) {
861
- return firstRow.map((_, idx) => String(idx));
862
- }
863
- return Object.keys(firstRow);
864
- }
865
- if (typeof columns.at(0) === "string") {
866
- return columns.map(String);
867
- }
868
- const cols = columns;
869
- return cols.map(({ label, key }) => label ?? capitalize(key));
870
- }
871
- function getColumnAlignmentForKeyAndIndex(targetKey, targetIdx, columns = []) {
872
- const column = columns.at(targetIdx) ?? columns.find((col) => col.key === targetKey);
873
- if (typeof column === "string") {
874
- return column;
875
- } else if (typeof column === "object") {
876
- return column.align ?? "center";
877
- } else {
878
- return "center";
879
- }
880
- }
881
- function getColumnAlignmentForIndex(targetIdx, columns = []) {
882
- const column = columns.at(targetIdx);
883
- if (column == null) {
884
- return "center";
885
- } else if (typeof column === "string") {
886
- return column;
887
- } else if (typeof column === "object") {
888
- return column.align ?? "center";
889
- } else {
890
- return "center";
891
- }
892
- }
893
- function getColumnAlignments(tableData) {
894
- const { rows, columns = [] } = tableData;
895
- if (rows.at(0) == null) {
896
- throw new Error("first row can`t be undefined.");
897
- }
898
- if (Array.isArray(rows.at(0))) {
899
- const firstPrimitiveRow = rows.at(0);
900
- return Array.from({ length: firstPrimitiveRow.length }).map(
901
- (_, idx) => getColumnAlignmentForIndex(idx, columns)
902
- );
903
- }
904
- const biggestRow = [...rows].sort((a, b) => Object.keys(a).length - Object.keys(b).length).at(-1);
905
- if (columns.length > 0) {
906
- return columns.map(
907
- (column, idx) => typeof column === "string" ? column : getColumnAlignmentForKeyAndIndex(
908
- column.key,
909
- idx,
910
- columns
911
- )
912
- );
913
- }
914
- return Object.keys(biggestRow ?? {}).map((_) => "center");
915
- }
916
-
917
- // packages/utils/src/lib/text-formats/html/table.ts
918
- function wrap(elem, content) {
919
- return `<${elem}>${content}</${elem}>${NEW_LINE}`;
920
- }
921
- function wrapRow(content) {
922
- const elem = "tr";
923
- return `<${elem}>${NEW_LINE}${content}</${elem}>${NEW_LINE}`;
924
- }
925
- function table(tableData) {
926
- if (tableData.rows.length === 0) {
927
- throw new Error("Data can't be empty");
928
- }
929
- const tableHeaderCols = columnsToStringArray(tableData).map((s) => wrap("th", s)).join("");
930
- const tableHeaderRow = wrapRow(tableHeaderCols);
931
- const tableBody = rowToStringArray(tableData).map((arr) => {
932
- const columns = arr.map((s) => wrap("td", s)).join("");
933
- return wrapRow(columns);
934
- }).join("");
935
- return wrap("table", `${NEW_LINE}${tableHeaderRow}${tableBody}`);
936
- }
937
-
938
- // packages/utils/src/lib/text-formats/md/font-style.ts
939
- var boldWrap = "**";
940
- function bold2(text) {
941
- return `${boldWrap}${text}${boldWrap}`;
942
- }
943
- var italicWrap = "_";
944
- function italic2(text) {
945
- return `${italicWrap}${text}${italicWrap}`;
946
- }
947
- var strikeThroughWrap = "~";
948
- function strikeThrough(text) {
949
- return `${strikeThroughWrap}${text}${strikeThroughWrap}`;
950
- }
951
- var codeWrap = "`";
952
- function code2(text) {
953
- return `${codeWrap}${text}${codeWrap}`;
954
- }
955
-
956
- // packages/utils/src/lib/text-formats/md/headline.ts
957
- function headline(text, hierarchy = 1) {
958
- return `${"#".repeat(hierarchy)} ${text}${NEW_LINE}`;
959
- }
960
- function h(text, hierarchy = 1) {
961
- return headline(text, hierarchy);
962
- }
963
- function h1(text) {
964
- return headline(text, 1);
965
- }
966
- function h2(text) {
967
- return headline(text, 2);
968
- }
969
- function h3(text) {
970
- return headline(text, 3);
971
- }
972
- function h4(text) {
973
- return headline(text, 4);
974
- }
975
- function h5(text) {
976
- return headline(text, 5);
977
- }
978
- function h6(text) {
979
- return headline(text, 6);
980
- }
981
-
982
- // packages/utils/src/lib/text-formats/md/image.ts
983
- function image(src, alt) {
984
- return `![${alt}](${src})`;
985
- }
986
-
987
- // packages/utils/src/lib/text-formats/md/link.ts
988
- function link2(href, text) {
989
- return `[${text || href}](${href})`;
990
- }
991
-
992
- // packages/utils/src/lib/text-formats/md/list.ts
993
- function li(text, order = "unordered") {
994
- const style = order === "unordered" ? "-" : "- [ ]";
995
- return `${style} ${text}`;
996
- }
997
- function indentation(text, level = 1) {
998
- return `${TAB.repeat(level)}${text}`;
999
- }
1000
-
1001
- // packages/utils/src/lib/text-formats/md/paragraphs.ts
1002
- function paragraphs(...sections) {
1003
- return sections.filter(Boolean).join(`${NEW_LINE}${NEW_LINE}`);
1004
- }
1005
-
1006
- // packages/utils/src/lib/text-formats/md/section.ts
1007
- function section(...contents) {
1008
- return `${lines(...contents)}${NEW_LINE}`;
1009
- }
1010
- function lines(...contents) {
1011
- const filteredContent = contents.filter(
1012
- (value) => value != null && value !== "" && value !== false
1013
- );
1014
- return `${filteredContent.join(NEW_LINE)}`;
1015
- }
1016
-
1017
- // packages/utils/src/lib/text-formats/md/table.ts
1018
- var alignString = /* @__PURE__ */ new Map([
1019
- ["left", ":--"],
1020
- ["center", ":--:"],
1021
- ["right", "--:"]
1022
- ]);
1023
- function tableRow(rows) {
1024
- return `|${rows.join("|")}|`;
1025
- }
1026
- function table2(data) {
1027
- if (data.rows.length === 0) {
1028
- throw new Error("Data can't be empty");
1029
- }
1030
- const alignmentRow = getColumnAlignments(data).map(
1031
- (s) => alignString.get(s) ?? String(alignString.get("center"))
1032
- );
1033
- return section(
1034
- `${lines(
1035
- tableRow(columnsToStringArray(data)),
1036
- tableRow(alignmentRow),
1037
- ...rowToStringArray(data).map(tableRow)
1038
- )}`
1039
- );
1040
- }
1041
-
1042
- // packages/utils/src/lib/text-formats/index.ts
1043
- var md = {
1044
- bold: bold2,
1045
- italic: italic2,
1046
- strikeThrough,
1047
- code: code2,
1048
- link: link2,
1049
- image,
1050
- headline,
1051
- h,
1052
- h1,
1053
- h2,
1054
- h3,
1055
- h4,
1056
- h5,
1057
- h6,
1058
- indentation,
1059
- lines,
1060
- li,
1061
- section,
1062
- paragraphs,
1063
- table: table2
1064
- };
1065
- var html = {
1066
- bold,
1067
- italic,
1068
- code,
1069
- link,
1070
- details,
1071
- table
1072
- };
1073
-
1074
- // packages/utils/src/lib/reports/utils.ts
1075
- var { image: image2, bold: boldMd } = md;
1076
- function calcDuration(start, stop) {
1077
- return Math.round((stop ?? performance.now()) - start);
1078
- }
1079
-
1080
- // packages/utils/src/lib/execute-process.ts
1081
- var ProcessError = class extends Error {
1082
- code;
1083
- stderr;
1084
- stdout;
1085
- constructor(result) {
1086
- super(result.stderr);
1087
- this.code = result.code;
1088
- this.stderr = result.stderr;
1089
- this.stdout = result.stdout;
1090
- }
1091
- };
1092
- function executeProcess(cfg) {
1093
- const { observer, cwd, command, args, ignoreExitCode = false } = cfg;
1094
- const { onStdout, onError, onComplete } = observer ?? {};
1095
- const date = (/* @__PURE__ */ new Date()).toISOString();
1096
- const start = performance.now();
1097
- return new Promise((resolve, reject) => {
1098
- const process2 = spawn(command, args, { cwd, shell: true });
1099
- let stdout = "";
1100
- let stderr = "";
1101
- process2.stdout.on("data", (data) => {
1102
- stdout += String(data);
1103
- onStdout?.(String(data));
1104
- });
1105
- process2.stderr.on("data", (data) => {
1106
- stderr += String(data);
1107
- });
1108
- process2.on("error", (err) => {
1109
- stderr += err.toString();
1110
- });
1111
- process2.on("close", (code3) => {
1112
- const timings = { date, duration: calcDuration(start) };
1113
- if (code3 === 0 || ignoreExitCode) {
1114
- onComplete?.();
1115
- resolve({ code: code3, stdout, stderr, ...timings });
1116
- } else {
1117
- const errorMsg = new ProcessError({ code: code3, stdout, stderr, ...timings });
1118
- onError?.(errorMsg);
1119
- reject(errorMsg);
1120
- }
1121
- });
1122
- });
1123
- }
1124
-
1125
- // packages/utils/src/lib/git/git.ts
1126
- import { simpleGit } from "simple-git";
1127
-
1128
846
  // packages/utils/src/lib/git/git.commits-and-tags.ts
1129
847
  import { simpleGit as simpleGit2 } from "simple-git";
1130
848
 
@@ -1132,34 +850,26 @@ import { simpleGit as simpleGit2 } from "simple-git";
1132
850
  import { rcompare, valid } from "semver";
1133
851
 
1134
852
  // packages/utils/src/lib/progress.ts
1135
- import chalk3 from "chalk";
853
+ import { black, bold as bold2, gray as gray2, green } from "ansis";
1136
854
  import { MultiProgressBars } from "multi-progress-bars";
1137
855
 
856
+ // packages/utils/src/lib/reports/generate-md-report.ts
857
+ import { MarkdownDocument as MarkdownDocument3, md as md4 } from "build-md";
858
+
1138
859
  // packages/utils/src/lib/reports/formatting.ts
1139
- var { headline: headline2, lines: lines2, link: link3, section: section2, table: table3 } = md;
860
+ import { MarkdownDocument, md as md2 } from "build-md";
1140
861
 
1141
862
  // packages/utils/src/lib/reports/generate-md-report-categoy-section.ts
1142
- var { link: link4, section: section3, h2: h22, lines: lines3, li: li2, bold: boldMd2, h3: h32, indentation: indentation2 } = md;
1143
-
1144
- // packages/utils/src/lib/reports/generate-md-report.ts
1145
- var { h1: h12, h2: h23, h3: h33, lines: lines4, link: link5, section: section4, code: codeMd } = md;
1146
- var { bold: boldHtml, details: details2 } = html;
863
+ import { MarkdownDocument as MarkdownDocument2, md as md3 } from "build-md";
1147
864
 
1148
865
  // packages/utils/src/lib/reports/generate-md-reports-diff.ts
1149
- var {
1150
- h1: h13,
1151
- h2: h24,
1152
- lines: lines5,
1153
- link: link6,
1154
- bold: boldMd3,
1155
- italic: italicMd,
1156
- table: table4,
1157
- section: section5
1158
- } = md;
1159
- var { details: details3 } = html;
866
+ import {
867
+ MarkdownDocument as MarkdownDocument4,
868
+ md as md5
869
+ } from "build-md";
1160
870
 
1161
871
  // packages/utils/src/lib/reports/log-stdout-summary.ts
1162
- import chalk4 from "chalk";
872
+ import { bold as bold4, cyan, cyanBright, green as green2, red } from "ansis";
1163
873
 
1164
874
  // packages/plugin-coverage/src/lib/runner/constants.ts
1165
875
  import { join as join2 } from "node:path";
@@ -1183,10 +893,10 @@ function mergeLcovResults(records) {
1183
893
  }
1184
894
  return records.reduce((accMerged, currRecord, currIndex) => {
1185
895
  const filePath = currRecord.file;
1186
- const lines6 = currRecord.lines.found;
896
+ const lines = currRecord.lines.found;
1187
897
  const duplicates = records.reduce(
1188
898
  (acc, candidateRecord, candidateIndex) => {
1189
- if (candidateRecord.file === filePath && candidateRecord.lines.found === lines6 && candidateIndex !== currIndex) {
899
+ if (candidateRecord.file === filePath && candidateRecord.lines.found === lines && candidateIndex !== currIndex) {
1190
900
  return [...acc, [candidateRecord, candidateIndex]];
1191
901
  }
1192
902
  return acc;
@@ -1253,8 +963,8 @@ function mergeDuplicateLcovRecords(records) {
1253
963
  };
1254
964
  return mergedRecord;
1255
965
  }
1256
- function mergeLcovLineDetails(details4) {
1257
- const flatDetails = details4.flat();
966
+ function mergeLcovLineDetails(details2) {
967
+ const flatDetails = details2.flat();
1258
968
  const uniqueLines = [
1259
969
  ...new Set(flatDetails.map((flatDetail) => flatDetail.line))
1260
970
  ];
@@ -1263,8 +973,8 @@ function mergeLcovLineDetails(details4) {
1263
973
  return { line, hit: hitSum };
1264
974
  });
1265
975
  }
1266
- function mergeLcovBranchesDetails(details4) {
1267
- const flatDetails = details4.flat();
976
+ function mergeLcovBranchesDetails(details2) {
977
+ const flatDetails = details2.flat();
1268
978
  const uniqueBranches = [
1269
979
  ...new Set(
1270
980
  flatDetails.map(
@@ -1281,8 +991,8 @@ function mergeLcovBranchesDetails(details4) {
1281
991
  return { line, block, branch, taken: takenSum };
1282
992
  });
1283
993
  }
1284
- function mergeLcovFunctionsDetails(details4) {
1285
- const flatDetails = details4.flat();
994
+ function mergeLcovFunctionsDetails(details2) {
995
+ const flatDetails = details2.flat();
1286
996
  const uniqueFunctions = [
1287
997
  ...new Set(
1288
998
  flatDetails.map(({ line, name }) => JSON.stringify({ line, name }))
@@ -1359,8 +1069,8 @@ function removeEmptyReport(record) {
1359
1069
  }
1360
1070
  function lcovReportToLineStat(record) {
1361
1071
  const missingCoverage = record.lines.hit < record.lines.found;
1362
- const lines6 = missingCoverage ? record.lines.details.filter((detail) => !detail.hit).map((detail) => detail.line) : [];
1363
- const linePositions = mergeConsecutiveNumbers(lines6);
1072
+ const lines = missingCoverage ? record.lines.details.filter((detail) => !detail.hit).map((detail) => detail.line) : [];
1073
+ const linePositions = mergeConsecutiveNumbers(lines);
1364
1074
  return {
1365
1075
  totalFound: record.lines.found,
1366
1076
  totalHit: record.lines.hit,
@@ -1496,13 +1206,9 @@ async function executeRunner() {
1496
1206
  await executeProcess({ command, args });
1497
1207
  } catch (error) {
1498
1208
  if (error instanceof ProcessError) {
1499
- ui().logger.error(
1500
- chalk5.bold("stdout from failed coverage tool process:")
1501
- );
1209
+ ui().logger.error(bold5("stdout from failed coverage tool process:"));
1502
1210
  ui().logger.error(error.stdout);
1503
- ui().logger.error(
1504
- chalk5.bold("stderr from failed coverage tool process:")
1505
- );
1211
+ ui().logger.error(bold5("stderr from failed coverage tool process:"));
1506
1212
  ui().logger.error(error.stderr);
1507
1213
  }
1508
1214
  throw new Error(
package/index.js CHANGED
@@ -697,21 +697,23 @@ var reportsDiffSchema = z15.object({
697
697
  })
698
698
  );
699
699
 
700
+ // packages/utils/src/lib/reports/utils.ts
701
+ import ansis from "ansis";
702
+ import { md } from "build-md";
703
+
704
+ // packages/utils/src/lib/reports/constants.ts
705
+ var TERMINAL_WIDTH = 80;
706
+
700
707
  // packages/utils/src/lib/file-system.ts
708
+ import { bold, gray } from "ansis";
701
709
  import { bundleRequire } from "bundle-require";
702
- import chalk2 from "chalk";
703
710
  import { mkdir, readFile, readdir, rm, stat } from "node:fs/promises";
704
711
  import { join } from "node:path";
705
712
 
706
713
  // packages/utils/src/lib/logging.ts
707
714
  import isaacs_cliui from "@isaacs/cliui";
708
715
  import { cliui } from "@poppinss/cliui";
709
- import chalk from "chalk";
710
-
711
- // packages/utils/src/lib/reports/constants.ts
712
- var TERMINAL_WIDTH = 80;
713
-
714
- // packages/utils/src/lib/logging.ts
716
+ import { underline } from "ansis";
715
717
  var singletonUiInstance;
716
718
  function ui() {
717
719
  if (singletonUiInstance === void 0) {
@@ -761,37 +763,8 @@ function filePathToCliArg(path) {
761
763
  return `"${path}"`;
762
764
  }
763
765
 
764
- // packages/utils/src/lib/text-formats/constants.ts
765
- var NEW_LINE = "\n";
766
- var TAB = " ";
767
-
768
- // packages/utils/src/lib/text-formats/html/details.ts
769
- function details(title, content, cfg = { open: false }) {
770
- return `<details${cfg.open ? " open" : ""}>${NEW_LINE}<summary>${title}</summary>${NEW_LINE}${// ⚠️ The blank line is needed to ensure Markdown in content is rendered correctly.
771
- NEW_LINE}${content}${NEW_LINE}${// @TODO in the future we could consider adding it only if the content ends with a code block
772
- // ⚠️ The blank line ensure Markdown in content is rendered correctly.
773
- NEW_LINE}</details>${// ⚠️ The blank line is needed to ensure Markdown after details is rendered correctly.
774
- NEW_LINE}`;
775
- }
776
-
777
- // packages/utils/src/lib/text-formats/html/font-style.ts
778
- var boldElement = "b";
779
- function bold(text) {
780
- return `<${boldElement}>${text}</${boldElement}>`;
781
- }
782
- var italicElement = "i";
783
- function italic(text) {
784
- return `<${italicElement}>${text}</${italicElement}>`;
785
- }
786
- var codeElement = "code";
787
- function code(text) {
788
- return `<${codeElement}>${text}</${codeElement}>`;
789
- }
790
-
791
- // packages/utils/src/lib/text-formats/html/link.ts
792
- function link(href, text) {
793
- return `<a href="${href}">${text || href}</a>`;
794
- }
766
+ // packages/utils/src/lib/git/git.ts
767
+ import { simpleGit } from "simple-git";
795
768
 
796
769
  // packages/utils/src/lib/transform.ts
797
770
  function capitalize(text) {
@@ -800,258 +773,6 @@ function capitalize(text) {
800
773
  )}`;
801
774
  }
802
775
 
803
- // packages/utils/src/lib/text-formats/table.ts
804
- function rowToStringArray({ rows, columns = [] }) {
805
- if (Array.isArray(rows.at(0)) && typeof columns.at(0) === "object") {
806
- throw new TypeError(
807
- "Column can`t be object when rows are primitive values"
808
- );
809
- }
810
- return rows.map((row) => {
811
- if (Array.isArray(row)) {
812
- return row.map(String);
813
- }
814
- const objectRow = row;
815
- if (columns.length === 0 || typeof columns.at(0) === "string") {
816
- return Object.values(objectRow).map(
817
- (value) => value == null ? "" : String(value)
818
- );
819
- }
820
- return columns.map(
821
- ({ key }) => objectRow[key] == null ? "" : String(objectRow[key])
822
- );
823
- });
824
- }
825
- function columnsToStringArray({
826
- rows,
827
- columns = []
828
- }) {
829
- const firstRow = rows.at(0);
830
- const primitiveRows = Array.isArray(firstRow);
831
- if (typeof columns.at(0) === "string" && !primitiveRows) {
832
- throw new Error("invalid union type. Caught by model parsing.");
833
- }
834
- if (columns.length === 0) {
835
- if (Array.isArray(firstRow)) {
836
- return firstRow.map((_, idx) => String(idx));
837
- }
838
- return Object.keys(firstRow);
839
- }
840
- if (typeof columns.at(0) === "string") {
841
- return columns.map(String);
842
- }
843
- const cols = columns;
844
- return cols.map(({ label, key }) => label ?? capitalize(key));
845
- }
846
- function getColumnAlignmentForKeyAndIndex(targetKey, targetIdx, columns = []) {
847
- const column = columns.at(targetIdx) ?? columns.find((col) => col.key === targetKey);
848
- if (typeof column === "string") {
849
- return column;
850
- } else if (typeof column === "object") {
851
- return column.align ?? "center";
852
- } else {
853
- return "center";
854
- }
855
- }
856
- function getColumnAlignmentForIndex(targetIdx, columns = []) {
857
- const column = columns.at(targetIdx);
858
- if (column == null) {
859
- return "center";
860
- } else if (typeof column === "string") {
861
- return column;
862
- } else if (typeof column === "object") {
863
- return column.align ?? "center";
864
- } else {
865
- return "center";
866
- }
867
- }
868
- function getColumnAlignments(tableData) {
869
- const { rows, columns = [] } = tableData;
870
- if (rows.at(0) == null) {
871
- throw new Error("first row can`t be undefined.");
872
- }
873
- if (Array.isArray(rows.at(0))) {
874
- const firstPrimitiveRow = rows.at(0);
875
- return Array.from({ length: firstPrimitiveRow.length }).map(
876
- (_, idx) => getColumnAlignmentForIndex(idx, columns)
877
- );
878
- }
879
- const biggestRow = [...rows].sort((a, b) => Object.keys(a).length - Object.keys(b).length).at(-1);
880
- if (columns.length > 0) {
881
- return columns.map(
882
- (column, idx) => typeof column === "string" ? column : getColumnAlignmentForKeyAndIndex(
883
- column.key,
884
- idx,
885
- columns
886
- )
887
- );
888
- }
889
- return Object.keys(biggestRow ?? {}).map((_) => "center");
890
- }
891
-
892
- // packages/utils/src/lib/text-formats/html/table.ts
893
- function wrap(elem, content) {
894
- return `<${elem}>${content}</${elem}>${NEW_LINE}`;
895
- }
896
- function wrapRow(content) {
897
- const elem = "tr";
898
- return `<${elem}>${NEW_LINE}${content}</${elem}>${NEW_LINE}`;
899
- }
900
- function table(tableData) {
901
- if (tableData.rows.length === 0) {
902
- throw new Error("Data can't be empty");
903
- }
904
- const tableHeaderCols = columnsToStringArray(tableData).map((s) => wrap("th", s)).join("");
905
- const tableHeaderRow = wrapRow(tableHeaderCols);
906
- const tableBody = rowToStringArray(tableData).map((arr) => {
907
- const columns = arr.map((s) => wrap("td", s)).join("");
908
- return wrapRow(columns);
909
- }).join("");
910
- return wrap("table", `${NEW_LINE}${tableHeaderRow}${tableBody}`);
911
- }
912
-
913
- // packages/utils/src/lib/text-formats/md/font-style.ts
914
- var boldWrap = "**";
915
- function bold2(text) {
916
- return `${boldWrap}${text}${boldWrap}`;
917
- }
918
- var italicWrap = "_";
919
- function italic2(text) {
920
- return `${italicWrap}${text}${italicWrap}`;
921
- }
922
- var strikeThroughWrap = "~";
923
- function strikeThrough(text) {
924
- return `${strikeThroughWrap}${text}${strikeThroughWrap}`;
925
- }
926
- var codeWrap = "`";
927
- function code2(text) {
928
- return `${codeWrap}${text}${codeWrap}`;
929
- }
930
-
931
- // packages/utils/src/lib/text-formats/md/headline.ts
932
- function headline(text, hierarchy = 1) {
933
- return `${"#".repeat(hierarchy)} ${text}${NEW_LINE}`;
934
- }
935
- function h(text, hierarchy = 1) {
936
- return headline(text, hierarchy);
937
- }
938
- function h1(text) {
939
- return headline(text, 1);
940
- }
941
- function h2(text) {
942
- return headline(text, 2);
943
- }
944
- function h3(text) {
945
- return headline(text, 3);
946
- }
947
- function h4(text) {
948
- return headline(text, 4);
949
- }
950
- function h5(text) {
951
- return headline(text, 5);
952
- }
953
- function h6(text) {
954
- return headline(text, 6);
955
- }
956
-
957
- // packages/utils/src/lib/text-formats/md/image.ts
958
- function image(src, alt) {
959
- return `![${alt}](${src})`;
960
- }
961
-
962
- // packages/utils/src/lib/text-formats/md/link.ts
963
- function link2(href, text) {
964
- return `[${text || href}](${href})`;
965
- }
966
-
967
- // packages/utils/src/lib/text-formats/md/list.ts
968
- function li(text, order = "unordered") {
969
- const style = order === "unordered" ? "-" : "- [ ]";
970
- return `${style} ${text}`;
971
- }
972
- function indentation(text, level = 1) {
973
- return `${TAB.repeat(level)}${text}`;
974
- }
975
-
976
- // packages/utils/src/lib/text-formats/md/paragraphs.ts
977
- function paragraphs(...sections) {
978
- return sections.filter(Boolean).join(`${NEW_LINE}${NEW_LINE}`);
979
- }
980
-
981
- // packages/utils/src/lib/text-formats/md/section.ts
982
- function section(...contents) {
983
- return `${lines(...contents)}${NEW_LINE}`;
984
- }
985
- function lines(...contents) {
986
- const filteredContent = contents.filter(
987
- (value) => value != null && value !== "" && value !== false
988
- );
989
- return `${filteredContent.join(NEW_LINE)}`;
990
- }
991
-
992
- // packages/utils/src/lib/text-formats/md/table.ts
993
- var alignString = /* @__PURE__ */ new Map([
994
- ["left", ":--"],
995
- ["center", ":--:"],
996
- ["right", "--:"]
997
- ]);
998
- function tableRow(rows) {
999
- return `|${rows.join("|")}|`;
1000
- }
1001
- function table2(data) {
1002
- if (data.rows.length === 0) {
1003
- throw new Error("Data can't be empty");
1004
- }
1005
- const alignmentRow = getColumnAlignments(data).map(
1006
- (s) => alignString.get(s) ?? String(alignString.get("center"))
1007
- );
1008
- return section(
1009
- `${lines(
1010
- tableRow(columnsToStringArray(data)),
1011
- tableRow(alignmentRow),
1012
- ...rowToStringArray(data).map(tableRow)
1013
- )}`
1014
- );
1015
- }
1016
-
1017
- // packages/utils/src/lib/text-formats/index.ts
1018
- var md = {
1019
- bold: bold2,
1020
- italic: italic2,
1021
- strikeThrough,
1022
- code: code2,
1023
- link: link2,
1024
- image,
1025
- headline,
1026
- h,
1027
- h1,
1028
- h2,
1029
- h3,
1030
- h4,
1031
- h5,
1032
- h6,
1033
- indentation,
1034
- lines,
1035
- li,
1036
- section,
1037
- paragraphs,
1038
- table: table2
1039
- };
1040
- var html = {
1041
- bold,
1042
- italic,
1043
- code,
1044
- link,
1045
- details,
1046
- table
1047
- };
1048
-
1049
- // packages/utils/src/lib/reports/utils.ts
1050
- var { image: image2, bold: boldMd } = md;
1051
-
1052
- // packages/utils/src/lib/git/git.ts
1053
- import { simpleGit } from "simple-git";
1054
-
1055
776
  // packages/utils/src/lib/git/git.commits-and-tags.ts
1056
777
  import { simpleGit as simpleGit2 } from "simple-git";
1057
778
 
@@ -1059,38 +780,30 @@ import { simpleGit as simpleGit2 } from "simple-git";
1059
780
  import { rcompare, valid } from "semver";
1060
781
 
1061
782
  // packages/utils/src/lib/progress.ts
1062
- import chalk3 from "chalk";
783
+ import { black, bold as bold2, gray as gray2, green } from "ansis";
1063
784
  import { MultiProgressBars } from "multi-progress-bars";
1064
785
 
786
+ // packages/utils/src/lib/reports/generate-md-report.ts
787
+ import { MarkdownDocument as MarkdownDocument3, md as md4 } from "build-md";
788
+
1065
789
  // packages/utils/src/lib/reports/formatting.ts
1066
- var { headline: headline2, lines: lines2, link: link3, section: section2, table: table3 } = md;
790
+ import { MarkdownDocument, md as md2 } from "build-md";
1067
791
 
1068
792
  // packages/utils/src/lib/reports/generate-md-report-categoy-section.ts
1069
- var { link: link4, section: section3, h2: h22, lines: lines3, li: li2, bold: boldMd2, h3: h32, indentation: indentation2 } = md;
1070
-
1071
- // packages/utils/src/lib/reports/generate-md-report.ts
1072
- var { h1: h12, h2: h23, h3: h33, lines: lines4, link: link5, section: section4, code: codeMd } = md;
1073
- var { bold: boldHtml, details: details2 } = html;
793
+ import { MarkdownDocument as MarkdownDocument2, md as md3 } from "build-md";
1074
794
 
1075
795
  // packages/utils/src/lib/reports/generate-md-reports-diff.ts
1076
- var {
1077
- h1: h13,
1078
- h2: h24,
1079
- lines: lines5,
1080
- link: link6,
1081
- bold: boldMd3,
1082
- italic: italicMd,
1083
- table: table4,
1084
- section: section5
1085
- } = md;
1086
- var { details: details3 } = html;
796
+ import {
797
+ MarkdownDocument as MarkdownDocument4,
798
+ md as md5
799
+ } from "build-md";
1087
800
 
1088
801
  // packages/utils/src/lib/reports/log-stdout-summary.ts
1089
- import chalk4 from "chalk";
802
+ import { bold as bold4, cyan, cyanBright, green as green2, red } from "ansis";
1090
803
 
1091
804
  // packages/plugin-coverage/package.json
1092
805
  var name = "@code-pushup/coverage-plugin";
1093
- var version = "0.47.0";
806
+ var version = "0.49.0";
1094
807
 
1095
808
  // packages/plugin-coverage/src/lib/config.ts
1096
809
  import { z as z16 } from "zod";
@@ -1127,7 +840,7 @@ var coveragePluginConfigSchema = z16.object({
1127
840
  });
1128
841
 
1129
842
  // packages/plugin-coverage/src/lib/runner/index.ts
1130
- import chalk5 from "chalk";
843
+ import { bold as bold5 } from "ansis";
1131
844
  import { writeFile } from "node:fs/promises";
1132
845
  import { dirname } from "node:path";
1133
846
 
@@ -1216,12 +929,12 @@ async function coveragePlugin(config) {
1216
929
  }
1217
930
 
1218
931
  // packages/plugin-coverage/src/lib/nx/coverage-paths.ts
1219
- import chalk6 from "chalk";
932
+ import { bold as bold6 } from "ansis";
1220
933
  import { isAbsolute, join as join4 } from "node:path";
1221
934
  async function getNxCoveragePaths(targets = ["test"], verbose) {
1222
935
  if (verbose) {
1223
936
  ui().logger.info(
1224
- chalk6.bold("\u{1F4A1} Gathering coverage from the following nx projects:")
937
+ bold6("\u{1F4A1} Gathering coverage from the following nx projects:")
1225
938
  );
1226
939
  }
1227
940
  const { createProjectGraphAsync } = await import("@nx/devkit");
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@code-pushup/coverage-plugin",
3
- "version": "0.47.0",
3
+ "version": "0.49.0",
4
4
  "dependencies": {
5
- "@code-pushup/models": "0.47.0",
6
- "@code-pushup/utils": "0.47.0",
5
+ "@code-pushup/models": "0.49.0",
6
+ "@code-pushup/utils": "0.49.0",
7
+ "ansis": "^3.3.0",
7
8
  "parse-lcov": "^1.0.4",
8
- "chalk": "^5.3.0",
9
9
  "zod": "^3.22.4"
10
10
  },
11
11
  "peerDependencies": {
@@ -36,7 +36,7 @@ export declare const coveragePluginConfigSchema: z.ZodObject<{
36
36
  }>, z.ZodString]>, "many">;
37
37
  perfectScoreThreshold: z.ZodOptional<z.ZodNumber>;
38
38
  }, "strip", z.ZodTypeAny, {
39
- coverageTypes: ("function" | "line" | "branch")[];
39
+ coverageTypes: ("function" | "branch" | "line")[];
40
40
  reports: (string | {
41
41
  resultsPath: string;
42
42
  pathToProject?: string | undefined;
@@ -55,7 +55,7 @@ export declare const coveragePluginConfigSchema: z.ZodObject<{
55
55
  command: string;
56
56
  args?: string[] | undefined;
57
57
  } | undefined;
58
- coverageTypes?: ("function" | "line" | "branch")[] | undefined;
58
+ coverageTypes?: ("function" | "branch" | "line")[] | undefined;
59
59
  perfectScoreThreshold?: number | undefined;
60
60
  }>;
61
61
  export type CoveragePluginConfig = z.input<typeof coveragePluginConfigSchema>;