@code-pushup/coverage-plugin 0.26.1 → 0.27.1

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 +145 -19
  2. package/index.js +153 -31
  3. package/package.json +1 -1
package/bin.js CHANGED
@@ -89,6 +89,9 @@ var descriptionSchema = z.string({ description: "Description (markdown)" }).max(
89
89
  var urlSchema = z.string().url();
90
90
  var docsUrlSchema = urlSchema.optional().or(z.literal("")).describe("Documentation site");
91
91
  var titleSchema = z.string({ description: "Descriptive name" }).max(MAX_TITLE_LENGTH);
92
+ var scoreSchema = z.number({
93
+ description: "Value between 0 and 1"
94
+ }).min(0).max(1);
92
95
  function metaSchema(options) {
93
96
  const {
94
97
  descriptionDescription,
@@ -220,6 +223,8 @@ var issueSchema = z3.object(
220
223
  );
221
224
 
222
225
  // packages/models/src/lib/audit-output.ts
226
+ var auditValueSchema = nonnegativeIntSchema.describe("Raw numeric value");
227
+ var auditDisplayValueSchema = z4.string({ description: "Formatted value (e.g. '0.9 s', '2.1 MB')" }).optional();
223
228
  var auditDetailsSchema = z4.object(
224
229
  {
225
230
  issues: z4.array(issueSchema, { description: "List of findings" })
@@ -229,11 +234,9 @@ var auditDetailsSchema = z4.object(
229
234
  var auditOutputSchema = z4.object(
230
235
  {
231
236
  slug: slugSchema.describe("Reference to audit"),
232
- displayValue: z4.string({ description: "Formatted value (e.g. '0.9 s', '2.1 MB')" }).optional(),
233
- value: nonnegativeIntSchema.describe("Raw numeric value"),
234
- score: z4.number({
235
- description: "Value between 0 and 1"
236
- }).min(0).max(1),
237
+ displayValue: auditDisplayValueSchema,
238
+ value: auditValueSchema,
239
+ score: scoreSchema,
237
240
  details: auditDetailsSchema.optional()
238
241
  },
239
242
  { description: "Audit information" }
@@ -556,14 +559,138 @@ var reportSchema = packageVersionSchema({
556
559
  })
557
560
  );
558
561
 
562
+ // packages/models/src/lib/reports-diff.ts
563
+ import { z as z14 } from "zod";
564
+ function makeComparisonSchema(schema) {
565
+ const sharedDescription = schema.description || "Result";
566
+ return z14.object({
567
+ before: schema.describe(`${sharedDescription} (source commit)`),
568
+ after: schema.describe(`${sharedDescription} (target commit)`)
569
+ });
570
+ }
571
+ function makeArraysComparisonSchema(diffSchema, resultSchema, description) {
572
+ return z14.object(
573
+ {
574
+ changed: z14.array(diffSchema),
575
+ unchanged: z14.array(resultSchema),
576
+ added: z14.array(resultSchema),
577
+ removed: z14.array(resultSchema)
578
+ },
579
+ { description }
580
+ );
581
+ }
582
+ var scorableMetaSchema = z14.object({ slug: slugSchema, title: titleSchema });
583
+ var scorableWithPluginMetaSchema = scorableMetaSchema.merge(
584
+ z14.object({
585
+ plugin: pluginMetaSchema.pick({ slug: true, title: true }).describe("Plugin which defines it")
586
+ })
587
+ );
588
+ var scorableDiffSchema = scorableMetaSchema.merge(
589
+ z14.object({
590
+ scores: makeComparisonSchema(scoreSchema).merge(
591
+ z14.object({
592
+ diff: z14.number().min(-1).max(1).describe("Score change (`scores.after - scores.before`)")
593
+ })
594
+ ).describe("Score comparison")
595
+ })
596
+ );
597
+ var scorableWithPluginDiffSchema = scorableDiffSchema.merge(
598
+ scorableWithPluginMetaSchema
599
+ );
600
+ var categoryDiffSchema = scorableDiffSchema;
601
+ var groupDiffSchema = scorableWithPluginDiffSchema;
602
+ var auditDiffSchema = scorableWithPluginDiffSchema.merge(
603
+ z14.object({
604
+ values: makeComparisonSchema(auditValueSchema).merge(
605
+ z14.object({
606
+ diff: z14.number().int().describe("Value change (`values.after - values.before`)")
607
+ })
608
+ ).describe("Audit `value` comparison"),
609
+ displayValues: makeComparisonSchema(auditDisplayValueSchema).describe(
610
+ "Audit `displayValue` comparison"
611
+ )
612
+ })
613
+ );
614
+ var categoryResultSchema = scorableMetaSchema.merge(
615
+ z14.object({ score: scoreSchema })
616
+ );
617
+ var groupResultSchema = scorableWithPluginMetaSchema.merge(
618
+ z14.object({ score: scoreSchema })
619
+ );
620
+ var auditResultSchema = scorableWithPluginMetaSchema.merge(
621
+ auditOutputSchema.pick({ score: true, value: true, displayValue: true })
622
+ );
623
+ var reportsDiffSchema = z14.object({
624
+ commits: makeComparisonSchema(commitSchema).nullable().describe("Commits identifying compared reports"),
625
+ categories: makeArraysComparisonSchema(
626
+ categoryDiffSchema,
627
+ categoryResultSchema,
628
+ "Changes affecting categories"
629
+ ),
630
+ groups: makeArraysComparisonSchema(
631
+ groupDiffSchema,
632
+ groupResultSchema,
633
+ "Changes affecting groups"
634
+ ),
635
+ audits: makeArraysComparisonSchema(
636
+ auditDiffSchema,
637
+ auditResultSchema,
638
+ "Changes affecting audits"
639
+ )
640
+ }).merge(
641
+ packageVersionSchema({
642
+ versionDescription: "NPM version of the CLI (when `compare` was run)",
643
+ required: true
644
+ })
645
+ ).merge(
646
+ executionMetaSchema({
647
+ descriptionDate: "Start date and time of the compare run",
648
+ descriptionDuration: "Duration of the compare run in ms"
649
+ })
650
+ );
651
+
559
652
  // packages/utils/src/lib/execute-process.ts
560
653
  import { spawn } from "node:child_process";
561
654
 
562
655
  // packages/utils/src/lib/file-system.ts
563
656
  import { bundleRequire } from "bundle-require";
564
- import chalk from "chalk";
657
+ import chalk2 from "chalk";
565
658
  import { mkdir, readFile, readdir, rm, stat } from "node:fs/promises";
566
659
  import { join } from "node:path";
660
+
661
+ // packages/utils/src/lib/logging.ts
662
+ import isaacs_cliui from "@isaacs/cliui";
663
+ import { cliui } from "@poppinss/cliui";
664
+ import chalk from "chalk";
665
+
666
+ // packages/utils/src/lib/reports/constants.ts
667
+ var TERMINAL_WIDTH = 80;
668
+
669
+ // packages/utils/src/lib/logging.ts
670
+ var singletonUiInstance;
671
+ function ui() {
672
+ if (singletonUiInstance === void 0) {
673
+ singletonUiInstance = cliui();
674
+ }
675
+ return {
676
+ ...singletonUiInstance,
677
+ row: (args) => {
678
+ logListItem(args);
679
+ }
680
+ };
681
+ }
682
+ var singletonisaacUi;
683
+ function logListItem(args) {
684
+ if (singletonisaacUi === void 0) {
685
+ singletonisaacUi = isaacs_cliui({ width: TERMINAL_WIDTH });
686
+ }
687
+ singletonisaacUi.div(...args);
688
+ const content = singletonisaacUi.toString();
689
+ singletonisaacUi.rows = [];
690
+ singletonUiInstance?.logger.log(content);
691
+ }
692
+
693
+ // packages/utils/src/lib/file-system.ts
567
694
  async function readTextFile(path) {
568
695
  const buffer = await readFile(path);
569
696
  return buffer.toString();
@@ -577,7 +704,7 @@ async function ensureDirectoryExists(baseDir) {
577
704
  await mkdir(baseDir, { recursive: true });
578
705
  return;
579
706
  } catch (error) {
580
- console.error(error.message);
707
+ ui().logger.error(error.message);
581
708
  if (error.code !== "EEXIST") {
582
709
  throw error;
583
710
  }
@@ -605,7 +732,7 @@ var ProcessError = class extends Error {
605
732
  }
606
733
  };
607
734
  function executeProcess(cfg) {
608
- const { observer, cwd, command, args } = cfg;
735
+ const { observer, cwd, command, args, alwaysResolve = false } = cfg;
609
736
  const { onStdout, onError, onComplete } = observer ?? {};
610
737
  const date = (/* @__PURE__ */ new Date()).toISOString();
611
738
  const start = performance.now();
@@ -625,7 +752,7 @@ function executeProcess(cfg) {
625
752
  });
626
753
  process2.on("close", (code) => {
627
754
  const timings = { date, duration: calcDuration(start) };
628
- if (code === 0) {
755
+ if (code === 0 || alwaysResolve) {
629
756
  onComplete?.();
630
757
  resolve({ code, stdout, stderr, ...timings });
631
758
  } else {
@@ -665,17 +792,12 @@ function toOrdinal(value) {
665
792
  return `${value}th`;
666
793
  }
667
794
 
668
- // packages/utils/src/lib/logging.ts
669
- import chalk2 from "chalk";
670
-
671
795
  // packages/utils/src/lib/progress.ts
672
796
  import chalk3 from "chalk";
673
797
  import { MultiProgressBars } from "multi-progress-bars";
674
798
 
675
- // packages/utils/src/lib/reports/generate-stdout-summary.ts
676
- import cliui from "@isaacs/cliui";
799
+ // packages/utils/src/lib/reports/log-stdout-summary.ts
677
800
  import chalk4 from "chalk";
678
- import CliTable3 from "cli-table3";
679
801
 
680
802
  // packages/plugin-coverage/src/lib/runner/constants.ts
681
803
  import { join as join2 } from "node:path";
@@ -857,10 +979,14 @@ async function executeRunner() {
857
979
  await executeProcess({ command, args });
858
980
  } catch (error) {
859
981
  if (error instanceof ProcessError) {
860
- console.error(chalk5.bold("stdout from failed coverage tool process:"));
861
- console.error(error.stdout);
862
- console.error(chalk5.bold("stderr from failed coverage tool process:"));
863
- console.error(error.stderr);
982
+ ui().logger.error(
983
+ chalk5.bold("stdout from failed coverage tool process:")
984
+ );
985
+ ui().logger.error(error.stdout);
986
+ ui().logger.error(
987
+ chalk5.bold("stderr from failed coverage tool process:")
988
+ );
989
+ ui().logger.error(error.stderr);
864
990
  }
865
991
  throw new Error(
866
992
  "Coverage plugin: Running coverage tool failed. Make sure all your provided tests are passing."
package/index.js CHANGED
@@ -88,6 +88,9 @@ var descriptionSchema = z.string({ description: "Description (markdown)" }).max(
88
88
  var urlSchema = z.string().url();
89
89
  var docsUrlSchema = urlSchema.optional().or(z.literal("")).describe("Documentation site");
90
90
  var titleSchema = z.string({ description: "Descriptive name" }).max(MAX_TITLE_LENGTH);
91
+ var scoreSchema = z.number({
92
+ description: "Value between 0 and 1"
93
+ }).min(0).max(1);
91
94
  function metaSchema(options) {
92
95
  const {
93
96
  descriptionDescription,
@@ -219,6 +222,8 @@ var issueSchema = z3.object(
219
222
  );
220
223
 
221
224
  // packages/models/src/lib/audit-output.ts
225
+ var auditValueSchema = nonnegativeIntSchema.describe("Raw numeric value");
226
+ var auditDisplayValueSchema = z4.string({ description: "Formatted value (e.g. '0.9 s', '2.1 MB')" }).optional();
222
227
  var auditDetailsSchema = z4.object(
223
228
  {
224
229
  issues: z4.array(issueSchema, { description: "List of findings" })
@@ -228,11 +233,9 @@ var auditDetailsSchema = z4.object(
228
233
  var auditOutputSchema = z4.object(
229
234
  {
230
235
  slug: slugSchema.describe("Reference to audit"),
231
- displayValue: z4.string({ description: "Formatted value (e.g. '0.9 s', '2.1 MB')" }).optional(),
232
- value: nonnegativeIntSchema.describe("Raw numeric value"),
233
- score: z4.number({
234
- description: "Value between 0 and 1"
235
- }).min(0).max(1),
236
+ displayValue: auditDisplayValueSchema,
237
+ value: auditValueSchema,
238
+ score: scoreSchema,
236
239
  details: auditDetailsSchema.optional()
237
240
  },
238
241
  { description: "Audit information" }
@@ -555,17 +558,141 @@ var reportSchema = packageVersionSchema({
555
558
  })
556
559
  );
557
560
 
561
+ // packages/models/src/lib/reports-diff.ts
562
+ import { z as z14 } from "zod";
563
+ function makeComparisonSchema(schema) {
564
+ const sharedDescription = schema.description || "Result";
565
+ return z14.object({
566
+ before: schema.describe(`${sharedDescription} (source commit)`),
567
+ after: schema.describe(`${sharedDescription} (target commit)`)
568
+ });
569
+ }
570
+ function makeArraysComparisonSchema(diffSchema, resultSchema, description) {
571
+ return z14.object(
572
+ {
573
+ changed: z14.array(diffSchema),
574
+ unchanged: z14.array(resultSchema),
575
+ added: z14.array(resultSchema),
576
+ removed: z14.array(resultSchema)
577
+ },
578
+ { description }
579
+ );
580
+ }
581
+ var scorableMetaSchema = z14.object({ slug: slugSchema, title: titleSchema });
582
+ var scorableWithPluginMetaSchema = scorableMetaSchema.merge(
583
+ z14.object({
584
+ plugin: pluginMetaSchema.pick({ slug: true, title: true }).describe("Plugin which defines it")
585
+ })
586
+ );
587
+ var scorableDiffSchema = scorableMetaSchema.merge(
588
+ z14.object({
589
+ scores: makeComparisonSchema(scoreSchema).merge(
590
+ z14.object({
591
+ diff: z14.number().min(-1).max(1).describe("Score change (`scores.after - scores.before`)")
592
+ })
593
+ ).describe("Score comparison")
594
+ })
595
+ );
596
+ var scorableWithPluginDiffSchema = scorableDiffSchema.merge(
597
+ scorableWithPluginMetaSchema
598
+ );
599
+ var categoryDiffSchema = scorableDiffSchema;
600
+ var groupDiffSchema = scorableWithPluginDiffSchema;
601
+ var auditDiffSchema = scorableWithPluginDiffSchema.merge(
602
+ z14.object({
603
+ values: makeComparisonSchema(auditValueSchema).merge(
604
+ z14.object({
605
+ diff: z14.number().int().describe("Value change (`values.after - values.before`)")
606
+ })
607
+ ).describe("Audit `value` comparison"),
608
+ displayValues: makeComparisonSchema(auditDisplayValueSchema).describe(
609
+ "Audit `displayValue` comparison"
610
+ )
611
+ })
612
+ );
613
+ var categoryResultSchema = scorableMetaSchema.merge(
614
+ z14.object({ score: scoreSchema })
615
+ );
616
+ var groupResultSchema = scorableWithPluginMetaSchema.merge(
617
+ z14.object({ score: scoreSchema })
618
+ );
619
+ var auditResultSchema = scorableWithPluginMetaSchema.merge(
620
+ auditOutputSchema.pick({ score: true, value: true, displayValue: true })
621
+ );
622
+ var reportsDiffSchema = z14.object({
623
+ commits: makeComparisonSchema(commitSchema).nullable().describe("Commits identifying compared reports"),
624
+ categories: makeArraysComparisonSchema(
625
+ categoryDiffSchema,
626
+ categoryResultSchema,
627
+ "Changes affecting categories"
628
+ ),
629
+ groups: makeArraysComparisonSchema(
630
+ groupDiffSchema,
631
+ groupResultSchema,
632
+ "Changes affecting groups"
633
+ ),
634
+ audits: makeArraysComparisonSchema(
635
+ auditDiffSchema,
636
+ auditResultSchema,
637
+ "Changes affecting audits"
638
+ )
639
+ }).merge(
640
+ packageVersionSchema({
641
+ versionDescription: "NPM version of the CLI (when `compare` was run)",
642
+ required: true
643
+ })
644
+ ).merge(
645
+ executionMetaSchema({
646
+ descriptionDate: "Start date and time of the compare run",
647
+ descriptionDuration: "Duration of the compare run in ms"
648
+ })
649
+ );
650
+
558
651
  // packages/utils/src/lib/file-system.ts
559
652
  import { bundleRequire } from "bundle-require";
560
- import chalk from "chalk";
653
+ import chalk2 from "chalk";
561
654
  import { mkdir, readFile, readdir, rm, stat } from "node:fs/promises";
562
655
  import { join } from "node:path";
656
+
657
+ // packages/utils/src/lib/logging.ts
658
+ import isaacs_cliui from "@isaacs/cliui";
659
+ import { cliui } from "@poppinss/cliui";
660
+ import chalk from "chalk";
661
+
662
+ // packages/utils/src/lib/reports/constants.ts
663
+ var TERMINAL_WIDTH = 80;
664
+
665
+ // packages/utils/src/lib/logging.ts
666
+ var singletonUiInstance;
667
+ function ui() {
668
+ if (singletonUiInstance === void 0) {
669
+ singletonUiInstance = cliui();
670
+ }
671
+ return {
672
+ ...singletonUiInstance,
673
+ row: (args) => {
674
+ logListItem(args);
675
+ }
676
+ };
677
+ }
678
+ var singletonisaacUi;
679
+ function logListItem(args) {
680
+ if (singletonisaacUi === void 0) {
681
+ singletonisaacUi = isaacs_cliui({ width: TERMINAL_WIDTH });
682
+ }
683
+ singletonisaacUi.div(...args);
684
+ const content = singletonisaacUi.toString();
685
+ singletonisaacUi.rows = [];
686
+ singletonUiInstance?.logger.log(content);
687
+ }
688
+
689
+ // packages/utils/src/lib/file-system.ts
563
690
  async function ensureDirectoryExists(baseDir) {
564
691
  try {
565
692
  await mkdir(baseDir, { recursive: true });
566
693
  return;
567
694
  } catch (error) {
568
- console.error(error.message);
695
+ ui().logger.error(error.message);
569
696
  if (error.code !== "EEXIST") {
570
697
  throw error;
571
698
  }
@@ -585,52 +712,47 @@ function capitalize(text) {
585
712
  )}`;
586
713
  }
587
714
 
588
- // packages/utils/src/lib/logging.ts
589
- import chalk2 from "chalk";
590
-
591
715
  // packages/utils/src/lib/progress.ts
592
716
  import chalk3 from "chalk";
593
717
  import { MultiProgressBars } from "multi-progress-bars";
594
718
 
595
- // packages/utils/src/lib/reports/generate-stdout-summary.ts
596
- import cliui from "@isaacs/cliui";
719
+ // packages/utils/src/lib/reports/log-stdout-summary.ts
597
720
  import chalk4 from "chalk";
598
- import CliTable3 from "cli-table3";
599
721
 
600
722
  // packages/plugin-coverage/package.json
601
723
  var name = "@code-pushup/coverage-plugin";
602
- var version = "0.26.1";
724
+ var version = "0.27.1";
603
725
 
604
726
  // packages/plugin-coverage/src/lib/config.ts
605
- import { z as z14 } from "zod";
606
- var coverageTypeSchema = z14.enum(["function", "branch", "line"]);
607
- var coverageResultSchema = z14.union([
608
- z14.object({
609
- resultsPath: z14.string({
727
+ import { z as z15 } from "zod";
728
+ var coverageTypeSchema = z15.enum(["function", "branch", "line"]);
729
+ var coverageResultSchema = z15.union([
730
+ z15.object({
731
+ resultsPath: z15.string({
610
732
  description: "Path to coverage results for Nx setup."
611
733
  }).includes("lcov"),
612
- pathToProject: z14.string({
734
+ pathToProject: z15.string({
613
735
  description: "Path from workspace root to project root. Necessary for LCOV reports which provide a relative path."
614
736
  }).optional()
615
737
  }),
616
- z14.string({
738
+ z15.string({
617
739
  description: "Path to coverage results for a single project setup."
618
740
  }).includes("lcov")
619
741
  ]);
620
- var coveragePluginConfigSchema = z14.object({
621
- coverageToolCommand: z14.object({
622
- command: z14.string({ description: "Command to run coverage tool." }).min(1),
623
- args: z14.array(z14.string(), {
742
+ var coveragePluginConfigSchema = z15.object({
743
+ coverageToolCommand: z15.object({
744
+ command: z15.string({ description: "Command to run coverage tool." }).min(1),
745
+ args: z15.array(z15.string(), {
624
746
  description: "Arguments to be passed to the coverage tool."
625
747
  }).optional()
626
748
  }).optional(),
627
- coverageTypes: z14.array(coverageTypeSchema, {
749
+ coverageTypes: z15.array(coverageTypeSchema, {
628
750
  description: "Coverage types measured. Defaults to all available types."
629
751
  }).min(1).default(["function", "branch", "line"]),
630
- reports: z14.array(coverageResultSchema, {
752
+ reports: z15.array(coverageResultSchema, {
631
753
  description: "Path to all code coverage report files. Only LCOV format is supported for now."
632
754
  }).min(1),
633
- perfectScoreThreshold: z14.number({
755
+ perfectScoreThreshold: z15.number({
634
756
  description: "Score will be 1 (perfect) for this coverage and above. Score range is 0 - 1."
635
757
  }).gt(0).max(1).optional()
636
758
  });
@@ -728,7 +850,7 @@ async function coveragePlugin(config) {
728
850
  import chalk6 from "chalk";
729
851
  import { join as join4 } from "node:path";
730
852
  async function getNxCoveragePaths(targets = ["test"]) {
731
- console.info(
853
+ ui().logger.info(
732
854
  chalk6.bold("\u{1F4A1} Gathering coverage from the following nx projects:")
733
855
  );
734
856
  const { createProjectGraphAsync } = await import("@nx/devkit");
@@ -741,14 +863,14 @@ async function getNxCoveragePaths(targets = ["test"]) {
741
863
  const targetConfig = data.targets?.[target];
742
864
  const coveragePath = getCoveragePathForTarget(target, targetConfig, name2);
743
865
  const rootToReportsDir = join4(data.root, coveragePath);
744
- console.info(`- ${name2}: ${target}`);
866
+ ui().logger.info(`- ${name2}: ${target}`);
745
867
  return {
746
868
  pathToProject: data.root,
747
869
  resultsPath: join4(rootToReportsDir, "lcov.info")
748
870
  };
749
871
  });
750
872
  });
751
- console.info("\n");
873
+ ui().logger.info("\n");
752
874
  return coverageResults.flat();
753
875
  }
754
876
  function hasNxTarget(project, target) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-pushup/coverage-plugin",
3
- "version": "0.26.1",
3
+ "version": "0.27.1",
4
4
  "dependencies": {
5
5
  "@code-pushup/models": "*",
6
6
  "@code-pushup/utils": "*",