@code-pushup/core 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.
package/index.js CHANGED
@@ -63,7 +63,7 @@ function missingRefsForCategoriesErrorMsg(categories, plugins) {
63
63
  }
64
64
 
65
65
  // packages/models/src/lib/implementation/schemas.ts
66
- var primitiveValueSchema = z.union([z.string(), z.number()]);
66
+ var tableCellValueSchema = z.union([z.string(), z.number(), z.boolean(), z.null()]).default(null);
67
67
  function executionMetaSchema(options = {
68
68
  descriptionDate: "Execution start date and time",
69
69
  descriptionDuration: "Execution duration in ms"
@@ -227,10 +227,10 @@ var tableColumnObjectSchema = z4.object({
227
227
  label: z4.string().optional(),
228
228
  align: tableAlignmentSchema.optional()
229
229
  });
230
- var tableRowObjectSchema = z4.record(primitiveValueSchema, {
230
+ var tableRowObjectSchema = z4.record(tableCellValueSchema, {
231
231
  description: "Object row"
232
232
  });
233
- var tableRowPrimitiveSchema = z4.array(primitiveValueSchema, {
233
+ var tableRowPrimitiveSchema = z4.array(tableCellValueSchema, {
234
234
  description: "Primitive row"
235
235
  });
236
236
  var tableSharedSchema = z4.object({
@@ -780,9 +780,9 @@ function formatBytes(bytes, decimals = 2) {
780
780
  function pluralizeToken(token, times) {
781
781
  return `${times} ${Math.abs(times) === 1 ? token : pluralize(token)}`;
782
782
  }
783
- function formatDuration(duration) {
783
+ function formatDuration(duration, granularity = 0) {
784
784
  if (duration < 1e3) {
785
- return `${duration} ms`;
785
+ return `${granularity ? duration.toFixed(granularity) : duration} ms`;
786
786
  }
787
787
  return `${(duration / 1e3).toFixed(2)} s`;
788
788
  }
@@ -965,20 +965,12 @@ function logMultipleFileResults(fileResults, messagePrefix) {
965
965
  failedTransform
966
966
  );
967
967
  }
968
- var NoExportError = class extends Error {
969
- constructor(filepath) {
970
- super(`No default export found in ${filepath}`);
968
+ async function importModule(options) {
969
+ const { mod } = await bundleRequire(options);
970
+ if (typeof mod === "object" && "default" in mod) {
971
+ return mod.default;
971
972
  }
972
- };
973
- async function importEsmModule(options) {
974
- const { mod } = await bundleRequire({
975
- format: "esm",
976
- ...options
977
- });
978
- if (!("default" in mod)) {
979
- throw new NoExportError(options.filepath);
980
- }
981
- return mod.default;
973
+ return mod;
982
974
  }
983
975
 
984
976
  // packages/utils/src/lib/text-formats/constants.ts
@@ -1011,7 +1003,7 @@ function code(text) {
1011
1003
 
1012
1004
  // packages/utils/src/lib/text-formats/html/link.ts
1013
1005
  function link(href, text) {
1014
- return `<a href="${href}">${text || href}"</a>`;
1006
+ return `<a href="${href}">${text || href}</a>`;
1015
1007
  }
1016
1008
 
1017
1009
  // packages/utils/src/lib/transform.ts
@@ -1030,7 +1022,7 @@ function capitalize(text) {
1030
1022
  )}`;
1031
1023
  }
1032
1024
 
1033
- // packages/utils/src/lib/table.ts
1025
+ // packages/utils/src/lib/text-formats/table.ts
1034
1026
  function rowToStringArray({ rows, columns = [] }) {
1035
1027
  if (Array.isArray(rows.at(0)) && typeof columns.at(0) === "object") {
1036
1028
  throw new TypeError(
@@ -1043,14 +1035,19 @@ function rowToStringArray({ rows, columns = [] }) {
1043
1035
  }
1044
1036
  const objectRow = row;
1045
1037
  if (columns.length === 0 || typeof columns.at(0) === "string") {
1046
- return Object.values(objectRow).map(String);
1038
+ return Object.values(objectRow).map(
1039
+ (value) => value == null ? "" : String(value)
1040
+ );
1047
1041
  }
1048
1042
  return columns.map(
1049
- ({ key }) => String(objectRow[key])
1043
+ ({ key }) => objectRow[key] == null ? "" : String(objectRow[key])
1050
1044
  );
1051
1045
  });
1052
1046
  }
1053
- function columnsToStringArray({ rows, columns = [] }) {
1047
+ function columnsToStringArray({
1048
+ rows,
1049
+ columns = []
1050
+ }) {
1054
1051
  const firstRow = rows.at(0);
1055
1052
  const primitiveRows = Array.isArray(firstRow);
1056
1053
  if (typeof columns.at(0) === "string" && !primitiveRows) {
@@ -1090,10 +1087,8 @@ function getColumnAlignmentForIndex(targetIdx, columns = []) {
1090
1087
  return "center";
1091
1088
  }
1092
1089
  }
1093
- function getColumnAlignments({
1094
- rows,
1095
- columns = []
1096
- }) {
1090
+ function getColumnAlignments(tableData) {
1091
+ const { rows, columns = [] } = tableData;
1097
1092
  if (rows.at(0) == null) {
1098
1093
  throw new Error("first row can`t be undefined.");
1099
1094
  }
@@ -1103,10 +1098,17 @@ function getColumnAlignments({
1103
1098
  (_, idx) => getColumnAlignmentForIndex(idx, columns)
1104
1099
  );
1105
1100
  }
1106
- const firstObject = rows.at(0);
1107
- return Object.keys(firstObject).map(
1108
- (key, idx) => getColumnAlignmentForKeyAndIndex(key, idx, columns)
1109
- );
1101
+ const biggestRow = [...rows].sort((a, b) => Object.keys(a).length - Object.keys(b).length).at(-1);
1102
+ if (columns.length > 0) {
1103
+ return columns.map(
1104
+ (column, idx) => typeof column === "string" ? column : getColumnAlignmentForKeyAndIndex(
1105
+ column.key,
1106
+ idx,
1107
+ columns
1108
+ )
1109
+ );
1110
+ }
1111
+ return Object.keys(biggestRow ?? {}).map((_) => "center");
1110
1112
  }
1111
1113
 
1112
1114
  // packages/utils/src/lib/text-formats/html/table.ts
@@ -1203,7 +1205,10 @@ function section(...contents) {
1203
1205
  return `${lines(...contents)}${NEW_LINE}`;
1204
1206
  }
1205
1207
  function lines(...contents) {
1206
- return `${contents.filter(Boolean).join(NEW_LINE)}`;
1208
+ const filteredContent = contents.filter(
1209
+ (value) => value != null && value !== "" && value !== false
1210
+ );
1211
+ return `${filteredContent.join(NEW_LINE)}`;
1207
1212
  }
1208
1213
 
1209
1214
  // packages/utils/src/lib/text-formats/md/table.ts
@@ -2017,8 +2022,8 @@ function formatDiffCategoriesSection(diff) {
2017
2022
  }
2018
2023
  const columns = [
2019
2024
  { key: "category", label: "\u{1F3F7}\uFE0F Category", align: "left" },
2020
- { key: "after", label: hasChanges ? "\u2B50 Current score" : "\u2B50 Score" },
2021
- { key: "before", label: "\u2B50 Previous score" },
2025
+ { key: "before", label: hasChanges ? "\u2B50 Previous score" : "\u2B50 Score" },
2026
+ { key: "after", label: "\u2B50 Current score" },
2022
2027
  { key: "change", label: "\u{1F504} Score change" }
2023
2028
  ];
2024
2029
  return lines5(
@@ -2047,7 +2052,7 @@ function formatDiffCategoriesSection(diff) {
2047
2052
  change: "\u2013"
2048
2053
  }))
2049
2054
  ].map(
2050
- (row) => hasChanges ? row : { category: row.category, after: row.after }
2055
+ (row) => hasChanges ? row : { category: row.category, before: row.before }
2051
2056
  )
2052
2057
  }),
2053
2058
  added.length > 0 && section5(italicMd("(\\*) New category."))
@@ -2063,8 +2068,8 @@ function formatDiffGroupsSection(diff) {
2063
2068
  columns: [
2064
2069
  { key: "plugin", label: "\u{1F50C} Plugin", align: "left" },
2065
2070
  { key: "group", label: "\u{1F5C3}\uFE0F Group", align: "left" },
2066
- { key: "after", label: "\u2B50 Current score" },
2067
2071
  { key: "before", label: "\u2B50 Previous score" },
2072
+ { key: "after", label: "\u2B50 Current score" },
2068
2073
  { key: "change", label: "\u{1F504} Score change" }
2069
2074
  ],
2070
2075
  rows: sortChanges(diff.groups.changed).map((group) => ({
@@ -2084,8 +2089,8 @@ function formatDiffAuditsSection(diff) {
2084
2089
  columns: [
2085
2090
  { key: "plugin", label: "\u{1F50C} Plugin", align: "left" },
2086
2091
  { key: "audit", label: "\u{1F6E1}\uFE0F Audit", align: "left" },
2087
- { key: "after", label: "\u{1F4CF} Current value" },
2088
2092
  { key: "before", label: "\u{1F4CF} Previous value" },
2093
+ { key: "after", label: "\u{1F4CF} Current value" },
2089
2094
  { key: "change", label: "\u{1F504} Value change" }
2090
2095
  ],
2091
2096
  rows: sortChanges(diff.audits.changed).map((audit) => ({
@@ -2456,7 +2461,7 @@ var verboseUtils = (verbose = false) => ({
2456
2461
 
2457
2462
  // packages/core/package.json
2458
2463
  var name = "@code-pushup/core";
2459
- var version = "0.46.0";
2464
+ var version = "0.48.0";
2460
2465
 
2461
2466
  // packages/core/src/lib/implementation/execute-plugin.ts
2462
2467
  import chalk5 from "chalk";
@@ -3001,9 +3006,9 @@ function tableToGQL(table5) {
3001
3006
  )
3002
3007
  },
3003
3008
  rows: table5.rows.map(
3004
- (row) => Array.isArray(row) ? row.map((content) => ({ content: content.toString() })) : Object.entries(row).map(([key, content]) => ({
3009
+ (row) => Array.isArray(row) ? row.map((content) => ({ content: content?.toString() ?? "" })) : Object.entries(row).map(([key, content]) => ({
3005
3010
  key,
3006
- content: content.toString()
3011
+ content: content?.toString() ?? ""
3007
3012
  }))
3008
3013
  )
3009
3014
  };
@@ -3121,7 +3126,7 @@ async function readRcByPath(filepath, tsconfig) {
3121
3126
  if (!await fileExists(filepath)) {
3122
3127
  throw new ConfigPathError(filepath);
3123
3128
  }
3124
- const cfg = await importEsmModule({ filepath, tsconfig });
3129
+ const cfg = await importModule({ filepath, tsconfig, format: "esm" });
3125
3130
  return coreConfigSchema.parse(cfg);
3126
3131
  }
3127
3132
  async function autoloadRc(tsconfig) {
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@code-pushup/core",
3
- "version": "0.46.0",
3
+ "version": "0.48.0",
4
4
  "license": "MIT",
5
5
  "dependencies": {
6
- "@code-pushup/models": "0.46.0",
7
- "@code-pushup/utils": "0.46.0",
8
- "@code-pushup/portal-client": "^0.7.0",
6
+ "@code-pushup/models": "0.48.0",
7
+ "@code-pushup/utils": "0.48.0",
8
+ "@code-pushup/portal-client": "^0.8.0",
9
9
  "chalk": "^5.3.0"
10
10
  },
11
11
  "type": "module",
@@ -9,5 +9,6 @@ export type UploadOptions = {
9
9
  /**
10
10
  * Uploads collected audits to the portal
11
11
  * @param options
12
+ * @param uploadFn
12
13
  */
13
14
  export declare function upload(options: UploadOptions, uploadFn?: typeof uploadToPortal): Promise<import("@code-pushup/portal-client").ReportFragment>;