@code-pushup/core 0.18.1 → 0.19.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
@@ -956,16 +956,32 @@ function executeProcess(cfg) {
956
956
  });
957
957
  }
958
958
 
959
+ // packages/utils/src/lib/transform.ts
960
+ function deepClone(obj) {
961
+ return obj == null || typeof obj !== "object" ? obj : structuredClone(obj);
962
+ }
963
+ function toUnixPath(path) {
964
+ return path.replace(/\\/g, "/");
965
+ }
966
+
959
967
  // packages/utils/src/lib/git.ts
968
+ import { isAbsolute, join as join2, relative } from "node:path";
960
969
  import { simpleGit } from "simple-git";
961
- var git = simpleGit();
962
- async function getLatestCommit() {
970
+ async function getLatestCommit(git = simpleGit()) {
963
971
  const log = await git.log({
964
972
  maxCount: 1,
965
973
  format: { hash: "%H", message: "%s", author: "%an", date: "%ad" }
966
974
  });
967
975
  return log.latest;
968
976
  }
977
+ function getGitRoot(git = simpleGit()) {
978
+ return git.revparse("--show-toplevel");
979
+ }
980
+ function formatGitPath(path, gitRoot) {
981
+ const absolutePath = isAbsolute(path) ? path : join2(process.cwd(), path);
982
+ const relativePath = relative(gitRoot, absolutePath);
983
+ return toUnixPath(relativePath);
984
+ }
969
985
  function validateCommitData(commitData, options = {}) {
970
986
  const { throwError = false } = options;
971
987
  if (!commitData) {
@@ -988,18 +1004,21 @@ function groupByStatus(results) {
988
1004
  );
989
1005
  }
990
1006
 
991
- // packages/utils/src/lib/progress.ts
1007
+ // packages/utils/src/lib/logging.ts
992
1008
  import chalk2 from "chalk";
1009
+
1010
+ // packages/utils/src/lib/progress.ts
1011
+ import chalk3 from "chalk";
993
1012
  import { MultiProgressBars } from "multi-progress-bars";
994
1013
  var barStyles = {
995
- active: (s) => chalk2.green(s),
996
- done: (s) => chalk2.gray(s),
997
- idle: (s) => chalk2.gray(s)
1014
+ active: (s) => chalk3.green(s),
1015
+ done: (s) => chalk3.gray(s),
1016
+ idle: (s) => chalk3.gray(s)
998
1017
  };
999
1018
  var messageStyles = {
1000
- active: (s) => chalk2.black(s),
1001
- done: (s) => chalk2.green(chalk2.bold(s)),
1002
- idle: (s) => chalk2.gray(s)
1019
+ active: (s) => chalk3.black(s),
1020
+ done: (s) => chalk3.green(chalk3.bold(s)),
1021
+ idle: (s) => chalk3.gray(s)
1003
1022
  };
1004
1023
  var mpb;
1005
1024
  function getSingletonProgressBars(options) {
@@ -1298,7 +1317,7 @@ function getAuditResult(audit, isHtml = false) {
1298
1317
 
1299
1318
  // packages/utils/src/lib/reports/generate-stdout-summary.ts
1300
1319
  import cliui from "@isaacs/cliui";
1301
- import chalk3 from "chalk";
1320
+ import chalk4 from "chalk";
1302
1321
  import CliTable3 from "cli-table3";
1303
1322
  function addLine(line = "") {
1304
1323
  return line + NEW_LINE;
@@ -1309,7 +1328,7 @@ function generateStdoutSummary(report) {
1309
1328
  }
1310
1329
  function reportToHeaderSection2(report) {
1311
1330
  const { packageName, version: version2 } = report;
1312
- return `${chalk3.bold(reportHeadlineText)} - ${packageName}@${version2}`;
1331
+ return `${chalk4.bold(reportHeadlineText)} - ${packageName}@${version2}`;
1313
1332
  }
1314
1333
  function reportToDetailSection(report) {
1315
1334
  const { plugins } = report;
@@ -1329,13 +1348,13 @@ function reportToDetailSection(report) {
1329
1348
  padding: [0, 3, 0, 0]
1330
1349
  },
1331
1350
  {
1332
- text: chalk3.cyanBright(audit.displayValue || `${audit.value}`),
1351
+ text: chalk4.cyanBright(audit.displayValue || `${audit.value}`),
1333
1352
  width: 10,
1334
1353
  padding: [0, 0, 0, 0]
1335
1354
  }
1336
1355
  );
1337
1356
  });
1338
- return acc + addLine() + addLine(chalk3.magentaBright.bold(`${title} audits`)) + addLine() + addLine(ui.toString()) + addLine();
1357
+ return acc + addLine() + addLine(chalk4.magentaBright.bold(`${title} audits`)) + addLine() + addLine(ui.toString()) + addLine();
1339
1358
  }, "");
1340
1359
  }
