@code-pushup/utils 0.54.0 → 0.56.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
|
@@ -29,7 +29,7 @@ function exists(value) {
|
|
|
29
29
|
return value != null;
|
|
30
30
|
}
|
|
31
31
|
function getMissingRefsForCategories(categories, plugins) {
|
|
32
|
-
if (categories.length === 0) {
|
|
32
|
+
if (!categories || categories.length === 0) {
|
|
33
33
|
return false;
|
|
34
34
|
}
|
|
35
35
|
const auditRefsFromCategory = categories.flatMap(
|
|
@@ -528,12 +528,9 @@ var unrefinedCoreConfigSchema = z14.object({
|
|
|
528
528
|
var coreConfigSchema = refineCoreConfig(unrefinedCoreConfigSchema);
|
|
529
529
|
function refineCoreConfig(schema) {
|
|
530
530
|
return schema.refine(
|
|
531
|
-
(
|
|
532
|
-
(
|
|
533
|
-
message: missingRefsForCategoriesErrorMsg(
|
|
534
|
-
coreCfg.categories ?? [],
|
|
535
|
-
coreCfg.plugins
|
|
536
|
-
)
|
|
531
|
+
({ categories, plugins }) => !getMissingRefsForCategories(categories, plugins),
|
|
532
|
+
({ categories, plugins }) => ({
|
|
533
|
+
message: missingRefsForCategoriesErrorMsg(categories, plugins)
|
|
537
534
|
})
|
|
538
535
|
);
|
|
539
536
|
}
|
|
@@ -585,19 +582,16 @@ var reportSchema = packageVersionSchema({
|
|
|
585
582
|
).merge(
|
|
586
583
|
z15.object(
|
|
587
584
|
{
|
|
588
|
-
categories: z15.array(categoryConfigSchema),
|
|
589
585
|
plugins: z15.array(pluginReportSchema).min(1),
|
|
586
|
+
categories: z15.array(categoryConfigSchema).optional(),
|
|
590
587
|
commit: commitSchema.describe("Git commit for which report was collected").nullable()
|
|
591
588
|
},
|
|
592
589
|
{ description: "Collect output data" }
|
|
593
590
|
)
|
|
594
591
|
).refine(
|
|
595
|
-
(
|
|
596
|
-
(
|
|
597
|
-
message: missingRefsForCategoriesErrorMsg(
|
|
598
|
-
report.categories,
|
|
599
|
-
report.plugins
|
|
600
|
-
)
|
|
592
|
+
({ categories, plugins }) => !getMissingRefsForCategories(categories, plugins),
|
|
593
|
+
({ categories, plugins }) => ({
|
|
594
|
+
message: missingRefsForCategoriesErrorMsg(categories, plugins)
|
|
601
595
|
})
|
|
602
596
|
);
|
|
603
597
|
|
|
@@ -1030,7 +1024,7 @@ function executeProcess(cfg) {
|
|
|
1030
1024
|
import { bold, gray } from "ansis";
|
|
1031
1025
|
import { bundleRequire } from "bundle-require";
|
|
1032
1026
|
import { mkdir, readFile, readdir, rm, stat } from "node:fs/promises";
|
|
1033
|
-
import { join } from "node:path";
|
|
1027
|
+
import { dirname, join } from "node:path";
|
|
1034
1028
|
|
|
1035
1029
|
// packages/utils/src/lib/formatting.ts
|
|
1036
1030
|
function slugify(text) {
|
|
@@ -1267,6 +1261,16 @@ async function crawlFileSystem(options) {
|
|
|
1267
1261
|
const resultsNestedArray = await Promise.all(promises);
|
|
1268
1262
|
return resultsNestedArray.flat();
|
|
1269
1263
|
}
|
|
1264
|
+
async function findNearestFile(fileNames, cwd = process.cwd()) {
|
|
1265
|
+
for (let directory = cwd; directory !== dirname(directory); directory = dirname(directory)) {
|
|
1266
|
+
for (const file of fileNames) {
|
|
1267
|
+
if (await fileExists(join(directory, file))) {
|
|
1268
|
+
return join(directory, file);
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
return void 0;
|
|
1273
|
+
}
|
|
1270
1274
|
function findLineNumberInText(content, pattern) {
|
|
1271
1275
|
const lines = content.split(/\r?\n/);
|
|
1272
1276
|
const lineNumber = lines.findIndex((line) => line.includes(pattern)) + 1;
|
|
@@ -2097,7 +2101,7 @@ function getSortableGroupByRef({ plugin, slug, weight }, plugins) {
|
|
|
2097
2101
|
}
|
|
2098
2102
|
function sortReport(report) {
|
|
2099
2103
|
const { categories, plugins } = report;
|
|
2100
|
-
const sortedCategories = categories
|
|
2104
|
+
const sortedCategories = categories?.map((category) => {
|
|
2101
2105
|
const { audits, groups } = category.refs.reduce(
|
|
2102
2106
|
(acc, ref) => ({
|
|
2103
2107
|
...acc,
|
|
@@ -2237,14 +2241,15 @@ function auditDetailsAuditValue({
|
|
|
2237
2241
|
String(displayValue ?? value)
|
|
2238
2242
|
)} (score: ${formatReportScore(score)})`;
|
|
2239
2243
|
}
|
|
2244
|
+
function hasCategories(report) {
|
|
2245
|
+
return !!report.categories && report.categories.length > 0;
|
|
2246
|
+
}
|
|
2240
2247
|
function generateMdReport(report, options) {
|
|
2241
|
-
return new MarkdownDocument3().heading(HIERARCHY.level_1, REPORT_HEADLINE_TEXT).$
|
|
2242
|
-
report
|
|
2243
|
-
(
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
)
|
|
2247
|
-
).$concat(auditsSection(report, options), aboutSection(report)).rule().paragraph(md4`${FOOTER_PREFIX} ${md4.link(README_LINK, "Code PushUp")}`).toString();
|
|
2248
|
+
return new MarkdownDocument3().heading(HIERARCHY.level_1, REPORT_HEADLINE_TEXT).$concat(
|
|
2249
|
+
...hasCategories(report) ? [categoriesOverviewSection(report), categoriesDetailsSection(report)] : [],
|
|
2250
|
+
auditsSection(report, options),
|
|
2251
|
+
aboutSection(report)
|
|
2252
|
+
).rule().paragraph(md4`${FOOTER_PREFIX} ${md4.link(README_LINK, "Code PushUp")}`).toString();
|
|
2248
2253
|
}
|
|
2249
2254
|
function auditDetailsIssues(issues = [], options) {
|
|
2250
2255
|
if (issues.length === 0) {
|
|
@@ -2346,7 +2351,7 @@ function reportMetaTable({
|
|
|
2346
2351
|
md4.code(version),
|
|
2347
2352
|
formatDuration(duration),
|
|
2348
2353
|
plugins.length.toString(),
|
|
2349
|
-
categories
|
|
2354
|
+
(categories?.length ?? 0).toString(),
|
|
2350
2355
|
plugins.reduce((acc, { audits }) => acc + audits.length, 0).toString()
|
|
2351
2356
|
]
|
|
2352
2357
|
]
|
|
@@ -2678,18 +2683,20 @@ function log(msg = "") {
|
|
|
2678
2683
|
ui().logger.log(msg);
|
|
2679
2684
|
}
|
|
2680
2685
|
function logStdoutSummary(report, verbose = false) {
|
|
2681
|
-
const
|
|
2682
|
-
log(reportToHeaderSection(
|
|
2686
|
+
const { plugins, categories, packageName, version } = report;
|
|
2687
|
+
log(reportToHeaderSection({ packageName, version }));
|
|
2683
2688
|
log();
|
|
2684
|
-
logPlugins(
|
|
2685
|
-
if (
|
|
2686
|
-
logCategories(
|
|
2689
|
+
logPlugins(plugins, verbose);
|
|
2690
|
+
if (categories && categories.length > 0) {
|
|
2691
|
+
logCategories({ plugins, categories });
|
|
2687
2692
|
}
|
|
2688
2693
|
log(`${FOOTER_PREFIX} ${CODE_PUSHUP_DOMAIN}`);
|
|
2689
2694
|
log();
|
|
2690
2695
|
}
|
|
2691
|
-
function reportToHeaderSection(
|
|
2692
|
-
|
|
2696
|
+
function reportToHeaderSection({
|
|
2697
|
+
packageName,
|
|
2698
|
+
version
|
|
2699
|
+
}) {
|
|
2693
2700
|
return `${bold4(REPORT_HEADLINE_TEXT)} - ${packageName}@${version}`;
|
|
2694
2701
|
}
|
|
2695
2702
|
function logPlugins(plugins, verbose) {
|
|
@@ -2735,7 +2742,10 @@ function logRow(score, title, value) {
|
|
|
2735
2742
|
] : []
|
|
2736
2743
|
]);
|
|
2737
2744
|
}
|
|
2738
|
-
function logCategories({
|
|
2745
|
+
function logCategories({
|
|
2746
|
+
plugins,
|
|
2747
|
+
categories
|
|
2748
|
+
}) {
|
|
2739
2749
|
const hAlign = (idx) => idx === 0 ? "left" : "right";
|
|
2740
2750
|
const rows = categories.map(({ title, score, refs, isBinary }) => [
|
|
2741
2751
|
title,
|
|
@@ -2817,7 +2827,7 @@ function scoreReport(report) {
|
|
|
2817
2827
|
}
|
|
2818
2828
|
return item.score;
|
|
2819
2829
|
}
|
|
2820
|
-
const scoredCategories = report.categories
|
|
2830
|
+
const scoredCategories = report.categories?.map((category) => ({
|
|
2821
2831
|
...category,
|
|
2822
2832
|
score: calculateScore(category.refs, catScoreFn)
|
|
2823
2833
|
}));
|
|
@@ -2904,6 +2914,7 @@ export {
|
|
|
2904
2914
|
filePathToCliArg,
|
|
2905
2915
|
filterItemRefsBy,
|
|
2906
2916
|
findLineNumberInText,
|
|
2917
|
+
findNearestFile,
|
|
2907
2918
|
formatBytes,
|
|
2908
2919
|
formatDuration,
|
|
2909
2920
|
formatGitPath,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@code-pushup/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.56.0",
|
|
4
4
|
"description": "Low-level utilities (helper functions, etc.) used by Code PushUp CLI",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/code-pushup/cli/tree/main/packages/utils#readme",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"main": "./index.js",
|
|
27
27
|
"types": "./src/index.d.ts",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@code-pushup/models": "0.
|
|
29
|
+
"@code-pushup/models": "0.56.0",
|
|
30
30
|
"@isaacs/cliui": "^8.0.2",
|
|
31
31
|
"@poppinss/cliui": "^6.4.0",
|
|
32
32
|
"ansis": "^3.3.0",
|
package/src/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { exists } from '@code-pushup/models';
|
|
|
2
2
|
export { comparePairs, matchArrayItemsByKey, type Diff } from './lib/diff';
|
|
3
3
|
export { stringifyError } from './lib/errors';
|
|
4
4
|
export { ProcessError, executeProcess, type ProcessConfig, type ProcessObserver, type ProcessResult, } from './lib/execute-process';
|
|
5
|
-
export { crawlFileSystem, directoryExists, ensureDirectoryExists, fileExists, filePathToCliArg, findLineNumberInText, importModule, logMultipleFileResults, pluginWorkDir, projectToFilename, readJsonFile, readTextFile, removeDirectoryIfExists, type CrawlFileSystemOptions, type FileResult, type MultipleFileResults, } from './lib/file-system';
|
|
5
|
+
export { crawlFileSystem, directoryExists, ensureDirectoryExists, fileExists, filePathToCliArg, findLineNumberInText, findNearestFile, importModule, logMultipleFileResults, pluginWorkDir, projectToFilename, readJsonFile, readTextFile, removeDirectoryIfExists, type CrawlFileSystemOptions, type FileResult, type MultipleFileResults, } from './lib/file-system';
|
|
6
6
|
export { filterItemRefsBy } from './lib/filter';
|
|
7
7
|
export { formatBytes, formatDuration, pluralize, pluralizeToken, slugify, truncateDescription, truncateIssueMessage, truncateText, truncateTitle, } from './lib/formatting';
|
|
8
8
|
export { formatGitPath, getGitRoot, guardAgainstLocalChanges, safeCheckout, toGitPath, } from './lib/git/git';
|
package/src/lib/file-system.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export type CrawlFileSystemOptions<T> = {
|
|
|
16
16
|
fileTransform?: (filePath: string) => Promise<T> | T;
|
|
17
17
|
};
|
|
18
18
|
export declare function crawlFileSystem<T = string>(options: CrawlFileSystemOptions<T>): Promise<T[]>;
|
|
19
|
+
export declare function findNearestFile(fileNames: string[], cwd?: string): Promise<string | undefined>;
|
|
19
20
|
export declare function findLineNumberInText(content: string, pattern: string): number | null;
|
|
20
21
|
export declare function filePathToCliArg(path: string): string;
|
|
21
22
|
export declare function projectToFilename(project: string): string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type InlineText, MarkdownDocument } from 'build-md';
|
|
2
2
|
import type { AuditReport } from '@code-pushup/models';
|
|
3
3
|
import type { ScoredGroup, ScoredReport } from './types';
|
|
4
|
-
export declare function categoriesOverviewSection(report: Pick<ScoredReport, '
|
|
5
|
-
export declare function categoriesDetailsSection(report: Pick<ScoredReport, '
|
|
4
|
+
export declare function categoriesOverviewSection(report: Required<Pick<ScoredReport, 'plugins' | 'categories'>>): MarkdownDocument;
|
|
5
|
+
export declare function categoriesDetailsSection(report: Required<Pick<ScoredReport, 'plugins' | 'categories'>>): MarkdownDocument;
|
|
6
6
|
export declare function categoryRef({ title, score, value, displayValue }: AuditReport, pluginTitle: string): InlineText;
|
|
7
7
|
export declare function categoryGroupItem({ score, title }: ScoredGroup, groupAudits: AuditReport[], pluginTitle: string): InlineText;
|
|
8
8
|
export declare function binaryIconSuffix(score: number, isBinary: boolean | undefined): string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ScoredReport } from './types';
|
|
2
2
|
export declare function logStdoutSummary(report: ScoredReport, verbose?: boolean): void;
|
|
3
3
|
export declare function logPlugins(plugins: ScoredReport['plugins'], verbose: boolean): void;
|
|
4
|
-
export declare function logCategories({ categories,
|
|
4
|
+
export declare function logCategories({ plugins, categories, }: Required<Pick<ScoredReport, 'plugins' | 'categories'>>): void;
|
|
5
5
|
export declare function binaryIconPrefix(score: number, isBinary: boolean | undefined): string;
|
|
@@ -9,7 +9,7 @@ export type ScoredReport = Omit<Report, 'plugins' | 'categories'> & {
|
|
|
9
9
|
plugins: (Omit<PluginReport, 'groups'> & {
|
|
10
10
|
groups?: ScoredGroup[];
|
|
11
11
|
})[];
|
|
12
|
-
categories
|
|
12
|
+
categories?: ScoredCategoryConfig[];
|
|
13
13
|
};
|
|
14
14
|
export type SortableGroup = ScoredGroup & {
|
|
15
15
|
weight: number;
|