@code-pushup/core 0.11.0 → 0.11.2

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
@@ -1518,91 +1518,15 @@ var verboseUtils = (verbose) => ({
1518
1518
  exec: getExecVerbose(verbose)
1519
1519
  });
1520
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
-
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";
1537
- var PersistDirError = class extends Error {
1538
- constructor(outputDir) {
1539
- super(`outPath: ${outputDir} is no directory.`);
1540
- }
1541
- };
1542
- var PersistError = class extends Error {
1543
- constructor(reportPath) {
1544
- super(`fileName: ${reportPath} could not be saved.`);
1545
- }
1546
- };
1547
- async function persistReport(report, options) {
1548
- const { outputDir, filename, format } = options;
1549
- const sortedScoredReport = sortReport(scoreReport(report));
1550
- console.info(generateStdoutSummary(sortedScoredReport));
1551
- const results = await Promise.all(
1552
- format.map(async (reportType) => {
1553
- switch (reportType) {
1554
- case "json":
1555
- return {
1556
- format: "json",
1557
- content: JSON.stringify(report, null, 2)
1558
- };
1559
- case "md":
1560
- const commitData = await getLatestCommit();
1561
- validateCommitData(commitData);
1562
- return {
1563
- format: "md",
1564
- content: generateMdReport(sortedScoredReport, commitData)
1565
- };
1566
- }
1567
- })
1568
- );
1569
- if (!await directoryExists(outputDir)) {
1570
- try {
1571
- await mkdir2(outputDir, { recursive: true });
1572
- } catch (error) {
1573
- console.warn(error);
1574
- throw new PersistDirError(outputDir);
1575
- }
1576
- }
1577
- return Promise.allSettled(
1578
- results.map(
1579
- (result) => persistResult(
1580
- join2(outputDir, `${filename}.${result.format}`),
1581
- result.content
1582
- )
1583
- )
1584
- );
1585
- }
1586
- function validateCommitData(commitData) {
1587
- if (!commitData) {
1588
- console.warn("no commit data available");
1589
- }
1590
- }
1591
- async function persistResult(reportPath, content) {
1592
- return writeFile(reportPath, content).then(() => stat2(reportPath)).then((stats) => [reportPath, stats.size]).catch((error) => {
1593
- console.warn(error);
1594
- throw new PersistError(reportPath);
1595
- });
1596
- }
1597
- function logPersistedResults(persistResults) {
1598
- logMultipleFileResults(persistResults, "Generated reports");
1599
- }
1521
+ // packages/core/package.json
1522
+ var name = "@code-pushup/core";
1523
+ var version = "0.11.2";
1600
1524
 
1601
1525
  // packages/core/src/lib/implementation/execute-plugin.ts
1602
1526
  import chalk4 from "chalk";
1603
1527
 
1604
1528
  // packages/core/src/lib/implementation/runner.ts
1605
- import { join as join3 } from "node:path";
1529
+ import { join as join2 } from "node:path";
1606
1530
  async function executeRunnerConfig(cfg, onProgress) {
1607
1531
  const { args, command, outputFile, outputTransform } = cfg;
1608
1532
  const { duration, date } = await executeProcess({
@@ -1610,7 +1534,7 @@ async function executeRunnerConfig(cfg, onProgress) {
1610
1534
  args,
1611
1535
  observer: { onStdout: onProgress }
1612
1536
  });
1613
- const outputs = await readJsonFile(join3(process.cwd(), outputFile));
1537
+ const outputs = await readJsonFile(join2(process.cwd(), outputFile));
1614
1538
  const audits = outputTransform ? await outputTransform(outputs) : outputs;
1615
1539
  return {
1616
1540
  duration,
@@ -1708,10 +1632,6 @@ function auditOutputsCorrelateWithPluginOutput(auditOutputs, pluginConfigAudits)
1708
1632
  });
1709
1633
  }
1710
1634
 
1711
- // packages/core/package.json
1712
- var name = "@code-pushup/core";
1713
- var version = "0.11.0";
1714
-
1715
1635
  // packages/core/src/lib/implementation/collect.ts
1716
1636
  async function collect(options) {
1717
1637
  const { plugins, categories } = options;
@@ -1728,6 +1648,132 @@ async function collect(options) {
1728
1648
  };
1729
1649
  }
1730
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
+
1731
1777
  // packages/core/src/lib/upload.ts
