@code-pushup/core 0.10.7 → 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 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,7 +1518,22 @@ 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
+
1521
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";
1522
1537
  var PersistDirError = class extends Error {
1523
1538
  constructor(outputDir) {
1524
1539
  super(`outPath: ${outputDir} is no directory.`);
@@ -1695,7 +1710,7 @@ function auditOutputsCorrelateWithPluginOutput(auditOutputs, pluginConfigAudits)
1695
1710
 
1696
1711
  // packages/core/package.json
1697
1712
  var name = "@code-pushup/core";
1698
- var version = "0.10.7";
1713
+ var version = "0.11.0";
1699
1714
 
1700
1715
  // packages/core/src/lib/implementation/collect.ts
1701
1716
  async function collect(options) {
@@ -1848,28 +1863,54 @@ async function collectAndPersistReports(options) {
1848
1863
  });
1849
1864
  }
1850
1865
 
1851
- // packages/core/src/lib/implementation/read-code-pushup-config.ts
1852
- var ConfigPathError = class extends Error {
1866
+ // packages/core/src/lib/implementation/read-rc-file.ts
1867
+ import { join as join4 } from "node:path";
1868
+ var ConfigPathError2 = class extends Error {
1853
1869
  constructor(configPath) {
1854
1870
  super(`Provided path '${configPath}' is not valid.`);
1855
1871
  }
1856
1872
  };
1857
- async function readCodePushupConfig(filepath) {
1873
+ async function readRcByPath(filepath) {
1874
+ if (filepath.length === 0) {
1875
+ throw new Error("The path to the configuration file is empty.");
1876
+ }
1858
1877
  if (!await fileExists(filepath)) {
1859
- throw new ConfigPathError(filepath);
1878
+ throw new ConfigPathError2(filepath);
1860
1879
  }
1861
- return coreConfigSchema.parse(await importEsmModule({ filepath }));
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}`));
1862
1901
  }
1863
1902
  export {
1864
- ConfigPathError,
1903
+ ConfigPathError2 as ConfigPathError,
1865
1904
  PersistDirError,
1866
1905
  PersistError,
1867
1906
  PluginOutputMissingAuditError,
1907
+ autoloadRc,
1868
1908
  collect,
1869
1909
  collectAndPersistReports,
1870
1910
  executePlugin,
1871
1911
  executePlugins,
1872
1912
  persistReport,
1873
1913
  readCodePushupConfig,
1914
+ readRcByPath,
1874
1915
  upload
1875
1916
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-pushup/core",
3
- "version": "0.10.7",
3
+ "version": "0.11.0",
4
4
  "license": "MIT",
5
5
  "dependencies": {
6
6
  "@code-pushup/models": "*",
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 { readCodePushupConfig, ConfigPathError, } from './lib/implementation/read-code-pushup-config';
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>;