@code-pushup/utils 0.28.0 → 0.30.0-alpha

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
@@ -1288,7 +1288,7 @@ var ProcessError = class extends Error {
1288
1288
  }
1289
1289
  };
1290
1290
  function executeProcess(cfg) {
1291
- const { observer, cwd, command, args, alwaysResolve = false } = cfg;
1291
+ const { observer, cwd, command, args, ignoreExitCode = false } = cfg;
1292
1292
  const { onStdout, onError, onComplete } = observer ?? {};
1293
1293
  const date = (/* @__PURE__ */ new Date()).toISOString();
1294
1294
  const start = performance.now();
@@ -1308,7 +1308,7 @@ function executeProcess(cfg) {
1308
1308
  });
1309
1309
  process2.on("close", (code) => {
1310
1310
  const timings = { date, duration: calcDuration(start) };
1311
- if (code === 0 || alwaysResolve) {
1311
+ if (code === 0 || ignoreExitCode) {
1312
1312
  onComplete?.();
1313
1313
  resolve({ code, stdout, stderr, ...timings });
1314
1314
  } else {
@@ -1343,6 +1343,9 @@ function objectToKeys(obj) {
1343
1343
  function objectToEntries(obj) {
1344
1344
  return Object.entries(obj);
1345
1345
  }
1346
+ function objectFromEntries(entries) {
1347
+ return Object.fromEntries(entries);
1348
+ }
1346
1349
  function countOccurrences(values) {
1347
1350
  return values.reduce(
1348
1351
  (acc, value) => ({ ...acc, [value]: (acc[value] ?? 0) + 1 }),
@@ -1396,11 +1399,23 @@ function toUnixPath(path) {
1396
1399
  function toUnixNewlines(text) {
1397
1400
  return platform() === "win32" ? text.replace(/\r\n/g, "\n") : text;
1398
1401
  }
1402
+ function fromJsonLines(jsonLines) {
1403
+ const unifiedNewLines = toUnixNewlines(jsonLines).trim();
1404
+ return JSON.parse(`[${unifiedNewLines.split("\n").join(",")}]`);
1405
+ }
1406
+ function toJsonLines(json) {
1407
+ return json.map((item) => JSON.stringify(item)).join("\n");
1408
+ }
1399
1409
  function capitalize(text) {
1400
1410
  return `${text.charAt(0).toLocaleUpperCase()}${text.slice(
1401
1411
  1
1402
1412
  )}`;
1403
1413
  }
1414
+ function apostrophize(text, upperCase) {
1415
+ const lastCharMatch = text.match(/(\w)\W*$/);
1416
+ const lastChar = lastCharMatch?.[1] ?? "";
1417
+ return `${text}'${lastChar.toLocaleLowerCase() === "s" ? "" : upperCase ? "S" : "s"}`;
1418
+ }
1404
1419
  function toNumberPrecision(value, decimalPlaces) {
1405
1420
  return Number(
1406
1421
  `${Math.round(
@@ -1686,7 +1701,7 @@ function reportToDetailsSection(audit) {
1686
1701
  function reportToAboutSection(report) {
1687
1702
  const date = formatDate(/* @__PURE__ */ new Date());
1688
1703
  const { duration, version, commit, plugins, categories } = report;
1689
- const commitInfo = commit ? `${commit.message} (${commit.hash.slice(0, 7)})` : "N/A";
1704
+ const commitInfo = commit ? `${commit.message} (${commit.hash})` : "N/A";
1690
1705
  const reportMetaTable = [
1691
1706
  reportMetaTableHeaders,
1692
1707
  [
@@ -1762,12 +1777,7 @@ function formatDiffHeaderSection(diff) {
1762
1777
  ...diff.audits.changed
1763
1778
  ])
1764
1779
  );
1765
- const styleCommit = (commit) => style(commit.hash.slice(0, 7), ["c"]);
1766
- const styleCommits = (commits) => {
1767
- const src = styleCommit(commits.before);
1768
- const tgt = styleCommit(commits.after);
1769
- return `compared target commit ${tgt} with source commit ${src}`;
1770
- };
1780
+ const styleCommits = (commits) => `compared target commit ${commits.after.hash} with source commit ${commits.before.hash}`;
1771
1781
  return paragraphs(
1772
1782
  h1("Code PushUp"),
1773
1783
  diff.commits ? `${outcomeTexts[outcome]} \u2013 ${styleCommits(diff.commits)}.` : `${outcomeTexts[outcome]}.`
@@ -2211,6 +2221,7 @@ export {
2211
2221
  ProcessError,
2212
2222
  README_LINK,
2213
2223
  TERMINAL_WIDTH,
2224
+ apostrophize,
2214
2225
  calcDuration,
2215
2226
  capitalize,
2216
2227
  compareIssueSeverity,
@@ -2229,6 +2240,7 @@ export {
2229
2240
  formatBytes,
2230
2241
  formatDuration,
2231
2242
  formatGitPath,
2243
+ fromJsonLines,
2232
2244
  generateMdReport,
2233
2245
  generateMdReportsDiff,
2234
2246
  getCurrentBranchOrTag,
@@ -2247,6 +2259,7 @@ export {
2247
2259
  logMultipleResults,
2248
2260
  logStdoutSummary,
2249
2261
  matchArrayItemsByKey,
2262
+ objectFromEntries,
2250
2263
  objectToCliArgs,
2251
2264
  objectToEntries,
2252
2265
  objectToKeys,
@@ -2262,6 +2275,7 @@ export {
2262
2275
  sortReport,
2263
2276
  toArray,
2264
2277
  toGitPath,
2278
+ toJsonLines,
2265
2279
  toNumberPrecision,
2266
2280
  toOrdinal,
2267
2281
  toUnixNewlines,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-pushup/utils",
3
- "version": "0.28.0",
3
+ "version": "0.30.0-alpha",
4
4
  "dependencies": {
5
5
  "@code-pushup/models": "*",
6
6
  "bundle-require": "^4.0.1",
package/src/index.d.ts CHANGED
@@ -19,5 +19,5 @@ export { scoreReport } from './lib/reports/scoring';
19
19
  export { sortReport } from './lib/reports/sorting';
20
20
  export { ScoredCategoryConfig, ScoredGroup, ScoredReport, } from './lib/reports/types';
21
21
  export { calcDuration, compareIssueSeverity, loadReport, } from './lib/reports/utils';
22
- export { CliArgsObject, capitalize, countOccurrences, distinct, factorOf, objectToCliArgs, objectToEntries, objectToKeys, toArray, toNumberPrecision, toOrdinal, toUnixNewlines, toUnixPath, } from './lib/transform';
22
+ export { CliArgsObject, apostrophize, capitalize, countOccurrences, distinct, factorOf, fromJsonLines, objectFromEntries, objectToCliArgs, objectToEntries, objectToKeys, toArray, toJsonLines, toNumberPrecision, toOrdinal, toUnixNewlines, toUnixPath, } from './lib/transform';
23
23
  export { verboseUtils } from './lib/verbose-utils';
@@ -71,7 +71,7 @@ export type ProcessConfig = {
71
71
  args?: string[];
72
72
  cwd?: string;
73
73
  observer?: ProcessObserver;
74
- alwaysResolve?: boolean;
74
+ ignoreExitCode?: boolean;
75
75
  };
76
76
  /**
77
77
  * Process observer object. Contains the onStdout, error and complete function.
@@ -1,6 +1,7 @@
1
1
  export declare function toArray<T>(val: T | T[]): T[];
2
2
  export declare function objectToKeys<T extends object>(obj: T): (keyof T)[];
3
3
  export declare function objectToEntries<T extends object>(obj: T): [keyof T, T[keyof T]][];
4
+ export declare function objectFromEntries<K extends PropertyKey, V>(entries: [K, V][]): Record<K, V>;
4
5
  export declare function countOccurrences<T extends PropertyKey>(values: T[]): Partial<Record<T, number>>;
5
6
  export declare function exists<T>(value: T): value is NonNullable<T>;
6
7
  export declare function distinct<T extends string | number | boolean>(array: T[]): T[];
@@ -24,7 +25,10 @@ Record<string, ArgumentValue | undefined> | {
24
25
  export declare function objectToCliArgs<T extends object = Record<string, ArgumentValue>>(params?: CliArgsObject<T>): string[];
25
26
  export declare function toUnixPath(path: string): string;
26
27
  export declare function toUnixNewlines(text: string): string;
28
+ export declare function fromJsonLines<T = unknown>(jsonLines: string): T;
29
+ export declare function toJsonLines<T>(json: T[]): string;
27
30
  export declare function capitalize<T extends string>(text: T): Capitalize<T>;
31
+ export declare function apostrophize(text: string, upperCase?: boolean): string;
28
32
  export declare function toNumberPrecision(value: number, decimalPlaces: number): number;
29
33
  export declare function toOrdinal(value: number): string;
30
34
  export {};