@code-pushup/js-packages-plugin 0.46.0 → 0.48.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.
Files changed (3) hide show
  1. package/bin.js +30 -17
  2. package/index.js +31 -18
  3. package/package.json +3 -3
package/bin.js CHANGED
@@ -67,7 +67,7 @@ function missingRefsForCategoriesErrorMsg(categories, plugins) {
67
67
  }
68
68
 
69
69
  // packages/models/src/lib/implementation/schemas.ts
70
- var primitiveValueSchema = z.union([z.string(), z.number()]);
70
+ var tableCellValueSchema = z.union([z.string(), z.number(), z.boolean(), z.null()]).default(null);
71
71
  function executionMetaSchema(options = {
72
72
  descriptionDate: "Execution start date and time",
73
73
  descriptionDuration: "Execution duration in ms"
@@ -231,10 +231,10 @@ var tableColumnObjectSchema = z4.object({
231
231
  label: z4.string().optional(),
232
232
  align: tableAlignmentSchema.optional()
233
233
  });
234
- var tableRowObjectSchema = z4.record(primitiveValueSchema, {
234
+ var tableRowObjectSchema = z4.record(tableCellValueSchema, {
235
235
  description: "Object row"
236
236
  });
237
- var tableRowPrimitiveSchema = z4.array(primitiveValueSchema, {
237
+ var tableRowPrimitiveSchema = z4.array(tableCellValueSchema, {
238
238
  description: "Primitive row"
239
239
  });
240
240
  var tableSharedSchema = z4.object({
@@ -834,7 +834,7 @@ function code(text) {
834
834
 
835
835
  // packages/utils/src/lib/text-formats/html/link.ts
836
836
  function link(href, text) {
837
- return `<a href="${href}">${text || href}"</a>`;
837
+ return `<a href="${href}">${text || href}</a>`;
838
838
  }
839
839
 
840
840
  // packages/utils/src/lib/transform.ts
@@ -866,7 +866,7 @@ function apostrophize(text, upperCase) {
866
866
  return `${text}'${lastChar.toLocaleLowerCase() === "s" ? "" : upperCase ? "S" : "s"}`;
867
867
  }
868
868
 
869
- // packages/utils/src/lib/table.ts
869
+ // packages/utils/src/lib/text-formats/table.ts
870
870
  function rowToStringArray({ rows, columns = [] }) {
871
871
  if (Array.isArray(rows.at(0)) && typeof columns.at(0) === "object") {
872
872
  throw new TypeError(
@@ -879,14 +879,19 @@ function rowToStringArray({ rows, columns = [] }) {
879
879
  }
880
880
  const objectRow = row;
881
881
  if (columns.length === 0 || typeof columns.at(0) === "string") {
882
- return Object.values(objectRow).map(String);
882
+ return Object.values(objectRow).map(
883
+ (value) => value == null ? "" : String(value)
884
+ );
883
885
  }
884
886
  return columns.map(
885
- ({ key }) => String(objectRow[key])
887
+ ({ key }) => objectRow[key] == null ? "" : String(objectRow[key])
886
888
  );
887
889
  });
888
890
  }
889
- function columnsToStringArray({ rows, columns = [] }) {
891
+ function columnsToStringArray({
892
+ rows,
893
+ columns = []
894
+ }) {
890
895
  const firstRow = rows.at(0);
891
896
  const primitiveRows = Array.isArray(firstRow);
892
897
  if (typeof columns.at(0) === "string" && !primitiveRows) {
@@ -926,10 +931,8 @@ function getColumnAlignmentForIndex(targetIdx, columns = []) {
926
931
  return "center";
927
932
  }
928
933
  }
929
- function getColumnAlignments({
930
- rows,
931
- columns = []
932
- }) {
934
+ function getColumnAlignments(tableData) {
935
+ const { rows, columns = [] } = tableData;
933
936
  if (rows.at(0) == null) {
934
937
  throw new Error("first row can`t be undefined.");
935
938
  }
@@ -939,10 +942,17 @@ function getColumnAlignments({
939
942
  (_, idx) => getColumnAlignmentForIndex(idx, columns)
940
943
  );
941
944
  }
942
- const firstObject = rows.at(0);
943
- return Object.keys(firstObject).map(
944
- (key, idx) => getColumnAlignmentForKeyAndIndex(key, idx, columns)
945
- );
945
+ const biggestRow = [...rows].sort((a, b) => Object.keys(a).length - Object.keys(b).length).at(-1);
946
+ if (columns.length > 0) {
947
+ return columns.map(
948
+ (column, idx) => typeof column === "string" ? column : getColumnAlignmentForKeyAndIndex(
949
+ column.key,
950
+ idx,
951
+ columns
952
+ )
953
+ );
954
+ }
955
+ return Object.keys(biggestRow ?? {}).map((_) => "center");
946
956
  }
947
957
 
948
958
  // packages/utils/src/lib/text-formats/html/table.ts
@@ -1039,7 +1049,10 @@ function section(...contents) {
1039
1049
  return `${lines(...contents)}${NEW_LINE}`;
1040
1050
  }
1041
1051
  function lines(...contents) {
1042
- return `${contents.filter(Boolean).join(NEW_LINE)}`;
1052
+ const filteredContent = contents.filter(
1053
+ (value) => value != null && value !== "" && value !== false
1054
+ );
1055
+ return `${filteredContent.join(NEW_LINE)}`;
1043
1056
  }
1044
1057
 
1045
1058
  // packages/utils/src/lib/text-formats/md/table.ts
package/index.js CHANGED
@@ -4,7 +4,7 @@ import { fileURLToPath } from "node:url";
4
4
 
5
5
  // packages/plugin-js-packages/package.json
6
6
  var name = "@code-pushup/js-packages-plugin";
7
- var version = "0.46.0";
7
+ var version = "0.48.0";
8
8
 
9
9
  // packages/plugin-js-packages/src/lib/config.ts
10
10
  import { z as z16 } from "zod";
@@ -74,7 +74,7 @@ function missingRefsForCategoriesErrorMsg(categories, plugins) {
74
74
  }
75
75
 
76
76
  // packages/models/src/lib/implementation/schemas.ts
77
- var primitiveValueSchema = z.union([z.string(), z.number()]);
77
+ var tableCellValueSchema = z.union([z.string(), z.number(), z.boolean(), z.null()]).default(null);
78
78
  function executionMetaSchema(options = {
79
79
  descriptionDate: "Execution start date and time",
80
80
  descriptionDuration: "Execution duration in ms"
@@ -238,10 +238,10 @@ var tableColumnObjectSchema = z4.object({
238
238
  label: z4.string().optional(),
239
239
  align: tableAlignmentSchema.optional()
240
240
  });
241
- var tableRowObjectSchema = z4.record(primitiveValueSchema, {
241
+ var tableRowObjectSchema = z4.record(tableCellValueSchema, {
242
242
  description: "Object row"
243
243
  });
244
- var tableRowPrimitiveSchema = z4.array(primitiveValueSchema, {
244
+ var tableRowPrimitiveSchema = z4.array(tableCellValueSchema, {
245
245
  description: "Primitive row"
246
246
  });
247
247
  var tableSharedSchema = z4.object({
@@ -861,7 +861,7 @@ function code(text) {
861
861
 
862
862
  // packages/utils/src/lib/text-formats/html/link.ts
863
863
  function link(href, text) {
864
- return `<a href="${href}">${text || href}"</a>`;
864
+ return `<a href="${href}">${text || href}</a>`;
865
865
  }
866
866
 
867
867
  // packages/utils/src/lib/transform.ts
@@ -888,7 +888,7 @@ function capitalize(text) {
888
888
  )}`;
889
889
  }
890
890
 
891
- // packages/utils/src/lib/table.ts
891
+ // packages/utils/src/lib/text-formats/table.ts
892
892
  function rowToStringArray({ rows, columns = [] }) {
893
893
  if (Array.isArray(rows.at(0)) && typeof columns.at(0) === "object") {
894
894
  throw new TypeError(
@@ -901,14 +901,19 @@ function rowToStringArray({ rows, columns = [] }) {
901
901
  }
902
902
  const objectRow = row;
903
903
  if (columns.length === 0 || typeof columns.at(0) === "string") {
904
- return Object.values(objectRow).map(String);
904
+ return Object.values(objectRow).map(
905
+ (value) => value == null ? "" : String(value)
906
+ );
905
907
  }
906
908
  return columns.map(
907
- ({ key }) => String(objectRow[key])
909
+ ({ key }) => objectRow[key] == null ? "" : String(objectRow[key])
908
910
  );
909
911
  });
910
912
  }
911
- function columnsToStringArray({ rows, columns = [] }) {
913
+ function columnsToStringArray({
914
+ rows,
915
+ columns = []
916
+ }) {
912
917
  const firstRow = rows.at(0);
913
918
  const primitiveRows = Array.isArray(firstRow);
914
919
  if (typeof columns.at(0) === "string" && !primitiveRows) {
@@ -948,10 +953,8 @@ function getColumnAlignmentForIndex(targetIdx, columns = []) {
948
953
  return "center";
949
954
  }
950
955
  }
951
- function getColumnAlignments({
952
- rows,
953
- columns = []
954
- }) {
956
+ function getColumnAlignments(tableData) {
957
+ const { rows, columns = [] } = tableData;
955
958
  if (rows.at(0) == null) {
956
959
  throw new Error("first row can`t be undefined.");
957
960
  }
@@ -961,10 +964,17 @@ function getColumnAlignments({
961
964
  (_, idx) => getColumnAlignmentForIndex(idx, columns)
962
965
  );
963
966
  }
964
- const firstObject = rows.at(0);
965
- return Object.keys(firstObject).map(
966
- (key, idx) => getColumnAlignmentForKeyAndIndex(key, idx, columns)
967
- );
967
+ const biggestRow = [...rows].sort((a, b) => Object.keys(a).length - Object.keys(b).length).at(-1);
968
+ if (columns.length > 0) {
969
+ return columns.map(
970
+ (column, idx) => typeof column === "string" ? column : getColumnAlignmentForKeyAndIndex(
971
+ column.key,
972
+ idx,
973
+ columns
974
+ )
975
+ );
976
+ }
977
+ return Object.keys(biggestRow ?? {}).map((_) => "center");
968
978
  }
969
979
 
970
980
  // packages/utils/src/lib/text-formats/html/table.ts
@@ -1061,7 +1071,10 @@ function section(...contents) {
1061
1071
  return `${lines(...contents)}${NEW_LINE}`;
1062
1072
  }
1063
1073
  function lines(...contents) {
1064
- return `${contents.filter(Boolean).join(NEW_LINE)}`;
1074
+ const filteredContent = contents.filter(
1075
+ (value) => value != null && value !== "" && value !== false
1076
+ );
1077
+ return `${filteredContent.join(NEW_LINE)}`;
1065
1078
  }
1066
1079
 
1067
1080
  // packages/utils/src/lib/text-formats/md/table.ts
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@code-pushup/js-packages-plugin",
3
- "version": "0.46.0",
3
+ "version": "0.48.0",
4
4
  "dependencies": {
5
- "@code-pushup/models": "0.46.0",
6
- "@code-pushup/utils": "0.46.0",
5
+ "@code-pushup/models": "0.48.0",
6
+ "@code-pushup/utils": "0.48.0",
7
7
  "semver": "^7.6.0",
8
8
  "zod": "^3.22.4"
9
9
  },