1732
1778
  import { uploadToPortal } from "@code-pushup/portal-client";
1733
1779
 
@@ -1817,14 +1863,6 @@ function transformSeverity(severity) {
1817
1863
  }
1818
1864
  }
1819
1865
 
1820
- // packages/core/src/lib/normalize.ts
1821
- var normalizePersistConfig = (cfg) => ({
1822
- outputDir: PERSIST_OUTPUT_DIR,
1823
- filename: PERSIST_FILENAME,
1824
- format: PERSIST_FORMAT,
1825
- ...cfg
1826
- });
1827
-
1828
1866
  // packages/core/src/lib/upload.ts
1829
1867
  async function upload(options, uploadFn = uploadToPortal) {
1830
1868
  const persist = normalizePersistConfig(options.persist);
@@ -1848,59 +1886,8 @@ async function upload(options, uploadFn = uploadToPortal) {
1848
1886
  };
1849
1887
  return uploadFn({ apiKey, server, data, timeout });
1850
1888
  }
1851
-
1852
- // packages/core/src/lib/collect-and-persist.ts
1853
- async function collectAndPersistReports(options) {
1854
- const { exec } = verboseUtils(options.verbose);
1855
- const report = await collect(options);
1856
- const persist = normalizePersistConfig(options.persist);
1857
- const persistResults = await persistReport(report, persist);
1858
- exec(() => {
1859
- logPersistedResults(persistResults);
1860
- });
1861
- report.plugins.forEach((plugin) => {
1862
- pluginReportSchema.parse(plugin);
1863
- });
1864
- }
1865
-
1866
- // packages/core/src/lib/implementation/read-rc-file.ts
1867
- import { join as join4 } from "node:path";
1868
- var ConfigPathError2 = class extends Error {
1869
- constructor(configPath) {
1870
- super(`Provided path '${configPath}' is not valid.`);
1871
- }
1872
- };
1873
- async function readRcByPath(filepath) {
1874
- if (filepath.length === 0) {
1875
- throw new Error("The path to the configuration file is empty.");
1876
- }
1877
- if (!await fileExists(filepath)) {
1878
- throw new ConfigPathError2(filepath);
1879
- }
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}`));
1901
- }
1902
1889
  export {
1903
- ConfigPathError2 as ConfigPathError,
1890
+ ConfigPathError,
1904
1891
  PersistDirError,
1905
1892
  PersistError,
1906
1893
  PluginOutputMissingAuditError,
@@ -1910,7 +1897,6 @@ export {
1910
1897
  executePlugin,
1911
1898
  executePlugins,
1912
1899
  persistReport,
1913
- readCodePushupConfig,
1914
1900
  readRcByPath,
1915
1901
  upload
1916
1902
  };
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@code-pushup/core",
3
- "version": "0.11.0",
3
+ "version": "0.11.2",
4
4
  "license": "MIT",
5
5
  "dependencies": {
6
6
  "@code-pushup/models": "*",
7
7
  "@code-pushup/utils": "*",
8
- "@code-pushup/portal-client": "^0.4.0",
8
+ "@code-pushup/portal-client": "^0.4.1",
9
9
  "chalk": "^5.3.0"
10
10
  },
11
11
  "type": "module",
package/src/index.d.ts CHANGED
@@ -1,8 +1,7 @@
1
- export { readCodePushupConfig } from './lib/implementation/read-code-pushup-config';
2
- export { persistReport, PersistError, PersistDirError, } from './lib/implementation/persist';
3
- export { executePlugin, executePlugins, PluginOutputMissingAuditError, } from './lib/implementation/execute-plugin';
4
- export { collect, CollectOptions } from './lib/implementation/collect';
5
- export { upload, UploadOptions } from './lib/upload';
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';
6
6
  export { GlobalOptions } from './lib/types';
7
- export { collectAndPersistReports, CollectAndPersistReportsOptions, } from './lib/collect-and-persist';
8
- export { autoloadRc, readRcByPath, ConfigPathError, } from './lib/implementation/read-rc-file';
7
+ export { UploadOptions, upload } from './lib/upload';
@@ -1,5 +0,0 @@
1
- import { CoreConfig } from '@code-pushup/models';
2
- export declare class ConfigPathError extends Error {
3
- constructor(configPath: string);
4
- }
5
- export declare function readCodePushupConfig(filepath: string): Promise<CoreConfig>;