@code-pushup/core 0.10.6 → 0.11.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 +88 -35
- package/package.json +1 -1
- package/src/index.d.ts +2 -1
- package/src/lib/implementation/read-rc-file.d.ts +6 -0
package/index.js
CHANGED
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
// packages/core/src/lib/implementation/persist.ts
|
|
2
|
-
import { mkdir as mkdir2, stat as stat2, writeFile } from "node:fs/promises";
|
|
3
|
-
import { join as join2 } from "node:path";
|
|
4
|
-
|
|
5
|
-
// packages/utils/src/lib/execute-process.ts
|
|
6
|
-
import { spawn } from "node:child_process";
|
|
7
|
-
|
|
8
|
-
// packages/utils/src/lib/reports/utils.ts
|
|
9
|
-
import { join } from "node:path";
|
|
10
|
-
|
|
11
1
|
// packages/models/src/lib/audit.ts
|
|
12
2
|
import { z as z2 } from "zod";
|
|
13
3
|
|
|
@@ -494,6 +484,10 @@ var PERSIST_OUTPUT_DIR = ".code-pushup";
|
|
|
494
484
|
var PERSIST_FORMAT = ["json"];
|
|
495
485
|
var PERSIST_FILENAME = "report";
|
|
496
486
|
|
|
487
|
+
// packages/models/src/lib/implementation/configuration.ts
|
|
488
|
+
var CONFIG_FILE_NAME = "code-pushup.config";
|
|
489
|
+
var SUPPORTED_CONFIG_FILE_FORMATS = ["ts", "mjs", "js"];
|
|
490
|
+
|
|
497
491
|
// packages/models/src/lib/report.ts
|
|
498
492
|
import { z as z12 } from "zod";
|
|
499
493
|
var auditReportSchema = auditSchema.merge(auditOutputSchema);
|
|
@@ -556,6 +550,12 @@ var reportSchema = packageVersionSchema({
|
|
|
556
550
|
})
|
|
557
551
|
);
|
|
558
552
|
|
|
553
|
+
// packages/utils/src/lib/execute-process.ts
|
|
554
|
+
import { spawn } from "node:child_process";
|
|
555
|
+
|
|
556
|
+
// packages/utils/src/lib/reports/utils.ts
|
|
557
|
+
import { join } from "node:path";
|
|
558
|
+
|
|
559
559
|
// packages/utils/src/lib/file-system.ts
|
|
560
560
|
import { bundleRequire } from "bundle-require";
|
|
561
561
|
import chalk from "chalk";
|
|
@@ -1364,24 +1364,6 @@ function deepClone(obj) {
|
|
|
1364
1364
|
}
|
|
1365
1365
|
|
|
1366
1366
|
// packages/utils/src/lib/reports/scoring.ts
|
|
1367
|
-
function calculateScore(refs, scoreFn) {
|
|
1368
|
-
const { numerator, denominator } = refs.reduce(
|
|
1369
|
-
(acc, ref) => {
|
|
1370
|
-
const score = scoreFn(ref);
|
|
1371
|
-
return {
|
|
1372
|
-
numerator: acc.numerator + score * ref.weight,
|
|
1373
|
-
denominator: acc.denominator + ref.weight
|
|
1374
|
-
};
|
|
1375
|
-
},
|
|
1376
|
-
{ numerator: 0, denominator: 0 }
|
|
1377
|
-
);
|
|
1378
|
-
if (!numerator && !denominator) {
|
|
1379
|
-
throw new Error(
|
|
1380
|
-
"0 division for score. This can be caused by refs only weighted with 0 or empty refs"
|
|
1381
|
-
);
|
|
1382
|
-
}
|
|
1383
|
-
return numerator / denominator;
|
|
1384
|
-
}
|
|
1385
1367
|
function scoreReport(report) {
|
|
1386
1368
|
const allScoredAuditsAndGroups = /* @__PURE__ */ new Map();
|
|
1387
1369
|
const scoredPlugins = report.plugins.map((plugin) => {
|
|
@@ -1431,6 +1413,36 @@ function scoreReport(report) {
|
|
|
1431
1413
|
categories: scoredCategories
|
|
1432
1414
|
};
|
|
1433
1415
|
}
|
|
1416
|
+
function calculateScore(refs, scoreFn) {
|
|
1417
|
+
const validatedRefs = parseScoringParameters(refs, scoreFn);
|
|
1418
|
+
const { numerator, denominator } = validatedRefs.reduce(
|
|
1419
|
+
(acc, ref) => ({
|
|
1420
|
+
numerator: acc.numerator + ref.score * ref.weight,
|
|
1421
|
+
denominator: acc.denominator + ref.weight
|
|
1422
|
+
}),
|
|
1423
|
+
{ numerator: 0, denominator: 0 }
|
|
1424
|
+
);
|
|
1425
|
+
return numerator / denominator;
|
|
1426
|
+
}
|
|
1427
|
+
function parseScoringParameters(refs, scoreFn) {
|
|
1428
|
+
if (refs.length === 0) {
|
|
1429
|
+
throw new Error("Reference array cannot be empty.");
|
|
1430
|
+
}
|
|
1431
|
+
if (refs.some((ref) => ref.weight < 0)) {
|
|
1432
|
+
throw new Error("Weight cannot be negative.");
|
|
1433
|
+
}
|
|
1434
|
+
if (refs.every((ref) => ref.weight === 0)) {
|
|
1435
|
+
throw new Error("All references cannot have zero weight.");
|
|
1436
|
+
}
|
|
1437
|
+
const scoredRefs = refs.map((ref) => ({
|
|
1438
|
+
weight: ref.weight,
|
|
1439
|
+
score: scoreFn(ref)
|
|
1440
|
+
}));
|
|
1441
|
+
if (scoredRefs.some((ref) => ref.score < 0 || ref.score > 1)) {
|
|
1442
|
+
throw new Error("All scores must be in range 0-1.");
|
|
1443
|
+
}
|
|
1444
|
+
return scoredRefs;
|
|
1445
|
+
}
|
|
1434
1446
|
|
|
1435
1447
|
// packages/utils/src/lib/reports/sorting.ts
|
|
1436
1448
|
function sortReport(report) {
|
|
@@ -1506,7 +1518,22 @@ var verboseUtils = (verbose) => ({
|
|
|
1506
1518
|
exec: getExecVerbose(verbose)
|
|
1507
1519
|
});
|
|
1508
1520
|
|
|
1521
|
+
// packages/core/src/lib/implementation/read-code-pushup-config.ts
|
|
1522
|
+
var ConfigPathError = class extends Error {
|
|
1523
|
+
constructor(configPath) {
|
|
1524
|
+
super(`Provided path '${configPath}' is not valid.`);
|
|
1525
|
+
}
|
|
1526
|
+
};
|
|
1527
|
+
async function readCodePushupConfig(filepath) {
|
|
1528
|
+
if (!await fileExists(filepath)) {
|
|
1529
|
+
throw new ConfigPathError(filepath);
|
|
1530
|
+
}
|
|
1531
|
+
return coreConfigSchema.parse(await importEsmModule({ filepath }));
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1509
1534
|
// packages/core/src/lib/implementation/persist.ts
|
|
1535
|
+
import { mkdir as mkdir2, stat as stat2, writeFile } from "node:fs/promises";
|
|
1536
|
+
import { join as join2 } from "node:path";
|
|
1510
1537
|
var PersistDirError = class extends Error {
|
|
1511
1538
|
constructor(outputDir) {
|
|
1512
1539
|
super(`outPath: ${outputDir} is no directory.`);
|
|
@@ -1683,7 +1710,7 @@ function auditOutputsCorrelateWithPluginOutput(auditOutputs, pluginConfigAudits)
|
|
|
1683
1710
|
|
|
1684
1711
|
// packages/core/package.json
|
|
1685
1712
|
var name = "@code-pushup/core";
|
|
1686
|
-
var version = "0.
|
|
1713
|
+
var version = "0.11.0";
|
|
1687
1714
|
|
|
1688
1715
|
// packages/core/src/lib/implementation/collect.ts
|
|
1689
1716
|
async function collect(options) {
|
|
@@ -1836,28 +1863,54 @@ async function collectAndPersistReports(options) {
|
|
|
1836
1863
|
});
|
|
1837
1864
|
}
|
|
1838
1865
|
|
|
1839
|
-
// packages/core/src/lib/implementation/read-
|
|
1840
|
-
|
|
1866
|
+
// packages/core/src/lib/implementation/read-rc-file.ts
|
|
1867
|
+
import { join as join4 } from "node:path";
|
|
1868
|
+
var ConfigPathError2 = class extends Error {
|
|
1841
1869
|
constructor(configPath) {
|
|
1842
1870
|
super(`Provided path '${configPath}' is not valid.`);
|
|
1843
1871
|
}
|
|
1844
1872
|
};
|
|
1845
|
-
async function
|
|
1873
|
+
async function readRcByPath(filepath) {
|
|
1874
|
+
if (filepath.length === 0) {
|
|
1875
|
+
throw new Error("The path to the configuration file is empty.");
|
|
1876
|
+
}
|
|
1846
1877
|
if (!await fileExists(filepath)) {
|
|
1847
|
-
throw new
|
|
1878
|
+
throw new ConfigPathError2(filepath);
|
|
1848
1879
|
}
|
|
1849
|
-
|
|
1880
|
+
const cfg = await importEsmModule({ filepath });
|
|
1881
|
+
return coreConfigSchema.parse(cfg);
|
|
1882
|
+
}
|
|
1883
|
+
async function autoloadRc() {
|
|
1884
|
+
let ext = "";
|
|
1885
|
+
for (const extension of SUPPORTED_CONFIG_FILE_FORMATS) {
|
|
1886
|
+
const path = `${CONFIG_FILE_NAME}.${extension}`;
|
|
1887
|
+
const exists2 = await fileExists(path);
|
|
1888
|
+
if (exists2) {
|
|
1889
|
+
ext = extension;
|
|
1890
|
+
break;
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
if (!ext) {
|
|
1894
|
+
throw new Error(
|
|
1895
|
+
`No file ${CONFIG_FILE_NAME}.(${SUPPORTED_CONFIG_FILE_FORMATS.join(
|
|
1896
|
+
"|"
|
|
1897
|
+
)}) present in ${process.cwd()}`
|
|
1898
|
+
);
|
|
1899
|
+
}
|
|
1900
|
+
return readRcByPath(join4(process.cwd(), `${CONFIG_FILE_NAME}.${ext}`));
|
|
1850
1901
|
}
|
|
1851
1902
|
export {
|
|
1852
|
-
ConfigPathError,
|
|
1903
|
+
ConfigPathError2 as ConfigPathError,
|
|
1853
1904
|
PersistDirError,
|
|
1854
1905
|
PersistError,
|
|
1855
1906
|
PluginOutputMissingAuditError,
|
|
1907
|
+
autoloadRc,
|
|
1856
1908
|
collect,
|
|
1857
1909
|
collectAndPersistReports,
|
|
1858
1910
|
executePlugin,
|
|
1859
1911
|
executePlugins,
|
|
1860
1912
|
persistReport,
|
|
1861
1913
|
readCodePushupConfig,
|
|
1914
|
+
readRcByPath,
|
|
1862
1915
|
upload
|
|
1863
1916
|
};
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
export { readCodePushupConfig } from './lib/implementation/read-code-pushup-config';
|
|
1
2
|
export { persistReport, PersistError, PersistDirError, } from './lib/implementation/persist';
|
|
2
3
|
export { executePlugin, executePlugins, PluginOutputMissingAuditError, } from './lib/implementation/execute-plugin';
|
|
3
4
|
export { collect, CollectOptions } from './lib/implementation/collect';
|
|
4
5
|
export { upload, UploadOptions } from './lib/upload';
|
|
5
6
|
export { GlobalOptions } from './lib/types';
|
|
6
7
|
export { collectAndPersistReports, CollectAndPersistReportsOptions, } from './lib/collect-and-persist';
|
|
7
|
-
export {
|
|
8
|
+
export { autoloadRc, readRcByPath, ConfigPathError, } from './lib/implementation/read-rc-file';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { CoreConfig } from '@code-pushup/models';
|
|
2
|
+
export declare class ConfigPathError extends Error {
|
|
3
|
+
constructor(configPath: string);
|
|
4
|
+
}
|
|
5
|
+
export declare function readRcByPath(filepath: string): Promise<CoreConfig>;
|
|
6
|
+
export declare function autoloadRc(): Promise<CoreConfig>;
|