1341
1360
  function reportToOverviewSection2({
@@ -1358,11 +1377,11 @@ function reportToOverviewSection2({
1358
1377
  countCategoryAudits(refs, plugins)
1359
1378
  ])
1360
1379
  );
1361
- return addLine(chalk3.magentaBright.bold("Categories")) + addLine() + addLine(table.toString());
1380
+ return addLine(chalk4.magentaBright.bold("Categories")) + addLine() + addLine(table.toString());
1362
1381
  }
1363
1382
  function withColor({ score, text }) {
1364
1383
  const formattedScore = text ?? formatReportScore(score);
1365
- const style2 = text ? chalk3 : chalk3.bold;
1384
+ const style2 = text ? chalk4 : chalk4.bold;
1366
1385
  if (score >= SCORE_COLOR_RANGE.GREEN_MIN) {
1367
1386
  return style2.green(formattedScore);
1368
1387
  }
@@ -1372,11 +1391,6 @@ function withColor({ score, text }) {
1372
1391
  return style2.red(formattedScore);
1373
1392
  }
1374
1393
 
1375
- // packages/utils/src/lib/transform.ts
1376
- function deepClone(obj) {
1377
- return obj == null || typeof obj !== "object" ? obj : structuredClone(obj);
1378
- }
1379
-
1380
1394
  // packages/utils/src/lib/reports/scoring.ts
1381
1395
  var GroupRefInvalidError = class extends Error {
1382
1396
  constructor(auditSlug, pluginSlug) {
@@ -1537,18 +1551,48 @@ var verboseUtils = (verbose = false) => ({
1537
1551
  exec: getExecVerbose(verbose)
1538
1552
  });
1539
1553
 
1540
- // packages/utils/src/lib/logging.ts
1541
- import chalk4 from "chalk";
1542
-
1543
1554
  // packages/core/package.json
1544
1555
  var name = "@code-pushup/core";
1545
- var version = "0.18.1";
1556
+ var version = "0.19.0";
1546
1557
 
1547
1558
  // packages/core/src/lib/implementation/execute-plugin.ts
1548
1559
  import chalk5 from "chalk";
1549
1560
 
1561
+ // packages/core/src/lib/normalize.ts
1562
+ function normalizePersistConfig(cfg) {
1563
+ return {
1564
+ outputDir: PERSIST_OUTPUT_DIR,
1565
+ filename: PERSIST_FILENAME,
1566
+ format: PERSIST_FORMAT,
1567
+ ...cfg
1568
+ };
1569
+ }
1570
+ async function normalizeAuditOutputs(audits) {
1571
+ const gitRoot = await getGitRoot();
1572
+ return audits.map((audit) => {
1573
+ if (audit.details?.issues == null || audit.details.issues.every((issue) => issue.source == null)) {
1574
+ return audit;
1575
+ }
1576
+ return {
1577
+ ...audit,
1578
+ details: {
1579
+ ...audit.details,
1580
+ issues: audit.details.issues.map(
1581
+ (issue) => issue.source == null ? issue : {
1582
+ ...issue,
1583
+ source: {
1584
+ ...issue.source,
1585
+ file: formatGitPath(issue.source.file, gitRoot)
1586
+ }
1587
+ }
1588
+ )
1589
+ }
1590
+ };
1591
+ });
1592
+ }
1593
+
1550
1594
  // packages/core/src/lib/implementation/runner.ts
1551
- import { join as join2 } from "node:path";
1595
+ import { join as join3 } from "node:path";
1552
1596
  async function executeRunnerConfig(cfg, onProgress) {
1553
1597
  const { args, command, outputFile, outputTransform } = cfg;
1554
1598
  const { duration, date } = await executeProcess({
@@ -1556,7 +1600,7 @@ async function executeRunnerConfig(cfg, onProgress) {
1556
1600
  args,
1557
1601
  observer: { onStdout: onProgress }
1558
1602
  });
1559
- const outputs = await readJsonFile(join2(process.cwd(), outputFile));
1603
+ const outputs = await readJsonFile(join3(process.cwd(), outputFile));
1560
1604
  const audits = outputTransform ? await outputTransform(outputs) : outputs;
1561
1605
  return {
1562
1606
  duration,
@@ -1594,7 +1638,8 @@ async function executePlugin(pluginConfig, onProgress) {
1594
1638
  const { audits: unvalidatedAuditOutputs, ...executionMeta } = runnerResult;
1595
1639
  const auditOutputs = auditOutputsSchema.parse(unvalidatedAuditOutputs);
1596
1640
  auditOutputsCorrelateWithPluginOutput(auditOutputs, pluginConfigAudits);
1597
- const auditReports = auditOutputs.map(
1641
+ const normalizedAuditOutputs = await normalizeAuditOutputs(auditOutputs);
1642
+ const auditReports = normalizedAuditOutputs.map(
1598
1643
  (auditOutput) => ({
1599
1644
  ...auditOutput,
1600
1645
  ...pluginConfigAudits.find(
@@ -1672,7 +1717,7 @@ async function collect(options) {
1672
1717
 
1673
1718
  // packages/core/src/lib/implementation/persist.ts
1674
1719
  import { mkdir as mkdir2, stat as stat2, writeFile } from "node:fs/promises";
1675
- import { join as join3 } from "node:path";
1720
+ import { join as join4 } from "node:path";
1676
1721
  var PersistDirError = class extends Error {
1677
1722
  constructor(outputDir) {
1678
1723
  super(`outPath: ${outputDir} is no directory.`);
@@ -1716,7 +1761,7 @@ async function persistReport(report, options) {
1716
1761
  return Promise.allSettled(
1717
1762
  results.map(
1718
1763
  (result) => persistResult(
1719
- join3(outputDir, `${filename}.${result.format}`),
1764
+ join4(outputDir, `${filename}.${result.format}`),
1720
1765
  result.content
1721
1766
  )
1722
1767
  )
@@ -1732,14 +1777,6 @@ function logPersistedResults(persistResults) {
1732
1777
  logMultipleFileResults(persistResults, "Generated reports");
1733
1778
  }
1734
1779
 
1735
- // packages/core/src/lib/normalize.ts
1736
- var normalizePersistConfig = (cfg) => ({
1737
- outputDir: PERSIST_OUTPUT_DIR,
1738
- filename: PERSIST_FILENAME,
1739
- format: PERSIST_FORMAT,
1740
- ...cfg
1741
- });
1742
-
1743
1780
  // packages/core/src/lib/collect-and-persist.ts
1744
1781
  async function collectAndPersistReports(options) {
1745
1782
  const { exec } = verboseUtils(options.verbose);
@@ -1755,7 +1792,7 @@ async function collectAndPersistReports(options) {
1755
1792
  }
1756
1793
 
1757
1794
  // packages/core/src/lib/implementation/read-rc-file.ts
1758
- import { join as join4 } from "node:path";
1795
+ import { join as join5 } from "node:path";
1759
1796
  var ConfigPathError = class extends Error {
1760
1797
  constructor(configPath) {
1761
1798
  super(`Provided path '${configPath}' is not valid.`);
@@ -1788,7 +1825,7 @@ async function autoloadRc() {
1788
1825
  )}) present in ${process.cwd()}`
1789
1826
  );
1790
1827
  }
1791
- return readRcByPath(join4(process.cwd(), `${CONFIG_FILE_NAME}.${ext}`));
1828
+ return readRcByPath(join5(process.cwd(), `${CONFIG_FILE_NAME}.${ext}`));
1792
1829
  }
1793
1830
 
1794
1831
  // packages/core/src/lib/upload.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-pushup/core",
3
- "version": "0.18.1",
3
+ "version": "0.19.0",
4
4
  "license": "MIT",
5
5
  "dependencies": {
6
6
  "@code-pushup/models": "*",
@@ -1,2 +1,3 @@
1
- import { PersistConfig } from '@code-pushup/models';
2
- export declare const normalizePersistConfig: (cfg?: Partial<PersistConfig>) => Required<PersistConfig>;
1
+ import { type AuditOutputs, PersistConfig } from '@code-pushup/models';
2
+ export declare function normalizePersistConfig(cfg?: Partial<PersistConfig>): Required<PersistConfig>;
3
+ export declare function normalizeAuditOutputs(audits: AuditOutputs): Promise<AuditOutputs>;