@code-pushup/core 0.25.7 → 0.26.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.
- package/index.js +81 -73
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -312,23 +312,42 @@ function getDuplicateSlugCategories(categories) {
|
|
|
312
312
|
return hasDuplicateStrings(categories.map(({ slug }) => slug));
|
|
313
313
|
}
|
|
314
314
|
|
|
315
|
+
// packages/models/src/lib/commit.ts
|
|
316
|
+
import { z as z6 } from "zod";
|
|
317
|
+
var commitSchema = z6.object(
|
|
318
|
+
{
|
|
319
|
+
hash: z6.string({ description: "Commit SHA (full)" }).regex(
|
|
320
|
+
/^[\da-f]{40}$/,
|
|
321
|
+
"Commit SHA should be a 40-character hexadecimal string"
|
|
322
|
+
),
|
|
323
|
+
message: z6.string({ description: "Commit message" }),
|
|
324
|
+
date: z6.coerce.date({
|
|
325
|
+
description: "Date and time when commit was authored"
|
|
326
|
+
}),
|
|
327
|
+
author: z6.string({
|
|
328
|
+
description: "Commit author name"
|
|
329
|
+
}).trim()
|
|
330
|
+
},
|
|
331
|
+
{ description: "Git commit" }
|
|
332
|
+
);
|
|
333
|
+
|
|
315
334
|
// packages/models/src/lib/core-config.ts
|
|
316
|
-
import { z as
|
|
335
|
+
import { z as z12 } from "zod";
|
|
317
336
|
|
|
318
337
|
// packages/models/src/lib/persist-config.ts
|
|
319
|
-
import { z as
|
|
320
|
-
var formatSchema =
|
|
321
|
-
var persistConfigSchema =
|
|
338
|
+
import { z as z7 } from "zod";
|
|
339
|
+
var formatSchema = z7.enum(["json", "md"]);
|
|
340
|
+
var persistConfigSchema = z7.object({
|
|
322
341
|
outputDir: filePathSchema.describe("Artifacts folder").optional(),
|
|
323
342
|
filename: fileNameSchema.describe("Artifacts file name (without extension)").optional(),
|
|
324
|
-
format:
|
|
343
|
+
format: z7.array(formatSchema).optional()
|
|
325
344
|
});
|
|
326
345
|
|
|
327
346
|
// packages/models/src/lib/plugin-config.ts
|
|
328
|
-
import { z as
|
|
347
|
+
import { z as z10 } from "zod";
|
|
329
348
|
|
|
330
349
|
// packages/models/src/lib/group.ts
|
|
331
|
-
import { z as
|
|
350
|
+
import { z as z8 } from "zod";
|
|
332
351
|
var groupRefSchema = weightedRefSchema(
|
|
333
352
|
"Weighted reference to a group",
|
|
334
353
|
"Reference slug to a group within this plugin (e.g. 'max-lines')"
|
|
@@ -345,7 +364,7 @@ var groupSchema = scorableSchema(
|
|
|
345
364
|
getDuplicateRefsInGroups,
|
|
346
365
|
duplicateRefsInGroupsErrorMsg
|
|
347
366
|
).merge(groupMetaSchema);
|
|
348
|
-
var groupsSchema =
|
|
367
|
+
var groupsSchema = z8.array(groupSchema, {
|
|
349
368
|
description: "List of groups"
|
|
350
369
|
}).optional().refine(
|
|
351
370
|
(groups) => !getDuplicateSlugsInGroups(groups),
|
|
@@ -373,14 +392,14 @@ function getDuplicateSlugsInGroups(groups) {
|
|
|
373
392
|
}
|
|
374
393
|
|
|
375
394
|
// packages/models/src/lib/runner-config.ts
|
|
376
|
-
import { z as
|
|
377
|
-
var outputTransformSchema =
|
|
378
|
-
var runnerConfigSchema =
|
|
395
|
+
import { z as z9 } from "zod";
|
|
396
|
+
var outputTransformSchema = z9.function().args(z9.unknown()).returns(z9.union([auditOutputsSchema, z9.promise(auditOutputsSchema)]));
|
|
397
|
+
var runnerConfigSchema = z9.object(
|
|
379
398
|
{
|
|
380
|
-
command:
|
|
399
|
+
command: z9.string({
|
|
381
400
|
description: "Shell command to execute"
|
|
382
401
|
}),
|
|
383
|
-
args:
|
|
402
|
+
args: z9.array(z9.string({ description: "Command arguments" })).optional(),
|
|
384
403
|
outputFile: filePathSchema.describe("Output path"),
|
|
385
404
|
outputTransform: outputTransformSchema.optional()
|
|
386
405
|
},
|
|
@@ -388,8 +407,8 @@ var runnerConfigSchema = z8.object(
|
|
|
388
407
|
description: "How to execute runner"
|
|
389
408
|
}
|
|
390
409
|
);
|
|
391
|
-
var onProgressSchema =
|
|
392
|
-
var runnerFunctionSchema =
|
|
410
|
+
var onProgressSchema = z9.function().args(z9.unknown()).returns(z9.void());
|
|
411
|
+
var runnerFunctionSchema = z9.function().args(onProgressSchema.optional()).returns(z9.union([auditOutputsSchema, z9.promise(auditOutputsSchema)]));
|
|
393
412
|
|
|
394
413
|
// packages/models/src/lib/plugin-config.ts
|
|
395
414
|
var pluginMetaSchema = packageVersionSchema().merge(
|
|
@@ -400,13 +419,13 @@ var pluginMetaSchema = packageVersionSchema().merge(
|
|
|
400
419
|
description: "Plugin metadata"
|
|
401
420
|
})
|
|
402
421
|
).merge(
|
|
403
|
-
|
|
422
|
+
z10.object({
|
|
404
423
|
slug: slugSchema.describe("Unique plugin slug within core config"),
|
|
405
424
|
icon: materialIconSchema
|
|
406
425
|
})
|
|
407
426
|
);
|
|
408
|
-
var pluginDataSchema =
|
|
409
|
-
runner:
|
|
427
|
+
var pluginDataSchema = z10.object({
|
|
428
|
+
runner: z10.union([runnerConfigSchema, runnerFunctionSchema]),
|
|
410
429
|
audits: pluginAuditsSchema,
|
|
411
430
|
groups: groupsSchema
|
|
412
431
|
});
|
|
@@ -432,22 +451,22 @@ function getMissingRefsFromGroups(pluginCfg) {
|
|
|
432
451
|
}
|
|
433
452
|
|
|
434
453
|
// packages/models/src/lib/upload-config.ts
|
|
435
|
-
import { z as
|
|
436
|
-
var uploadConfigSchema =
|
|
454
|
+
import { z as z11 } from "zod";
|
|
455
|
+
var uploadConfigSchema = z11.object({
|
|
437
456
|
server: urlSchema.describe("URL of deployed portal API"),
|
|
438
|
-
apiKey:
|
|
457
|
+
apiKey: z11.string({
|
|
439
458
|
description: "API key with write access to portal (use `process.env` for security)"
|
|
440
459
|
}),
|
|
441
460
|
organization: slugSchema.describe(
|
|
442
461
|
"Organization slug from Code PushUp portal"
|
|
443
462
|
),
|
|
444
463
|
project: slugSchema.describe("Project slug from Code PushUp portal"),
|
|
445
|
-
timeout:
|
|
464
|
+
timeout: z11.number({ description: "Request timeout in minutes (default is 5)" }).positive().int().optional()
|
|
446
465
|
});
|
|
447
466
|
|
|
448
467
|
// packages/models/src/lib/core-config.ts
|
|
449
|
-
var unrefinedCoreConfigSchema =
|
|
450
|
-
plugins:
|
|
468
|
+
var unrefinedCoreConfigSchema = z12.object({
|
|
469
|
+
plugins: z12.array(pluginConfigSchema, {
|
|
451
470
|
description: "List of plugins to be used (official, community-provided, or custom)"
|
|
452
471
|
}).min(1),
|
|
453
472
|
/** portal configuration for persisting results */
|
|
@@ -474,7 +493,7 @@ var CONFIG_FILE_NAME = "code-pushup.config";
|
|
|
474
493
|
var SUPPORTED_CONFIG_FILE_FORMATS = ["ts", "mjs", "js"];
|
|
475
494
|
|
|
476
495
|
// packages/models/src/lib/report.ts
|
|
477
|
-
import { z as
|
|
496
|
+
import { z as z13 } from "zod";
|
|
478
497
|
var auditReportSchema = auditSchema.merge(auditOutputSchema);
|
|
479
498
|
var pluginReportSchema = pluginMetaSchema.merge(
|
|
480
499
|
executionMetaSchema({
|
|
@@ -482,9 +501,9 @@ var pluginReportSchema = pluginMetaSchema.merge(
|
|
|
482
501
|
descriptionDuration: "Duration of the plugin run in ms"
|
|
483
502
|
})
|
|
484
503
|
).merge(
|
|
485
|
-
|
|
486
|
-
audits:
|
|
487
|
-
groups:
|
|
504
|
+
z13.object({
|
|
505
|
+
audits: z13.array(auditReportSchema).min(1),
|
|
506
|
+
groups: z13.array(groupSchema).optional()
|
|
488
507
|
})
|
|
489
508
|
).refine(
|
|
490
509
|
(pluginReport) => !getMissingRefsFromGroups2(pluginReport.audits, pluginReport.groups ?? []),
|
|
@@ -518,10 +537,11 @@ var reportSchema = packageVersionSchema({
|
|
|
518
537
|
descriptionDuration: "Duration of the collect run in ms"
|
|
519
538
|
})
|
|
520
539
|
).merge(
|
|
521
|
-
|
|
540
|
+
z13.object(
|
|
522
541
|
{
|
|
523
|
-
categories:
|
|
524
|
-
plugins:
|
|
542
|
+
categories: z13.array(categoryConfigSchema),
|
|
543
|
+
plugins: z13.array(pluginReportSchema).min(1),
|
|
544
|
+
commit: commitSchema.describe("Git commit for which report was collected").nullable()
|
|
525
545
|
},
|
|
526
546
|
{ description: "Collect output data" }
|
|
527
547
|
)
|
|
@@ -967,9 +987,12 @@ function toUnixPath(path) {
|
|
|
967
987
|
async function getLatestCommit(git = simpleGit()) {
|
|
968
988
|
const log = await git.log({
|
|
969
989
|
maxCount: 1,
|
|
970
|
-
format: { hash: "%H", message: "%s", author: "%an", date: "%
|
|
990
|
+
format: { hash: "%H", message: "%s", author: "%an", date: "%aI" }
|
|
971
991
|
});
|
|
972
|
-
|
|
992
|
+
if (!log.latest) {
|
|
993
|
+
return null;
|
|
994
|
+
}
|
|
995
|
+
return commitSchema.parse(log.latest);
|
|
973
996
|
}
|
|
974
997
|
function getGitRoot(git = simpleGit()) {
|
|
975
998
|
return git.revparse("--show-toplevel");
|
|
@@ -979,18 +1002,6 @@ function formatGitPath(path, gitRoot) {
|
|
|
979
1002
|
const relativePath = relative(gitRoot, absolutePath);
|
|
980
1003
|
return toUnixPath(relativePath);
|
|
981
1004
|
}
|
|
982
|
-
function validateCommitData(commitData, options = {}) {
|
|
983
|
-
if (!commitData) {
|
|
984
|
-
const msg = "no commit data available";
|
|
985
|
-
if (options.throwError) {
|
|
986
|
-
throw new Error(msg);
|
|
987
|
-
} else {
|
|
988
|
-
console.warn(msg);
|
|
989
|
-
return false;
|
|
990
|
-
}
|
|
991
|
-
}
|
|
992
|
-
return true;
|
|
993
|
-
}
|
|
994
1005
|
|
|
995
1006
|
// packages/utils/src/lib/group-by-status.ts
|
|
996
1007
|
function groupByStatus(results) {
|
|
@@ -1135,7 +1146,7 @@ function tableHtml(data) {
|
|
|
1135
1146
|
}
|
|
1136
1147
|
|
|
1137
1148
|
// packages/utils/src/lib/reports/generate-md-report.ts
|
|
1138
|
-
function generateMdReport(report
|
|
1149
|
+
function generateMdReport(report) {
|
|
1139
1150
|
const printCategories = report.categories.length > 0;
|
|
1140
1151
|
return (
|
|
1141
1152
|
// header section
|
|
@@ -1144,7 +1155,7 @@ function generateMdReport(report, commitData) {
|
|
|
1144
1155
|
(printCategories ? reportToOverviewSection(report) + NEW_LINE + NEW_LINE : "") + // categories section
|
|
1145
1156
|
(printCategories ? reportToCategoriesSection(report) + NEW_LINE + NEW_LINE : "") + // audits section
|
|
1146
1157
|
reportToAuditsSection(report) + NEW_LINE + NEW_LINE + // about section
|
|
1147
|
-
reportToAboutSection(report
|
|
1158
|
+
reportToAboutSection(report) + NEW_LINE + NEW_LINE + // footer section
|
|
1148
1159
|
`${FOOTER_PREFIX} ${link(README_LINK, "Code PushUp")}`
|
|
1149
1160
|
);
|
|
1150
1161
|
}
|
|
@@ -1268,10 +1279,10 @@ function reportToDetailsSection(audit) {
|
|
|
1268
1279
|
const detailsTable = `<h4>Issues</h4>${tableHtml(detailsTableData)}`;
|
|
1269
1280
|
return details(detailsTitle, detailsTable);
|
|
1270
1281
|
}
|
|
1271
|
-
function reportToAboutSection(report
|
|
1282
|
+
function reportToAboutSection(report) {
|
|
1272
1283
|
const date = formatDate(/* @__PURE__ */ new Date());
|
|
1273
|
-
const { duration, version: version2, plugins, categories } = report;
|
|
1274
|
-
const commitInfo =
|
|
1284
|
+
const { duration, version: version2, commit, plugins, categories } = report;
|
|
1285
|
+
const commitInfo = commit ? `${commit.message} (${commit.hash.slice(0, 7)})` : "N/A";
|
|
1275
1286
|
const reportMetaTable = [
|
|
1276
1287
|
reportMetaTableHeaders,
|
|
1277
1288
|
[
|
|
@@ -1556,7 +1567,7 @@ var verboseUtils = (verbose = false) => ({
|
|
|
1556
1567
|
|
|
1557
1568
|
// packages/core/package.json
|
|
1558
1569
|
var name = "@code-pushup/core";
|
|
1559
|
-
var version = "0.
|
|
1570
|
+
var version = "0.26.1";
|
|
1560
1571
|
|
|
1561
1572
|
// packages/core/src/lib/implementation/execute-plugin.ts
|
|
1562
1573
|
import chalk5 from "chalk";
|
|
@@ -1699,8 +1710,10 @@ async function collect(options) {
|
|
|
1699
1710
|
const { plugins, categories } = options;
|
|
1700
1711
|
const date = (/* @__PURE__ */ new Date()).toISOString();
|
|
1701
1712
|
const start = performance.now();
|
|
1713
|
+
const commit = await getLatestCommit();
|
|
1702
1714
|
const pluginOutputs = await executePlugins(plugins, options);
|
|
1703
1715
|
return {
|
|
1716
|
+
commit,
|
|
1704
1717
|
packageName: name,
|
|
1705
1718
|
version,
|
|
1706
1719
|
date,
|
|
@@ -1727,24 +1740,20 @@ async function persistReport(report, options) {
|
|
|
1727
1740
|
const { outputDir, filename, format } = options;
|
|
1728
1741
|
const sortedScoredReport = sortReport(scoreReport(report));
|
|
1729
1742
|
console.info(generateStdoutSummary(sortedScoredReport));
|
|
1730
|
-
const results =
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
};
|
|
1745
|
-
}
|
|
1746
|
-
})
|
|
1747
|
-
);
|
|
1743
|
+
const results = format.map((reportType) => {
|
|
1744
|
+
switch (reportType) {
|
|
1745
|
+
case "json":
|
|
1746
|
+
return {
|
|
1747
|
+
format: "json",
|
|
1748
|
+
content: JSON.stringify(report, null, 2)
|
|
1749
|
+
};
|
|
1750
|
+
case "md":
|
|
1751
|
+
return {
|
|
1752
|
+
format: "md",
|
|
1753
|
+
content: generateMdReport(sortedScoredReport)
|
|
1754
|
+
};
|
|
1755
|
+
}
|
|
1756
|
+
});
|
|
1748
1757
|
if (!await directoryExists(outputDir)) {
|
|
1749
1758
|
try {
|
|
1750
1759
|
await mkdir2(outputDir, { recursive: true });
|
|
@@ -1941,14 +1950,13 @@ async function upload(options, uploadFn = uploadToPortal) {
|
|
|
1941
1950
|
...options.persist,
|
|
1942
1951
|
format: "json"
|
|
1943
1952
|
});
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
throw new Error("no commit data available");
|
|
1953
|
+
if (!report.commit) {
|
|
1954
|
+
throw new Error("Commit must be linked in order to upload report");
|
|
1947
1955
|
}
|
|
1948
1956
|
const data = {
|
|
1949
1957
|
organization,
|
|
1950
1958
|
project,
|
|
1951
|
-
commit:
|
|
1959
|
+
commit: report.commit.hash,
|
|
1952
1960
|
...reportToGQL(report)
|
|
1953
1961
|
};
|
|
1954
1962
|
return uploadFn({ apiKey, server, data, timeout });
|