@code-pushup/core 0.50.0 → 0.51.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 +205 -133
- package/package.json +3 -3
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/
|
|
158
|
+
// packages/models/src/lib/source.ts
|
|
159
159
|
import { z as z2 } from "zod";
|
|
160
|
-
var
|
|
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 =
|
|
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
|
|
207
|
+
import { z as z6 } from "zod";
|
|
190
208
|
|
|
191
209
|
// packages/models/src/lib/issue.ts
|
|
192
|
-
import { z as
|
|
193
|
-
var
|
|
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 =
|
|
214
|
+
var issueSchema = z4.object(
|
|
212
215
|
{
|
|
213
|
-
message:
|
|
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
|
|
222
|
-
var tableAlignmentSchema =
|
|
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 =
|
|
226
|
-
key:
|
|
227
|
-
label:
|
|
228
|
+
var tableColumnObjectSchema = z5.object({
|
|
229
|
+
key: z5.string(),
|
|
230
|
+
label: z5.string().optional(),
|
|
228
231
|
align: tableAlignmentSchema.optional()
|
|
229
232
|
});
|
|
230
|
-
var tableRowObjectSchema =
|
|
233
|
+
var tableRowObjectSchema = z5.record(tableCellValueSchema, {
|
|
231
234
|
description: "Object row"
|
|
232
235
|
});
|
|
233
|
-
var tableRowPrimitiveSchema =
|
|
236
|
+
var tableRowPrimitiveSchema = z5.array(tableCellValueSchema, {
|
|
234
237
|
description: "Primitive row"
|
|
235
238
|
});
|
|
236
|
-
var tableSharedSchema =
|
|
237
|
-
title:
|
|
239
|
+
var tableSharedSchema = z5.object({
|
|
240
|
+
title: z5.string().optional().describe("Display title for table")
|
|
238
241
|
});
|
|
239
242
|
var tablePrimitiveSchema = tableSharedSchema.merge(
|
|
240
|
-
|
|
243
|
+
z5.object(
|
|
241
244
|
{
|
|
242
|
-
columns:
|
|
243
|
-
rows:
|
|
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
|
-
|
|
252
|
+
z5.object(
|
|
250
253
|
{
|
|
251
|
-
columns:
|
|
252
|
-
|
|
253
|
-
|
|
254
|
+
columns: z5.union([
|
|
255
|
+
z5.array(tableAlignmentSchema),
|
|
256
|
+
z5.array(tableColumnObjectSchema)
|
|
254
257
|
]).optional(),
|
|
255
|
-
rows:
|
|
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") =>
|
|
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 =
|
|
267
|
-
var auditDetailsSchema =
|
|
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:
|
|
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 =
|
|
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 =
|
|
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
|
|
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
|
-
|
|
307
|
-
type:
|
|
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
|
-
|
|
329
|
-
isBinary:
|
|
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 =
|
|
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
|
|
365
|
-
var commitSchema =
|
|
367
|
+
import { z as z8 } from "zod";
|
|
368
|
+
var commitSchema = z8.object(
|
|
366
369
|
{
|
|
367
|
-
hash:
|
|
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:
|
|
372
|
-
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:
|
|
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
|
|
386
|
+
import { z as z14 } from "zod";
|
|
384
387
|
|
|
385
388
|
// packages/models/src/lib/persist-config.ts
|
|
386
|
-
import { z as
|
|
387
|
-
var formatSchema =
|
|
388
|
-
var persistConfigSchema =
|
|
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:
|
|
394
|
+
format: z9.array(formatSchema).optional()
|
|
392
395
|
});
|
|
393
396
|
|
|
394
397
|
// packages/models/src/lib/plugin-config.ts
|
|
395
|
-
import { z as
|
|
398
|
+
import { z as z12 } from "zod";
|
|
396
399
|
|
|
397
400
|
// packages/models/src/lib/group.ts
|
|
398
|
-
import { z as
|
|
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 =
|
|
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
|
|
444
|
-
var outputTransformSchema =
|
|
445
|
-
var runnerConfigSchema =
|
|
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:
|
|
450
|
+
command: z11.string({
|
|
448
451
|
description: "Shell command to execute"
|
|
449
452
|
}),
|
|
450
|
-
args:
|
|
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 =
|
|
459
|
-
var runnerFunctionSchema =
|
|
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
|
-
|
|
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 =
|
|
476
|
-
runner:
|
|
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
|
|
503
|
-
var uploadConfigSchema =
|
|
505
|
+
import { z as z13 } from "zod";
|
|
506
|
+
var uploadConfigSchema = z13.object({
|
|
504
507
|
server: urlSchema.describe("URL of deployed portal API"),
|
|
505
|
-
apiKey:
|
|
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:
|
|
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 =
|
|
517
|
-
plugins:
|
|
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
|
|
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
|
-
|
|
553
|
-
audits:
|
|
554
|
-
groups:
|
|
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
|
-
|
|
591
|
+
z15.object(
|
|
589
592
|
{
|
|
590
|
-
categories:
|
|
591
|
-
plugins:
|
|
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
|
|
610
|
+
import { z as z16 } from "zod";
|
|
608
611
|
function makeComparisonSchema(schema) {
|
|
609
612
|
const sharedDescription = schema.description || "Result";
|
|
610
|
-
return
|
|
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
|
|
619
|
+
return z16.object(
|
|
617
620
|
{
|
|
618
|
-
changed:
|
|
619
|
-
unchanged:
|
|
620
|
-
added:
|
|
621
|
-
removed:
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
640
|
+
z16.object({
|
|
638
641
|
scores: makeComparisonSchema(scoreSchema).merge(
|
|
639
|
-
|
|
640
|
-
diff:
|
|
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
|
-
|
|
654
|
+
z16.object({
|
|
652
655
|
values: makeComparisonSchema(auditValueSchema).merge(
|
|
653
|
-
|
|
654
|
-
diff:
|
|
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
|
-
|
|
666
|
+
z16.object({ score: scoreSchema })
|
|
664
667
|
);
|
|
665
668
|
var groupResultSchema = scorableWithPluginMetaSchema.merge(
|
|
666
|
-
|
|
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 =
|
|
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:
|
|
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(
|
|
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 :
|
|
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 =
|
|
1819
|
+
const file = linkToLocalSourceForIde(source, options);
|
|
1748
1820
|
if (!source.position) {
|
|
1749
1821
|
return [severity, message, file];
|
|
1750
1822
|
}
|
|
1751
|
-
const
|
|
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))
|
|
@@ -2349,7 +2421,7 @@ var verboseUtils = (verbose = false) => ({
|
|
|
2349
2421
|
|
|
2350
2422
|
// packages/core/package.json
|
|
2351
2423
|
var name = "@code-pushup/core";
|
|
2352
|
-
var version = "0.
|
|
2424
|
+
var version = "0.51.0";
|
|
2353
2425
|
|
|
2354
2426
|
// packages/core/src/lib/implementation/execute-plugin.ts
|
|
2355
2427
|
import { bold as bold5 } from "ansis";
|
|
@@ -2558,7 +2630,7 @@ async function persistReport(report, options) {
|
|
|
2558
2630
|
case "md":
|
|
2559
2631
|
return {
|
|
2560
2632
|
format: "md",
|
|
2561
|
-
content: generateMdReport(sortedScoredReport)
|
|
2633
|
+
content: generateMdReport(sortedScoredReport, { outputDir })
|
|
2562
2634
|
};
|
|
2563
2635
|
}
|
|
2564
2636
|
});
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@code-pushup/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.51.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.
|
|
8
|
-
"@code-pushup/utils": "0.
|
|
7
|
+
"@code-pushup/models": "0.51.0",
|
|
8
|
+
"@code-pushup/utils": "0.51.0",
|
|
9
9
|
"@code-pushup/portal-client": "^0.9.0",
|
|
10
10
|
"ansis": "^3.3.0"
|
|
11
11
|
},
|