@code-pushup/core 0.54.0 → 0.56.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
@@ -29,7 +29,7 @@ function exists(value) {
29
29
  return value != null;
30
30
  }
31
31
  function getMissingRefsForCategories(categories, plugins) {
32
- if (categories.length === 0) {
32
+ if (!categories || categories.length === 0) {
33
33
  return false;
34
34
  }
35
35
  const auditRefsFromCategory = categories.flatMap(
@@ -528,12 +528,9 @@ var unrefinedCoreConfigSchema = z14.object({
528
528
  var coreConfigSchema = refineCoreConfig(unrefinedCoreConfigSchema);
529
529
  function refineCoreConfig(schema) {
530
530
  return schema.refine(
531
- (coreCfg) => !getMissingRefsForCategories(coreCfg.categories ?? [], coreCfg.plugins),
532
- (coreCfg) => ({
533
- message: missingRefsForCategoriesErrorMsg(
534
- coreCfg.categories ?? [],
535
- coreCfg.plugins
536
- )
531
+ ({ categories, plugins }) => !getMissingRefsForCategories(categories, plugins),
532
+ ({ categories, plugins }) => ({
533
+ message: missingRefsForCategoriesErrorMsg(categories, plugins)
537
534
  })
538
535
  );
539
536
  }
@@ -589,19 +586,16 @@ var reportSchema = packageVersionSchema({
589
586
  ).merge(
590
587
  z15.object(
591
588
  {
592
- categories: z15.array(categoryConfigSchema),
593
589
  plugins: z15.array(pluginReportSchema).min(1),
590
+ categories: z15.array(categoryConfigSchema).optional(),
594
591
  commit: commitSchema.describe("Git commit for which report was collected").nullable()
595
592
  },
596
593
  { description: "Collect output data" }
597
594
  )
598
595
  ).refine(
599
- (report) => !getMissingRefsForCategories(report.categories, report.plugins),
600
- (report) => ({
601
- message: missingRefsForCategoriesErrorMsg(
602
- report.categories,
603
- report.plugins
604
- )
596
+ ({ categories, plugins }) => !getMissingRefsForCategories(categories, plugins),
597
+ ({ categories, plugins }) => ({
598
+ message: missingRefsForCategoriesErrorMsg(categories, plugins)
605
599
  })
606
600
  );
607
601
 
@@ -1667,7 +1661,7 @@ function getSortableGroupByRef({ plugin, slug, weight }, plugins) {
1667
1661
  }
1668
1662
  function sortReport(report) {
1669
1663
  const { categories, plugins } = report;
1670
- const sortedCategories = categories.map((category) => {
1664
+ const sortedCategories = categories?.map((category) => {
1671
1665
  const { audits, groups } = category.refs.reduce(
1672
1666
  (acc, ref) => ({
1673
1667
  ...acc,
@@ -1807,14 +1801,15 @@ function auditDetailsAuditValue({
1807
1801
  String(displayValue ?? value)
1808
1802
  )} (score: ${formatReportScore(score)})`;
1809
1803
  }
1804
+ function hasCategories(report) {
1805
+ return !!report.categories && report.categories.length > 0;
1806
+ }
1810
1807
  function generateMdReport(report, options) {
1811
- return new MarkdownDocument3().heading(HIERARCHY.level_1, REPORT_HEADLINE_TEXT).$if(
1812
- report.categories.length > 0,
1813
- (doc) => doc.$concat(
1814
- categoriesOverviewSection(report),
1815
- categoriesDetailsSection(report)
1816
- )
1817
- ).$concat(auditsSection(report, options), aboutSection(report)).rule().paragraph(md4`${FOOTER_PREFIX} ${md4.link(README_LINK, "Code PushUp")}`).toString();
1808
+ return new MarkdownDocument3().heading(HIERARCHY.level_1, REPORT_HEADLINE_TEXT).$concat(
1809
+ ...hasCategories(report) ? [categoriesOverviewSection(report), categoriesDetailsSection(report)] : [],
1810
+ auditsSection(report, options),
1811
+ aboutSection(report)
1812
+ ).rule().paragraph(md4`${FOOTER_PREFIX} ${md4.link(README_LINK, "Code PushUp")}`).toString();
1818
1813
  }
1819
1814
  function auditDetailsIssues(issues = [], options) {
1820
1815
  if (issues.length === 0) {
@@ -1916,7 +1911,7 @@ function reportMetaTable({
1916
1911
  md4.code(version2),
1917
1912
  formatDuration(duration),
1918
1913
  plugins.length.toString(),
1919
- categories.length.toString(),
1914
+ (categories?.length ?? 0).toString(),
1920
1915
  plugins.reduce((acc, { audits }) => acc + audits.length, 0).toString()
1921
1916
  ]
1922
1917
  ]
@@ -2248,18 +2243,20 @@ function log(msg = "") {
2248
2243
  ui().logger.log(msg);
2249
2244
  }
2250
2245
  function logStdoutSummary(report, verbose = false) {
2251
- const printCategories = report.categories.length > 0;
2252
- log(reportToHeaderSection(report));
2246
+ const { plugins, categories, packageName, version: version2 } = report;
2247
+ log(reportToHeaderSection({ packageName, version: version2 }));
2253
2248
  log();
2254
- logPlugins(report.plugins, verbose);
2255
- if (printCategories) {
2256
- logCategories(report);
2249
+ logPlugins(plugins, verbose);
2250
+ if (categories && categories.length > 0) {
2251
+ logCategories({ plugins, categories });
2257
2252
  }
2258
2253
  log(`${FOOTER_PREFIX} ${CODE_PUSHUP_DOMAIN}`);
2259
2254
  log();
2260
2255
  }
2261
- function reportToHeaderSection(report) {
2262
- const { packageName, version: version2 } = report;
2256
+ function reportToHeaderSection({
2257
+ packageName,
2258
+ version: version2
2259
+ }) {
2263
2260
  return `${bold4(REPORT_HEADLINE_TEXT)} - ${packageName}@${version2}`;
2264
2261
  }
2265
2262
  function logPlugins(plugins, verbose) {
@@ -2305,7 +2302,10 @@ function logRow(score, title, value) {
2305
2302
  ] : []
2306
2303
  ]);
2307
2304
  }
2308
- function logCategories({ categories, plugins }) {
2305
+ function logCategories({
2306
+ plugins,
2307
+ categories
2308
+ }) {
2309
2309
  const hAlign = (idx) => idx === 0 ? "left" : "right";
2310
2310
  const rows = categories.map(({ title, score, refs, isBinary }) => [
2311
2311
  title,
@@ -2387,7 +2387,7 @@ function scoreReport(report) {
2387
2387
  }
2388
2388
  return item.score;
2389
2389
  }
2390
- const scoredCategories = report.categories.map((category) => ({
2390
+ const scoredCategories = report.categories?.map((category) => ({
2391
2391
  ...category,
2392
2392
  score: calculateScore(category.refs, catScoreFn)
2393
2393
  }));
@@ -2450,7 +2450,7 @@ var verboseUtils = (verbose = false) => ({
2450
2450
 
2451
2451
  // packages/core/package.json
2452
2452
  var name = "@code-pushup/core";
2453
- var version = "0.54.0";
2453
+ var version = "0.56.0";
2454
2454
 
2455
2455
  // packages/core/src/lib/implementation/execute-plugin.ts
2456
2456
  import { bold as bold5 } from "ansis";
@@ -2714,8 +2714,8 @@ import { join as join5 } from "node:path";
2714
2714
  // packages/core/src/lib/implementation/compare-scorables.ts
2715
2715
  function compareCategories(reports) {
2716
2716
  const { pairs, added, removed } = matchArrayItemsByKey({
2717
- before: reports.before.categories,
2718
- after: reports.after.categories,
2717
+ before: reports.before.categories ?? [],
2718
+ after: reports.after.categories ?? [],
2719
2719
  key: "slug"
2720
2720
  });
2721
2721
  const { changed, unchanged } = comparePairs(
@@ -2956,7 +2956,7 @@ function reportToGQL(report) {
2956
2956
  commandStartDate: report.date,
2957
2957
  commandDuration: report.duration,
2958
2958
  plugins: report.plugins.map(pluginToGQL),
2959
- categories: report.categories.map(categoryToGQL)
2959
+ categories: (report.categories ?? []).map(categoryToGQL)
2960
2960
  };
2961
2961
  }
2962
2962
  function pluginToGQL(plugin) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-pushup/core",
3
- "version": "0.54.0",
3
+ "version": "0.56.0",
4
4
  "license": "MIT",
5
5
  "description": "Core business logic for the used by the Code PushUp CLI",
6
6
  "homepage": "https://github.com/code-pushup/cli/tree/main/packages/core#readme",
@@ -41,8 +41,8 @@
41
41
  "main": "./index.js",
42
42
  "types": "./src/index.d.ts",
43
43
  "dependencies": {
44
- "@code-pushup/models": "0.54.0",
45
- "@code-pushup/utils": "0.54.0",
44
+ "@code-pushup/models": "0.56.0",
45
+ "@code-pushup/utils": "0.56.0",
46
46
  "ansis": "^3.3.0"
47
47
  },
48
48
  "peerDependencies": {
@@ -1,6 +1,6 @@
1
1
  import { type CoreConfig, type PersistConfig } from '@code-pushup/models';
2
2
  import type { GlobalOptions } from './types';
3
- export type CollectAndPersistReportsOptions = Required<Pick<CoreConfig, 'plugins' | 'categories'>> & {
3
+ export type CollectAndPersistReportsOptions = Pick<CoreConfig, 'plugins' | 'categories'> & {
4
4
  persist: Required<PersistConfig>;
5
5
  } & Partial<GlobalOptions>;
6
6
  export declare function collectAndPersistReports(options: CollectAndPersistReportsOptions): Promise<void>;
@@ -5,7 +5,7 @@ export type HistoryOnlyOptions = {
5
5
  skipUploads?: boolean;
6
6
  forceCleanStatus?: boolean;
7
7
  };
8
- export type HistoryOptions = Required<Pick<CoreConfig, 'plugins'> & Required<Pick<CoreConfig, 'categories'>>> & {
8
+ export type HistoryOptions = Pick<CoreConfig, 'plugins' | 'categories'> & {
9
9
  persist: Required<PersistConfig>;
10
10
  upload?: Required<UploadConfig>;
11
11
  } & HistoryOnlyOptions & Partial<GlobalOptions>;
@@ -1,6 +1,6 @@
1
1
  import type { CoreConfig, Report } from '@code-pushup/models';
2
2
  import type { GlobalOptions } from '../types';
3
- export type CollectOptions = Required<Pick<CoreConfig, 'plugins' | 'categories'>> & Partial<GlobalOptions>;
3
+ export type CollectOptions = Pick<CoreConfig, 'plugins' | 'categories'> & Partial<GlobalOptions>;
4
4
  /**
5
5
  * Run audits, collect plugin output and aggregate it into a JSON object
6
6
  * @param options