@code-pushup/core 0.50.0 → 0.52.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
@@ -155,9 +155,27 @@ function hasNonZeroWeightedRef(refs) {
155
155
  return refs.reduce((acc, { weight }) => weight + acc, 0) !== 0;
156
156
  }
157
157
 
158
- // packages/models/src/lib/audit.ts
158
+ // packages/models/src/lib/source.ts
159
159
  import { z as z2 } from "zod";
160
- var auditSchema = z2.object({
160
+ var sourceFileLocationSchema = z2.object(
161
+ {
162
+ file: filePathSchema.describe("Relative path to source file in Git repo"),
163
+ position: z2.object(
164
+ {
165
+ startLine: positiveIntSchema.describe("Start line"),
166
+ startColumn: positiveIntSchema.describe("Start column").optional(),
167
+ endLine: positiveIntSchema.describe("End line").optional(),
168
+ endColumn: positiveIntSchema.describe("End column").optional()
169
+ },
170
+ { description: "Location in file" }
171
+ ).optional()
172
+ },
173
+ { description: "Source file location" }
174
+ );
175
+
176
+ // packages/models/src/lib/audit.ts
177
+ import { z as z3 } from "zod";
178
+ var auditSchema = z3.object({
161
179
  slug: slugSchema.describe("ID (unique within plugin)")
162
180
  }).merge(
163
181
  metaSchema({
@@ -167,7 +185,7 @@ var auditSchema = z2.object({
167
185
  description: "List of scorable metrics for the given plugin"
168
186
  })
169
187
  );
170
- var pluginAuditsSchema = z2.array(auditSchema, {
188
+ var pluginAuditsSchema = z3.array(auditSchema, {
171
189
  description: "List of audits maintained in a plugin"
172
190
  }).min(1).refine(
173
191
  (auditMetadata) => !getDuplicateSlugsInAudits(auditMetadata),
@@ -186,31 +204,16 @@ function getDuplicateSlugsInAudits(audits) {
186
204
  }
187
205
 
188
206
  // packages/models/src/lib/audit-output.ts
189
- import { z as z5 } from "zod";
207
+ import { z as z6 } from "zod";
190
208
 
191
209
  // packages/models/src/lib/issue.ts
192
- import { z as z3 } from "zod";
193
- var sourceFileLocationSchema = z3.object(
194
- {
195
- file: filePathSchema.describe("Relative path to source file in Git repo"),
196
- position: z3.object(
197
- {
198
- startLine: positiveIntSchema.describe("Start line"),
199
- startColumn: positiveIntSchema.describe("Start column").optional(),
200
- endLine: positiveIntSchema.describe("End line").optional(),
201
- endColumn: positiveIntSchema.describe("End column").optional()
202
- },
203
- { description: "Location in file" }
204
- ).optional()
205
- },
206
- { description: "Source file location" }
207
- );
208
- var issueSeveritySchema = z3.enum(["info", "warning", "error"], {
210
+ import { z as z4 } from "zod";
211
+ var issueSeveritySchema = z4.enum(["info", "warning", "error"], {
209
212
  description: "Severity level"
210
213
  });
211
- var issueSchema = z3.object(
214
+ var issueSchema = z4.object(
212
215
  {
213
- message: z3.string({ description: "Descriptive error message" }).max(MAX_ISSUE_MESSAGE_LENGTH),
216
+ message: z4.string({ description: "Descriptive error message" }).max(MAX_ISSUE_MESSAGE_LENGTH),
214
217
  severity: issueSeveritySchema,
215
218
  source: sourceFileLocationSchema.optional()
216
219
  },
@@ -218,60 +221,60 @@ var issueSchema = z3.object(
218
221
  );
219
222
 
220
223
  // packages/models/src/lib/table.ts
221
- import { z as z4 } from "zod";
222
- var tableAlignmentSchema = z4.enum(["left", "center", "right"], {
224
+ import { z as z5 } from "zod";
225
+ var tableAlignmentSchema = z5.enum(["left", "center", "right"], {
223
226
  description: "Cell alignment"
224
227
  });
225
- var tableColumnObjectSchema = z4.object({
226
- key: z4.string(),
227
- label: z4.string().optional(),
228
+ var tableColumnObjectSchema = z5.object({
229
+ key: z5.string(),
230
+ label: z5.string().optional(),
228
231
  align: tableAlignmentSchema.optional()
229
232
  });
230
- var tableRowObjectSchema = z4.record(tableCellValueSchema, {
233
+ var tableRowObjectSchema = z5.record(tableCellValueSchema, {
231
234
  description: "Object row"
232
235
  });
233
- var tableRowPrimitiveSchema = z4.array(tableCellValueSchema, {
236
+ var tableRowPrimitiveSchema = z5.array(tableCellValueSchema, {
234
237
  description: "Primitive row"
235
238
  });
236
- var tableSharedSchema = z4.object({
237
- title: z4.string().optional().describe("Display title for table")
239
+ var tableSharedSchema = z5.object({
240
+ title: z5.string().optional().describe("Display title for table")
238
241
  });
239
242
  var tablePrimitiveSchema = tableSharedSchema.merge(
240
- z4.object(
243
+ z5.object(
241
244
  {
242
- columns: z4.array(tableAlignmentSchema).optional(),
243
- rows: z4.array(tableRowPrimitiveSchema)
245
+ columns: z5.array(tableAlignmentSchema).optional(),
246
+ rows: z5.array(tableRowPrimitiveSchema)
244
247
  },
245
248
  { description: "Table with primitive rows and optional alignment columns" }
246
249
  )
247
250
  );
248
251
  var tableObjectSchema = tableSharedSchema.merge(
249
- z4.object(
252
+ z5.object(
250
253
  {
251
- columns: z4.union([
252
- z4.array(tableAlignmentSchema),
253
- z4.array(tableColumnObjectSchema)
254
+ columns: z5.union([
255
+ z5.array(tableAlignmentSchema),
256
+ z5.array(tableColumnObjectSchema)
254
257
  ]).optional(),
255
- rows: z4.array(tableRowObjectSchema)
258
+ rows: z5.array(tableRowObjectSchema)
256
259
  },
257
260
  {
258
261
  description: "Table with object rows and optional alignment or object columns"
259
262
  }
260
263
  )
261
264
  );
262
- var tableSchema = (description = "Table information") => z4.union([tablePrimitiveSchema, tableObjectSchema], { description });
265
+ var tableSchema = (description = "Table information") => z5.union([tablePrimitiveSchema, tableObjectSchema], { description });
263
266
 
264
267
  // packages/models/src/lib/audit-output.ts
265
268
  var auditValueSchema = nonnegativeNumberSchema.describe("Raw numeric value");
266
- var auditDisplayValueSchema = z5.string({ description: "Formatted value (e.g. '0.9 s', '2.1 MB')" }).optional();
267
- var auditDetailsSchema = z5.object(
269
+ var auditDisplayValueSchema = z6.string({ description: "Formatted value (e.g. '0.9 s', '2.1 MB')" }).optional();
270
+ var auditDetailsSchema = z6.object(
268
271
  {
269
- issues: z5.array(issueSchema, { description: "List of findings" }).optional(),
272
+ issues: z6.array(issueSchema, { description: "List of findings" }).optional(),
270
273
  table: tableSchema("Table of related findings").optional()
271
274
  },
272
275
  { description: "Detailed information" }
273
276
  );
274
- var auditOutputSchema = z5.object(
277
+ var auditOutputSchema = z6.object(
275
278
  {
276
279
  slug: slugSchema.describe("Reference to audit"),
277
280
  displayValue: auditDisplayValueSchema,
@@ -281,7 +284,7 @@ var auditOutputSchema = z5.object(
281
284
  },
282
285
  { description: "Audit information" }
283
286
  );
284
- var auditOutputsSchema = z5.array(auditOutputSchema, {
287
+ var auditOutputsSchema = z6.array(auditOutputSchema, {
285
288
  description: "List of JSON formatted audit output emitted by the runner process of a plugin"
286
289
  }).refine(
287
290
  (audits) => !getDuplicateSlugsInAudits2(audits),
@@ -298,13 +301,13 @@ function getDuplicateSlugsInAudits2(audits) {
298
301
  }
299
302
 
300
303
  // packages/models/src/lib/category-config.ts
301
- import { z as z6 } from "zod";
304
+ import { z as z7 } from "zod";
302
305
  var categoryRefSchema = weightedRefSchema(
303
306
  "Weighted references to audits and/or groups for the category",
304
307
  "Slug of an audit or group (depending on `type`)"
305
308
  ).merge(
306
- z6.object({
307
- type: z6.enum(["audit", "group"], {
309
+ z7.object({
310
+ type: z7.enum(["audit", "group"], {
308
311
  description: "Discriminant for reference kind, affects where `slug` is looked up"
309
312
  }),
310
313
  plugin: slugSchema.describe(
@@ -325,8 +328,8 @@ var categoryConfigSchema = scorableSchema(
325
328
  description: "Meta info for category"
326
329
  })
327
330
  ).merge(
328
- z6.object({
329
- isBinary: z6.boolean({
331
+ z7.object({
332
+ isBinary: z7.boolean({
330
333
  description: 'Is this a binary category (i.e. only a perfect score considered a "pass")?'
331
334
  }).optional()
332
335
  })
@@ -342,7 +345,7 @@ function getDuplicateRefsInCategoryMetrics(metrics) {
342
345
  metrics.map(({ slug, type, plugin }) => `${type} :: ${plugin} / ${slug}`)
343
346
  );
344
347
  }
345
- var categoriesSchema = z6.array(categoryConfigSchema, {
348
+ var categoriesSchema = z7.array(categoryConfigSchema, {
346
349
  description: "Categorization of individual audits"
347
350
  }).refine(
348
351
  (categoryCfg) => !getDuplicateSlugCategories(categoryCfg),
@@ -361,18 +364,18 @@ function getDuplicateSlugCategories(categories) {
361
364
  }
362
365
 
363
366
  // packages/models/src/lib/commit.ts
364
- import { z as z7 } from "zod";
365
- var commitSchema = z7.object(
367
+ import { z as z8 } from "zod";
368
+ var commitSchema = z8.object(
366
369
  {
367
- hash: z7.string({ description: "Commit SHA (full)" }).regex(
370
+ hash: z8.string({ description: "Commit SHA (full)" }).regex(
368
371
  /^[\da-f]{40}$/,
369
372
  "Commit SHA should be a 40-character hexadecimal string"
370
373
  ),
371
- message: z7.string({ description: "Commit message" }),
372
- date: z7.coerce.date({
374
+ message: z8.string({ description: "Commit message" }),
375
+ date: z8.coerce.date({
373
376
  description: "Date and time when commit was authored"
374
377
  }),
375
- author: z7.string({
378
+ author: z8.string({
376
379
  description: "Commit author name"
377
380
  }).trim()
378
381
  },
@@ -380,22 +383,22 @@ var commitSchema = z7.object(
380
383
  );
381
384
 
382
385
  // packages/models/src/lib/core-config.ts
383
- import { z as z13 } from "zod";
386
+ import { z as z14 } from "zod";
384
387
 
385
388
  // packages/models/src/lib/persist-config.ts
386
- import { z as z8 } from "zod";
387
- var formatSchema = z8.enum(["json", "md"]);
388
- var persistConfigSchema = z8.object({
389
+ import { z as z9 } from "zod";
390
+ var formatSchema = z9.enum(["json", "md"]);
391
+ var persistConfigSchema = z9.object({
389
392
  outputDir: filePathSchema.describe("Artifacts folder").optional(),
390
393
  filename: fileNameSchema.describe("Artifacts file name (without extension)").optional(),
391
- format: z8.array(formatSchema).optional()
394
+ format: z9.array(formatSchema).optional()
392
395
  });
393
396
 
394
397
  // packages/models/src/lib/plugin-config.ts
395
- import { z as z11 } from "zod";
398
+ import { z as z12 } from "zod";
396
399
 
397
400
  // packages/models/src/lib/group.ts
398
- import { z as z9 } from "zod";
401
+ import { z as z10 } from "zod";
399
402
  var groupRefSchema = weightedRefSchema(
400
403
  "Weighted reference to a group",
401
404
  "Reference slug to a group within this plugin (e.g. 'max-lines')"
@@ -412,7 +415,7 @@ var groupSchema = scorableSchema(
412
415
  getDuplicateRefsInGroups,
413
416
  duplicateRefsInGroupsErrorMsg
414
417
  ).merge(groupMetaSchema);
415
- var groupsSchema = z9.array(groupSchema, {
418
+ var groupsSchema = z10.array(groupSchema, {
416
419
  description: "List of groups"
417
420
  }).optional().refine(
418
421
  (groups) => !getDuplicateSlugsInGroups(groups),
@@ -440,14 +443,14 @@ function getDuplicateSlugsInGroups(groups) {
440
443
  }
441
444
 
442
445
  // packages/models/src/lib/runner-config.ts
443
- import { z as z10 } from "zod";
444
- var outputTransformSchema = z10.function().args(z10.unknown()).returns(z10.union([auditOutputsSchema, z10.promise(auditOutputsSchema)]));
445
- var runnerConfigSchema = z10.object(
446
+ import { z as z11 } from "zod";
447
+ var outputTransformSchema = z11.function().args(z11.unknown()).returns(z11.union([auditOutputsSchema, z11.promise(auditOutputsSchema)]));
448
+ var runnerConfigSchema = z11.object(
446
449
  {
447
- command: z10.string({
450
+ command: z11.string({
448
451
  description: "Shell command to execute"
449
452
  }),
450
- args: z10.array(z10.string({ description: "Command arguments" })).optional(),
453
+ args: z11.array(z11.string({ description: "Command arguments" })).optional(),
451
454
  outputFile: filePathSchema.describe("Output path"),
452
455
  outputTransform: outputTransformSchema.optional()
453
456
  },
@@ -455,8 +458,8 @@ var runnerConfigSchema = z10.object(
455
458
  description: "How to execute runner"
456
459
  }
457
460
  );
458
- var onProgressSchema = z10.function().args(z10.unknown()).returns(z10.void());
459
- var runnerFunctionSchema = z10.function().args(onProgressSchema.optional()).returns(z10.union([auditOutputsSchema, z10.promise(auditOutputsSchema)]));
461
+ var onProgressSchema = z11.function().args(z11.unknown()).returns(z11.void());
462
+ var runnerFunctionSchema = z11.function().args(onProgressSchema.optional()).returns(z11.union([auditOutputsSchema, z11.promise(auditOutputsSchema)]));
460
463
 
461
464
  // packages/models/src/lib/plugin-config.ts
462
465
  var pluginMetaSchema = packageVersionSchema().merge(
@@ -467,13 +470,13 @@ var pluginMetaSchema = packageVersionSchema().merge(
467
470
  description: "Plugin metadata"
468
471
  })
469
472
  ).merge(
470
- z11.object({
473
+ z12.object({
471
474
  slug: slugSchema.describe("Unique plugin slug within core config"),
472
475
  icon: materialIconSchema
473
476
  })
474
477
  );
475
- var pluginDataSchema = z11.object({
476
- runner: z11.union([runnerConfigSchema, runnerFunctionSchema]),
478
+ var pluginDataSchema = z12.object({
479
+ runner: z12.union([runnerConfigSchema, runnerFunctionSchema]),
477
480
  audits: pluginAuditsSchema,
478
481
  groups: groupsSchema
479
482
  });
@@ -499,22 +502,22 @@ function getMissingRefsFromGroups(pluginCfg) {
499
502
  }
500
503
 
501
504
  // packages/models/src/lib/upload-config.ts
502
- import { z as z12 } from "zod";
503
- var uploadConfigSchema = z12.object({
505
+ import { z as z13 } from "zod";
506
+ var uploadConfigSchema = z13.object({
504
507
  server: urlSchema.describe("URL of deployed portal API"),
505
- apiKey: z12.string({
508
+ apiKey: z13.string({
506
509
  description: "API key with write access to portal (use `process.env` for security)"
507
510
  }),
508
511
  organization: slugSchema.describe(
509
512
  "Organization slug from Code PushUp portal"
510
513
  ),
511
514
  project: slugSchema.describe("Project slug from Code PushUp portal"),
512
- timeout: z12.number({ description: "Request timeout in minutes (default is 5)" }).positive().int().optional()
515
+ timeout: z13.number({ description: "Request timeout in minutes (default is 5)" }).positive().int().optional()
513
516
  });
514
517
 
515
518
  // packages/models/src/lib/core-config.ts
516
- var unrefinedCoreConfigSchema = z13.object({
517
- plugins: z13.array(pluginConfigSchema, {
519
+ var unrefinedCoreConfigSchema = z14.object({
520
+ plugins: z14.array(pluginConfigSchema, {
518
521
  description: "List of plugins to be used (official, community-provided, or custom)"
519
522
  }).min(1),
520
523
  /** portal configuration for persisting results */
@@ -541,7 +544,7 @@ var CONFIG_FILE_NAME = "code-pushup.config";
541
544
  var SUPPORTED_CONFIG_FILE_FORMATS = ["ts", "mjs", "js"];
542
545
 
543
546
  // packages/models/src/lib/report.ts
544
- import { z as z14 } from "zod";
547
+ import { z as z15 } from "zod";
545
548
  var auditReportSchema = auditSchema.merge(auditOutputSchema);
546
549
  var pluginReportSchema = pluginMetaSchema.merge(
547
550
  executionMetaSchema({
@@ -549,9 +552,9 @@ var pluginReportSchema = pluginMetaSchema.merge(
549
552
  descriptionDuration: "Duration of the plugin run in ms"
550
553
  })
551
554
  ).merge(
552
- z14.object({
553
- audits: z14.array(auditReportSchema).min(1),
554
- groups: z14.array(groupSchema).optional()
555
+ z15.object({
556
+ audits: z15.array(auditReportSchema).min(1),
557
+ groups: z15.array(groupSchema).optional()
555
558
  })
556
559
  ).refine(
557
560
  (pluginReport) => !getMissingRefsFromGroups2(pluginReport.audits, pluginReport.groups ?? []),
@@ -585,10 +588,10 @@ var reportSchema = packageVersionSchema({
585
588
  descriptionDuration: "Duration of the collect run in ms"
586
589
  })
587
590
  ).merge(
588
- z14.object(
591
+ z15.object(
589
592
  {
590
- categories: z14.array(categoryConfigSchema),
591
- plugins: z14.array(pluginReportSchema).min(1),
593
+ categories: z15.array(categoryConfigSchema),
594
+ plugins: z15.array(pluginReportSchema).min(1),
592
595
  commit: commitSchema.describe("Git commit for which report was collected").nullable()
593
596
  },
594
597
  { description: "Collect output data" }
@@ -604,40 +607,40 @@ var reportSchema = packageVersionSchema({
604
607
  );
605
608
 
606
609
  // packages/models/src/lib/reports-diff.ts
607
- import { z as z15 } from "zod";
610
+ import { z as z16 } from "zod";
608
611
  function makeComparisonSchema(schema) {
609
612
  const sharedDescription = schema.description || "Result";
610
- return z15.object({
613
+ return z16.object({
611
614
  before: schema.describe(`${sharedDescription} (source commit)`),
612
615
  after: schema.describe(`${sharedDescription} (target commit)`)
613
616
  });
614
617
  }
615
618
  function makeArraysComparisonSchema(diffSchema, resultSchema, description) {
616
- return z15.object(
619
+ return z16.object(
617
620
  {
618
- changed: z15.array(diffSchema),
619
- unchanged: z15.array(resultSchema),
620
- added: z15.array(resultSchema),
621
- removed: z15.array(resultSchema)
621
+ changed: z16.array(diffSchema),
622
+ unchanged: z16.array(resultSchema),
623
+ added: z16.array(resultSchema),
624
+ removed: z16.array(resultSchema)
622
625
  },
623
626
  { description }
624
627
  );
625
628
  }
626
- var scorableMetaSchema = z15.object({
629
+ var scorableMetaSchema = z16.object({
627
630
  slug: slugSchema,
628
631
  title: titleSchema,
629
632
  docsUrl: docsUrlSchema
630
633
  });
631
634
  var scorableWithPluginMetaSchema = scorableMetaSchema.merge(
632
- z15.object({
635
+ z16.object({
633
636
  plugin: pluginMetaSchema.pick({ slug: true, title: true, docsUrl: true }).describe("Plugin which defines it")
634
637
  })
635
638
  );
636
639
  var scorableDiffSchema = scorableMetaSchema.merge(
637
- z15.object({
640
+ z16.object({
638
641
  scores: makeComparisonSchema(scoreSchema).merge(
639
- z15.object({
640
- diff: z15.number().min(-1).max(1).describe("Score change (`scores.after - scores.before`)")
642
+ z16.object({
643
+ diff: z16.number().min(-1).max(1).describe("Score change (`scores.after - scores.before`)")
641
644
  })
642
645
  ).describe("Score comparison")
643
646
  })
@@ -648,10 +651,10 @@ var scorableWithPluginDiffSchema = scorableDiffSchema.merge(
648
651
  var categoryDiffSchema = scorableDiffSchema;
649
652
  var groupDiffSchema = scorableWithPluginDiffSchema;
650
653
  var auditDiffSchema = scorableWithPluginDiffSchema.merge(
651
- z15.object({
654
+ z16.object({
652
655
  values: makeComparisonSchema(auditValueSchema).merge(
653
- z15.object({
654
- diff: z15.number().int().describe("Value change (`values.after - values.before`)")
656
+ z16.object({
657
+ diff: z16.number().int().describe("Value change (`values.after - values.before`)")
655
658
  })
656
659
  ).describe("Audit `value` comparison"),
657
660
  displayValues: makeComparisonSchema(auditDisplayValueSchema).describe(
@@ -660,18 +663,18 @@ var auditDiffSchema = scorableWithPluginDiffSchema.merge(
660
663
  })
661
664
  );
662
665
  var categoryResultSchema = scorableMetaSchema.merge(
663
- z15.object({ score: scoreSchema })
666
+ z16.object({ score: scoreSchema })
664
667
  );
665
668
  var groupResultSchema = scorableWithPluginMetaSchema.merge(
666
- z15.object({ score: scoreSchema })
669
+ z16.object({ score: scoreSchema })
667
670
  );
668
671
  var auditResultSchema = scorableWithPluginMetaSchema.merge(
669
672
  auditOutputSchema.pick({ score: true, value: true, displayValue: true })
670
673
  );
671
- var reportsDiffSchema = z15.object({
674
+ var reportsDiffSchema = z16.object({
672
675
  commits: makeComparisonSchema(commitSchema).nullable().describe("Commits identifying compared reports"),
673
676
  portalUrl: urlSchema.optional().describe("Link to comparison page in Code PushUp portal"),
674
- label: z15.string().optional().describe("Label (e.g. project name)"),
677
+ label: z16.string().optional().describe("Label (e.g. project name)"),
675
678
  categories: makeArraysComparisonSchema(
676
679
  categoryDiffSchema,
677
680
  categoryResultSchema,
@@ -844,9 +847,17 @@ function severityMarker(severity) {
844
847
  }
845
848
  return "\u2139\uFE0F";
846
849
  }
850
+ var MIN_NON_ZERO_RESULT = 0.1;
851
+ function roundValue(value) {
852
+ const roundedValue = Math.round(value * 10) / 10;
853
+ if (roundedValue === 0 && value !== 0) {
854
+ return MIN_NON_ZERO_RESULT * Math.sign(value);
855
+ }
856
+ return roundedValue;
857
+ }
847
858
  function formatScoreChange(diff) {
848
859
  const marker = getDiffMarker(diff);
849
- const text = formatDiffNumber(Math.round(diff * 1e3) / 10);
860
+ const text = formatDiffNumber(roundValue(diff * 100));
850
861
  return colorByScoreDiff(`${marker} ${text}`, diff);
851
862
  }
852
863
  function formatValueChange({
@@ -854,7 +865,7 @@ function formatValueChange({
854
865
  scores
855
866
  }) {
856
867
  const marker = getDiffMarker(values.diff);
857
- const percentage = values.before === 0 ? values.diff > 0 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY : Math.round(100 * values.diff / values.before);
868
+ const percentage = values.before === 0 ? values.diff > 0 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY : roundValue(values.diff / values.before * 100);
858
869
  const text = `${formatDiffNumber(percentage)}\u2009%`;
859
870
  return colorByScoreDiff(`${marker} ${text}`, scores.diff);
860
871
  }
@@ -1481,6 +1492,29 @@ import {
1481
1492
  MarkdownDocument,
1482
1493
  md as md2
1483
1494
  } from "build-md";
1495
+ import { posix as pathPosix } from "node:path";
1496
+
1497
+ // packages/utils/src/lib/reports/ide-environment.ts
1498
+ function getEnvironmentType() {
1499
+ if (isVSCode()) {
1500
+ return "vscode";
1501
+ }
1502
+ if (isGitHub()) {
1503
+ return "github";
1504
+ }
1505
+ return "other";
1506
+ }
1507
+ function isVSCode() {
1508
+ return process.env["TERM_PROGRAM"] === "vscode";
1509
+ }
1510
+ function isGitHub() {
1511
+ return process.env["GITHUB_ACTIONS"] === "true";
1512
+ }
1513
+ function getGitHubBaseUrl() {
1514
+ return `${process.env["GITHUB_SERVER_URL"]}/${process.env["GITHUB_REPOSITORY"]}/blob/${process.env["GITHUB_SHA"]}`;
1515
+ }
1516
+
1517
+ // packages/utils/src/lib/reports/formatting.ts
1484
1518
  function tableSection(tableData, options) {
1485
1519
  if (tableData.rows.length === 0) {
1486
1520
  return null;
@@ -1518,6 +1552,44 @@ function metaDescription(audit) {
1518
1552
  }
1519
1553
  return "";
1520
1554
  }
1555
+ function linkToLocalSourceForIde(source, options) {
1556
+ const { file, position } = source;
1557
+ const { outputDir } = options ?? {};
1558
+ if (!outputDir) {
1559
+ return md2.code(file);
1560
+ }
1561
+ return md2.link(formatFileLink(file, position, outputDir), md2.code(file));
1562
+ }
1563
+ function formatSourceLine(position) {
1564
+ if (!position) {
1565
+ return "";
1566
+ }
1567
+ const { startLine, endLine } = position;
1568
+ return endLine && startLine !== endLine ? `${startLine}-${endLine}` : `${startLine}`;
1569
+ }
1570
+ function formatGitHubLink(file, position) {
1571
+ const baseUrl = getGitHubBaseUrl();
1572
+ if (!position) {
1573
+ return `${baseUrl}/${file}`;
1574
+ }
1575
+ const { startLine, endLine, startColumn, endColumn } = position;
1576
+ const start = startColumn ? `L${startLine}C${startColumn}` : `L${startLine}`;
1577
+ const end = endLine ? endColumn ? `L${endLine}C${endColumn}` : `L${endLine}` : "";
1578
+ const lineRange = end && start !== end ? `${start}-${end}` : start;
1579
+ return `${baseUrl}/${file}#${lineRange}`;
1580
+ }
1581
+ function formatFileLink(file, position, outputDir) {
1582
+ const relativePath = pathPosix.relative(outputDir, file);
1583
+ const env = getEnvironmentType();
1584
+ switch (env) {
1585
+ case "vscode":
1586
+ return position ? `${relativePath}#L${position.startLine}` : relativePath;
1587
+ case "github":
1588
+ return formatGitHubLink(file, position);
1589
+ default:
1590
+ return relativePath;
1591
+ }
1592
+ }
1521
1593
 
1522
1594
  // packages/utils/src/lib/reports/generate-md-report-categoy-section.ts
1523
1595
  import { MarkdownDocument as MarkdownDocument2, md as md3 } from "build-md";
@@ -1719,16 +1791,16 @@ function auditDetailsAuditValue({
1719
1791
  String(displayValue ?? value)
1720
1792
  )} (score: ${formatReportScore(score)})`;
1721
1793
  }
1722
- function generateMdReport(report) {
1794
+ function generateMdReport(report, options) {
1723
1795
  return new MarkdownDocument3().heading(HIERARCHY.level_1, REPORT_HEADLINE_TEXT).$if(
1724
1796
  report.categories.length > 0,
1725
1797
  (doc) => doc.$concat(
1726
1798
  categoriesOverviewSection(report),
1727
1799
  categoriesDetailsSection(report)
1728
1800
  )
1729
- ).$concat(auditsSection(report), aboutSection(report)).rule().paragraph(md4`${FOOTER_PREFIX} ${md4.link(README_LINK, "Code PushUp")}`).toString();
1801
+ ).$concat(auditsSection(report, options), aboutSection(report)).rule().paragraph(md4`${FOOTER_PREFIX} ${md4.link(README_LINK, "Code PushUp")}`).toString();
1730
1802
  }
1731
- function auditDetailsIssues(issues = []) {
1803
+ function auditDetailsIssues(issues = [], options) {
1732
1804
  if (issues.length === 0) {
1733
1805
  return null;
1734
1806
  }
@@ -1744,39 +1816,36 @@ function auditDetailsIssues(issues = []) {
1744
1816
  if (!source) {
1745
1817
  return [severity, message];
1746
1818
  }
1747
- const file = md4.code(source.file);
1819
+ const file = linkToLocalSourceForIde(source, options);
1748
1820
  if (!source.position) {
1749
1821
  return [severity, message, file];
1750
1822
  }
1751
- const { startLine, endLine } = source.position;
1752
- const line = `${startLine || ""}${endLine && startLine !== endLine ? `-${endLine}` : ""}`;
1823
+ const line = formatSourceLine(source.position);
1753
1824
  return [severity, message, file, line];
1754
1825
  })
1755
1826
  );
1756
1827
  }
1757
- function auditDetails(audit) {
1828
+ function auditDetails(audit, options) {
1758
1829
  const { table: table2, issues = [] } = audit.details ?? {};
1759
1830
  const detailsValue = auditDetailsAuditValue(audit);
1760
1831
  if (issues.length === 0 && !table2?.rows.length) {
1761
1832
  return new MarkdownDocument3().paragraph(detailsValue);
1762
1833
  }
1763
1834
  const tableSectionContent = table2 && tableSection(table2);
1764
- const issuesSectionContent = issues.length > 0 && auditDetailsIssues(issues);
1835
+ const issuesSectionContent = issues.length > 0 && auditDetailsIssues(issues, options);
1765
1836
  return new MarkdownDocument3().details(
1766
1837
  detailsValue,
1767
1838
  new MarkdownDocument3().$concat(tableSectionContent, issuesSectionContent)
1768
1839
  );
1769
1840
  }
1770
- function auditsSection({
1771
- plugins
1772
- }) {
1841
+ function auditsSection({ plugins }, options) {
1773
1842
  return new MarkdownDocument3().heading(HIERARCHY.level_2, "\u{1F6E1}\uFE0F Audits").$foreach(
1774
1843
  plugins.flatMap(
1775
1844
  (plugin) => plugin.audits.map((audit) => ({ ...audit, plugin }))
1776
1845
  ),
1777
1846
  (doc, { plugin, ...audit }) => {
1778
1847
  const auditTitle = `${audit.title} (${plugin.title})`;
1779
- const detailsContent = auditDetails(audit);
1848
+ const detailsContent = auditDetails(audit, options);
1780
1849
  const descriptionContent = metaDescription(audit);
1781
1850
  return doc.heading(HIERARCHY.level_3, auditTitle).$concat(detailsContent).paragraph(descriptionContent);
1782
1851
  }
@@ -2038,15 +2107,6 @@ function createDiffCategoriesSection(diff, options) {
2038
2107
  function createCategoriesTable(diff, options) {
2039
2108
  const { changed, unchanged, added } = diff.categories;
2040
2109
  const { hasChanges, skipUnchanged } = options;
2041
- const columns = [
2042
- { heading: "\u{1F3F7}\uFE0F Category", alignment: "left" },
2043
- {
2044
- heading: hasChanges ? "\u2B50 Previous score" : "\u2B50 Score",
2045
- alignment: "center"
2046
- },
2047
- { heading: "\u2B50 Current score", alignment: "center" },
2048
- { heading: "\u{1F504} Score change", alignment: "center" }
2049
- ];
2050
2110
  const rows = [
2051
2111
  ...sortChanges(changed).map((category) => [
2052
2112
  formatTitle(category),
@@ -2069,6 +2129,18 @@ function createCategoriesTable(diff, options) {
2069
2129
  "\u2013"
2070
2130
  ])
2071
2131
  ];
2132
+ if (rows.length === 0) {
2133
+ return [[], []];
2134
+ }
2135
+ const columns = [
2136
+ { heading: "\u{1F3F7}\uFE0F Category", alignment: "left" },
2137
+ {
2138
+ heading: hasChanges ? "\u2B50 Previous score" : "\u2B50 Score",
2139
+ alignment: "center"
2140
+ },
2141
+ { heading: "\u2B50 Current score", alignment: "center" },
2142
+ { heading: "\u{1F504} Score change", alignment: "center" }
2143
+ ];
2072
2144
  return [
2073
2145
  hasChanges ? columns : columns.slice(0, 2),
2074
2146
  rows.map((row) => hasChanges ? row : row.slice(0, 2))
@@ -2159,11 +2231,11 @@ import { bold as bold4, cyan, cyanBright, green as green2, red } from "ansis";
2159
2231
  function log(msg = "") {
2160
2232
  ui().logger.log(msg);
2161
2233
  }
2162
- function logStdoutSummary(report) {
2234
+ function logStdoutSummary(report, verbose = false) {
2163
2235
  const printCategories = report.categories.length > 0;
2164
2236
  log(reportToHeaderSection(report));
2165
2237
  log();
2166
- logPlugins(report);
2238
+ logPlugins(report.plugins, verbose);
2167
2239
  if (printCategories) {
2168
2240
  logCategories(report);
2169
2241
  }
@@ -2174,36 +2246,49 @@ function reportToHeaderSection(report) {
2174
2246
  const { packageName, version: version2 } = report;
2175
2247
  return `${bold4(REPORT_HEADLINE_TEXT)} - ${packageName}@${version2}`;
2176
2248
  }
2177
- function logPlugins(report) {
2178
- const { plugins } = report;
2249
+ function logPlugins(plugins, verbose) {
2179
2250
  plugins.forEach((plugin) => {
2180
2251
  const { title, audits } = plugin;
2181
- log();
2182
- log(bold4.magentaBright(`${title} audits`));
2183
- log();
2184
- audits.forEach((audit) => {
2185
- ui().row([
2186
- {
2187
- text: applyScoreColor({ score: audit.score, text: "\u25CF" }),
2188
- width: 2,
2189
- padding: [0, 1, 0, 0]
2190
- },
2191
- {
2192
- text: audit.title,
2193
- // eslint-disable-next-line no-magic-numbers
2194
- padding: [0, 3, 0, 0]
2195
- },
2196
- {
2197
- text: cyanBright(audit.displayValue || `${audit.value}`),
2198
- // eslint-disable-next-line no-magic-numbers
2199
- width: 20,
2200
- padding: [0, 0, 0, 0]
2201
- }
2202
- ]);
2203
- });
2252
+ const filteredAudits = verbose ? audits : audits.filter(({ score }) => score !== 1);
2253
+ const diff = audits.length - filteredAudits.length;
2254
+ logAudits(title, filteredAudits);
2255
+ if (diff > 0) {
2256
+ const notice = filteredAudits.length === 0 ? `... All ${diff} audits have perfect scores ...` : `... ${diff} audits with perfect scores omitted for brevity ...`;
2257
+ logRow(1, notice);
2258
+ }
2204
2259
  log();
2205
2260
  });
2206
2261
  }
2262
+ function logAudits(pluginTitle, audits) {
2263
+ log();
2264
+ log(bold4.magentaBright(`${pluginTitle} audits`));
2265
+ log();
2266
+ audits.forEach(({ score, title, displayValue, value }) => {
2267
+ logRow(score, title, displayValue || `${value}`);
2268
+ });
2269
+ }
2270
+ function logRow(score, title, value) {
2271
+ ui().row([
2272
+ {
2273
+ text: applyScoreColor({ score, text: "\u25CF" }),
2274
+ width: 2,
2275
+ padding: [0, 1, 0, 0]
2276
+ },
2277
+ {
2278
+ text: title,
2279
+ // eslint-disable-next-line no-magic-numbers
2280
+ padding: [0, 3, 0, 0]
2281
+ },
2282
+ ...value ? [
2283
+ {
2284
+ text: cyanBright(value),
2285
+ // eslint-disable-next-line no-magic-numbers
2286
+ width: 20,
2287
+ padding: [0, 0, 0, 0]
2288
+ }
2289
+ ] : []
2290
+ ]);
2291
+ }
2207
2292
  function logCategories({ categories, plugins }) {
2208
2293
  const hAlign = (idx) => idx === 0 ? "left" : "right";
2209
2294
  const rows = categories.map(({ title, score, refs, isBinary }) => [
@@ -2349,7 +2434,7 @@ var verboseUtils = (verbose = false) => ({
2349
2434
 
2350
2435
  // packages/core/package.json
2351
2436
  var name = "@code-pushup/core";
2352
- var version = "0.50.0";
2437
+ var version = "0.52.0";
2353
2438
 
2354
2439
  // packages/core/src/lib/implementation/execute-plugin.ts
2355
2440
  import { bold as bold5 } from "ansis";
@@ -2544,10 +2629,8 @@ var PersistError = class extends Error {
2544
2629
  super(`fileName: ${reportPath} could not be saved.`);
2545
2630
  }
2546
2631
  };
2547
- async function persistReport(report, options) {
2632
+ async function persistReport(report, sortedScoredReport, options) {
2548
2633
  const { outputDir, filename, format } = options;
2549
- const sortedScoredReport = sortReport(scoreReport(report));
2550
- logStdoutSummary(sortedScoredReport);
2551
2634
  const results = format.map((reportType) => {
2552
2635
  switch (reportType) {
2553
2636
  case "json":
@@ -2558,7 +2641,7 @@ async function persistReport(report, options) {
2558
2641
  case "md":
2559
2642
  return {
2560
2643
  format: "md",
2561
- content: generateMdReport(sortedScoredReport)
2644
+ content: generateMdReport(sortedScoredReport, { outputDir })
2562
2645
  };
2563
2646
  }
2564
2647
  });
@@ -2593,7 +2676,13 @@ function logPersistedResults(persistResults) {
2593
2676
  async function collectAndPersistReports(options) {
2594
2677
  const { exec } = verboseUtils(options.verbose);
2595
2678
  const report = await collect(options);
2596
- const persistResults = await persistReport(report, options.persist);
2679
+ const sortedScoredReport = sortReport(scoreReport(report));
2680
+ const persistResults = await persistReport(
2681
+ report,
2682
+ sortedScoredReport,
2683
+ options.persist
2684
+ );
2685
+ logStdoutSummary(sortedScoredReport, options.verbose);
2597
2686
  exec(() => {
2598
2687
  logPersistedResults(persistResults);
2599
2688
  });
@@ -2605,10 +2694,6 @@ async function collectAndPersistReports(options) {
2605
2694
  // packages/core/src/lib/compare.ts
2606
2695
  import { writeFile as writeFile2 } from "node:fs/promises";
2607
2696
  import { join as join5 } from "node:path";
2608
- import {
2609
- PortalOperationError,
2610
- getPortalComparisonLink
2611
- } from "@code-pushup/portal-client";
2612
2697
 
2613
2698
  // packages/core/src/lib/implementation/compare-scorables.ts
2614
2699
  function compareCategories(reports) {
@@ -2744,6 +2829,18 @@ function selectMeta(meta) {
2744
2829
  };
2745
2830
  }
2746
2831
 
2832
+ // packages/core/src/lib/load-portal-client.ts
2833
+ async function loadPortalClient() {
2834
+ try {
2835
+ return await import("@code-pushup/portal-client");
2836
+ } catch {
2837
+ ui().logger.error(
2838
+ "Optional peer dependency @code-pushup/portal-client is not available. Make sure it is installed to enable upload functionality."
2839
+ );
2840
+ return null;
2841
+ }
2842
+ }
2843
+
2747
2844
  // packages/core/src/lib/compare.ts
2748
2845
  async function compareReportFiles(inputPaths, persistConfig, uploadConfig, label) {
2749
2846
  const { outputDir, filename, format } = persistConfig;
@@ -2808,6 +2905,11 @@ function reportsDiffToFileContent(reportsDiff, format) {
2808
2905
  }
2809
2906
  async function fetchPortalComparisonLink(uploadConfig, commits) {
2810
2907
  const { server, apiKey, organization, project } = uploadConfig;
2908
+ const portalClient = await loadPortalClient();
2909
+ if (!portalClient) {
2910
+ return;
2911
+ }
2912
+ const { PortalOperationError, getPortalComparisonLink } = portalClient;
2811
2913
  try {
2812
2914
  return await getPortalComparisonLink({
2813
2915
  server,
@@ -2830,11 +2932,6 @@ async function fetchPortalComparisonLink(uploadConfig, commits) {
2830
2932
  }
2831
2933
  }
2832
2934
 
2833
- // packages/core/src/lib/upload.ts
2834
- import {
2835
- uploadToPortal
2836
- } from "@code-pushup/portal-client";
2837
-
2838
2935
  // packages/core/src/lib/implementation/report-to-gql.ts
2839
2936
  import {
2840
2937
  CategoryConfigRefType as PortalCategoryRefType,
@@ -2981,10 +3078,15 @@ function tableAlignmentToGQL(alignment) {
2981
3078
  }
2982
3079
 
2983
3080
  // packages/core/src/lib/upload.ts
2984
- async function upload(options, uploadFn = uploadToPortal) {
3081
+ async function upload(options) {
2985
3082
  if (options.upload == null) {
2986
3083
  throw new Error("Upload configuration is not set.");
2987
3084
  }
3085
+ const portalClient = await loadPortalClient();
3086
+ if (!portalClient) {
3087
+ return;
3088
+ }
3089
+ const { uploadToPortal } = portalClient;
2988
3090
  const { apiKey, server, organization, project, timeout } = options.upload;
2989
3091
  const report = await loadReport({
2990
3092
  ...options.persist,
@@ -2999,7 +3101,7 @@ async function upload(options, uploadFn = uploadToPortal) {
2999
3101
  commit: report.commit.hash,
3000
3102
  ...reportToGQL(report)
3001
3103
  };
3002
- return uploadFn({ apiKey, server, data, timeout });
3104
+ return uploadToPortal({ apiKey, server, data, timeout });
3003
3105
  }
3004
3106
 
3005
3107
  // packages/core/src/lib/history.ts
package/package.json CHANGED
@@ -1,14 +1,21 @@
1
1
  {
2
2
  "name": "@code-pushup/core",
3
- "version": "0.50.0",
3
+ "version": "0.52.0",
4
4
  "license": "MIT",
5
5
  "description": "Core business logic for the used by the Code PushUp CLI",
6
6
  "dependencies": {
7
- "@code-pushup/models": "0.50.0",
8
- "@code-pushup/utils": "0.50.0",
9
- "@code-pushup/portal-client": "^0.9.0",
7
+ "@code-pushup/models": "0.52.0",
8
+ "@code-pushup/utils": "0.52.0",
10
9
  "ansis": "^3.3.0"
11
10
  },
11
+ "peerDependencies": {
12
+ "@code-pushup/portal-client": "^0.9.0"
13
+ },
14
+ "peerDependenciesMeta": {
15
+ "@code-pushup/portal-client": {
16
+ "optional": true
17
+ }
18
+ },
12
19
  "homepage": "https://github.com/code-pushup/cli/tree/main/packages/core#readme",
13
20
  "bugs": {
14
21
  "url": "https://github.com/code-pushup/cli/issues"
@@ -18,6 +25,9 @@
18
25
  "url": "git+https://github.com/code-pushup/cli.git",
19
26
  "directory": "packages/core"
20
27
  },
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
21
31
  "type": "module",
22
32
  "main": "./index.js",
23
33
  "types": "./src/index.d.ts"
@@ -1,10 +1,10 @@
1
1
  import type { PersistConfig, Report } from '@code-pushup/models';
2
- import { type MultipleFileResults } from '@code-pushup/utils';
2
+ import { type MultipleFileResults, type ScoredReport } from '@code-pushup/utils';
3
3
  export declare class PersistDirError extends Error {
4
4
  constructor(outputDir: string);
5
5
  }
6
6
  export declare class PersistError extends Error {
7
7
  constructor(reportPath: string);
8
8
  }
9
- export declare function persistReport(report: Report, options: Required<PersistConfig>): Promise<MultipleFileResults>;
9
+ export declare function persistReport(report: Report, sortedScoredReport: ScoredReport, options: Required<PersistConfig>): Promise<MultipleFileResults>;
10
10
  export declare function logPersistedResults(persistResults: MultipleFileResults): void;
@@ -0,0 +1 @@
1
+ export declare function loadPortalClient(): Promise<typeof import('@code-pushup/portal-client') | null>;
@@ -1,4 +1,3 @@
1
- import { uploadToPortal } from '@code-pushup/portal-client';
2
1
  import type { PersistConfig, UploadConfig } from '@code-pushup/models';
3
2
  import type { GlobalOptions } from './types';
4
3
  export type UploadOptions = {
@@ -11,4 +10,4 @@ export type UploadOptions = {
11
10
  * @param options
12
11
  * @param uploadFn
13
12
  */
14
- export declare function upload(options: UploadOptions, uploadFn?: typeof uploadToPortal): Promise<import("@code-pushup/portal-client").ReportFragment>;
13
+ export declare function upload(options: UploadOptions): Promise<import("@code-pushup/portal-client").ReportFragment | undefined>;