@code-pushup/core 0.51.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 +73 -43
- package/package.json +14 -4
- package/src/lib/implementation/persist.d.ts +2 -2
- package/src/lib/load-portal-client.d.ts +1 -0
- package/src/lib/upload.d.ts +1 -2
package/index.js
CHANGED
|
@@ -2231,11 +2231,11 @@ import { bold as bold4, cyan, cyanBright, green as green2, red } from "ansis";
|
|
|
2231
2231
|
function log(msg = "") {
|
|
2232
2232
|
ui().logger.log(msg);
|
|
2233
2233
|
}
|
|
2234
|
-
function logStdoutSummary(report) {
|
|
2234
|
+
function logStdoutSummary(report, verbose = false) {
|
|
2235
2235
|
const printCategories = report.categories.length > 0;
|
|
2236
2236
|
log(reportToHeaderSection(report));
|
|
2237
2237
|
log();
|
|
2238
|
-
logPlugins(report);
|
|
2238
|
+
logPlugins(report.plugins, verbose);
|
|
2239
2239
|
if (printCategories) {
|
|
2240
2240
|
logCategories(report);
|
|
2241
2241
|
}
|
|
@@ -2246,36 +2246,49 @@ function reportToHeaderSection(report) {
|
|
|
2246
2246
|
const { packageName, version: version2 } = report;
|
|
2247
2247
|
return `${bold4(REPORT_HEADLINE_TEXT)} - ${packageName}@${version2}`;
|
|
2248
2248
|
}
|
|
2249
|
-
function logPlugins(
|
|
2250
|
-
const { plugins } = report;
|
|
2249
|
+
function logPlugins(plugins, verbose) {
|
|
2251
2250
|
plugins.forEach((plugin) => {
|
|
2252
2251
|
const { title, audits } = plugin;
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
width: 2,
|
|
2261
|
-
padding: [0, 1, 0, 0]
|
|
2262
|
-
},
|
|
2263
|
-
{
|
|
2264
|
-
text: audit.title,
|
|
2265
|
-
// eslint-disable-next-line no-magic-numbers
|
|
2266
|
-
padding: [0, 3, 0, 0]
|
|
2267
|
-
},
|
|
2268
|
-
{
|
|
2269
|
-
text: cyanBright(audit.displayValue || `${audit.value}`),
|
|
2270
|
-
// eslint-disable-next-line no-magic-numbers
|
|
2271
|
-
width: 20,
|
|
2272
|
-
padding: [0, 0, 0, 0]
|
|
2273
|
-
}
|
|
2274
|
-
]);
|
|
2275
|
-
});
|
|
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
|
+
}
|
|
2276
2259
|
log();
|
|
2277
2260
|
});
|
|
2278
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
|
+
}
|
|
2279
2292
|
function logCategories({ categories, plugins }) {
|
|
2280
2293
|
const hAlign = (idx) => idx === 0 ? "left" : "right";
|
|
2281
2294
|
const rows = categories.map(({ title, score, refs, isBinary }) => [
|
|
@@ -2421,7 +2434,7 @@ var verboseUtils = (verbose = false) => ({
|
|
|
2421
2434
|
|
|
2422
2435
|
// packages/core/package.json
|
|
2423
2436
|
var name = "@code-pushup/core";
|
|
2424
|
-
var version = "0.
|
|
2437
|
+
var version = "0.52.0";
|
|
2425
2438
|
|
|
2426
2439
|
// packages/core/src/lib/implementation/execute-plugin.ts
|
|
2427
2440
|
import { bold as bold5 } from "ansis";
|
|
@@ -2616,10 +2629,8 @@ var PersistError = class extends Error {
|
|
|
2616
2629
|
super(`fileName: ${reportPath} could not be saved.`);
|
|
2617
2630
|
}
|
|
2618
2631
|
};
|
|
2619
|
-
async function persistReport(report, options) {
|
|
2632
|
+
async function persistReport(report, sortedScoredReport, options) {
|
|
2620
2633
|
const { outputDir, filename, format } = options;
|
|
2621
|
-
const sortedScoredReport = sortReport(scoreReport(report));
|
|
2622
|
-
logStdoutSummary(sortedScoredReport);
|
|
2623
2634
|
const results = format.map((reportType) => {
|
|
2624
2635
|
switch (reportType) {
|
|
2625
2636
|
case "json":
|
|
@@ -2665,7 +2676,13 @@ function logPersistedResults(persistResults) {
|
|
|
2665
2676
|
async function collectAndPersistReports(options) {
|
|
2666
2677
|
const { exec } = verboseUtils(options.verbose);
|
|
2667
2678
|
const report = await collect(options);
|
|
2668
|
-
const
|
|
2679
|
+
const sortedScoredReport = sortReport(scoreReport(report));
|
|
2680
|
+
const persistResults = await persistReport(
|
|
2681
|
+
report,
|
|
2682
|
+
sortedScoredReport,
|
|
2683
|
+
options.persist
|
|
2684
|
+
);
|
|
2685
|
+
logStdoutSummary(sortedScoredReport, options.verbose);
|
|
2669
2686
|
exec(() => {
|
|
2670
2687
|
logPersistedResults(persistResults);
|
|
2671
2688
|
});
|
|
@@ -2677,10 +2694,6 @@ async function collectAndPersistReports(options) {
|
|
|
2677
2694
|
// packages/core/src/lib/compare.ts
|
|
2678
2695
|
import { writeFile as writeFile2 } from "node:fs/promises";
|
|
2679
2696
|
import { join as join5 } from "node:path";
|
|
2680
|
-
import {
|
|
2681
|
-
PortalOperationError,
|
|
2682
|
-
getPortalComparisonLink
|
|
2683
|
-
} from "@code-pushup/portal-client";
|
|
2684
2697
|
|
|
2685
2698
|
// packages/core/src/lib/implementation/compare-scorables.ts
|
|
2686
2699
|
function compareCategories(reports) {
|
|
@@ -2816,6 +2829,18 @@ function selectMeta(meta) {
|
|
|
2816
2829
|
};
|
|
2817
2830
|
}
|
|
2818
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
|
+
|
|
2819
2844
|
// packages/core/src/lib/compare.ts
|
|
2820
2845
|
async function compareReportFiles(inputPaths, persistConfig, uploadConfig, label) {
|
|
2821
2846
|
const { outputDir, filename, format } = persistConfig;
|
|
@@ -2880,6 +2905,11 @@ function reportsDiffToFileContent(reportsDiff, format) {
|
|
|
2880
2905
|
}
|
|
2881
2906
|
async function fetchPortalComparisonLink(uploadConfig, commits) {
|
|
2882
2907
|
const { server, apiKey, organization, project } = uploadConfig;
|
|
2908
|
+
const portalClient = await loadPortalClient();
|
|
2909
|
+
if (!portalClient) {
|
|
2910
|
+
return;
|
|
2911
|
+
}
|
|
2912
|
+
const { PortalOperationError, getPortalComparisonLink } = portalClient;
|
|
2883
2913
|
try {
|
|
2884
2914
|
return await getPortalComparisonLink({
|
|
2885
2915
|
server,
|
|
@@ -2902,11 +2932,6 @@ async function fetchPortalComparisonLink(uploadConfig, commits) {
|
|
|
2902
2932
|
}
|
|
2903
2933
|
}
|
|
2904
2934
|
|
|
2905
|
-
// packages/core/src/lib/upload.ts
|
|
2906
|
-
import {
|
|
2907
|
-
uploadToPortal
|
|
2908
|
-
} from "@code-pushup/portal-client";
|
|
2909
|
-
|
|
2910
2935
|
// packages/core/src/lib/implementation/report-to-gql.ts
|
|
2911
2936
|
import {
|
|
2912
2937
|
CategoryConfigRefType as PortalCategoryRefType,
|
|
@@ -3053,10 +3078,15 @@ function tableAlignmentToGQL(alignment) {
|
|
|
3053
3078
|
}
|
|
3054
3079
|
|
|
3055
3080
|
// packages/core/src/lib/upload.ts
|
|
3056
|
-
async function upload(options
|
|
3081
|
+
async function upload(options) {
|
|
3057
3082
|
if (options.upload == null) {
|
|
3058
3083
|
throw new Error("Upload configuration is not set.");
|
|
3059
3084
|
}
|
|
3085
|
+
const portalClient = await loadPortalClient();
|
|
3086
|
+
if (!portalClient) {
|
|
3087
|
+
return;
|
|
3088
|
+
}
|
|
3089
|
+
const { uploadToPortal } = portalClient;
|
|
3060
3090
|
const { apiKey, server, organization, project, timeout } = options.upload;
|
|
3061
3091
|
const report = await loadReport({
|
|
3062
3092
|
...options.persist,
|
|
@@ -3071,7 +3101,7 @@ async function upload(options, uploadFn = uploadToPortal) {
|
|
|
3071
3101
|
commit: report.commit.hash,
|
|
3072
3102
|
...reportToGQL(report)
|
|
3073
3103
|
};
|
|
3074
|
-
return
|
|
3104
|
+
return uploadToPortal({ apiKey, server, data, timeout });
|
|
3075
3105
|
}
|
|
3076
3106
|
|
|
3077
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.
|
|
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.
|
|
8
|
-
"@code-pushup/utils": "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>;
|
package/src/lib/upload.d.ts
CHANGED
|
@@ -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
|
|
13
|
+
export declare function upload(options: UploadOptions): Promise<import("@code-pushup/portal-client").ReportFragment | undefined>;
|