@code-pushup/core 0.10.7 → 0.11.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
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";
|
|
@@ -1518,76 +1518,15 @@ var verboseUtils = (verbose) => ({
|
|
|
1518
1518
|
exec: getExecVerbose(verbose)
|
|
1519
1519
|
});
|
|
1520
1520
|
|
|
1521
|
-
// packages/core/
|
|
1522
|
-
var
|
|
1523
|
-
|
|
1524
|
-
super(`outPath: ${outputDir} is no directory.`);
|
|
1525
|
-
}
|
|
1526
|
-
};
|
|
1527
|
-
var PersistError = class extends Error {
|
|
1528
|
-
constructor(reportPath) {
|
|
1529
|
-
super(`fileName: ${reportPath} could not be saved.`);
|
|
1530
|
-
}
|
|
1531
|
-
};
|
|
1532
|
-
async function persistReport(report, options) {
|
|
1533
|
-
const { outputDir, filename, format } = options;
|
|
1534
|
-
const sortedScoredReport = sortReport(scoreReport(report));
|
|
1535
|
-
console.info(generateStdoutSummary(sortedScoredReport));
|
|
1536
|
-
const results = await Promise.all(
|
|
1537
|
-
format.map(async (reportType) => {
|
|
1538
|
-
switch (reportType) {
|
|
1539
|
-
case "json":
|
|
1540
|
-
return {
|
|
1541
|
-
format: "json",
|
|
1542
|
-
content: JSON.stringify(report, null, 2)
|
|
1543
|
-
};
|
|
1544
|
-
case "md":
|
|
1545
|
-
const commitData = await getLatestCommit();
|
|
1546
|
-
validateCommitData(commitData);
|
|
1547
|
-
return {
|
|
1548
|
-
format: "md",
|
|
1549
|
-
content: generateMdReport(sortedScoredReport, commitData)
|
|
1550
|
-
};
|
|
1551
|
-
}
|
|
1552
|
-
})
|
|
1553
|
-
);
|
|
1554
|
-
if (!await directoryExists(outputDir)) {
|
|
1555
|
-
try {
|
|
1556
|
-
await mkdir2(outputDir, { recursive: true });
|
|
1557
|
-
} catch (error) {
|
|
1558
|
-
console.warn(error);
|
|
1559
|
-
throw new PersistDirError(outputDir);
|
|
1560
|
-
}
|
|
1561
|
-
}
|
|
1562
|
-
return Promise.allSettled(
|
|
1563
|
-
results.map(
|
|
1564
|
-
(result) => persistResult(
|
|
1565
|
-
join2(outputDir, `${filename}.${result.format}`),
|
|
1566
|
-
result.content
|
|
1567
|
-
)
|
|
1568
|
-
)
|
|
1569
|
-
);
|
|
1570
|
-
}
|
|
1571
|
-
function validateCommitData(commitData) {
|
|
1572
|
-
if (!commitData) {
|
|
1573
|
-
console.warn("no commit data available");
|
|
1574
|
-
}
|
|
1575
|
-
}
|
|
1576
|
-
async function persistResult(reportPath, content) {
|
|
1577
|
-
return writeFile(reportPath, content).then(() => stat2(reportPath)).then((stats) => [reportPath, stats.size]).catch((error) => {
|
|
1578
|
-
console.warn(error);
|
|
1579
|
-
throw new PersistError(reportPath);
|
|
1580
|
-
});
|
|
1581
|
-
}
|
|
1582
|
-
function logPersistedResults(persistResults) {
|
|
1583
|
-
logMultipleFileResults(persistResults, "Generated reports");
|
|
1584
|
-
}
|
|
1521
|
+
// packages/core/package.json
|
|
1522
|
+
var name = "@code-pushup/core";
|
|
1523
|
+
var version = "0.11.1";
|
|
1585
1524
|
|
|
1586
1525
|
// packages/core/src/lib/implementation/execute-plugin.ts
|
|
1587
1526
|
import chalk4 from "chalk";
|
|
1588
1527
|
|
|
1589
1528
|
// packages/core/src/lib/implementation/runner.ts
|
|
1590
|
-
import { join as
|
|
1529
|
+
import { join as join2 } from "node:path";
|
|
1591
1530
|
async function executeRunnerConfig(cfg, onProgress) {
|
|
1592
1531
|
const { args, command, outputFile, outputTransform } = cfg;
|
|
1593
1532
|
const { duration, date } = await executeProcess({
|
|
@@ -1595,7 +1534,7 @@ async function executeRunnerConfig(cfg, onProgress) {
|
|
|
1595
1534
|
args,
|
|
1596
1535
|
observer: { onStdout: onProgress }
|
|
1597
1536
|
});
|
|
1598
|
-
const outputs = await readJsonFile(
|
|
1537
|
+
const outputs = await readJsonFile(join2(process.cwd(), outputFile));
|
|
1599
1538
|
const audits = outputTransform ? await outputTransform(outputs) : outputs;
|
|
1600
1539
|
return {
|
|
1601
1540
|
duration,
|
|
@@ -1693,10 +1632,6 @@ function auditOutputsCorrelateWithPluginOutput(auditOutputs, pluginConfigAudits)
|
|
|
1693
1632
|
});
|
|
1694
1633
|
}
|
|
1695
1634
|
|
|
1696
|
-
// packages/core/package.json
|
|
1697
|
-
var name = "@code-pushup/core";
|
|
1698
|
-
var version = "0.10.7";
|
|
1699
|
-
|
|
1700
1635
|
// packages/core/src/lib/implementation/collect.ts
|
|
1701
1636
|
async function collect(options) {
|
|
1702
1637
|
const { plugins, categories } = options;
|
|
@@ -1713,6 +1648,132 @@ async function collect(options) {
|
|
|
1713
1648
|
};
|
|
1714
1649
|
}
|
|
1715
1650
|
|
|
1651
|
+
// packages/core/src/lib/implementation/persist.ts
|
|
1652
|
+
import { mkdir as mkdir2, stat as stat2, writeFile } from "node:fs/promises";
|
|
1653
|
+
import { join as join3 } from "node:path";
|
|
1654
|
+
var PersistDirError = class extends Error {
|
|
1655
|
+
constructor(outputDir) {
|
|
1656
|
+
super(`outPath: ${outputDir} is no directory.`);
|
|
1657
|
+
}
|
|
1658
|
+
};
|
|
1659
|
+
var PersistError = class extends Error {
|
|
1660
|
+
constructor(reportPath) {
|
|
1661
|
+
super(`fileName: ${reportPath} could not be saved.`);
|
|
1662
|
+
}
|
|
1663
|
+
};
|
|
1664
|
+
async function persistReport(report, options) {
|
|
1665
|
+
const { outputDir, filename, format } = options;
|
|
1666
|
+
const sortedScoredReport = sortReport(scoreReport(report));
|
|
1667
|
+
console.info(generateStdoutSummary(sortedScoredReport));
|
|
1668
|
+
const results = await Promise.all(
|
|
1669
|
+
format.map(async (reportType) => {
|
|
1670
|
+
switch (reportType) {
|
|
1671
|
+
case "json":
|
|
1672
|
+
return {
|
|
1673
|
+
format: "json",
|
|
1674
|
+
content: JSON.stringify(report, null, 2)
|
|
1675
|
+
};
|
|
1676
|
+
case "md":
|
|
1677
|
+
const commitData = await getLatestCommit();
|
|
1678
|
+
validateCommitData(commitData);
|
|
1679
|
+
return {
|
|
1680
|
+
format: "md",
|
|
1681
|
+
content: generateMdReport(sortedScoredReport, commitData)
|
|
1682
|
+
};
|
|
1683
|
+
}
|
|
1684
|
+
})
|
|
1685
|
+
);
|
|
1686
|
+
if (!await directoryExists(outputDir)) {
|
|
1687
|
+
try {
|
|
1688
|
+
await mkdir2(outputDir, { recursive: true });
|
|
1689
|
+
} catch (error) {
|
|
1690
|
+
console.warn(error);
|
|
1691
|
+
throw new PersistDirError(outputDir);
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
return Promise.allSettled(
|
|
1695
|
+
results.map(
|
|
1696
|
+
(result) => persistResult(
|
|
1697
|
+
join3(outputDir, `${filename}.${result.format}`),
|
|
1698
|
+
result.content
|
|
1699
|
+
)
|
|
1700
|
+
)
|
|
1701
|
+
);
|
|
1702
|
+
}
|
|
1703
|
+
function validateCommitData(commitData) {
|
|
1704
|
+
if (!commitData) {
|
|
1705
|
+
console.warn("no commit data available");
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
async function persistResult(reportPath, content) {
|
|
1709
|
+
return writeFile(reportPath, content).then(() => stat2(reportPath)).then((stats) => [reportPath, stats.size]).catch((error) => {
|
|
1710
|
+
console.warn(error);
|
|
1711
|
+
throw new PersistError(reportPath);
|
|
1712
|
+
});
|
|
1713
|
+
}
|
|
1714
|
+
function logPersistedResults(persistResults) {
|
|
1715
|
+
logMultipleFileResults(persistResults, "Generated reports");
|
|
1716
|
+
}
|
|
1717
|
+
|
|
1718
|
+
// packages/core/src/lib/normalize.ts
|
|
1719
|
+
var normalizePersistConfig = (cfg) => ({
|
|
1720
|
+
outputDir: PERSIST_OUTPUT_DIR,
|
|
1721
|
+
filename: PERSIST_FILENAME,
|
|
1722
|
+
format: PERSIST_FORMAT,
|
|
1723
|
+
...cfg
|
|
1724
|
+
});
|
|
1725
|
+
|
|
1726
|
+
// packages/core/src/lib/collect-and-persist.ts
|
|
1727
|
+
async function collectAndPersistReports(options) {
|
|
1728
|
+
const { exec } = verboseUtils(options.verbose);
|
|
1729
|
+
const report = await collect(options);
|
|
1730
|
+
const persist = normalizePersistConfig(options.persist);
|
|
1731
|
+
const persistResults = await persistReport(report, persist);
|
|
1732
|
+
exec(() => {
|
|
1733
|
+
logPersistedResults(persistResults);
|
|
1734
|
+
});
|
|
1735
|
+
report.plugins.forEach((plugin) => {
|
|
1736
|
+
pluginReportSchema.parse(plugin);
|
|
1737
|
+
});
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1740
|
+
// packages/core/src/lib/implementation/read-rc-file.ts
|
|
1741
|
+
import { join as join4 } from "node:path";
|
|
1742
|
+
var ConfigPathError = class extends Error {
|
|
1743
|
+
constructor(configPath) {
|
|
1744
|
+
super(`Provided path '${configPath}' is not valid.`);
|
|
1745
|
+
}
|
|
1746
|
+
};
|
|
1747
|
+
async function readRcByPath(filepath) {
|
|
1748
|
+
if (filepath.length === 0) {
|
|
1749
|
+
throw new Error("The path to the configuration file is empty.");
|
|
1750
|
+
}
|
|
1751
|
+
if (!await fileExists(filepath)) {
|
|
1752
|
+
throw new ConfigPathError(filepath);
|
|
1753
|
+
}
|
|
1754
|
+
const cfg = await importEsmModule({ filepath });
|
|
1755
|
+
return coreConfigSchema.parse(cfg);
|
|
1756
|
+
}
|
|
1757
|
+
async function autoloadRc() {
|
|
1758
|
+
let ext = "";
|
|
1759
|
+
for (const extension of SUPPORTED_CONFIG_FILE_FORMATS) {
|
|
1760
|
+
const path = `${CONFIG_FILE_NAME}.${extension}`;
|
|
1761
|
+
const exists2 = await fileExists(path);
|
|
1762
|
+
if (exists2) {
|
|
1763
|
+
ext = extension;
|
|
1764
|
+
break;
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1767
|
+
if (!ext) {
|
|
1768
|
+
throw new Error(
|
|
1769
|
+
`No file ${CONFIG_FILE_NAME}.(${SUPPORTED_CONFIG_FILE_FORMATS.join(
|
|
1770
|
+
"|"
|
|
1771
|
+
)}) present in ${process.cwd()}`
|
|
1772
|
+
);
|
|
1773
|
+
}
|
|
1774
|
+
return readRcByPath(join4(process.cwd(), `${CONFIG_FILE_NAME}.${ext}`));
|
|
1775
|
+
}
|
|
1776
|
+
|
|
1716
1777
|
// packages/core/src/lib/upload.ts
|
|
1717
1778
|
import { uploadToPortal } from "@code-pushup/portal-client";
|
|
1718
1779
|
|
|
@@ -1802,14 +1863,6 @@ function transformSeverity(severity) {
|
|
|
1802
1863
|
}
|
|
1803
1864
|
}
|
|
1804
1865
|
|
|
1805
|
-
// packages/core/src/lib/normalize.ts
|
|
1806
|
-
var normalizePersistConfig = (cfg) => ({
|
|
1807
|
-
outputDir: PERSIST_OUTPUT_DIR,
|
|
1808
|
-
filename: PERSIST_FILENAME,
|
|
1809
|
-
format: PERSIST_FORMAT,
|
|
1810
|
-
...cfg
|
|
1811
|
-
});
|
|
1812
|
-
|
|
1813
1866
|
// packages/core/src/lib/upload.ts
|
|
1814
1867
|
async function upload(options, uploadFn = uploadToPortal) {
|
|
1815
1868
|
const persist = normalizePersistConfig(options.persist);
|
|
@@ -1833,43 +1886,17 @@ async function upload(options, uploadFn = uploadToPortal) {
|
|
|
1833
1886
|
};
|
|
1834
1887
|
return uploadFn({ apiKey, server, data, timeout });
|
|
1835
1888
|
}
|
|
1836
|
-
|
|
1837
|
-
// packages/core/src/lib/collect-and-persist.ts
|
|
1838
|
-
async function collectAndPersistReports(options) {
|
|
1839
|
-
const { exec } = verboseUtils(options.verbose);
|
|
1840
|
-
const report = await collect(options);
|
|
1841
|
-
const persist = normalizePersistConfig(options.persist);
|
|
1842
|
-
const persistResults = await persistReport(report, persist);
|
|
1843
|
-
exec(() => {
|
|
1844
|
-
logPersistedResults(persistResults);
|
|
1845
|
-
});
|
|
1846
|
-
report.plugins.forEach((plugin) => {
|
|
1847
|
-
pluginReportSchema.parse(plugin);
|
|
1848
|
-
});
|
|
1849
|
-
}
|
|
1850
|
-
|
|
1851
|
-
// packages/core/src/lib/implementation/read-code-pushup-config.ts
|
|
1852
|
-
var ConfigPathError = class extends Error {
|
|
1853
|
-
constructor(configPath) {
|
|
1854
|
-
super(`Provided path '${configPath}' is not valid.`);
|
|
1855
|
-
}
|
|
1856
|
-
};
|
|
1857
|
-
async function readCodePushupConfig(filepath) {
|
|
1858
|
-
if (!await fileExists(filepath)) {
|
|
1859
|
-
throw new ConfigPathError(filepath);
|
|
1860
|
-
}
|
|
1861
|
-
return coreConfigSchema.parse(await importEsmModule({ filepath }));
|
|
1862
|
-
}
|
|
1863
1889
|
export {
|
|
1864
1890
|
ConfigPathError,
|
|
1865
1891
|
PersistDirError,
|
|
1866
1892
|
PersistError,
|
|
1867
1893
|
PluginOutputMissingAuditError,
|
|
1894
|
+
autoloadRc,
|
|
1868
1895
|
collect,
|
|
1869
1896
|
collectAndPersistReports,
|
|
1870
1897
|
executePlugin,
|
|
1871
1898
|
executePlugins,
|
|
1872
1899
|
persistReport,
|
|
1873
|
-
|
|
1900
|
+
readRcByPath,
|
|
1874
1901
|
upload
|
|
1875
1902
|
};
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
1
|
+
export { CollectAndPersistReportsOptions, collectAndPersistReports, } from './lib/collect-and-persist';
|
|
2
|
+
export { CollectOptions, collect } from './lib/implementation/collect';
|
|
3
|
+
export { PluginOutputMissingAuditError, executePlugin, executePlugins, } from './lib/implementation/execute-plugin';
|
|
4
|
+
export { PersistDirError, PersistError, persistReport, } from './lib/implementation/persist';
|
|
5
|
+
export { ConfigPathError, autoloadRc, readRcByPath, } from './lib/implementation/read-rc-file';
|
|
5
6
|
export { GlobalOptions } from './lib/types';
|
|
6
|
-
export {
|
|
7
|
-
export { readCodePushupConfig, ConfigPathError, } from './lib/implementation/read-code-pushup-config';
|
|
7
|
+
export { UploadOptions, upload } from './lib/upload';
|
|
@@ -2,4 +2,5 @@ import { CoreConfig } from '@code-pushup/models';
|
|
|
2
2
|
export declare class ConfigPathError extends Error {
|
|
3
3
|
constructor(configPath: string);
|
|
4
4
|
}
|
|
5
|
-
export declare function
|
|
5
|
+
export declare function readRcByPath(filepath: string): Promise<CoreConfig>;
|
|
6
|
+
export declare function autoloadRc(): Promise<CoreConfig>;
|