@code-pushup/utils 0.6.5 → 0.6.6
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 +36 -38
- package/package.json +1 -1
- package/src/index.d.ts +2 -2
- package/src/lib/file-system.d.ts +1 -4
- package/src/lib/transform.d.ts +3 -0
package/index.js
CHANGED
|
@@ -650,13 +650,6 @@ async function fileExists(path) {
|
|
|
650
650
|
return false;
|
|
651
651
|
}
|
|
652
652
|
}
|
|
653
|
-
function toUnixPath(path, options) {
|
|
654
|
-
const unixPath = path.replace(/\\/g, "/");
|
|
655
|
-
if (options?.toRelative) {
|
|
656
|
-
return unixPath.replace(process.cwd().replace(/\\/g, "/") + "/", "");
|
|
657
|
-
}
|
|
658
|
-
return unixPath;
|
|
659
|
-
}
|
|
660
653
|
async function ensureDirectoryExists(baseDir) {
|
|
661
654
|
try {
|
|
662
655
|
await mkdir(baseDir, { recursive: true });
|
|
@@ -687,20 +680,18 @@ function logMultipleFileResults(fileResults, messagePrefix) {
|
|
|
687
680
|
}
|
|
688
681
|
var NoExportError = class extends Error {
|
|
689
682
|
constructor(filepath) {
|
|
690
|
-
super(`No export found in ${filepath}`);
|
|
683
|
+
super(`No default export found in ${filepath}`);
|
|
691
684
|
}
|
|
692
685
|
};
|
|
693
|
-
async function importEsmModule(options
|
|
694
|
-
|
|
695
|
-
options = {
|
|
686
|
+
async function importEsmModule(options) {
|
|
687
|
+
const { mod } = await bundleRequire({
|
|
696
688
|
format: "esm",
|
|
697
689
|
...options
|
|
698
|
-
};
|
|
699
|
-
|
|
700
|
-
if (mod.default === void 0) {
|
|
690
|
+
});
|
|
691
|
+
if (!("default" in mod)) {
|
|
701
692
|
throw new NoExportError(options.filepath);
|
|
702
693
|
}
|
|
703
|
-
return
|
|
694
|
+
return mod.default;
|
|
704
695
|
}
|
|
705
696
|
function pluginWorkDir(slug) {
|
|
706
697
|
return join("node_modules", ".code-pushup", slug);
|
|
@@ -1334,29 +1325,6 @@ function reportToHeaderSection2(report) {
|
|
|
1334
1325
|
const { packageName, version } = report;
|
|
1335
1326
|
return `${chalk3.bold(reportHeadlineText)} - ${packageName}@${version}`;
|
|
1336
1327
|
}
|
|
1337
|
-
function reportToOverviewSection2({
|
|
1338
|
-
categories,
|
|
1339
|
-
plugins
|
|
1340
|
-
}) {
|
|
1341
|
-
let output = addLine(chalk3.magentaBright.bold("Categories"));
|
|
1342
|
-
output += addLine();
|
|
1343
|
-
const table = new Table({
|
|
1344
|
-
head: reportRawOverviewTableHeaders,
|
|
1345
|
-
colAligns: ["left", "right", "right"],
|
|
1346
|
-
style: {
|
|
1347
|
-
head: ["cyan"]
|
|
1348
|
-
}
|
|
1349
|
-
});
|
|
1350
|
-
table.push(
|
|
1351
|
-
...categories.map(({ title, score, refs }) => [
|
|
1352
|
-
title,
|
|
1353
|
-
withColor({ score }),
|
|
1354
|
-
countCategoryAudits(refs, plugins)
|
|
1355
|
-
])
|
|
1356
|
-
);
|
|
1357
|
-
output += addLine(table.toString());
|
|
1358
|
-
return output;
|
|
1359
|
-
}
|
|
1360
1328
|
function reportToDetailSection(report) {
|
|
1361
1329
|
const { plugins } = report;
|
|
1362
1330
|
let output = "";
|
|
@@ -1388,6 +1356,29 @@ function reportToDetailSection(report) {
|
|
|
1388
1356
|
});
|
|
1389
1357
|
return output;
|
|
1390
1358
|
}
|
|
1359
|
+
function reportToOverviewSection2({
|
|
1360
|
+
categories,
|
|
1361
|
+
plugins
|
|
1362
|
+
}) {
|
|
1363
|
+
let output = addLine(chalk3.magentaBright.bold("Categories"));
|
|
1364
|
+
output += addLine();
|
|
1365
|
+
const table = new Table({
|
|
1366
|
+
head: reportRawOverviewTableHeaders,
|
|
1367
|
+
colAligns: ["left", "right", "right"],
|
|
1368
|
+
style: {
|
|
1369
|
+
head: ["cyan"]
|
|
1370
|
+
}
|
|
1371
|
+
});
|
|
1372
|
+
table.push(
|
|
1373
|
+
...categories.map(({ title, score, refs }) => [
|
|
1374
|
+
title,
|
|
1375
|
+
withColor({ score }),
|
|
1376
|
+
countCategoryAudits(refs, plugins)
|
|
1377
|
+
])
|
|
1378
|
+
);
|
|
1379
|
+
output += addLine(table.toString());
|
|
1380
|
+
return output;
|
|
1381
|
+
}
|
|
1391
1382
|
function withColor({ score, text }) {
|
|
1392
1383
|
const formattedScore = text ?? formatReportScore(score);
|
|
1393
1384
|
const style2 = text ? chalk3 : chalk3.bold;
|
|
@@ -1470,6 +1461,13 @@ function objectToCliArgs(params) {
|
|
|
1470
1461
|
throw new Error(`Unsupported type ${typeof value} for key ${key}`);
|
|
1471
1462
|
});
|
|
1472
1463
|
}
|
|
1464
|
+
function toUnixPath(path, options) {
|
|
1465
|
+
const unixPath = path.replace(/\\/g, "/");
|
|
1466
|
+
if (options?.toRelative) {
|
|
1467
|
+
return unixPath.replace(process.cwd().replace(/\\/g, "/") + "/", "");
|
|
1468
|
+
}
|
|
1469
|
+
return unixPath;
|
|
1470
|
+
}
|
|
1473
1471
|
|
|
1474
1472
|
// packages/utils/src/lib/scoring.ts
|
|
1475
1473
|
function calculateScore(refs, scoreFn) {
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { ProcessConfig, ProcessError, ProcessObserver, ProcessResult, executeProcess, } from './lib/execute-process';
|
|
2
|
-
export { CrawlFileSystemOptions, FileResult, MultipleFileResults, crawlFileSystem, ensureDirectoryExists, fileExists, findLineNumberInText, importEsmModule, logMultipleFileResults, pluginWorkDir, readJsonFile, readTextFile,
|
|
2
|
+
export { CrawlFileSystemOptions, FileResult, MultipleFileResults, crawlFileSystem, ensureDirectoryExists, fileExists, findLineNumberInText, importEsmModule, logMultipleFileResults, pluginWorkDir, readJsonFile, readTextFile, } from './lib/file-system';
|
|
3
3
|
export { formatBytes, formatDuration, pluralize, pluralizeToken, slugify, truncateDescription, truncateText, truncateTitle, } from './lib/formatting';
|
|
4
4
|
export { getLatestCommit, git } from './lib/git';
|
|
5
5
|
export { isPromiseFulfilledResult, isPromiseRejectedResult, } from './lib/guards';
|
|
@@ -10,5 +10,5 @@ export { CODE_PUSHUP_DOMAIN, FOOTER_PREFIX, README_LINK, calcDuration, compareIs
|
|
|
10
10
|
export { reportToMd } from './lib/report-to-md';
|
|
11
11
|
export { reportToStdout } from './lib/report-to-stdout';
|
|
12
12
|
export { ScoredReport, scoreReport } from './lib/scoring';
|
|
13
|
-
export { CliArgsObject, countOccurrences, distinct, factorOf, objectToCliArgs, objectToEntries, objectToKeys, toArray, } from './lib/transform';
|
|
13
|
+
export { CliArgsObject, countOccurrences, distinct, factorOf, objectToCliArgs, objectToEntries, objectToKeys, toArray, toUnixPath, } from './lib/transform';
|
|
14
14
|
export { verboseUtils } from './lib/verbose-utils';
|
package/src/lib/file-system.d.ts
CHANGED
|
@@ -2,9 +2,6 @@ import { type Options } from 'bundle-require';
|
|
|
2
2
|
export declare function readTextFile(path: string): Promise<string>;
|
|
3
3
|
export declare function readJsonFile<T = unknown>(path: string): Promise<T>;
|
|
4
4
|
export declare function fileExists(path: string): Promise<boolean>;
|
|
5
|
-
export declare function toUnixPath(path: string, options?: {
|
|
6
|
-
toRelative?: boolean;
|
|
7
|
-
}): string;
|
|
8
5
|
export declare function ensureDirectoryExists(baseDir: string): Promise<void>;
|
|
9
6
|
export type FileResult = readonly [string] | readonly [string, number];
|
|
10
7
|
export type MultipleFileResults = PromiseSettledResult<FileResult>[];
|
|
@@ -12,7 +9,7 @@ export declare function logMultipleFileResults(fileResults: MultipleFileResults,
|
|
|
12
9
|
export declare class NoExportError extends Error {
|
|
13
10
|
constructor(filepath: string);
|
|
14
11
|
}
|
|
15
|
-
export declare function importEsmModule
|
|
12
|
+
export declare function importEsmModule(options: Options): Promise<unknown>;
|
|
16
13
|
export declare function pluginWorkDir(slug: string): string;
|
|
17
14
|
export type CrawlFileSystemOptions<T> = {
|
|
18
15
|
directory: string;
|
package/src/lib/transform.d.ts
CHANGED
|
@@ -20,4 +20,7 @@ export type CliArgsObject<T extends object = Record<string, ArgumentValue>> = T
|
|
|
20
20
|
* });
|
|
21
21
|
*/
|
|
22
22
|
export declare function objectToCliArgs<T extends object = Record<string, ArgumentValue>>(params?: CliArgsObject<T>): string[];
|
|
23
|
+
export declare function toUnixPath(path: string, options?: {
|
|
24
|
+
toRelative?: boolean;
|
|
25
|
+
}): string;
|
|
23
26
|
export {};
|