@code-pushup/utils 0.35.0 → 0.42.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.
Files changed (33) hide show
  1. package/index.js +1087 -597
  2. package/package.json +6 -4
  3. package/src/index.d.ts +5 -1
  4. package/src/lib/git/git.commits-and-tags.d.ts +57 -0
  5. package/src/lib/{git.d.ts → git/git.d.ts} +8 -3
  6. package/src/lib/reports/constants.d.ts +26 -6
  7. package/src/lib/reports/formatting.d.ts +6 -0
  8. package/src/lib/reports/generate-md-report-categoy-section.d.ts +6 -0
  9. package/src/lib/reports/generate-md-report.d.ts +8 -0
  10. package/src/lib/reports/utils.d.ts +5 -3
  11. package/src/lib/semver.d.ts +3 -0
  12. package/src/lib/table.d.ts +6 -0
  13. package/src/lib/text-formats/constants.d.ts +3 -0
  14. package/src/lib/{reports/md → text-formats/html}/details.d.ts +2 -0
  15. package/src/lib/text-formats/html/font-style.d.ts +3 -0
  16. package/src/lib/text-formats/html/link.d.ts +1 -0
  17. package/src/lib/text-formats/html/table.d.ts +2 -0
  18. package/src/lib/text-formats/index.d.ts +44 -0
  19. package/src/lib/text-formats/md/font-style.d.ts +4 -0
  20. package/src/lib/{reports → text-formats}/md/headline.d.ts +1 -1
  21. package/src/lib/text-formats/md/link.d.ts +1 -0
  22. package/src/lib/{reports → text-formats}/md/list.d.ts +2 -0
  23. package/src/lib/text-formats/md/section.d.ts +2 -0
  24. package/src/lib/text-formats/md/table.d.ts +9 -0
  25. package/src/lib/text-formats/table.d.ts +6 -0
  26. package/src/lib/text-formats/types.d.ts +1 -0
  27. package/src/lib/types.d.ts +3 -0
  28. package/src/lib/reports/md/font-style.d.ts +0 -16
  29. package/src/lib/reports/md/index.d.ts +0 -8
  30. package/src/lib/reports/md/link.d.ts +0 -6
  31. package/src/lib/reports/md/table.d.ts +0 -10
  32. /package/src/lib/{reports → text-formats}/md/image.d.ts +0 -0
  33. /package/src/lib/{reports → text-formats}/md/paragraphs.d.ts +0 -0
package/package.json CHANGED
@@ -1,14 +1,16 @@
1
1
  {
2
2
  "name": "@code-pushup/utils",
3
- "version": "0.35.0",
3
+ "version": "0.42.0",
4
4
  "dependencies": {
5
- "@code-pushup/models": "0.35.0",
5
+ "@code-pushup/models": "0.42.0",
6
6
  "bundle-require": "^4.0.1",
7
+ "esbuild": "^0.19.2",
7
8
  "chalk": "^5.3.0",
8
9
  "@isaacs/cliui": "^8.0.2",
9
10
  "simple-git": "^3.20.0",
10
11
  "multi-progress-bars": "^5.0.3",
11
- "@poppinss/cliui": "^6.4.0"
12
+ "@poppinss/cliui": "^6.4.0",
13
+ "semver": "^7.6.0"
12
14
  },
13
15
  "license": "MIT",
14
16
  "homepage": "https://github.com/code-pushup/cli#readme",
@@ -17,7 +19,7 @@
17
19
  },
18
20
  "repository": {
19
21
  "type": "git",
20
- "url": "https://github.com/code-pushup/cli.git",
22
+ "url": "git+https://github.com/code-pushup/cli.git",
21
23
  "directory": "packages/utils"
22
24
  },
23
25
  "contributors": [
package/src/index.d.ts CHANGED
@@ -1,10 +1,13 @@
1
+ export * from './lib/text-formats';
2
+ export { ExcludeNullFromPropertyTypes } from './lib/types';
1
3
  export { exists } from '@code-pushup/models';
2
4
  export { Diff, comparePairs, matchArrayItemsByKey } from './lib/diff';
3
5
  export { ProcessConfig, ProcessError, ProcessObserver, ProcessResult, executeProcess, } from './lib/execute-process';
4
6
  export { CrawlFileSystemOptions, FileResult, MultipleFileResults, crawlFileSystem, directoryExists, ensureDirectoryExists, fileExists, findLineNumberInText, importEsmModule, logMultipleFileResults, pluginWorkDir, readJsonFile, readTextFile, removeDirectoryIfExists, } from './lib/file-system';
5
7
  export { filterItemRefsBy } from './lib/filter';
6
8
  export { formatBytes, formatDuration, pluralize, pluralizeToken, slugify, truncateDescription, truncateIssueMessage, truncateText, truncateTitle, } from './lib/formatting';
7
- export { formatGitPath, getCurrentBranchOrTag, getGitRoot, getLatestCommit, safeCheckout, toGitPath, } from './lib/git';
9
+ export { formatGitPath, guardAgainstLocalChanges, getGitRoot, safeCheckout, toGitPath, } from './lib/git/git';
10
+ export { getSemverTags, LogResult, getHashes, getHashFromTag, getCurrentBranchOrTag, getLatestCommit, } from './lib/git/git.commits-and-tags';
8
11
  export { groupByStatus } from './lib/group-by-status';
9
12
  export { isPromiseFulfilledResult, isPromiseRejectedResult, } from './lib/guards';
10
13
  export { logMultipleResults } from './lib/log-results';
@@ -21,3 +24,4 @@ export { ScoredCategoryConfig, ScoredGroup, ScoredReport, } from './lib/reports/
21
24
  export { calcDuration, compareIssueSeverity, loadReport, } from './lib/reports/utils';
22
25
  export { CliArgsObject, apostrophize, capitalize, countOccurrences, distinct, factorOf, fromJsonLines, objectFromEntries, objectToCliArgs, objectToEntries, objectToKeys, toArray, toJsonLines, toNumberPrecision, toOrdinal, toUnixNewlines, toUnixPath, } from './lib/transform';
23
26
  export { verboseUtils } from './lib/verbose-utils';
27
+ export { isSemver, normalizeSemver, sortSemvers } from './lib/semver';
@@ -0,0 +1,57 @@
1
+ import { LogOptions as SimpleGitLogOptions } from 'simple-git';
2
+ import { Commit } from '@code-pushup/models';
3
+ export declare function getLatestCommit(git?: import("simple-git").SimpleGit): Promise<Commit | null>;
4
+ export declare function getCurrentBranchOrTag(git?: import("simple-git").SimpleGit): Promise<string>;
5
+ export type LogResult = {
6
+ hash: string;
7
+ message: string;
8
+ };
9
+ export declare function filterLogs(allTags: string[], opt?: Pick<LogOptions, 'from' | 'to' | 'maxCount'>): string[];
10
+ export declare function getHashFromTag(tag: string, git?: import("simple-git").SimpleGit): Promise<LogResult>;
11
+ export type LogOptions = {
12
+ targetBranch?: string;
13
+ from?: string;
14
+ to?: string;
15
+ maxCount?: number;
16
+ };
17
+ export declare function getSemverTags(opt?: LogOptions, git?: import("simple-git").SimpleGit): Promise<LogResult[]>;
18
+ /**
19
+ * `getHashes` returns a list of commit hashes. Internally it uses `git.log()` to determine the commits within a range.
20
+ * The amount can be limited to a maximum number of commits specified by `maxCount`.
21
+ * With `from` and `to`, you can specify a range of commits.
22
+ *
23
+ * **NOTE:**
24
+ * In Git, specifying a range with two dots (`from..to`) selects commits that are reachable from `to` but not from `from`.
25
+ * Essentially, it shows the commits that are in `to` but not in `from`, excluding the commits unique to `from`.
26
+ *
27
+ * Example:
28
+ *
29
+ * Let's consider the following commit history:
30
+ *
31
+ * A---B---C---D---E (main)
32
+ *
33
+ * Using `git log B..D`, you would get the commits C and D:
34
+ *
35
+ * C---D
36
+ *
37
+ * This is because these commits are reachable from D but not from B.
38
+ *
39
+ * ASCII Representation:
40
+ *
41
+ * Main Branch: A---B---C---D---E
42
+ * \ \
43
+ * \ +--- Commits included in `git log B..D`
44
+ * \
45
+ * +--- Excluded by the `from` parameter
46
+ *
47
+ * With `simple-git`, when you specify a `from` and `to` range like this:
48
+ *
49
+ * git.log({ from: 'B', to: 'D' });
50
+ *
51
+ * It interprets it similarly, selecting commits between B and D, inclusive of D but exclusive of B.
52
+ * For `git.log({ from: 'B', to: 'D' })` or `git log B..D`, commits C and D are selected.
53
+ *
54
+ * @param options Object containing `from`, `to`, and optionally `maxCount` to specify the commit range and limit.
55
+ * @param git The `simple-git` instance used to execute Git commands.
56
+ */
57
+ export declare function getHashes(options?: SimpleGitLogOptions & Pick<LogOptions, 'targetBranch'>, git?: import("simple-git").SimpleGit): Promise<LogResult[]>;
@@ -1,8 +1,13 @@
1
- import { Commit } from '@code-pushup/models';
2
- export declare function getLatestCommit(git?: import("simple-git").SimpleGit): Promise<Commit | null>;
1
+ import { StatusResult } from 'simple-git';
3
2
  export declare function getGitRoot(git?: import("simple-git").SimpleGit): Promise<string>;
4
3
  export declare function formatGitPath(path: string, gitRoot: string): string;
5
4
  export declare function toGitPath(path: string, git?: import("simple-git").SimpleGit): Promise<string>;
5
+ export declare class GitStatusError extends Error {
6
+ static ignoredProps: Set<string>;
7
+ static getReducedStatus(status: StatusResult): {
8
+ [k: string]: any;
9
+ };
10
+ constructor(status: StatusResult);
11
+ }
6
12
  export declare function guardAgainstLocalChanges(git?: import("simple-git").SimpleGit): Promise<void>;
7
- export declare function getCurrentBranchOrTag(git?: import("simple-git").SimpleGit): Promise<string>;
8
13
  export declare function safeCheckout(branchOrHash: string, forceCleanStatus?: boolean, git?: import("simple-git").SimpleGit): Promise<void>;
@@ -1,15 +1,35 @@
1
1
  export declare const TERMINAL_WIDTH = 80;
2
- export declare const NEW_LINE = "\n";
3
2
  export declare const SCORE_COLOR_RANGE: {
4
3
  GREEN_MIN: number;
5
4
  YELLOW_MIN: number;
6
5
  };
6
+ export declare const CATEGORIES_TITLE = "\uD83C\uDFF7 Categories";
7
7
  export declare const FOOTER_PREFIX = "Made with \u2764 by";
8
8
  export declare const CODE_PUSHUP_DOMAIN = "code-pushup.dev";
9
- export declare const README_LINK = "https://github.com/flowup/quality-metrics-cli#readme";
9
+ export declare const README_LINK = "https://github.com/code-pushup/cli#readme";
10
10
  export declare const reportHeadlineText = "Code PushUp Report";
11
- export declare const reportOverviewTableHeaders: string[];
11
+ export declare const reportOverviewTableHeaders: [{
12
+ readonly key: "category";
13
+ readonly label: "🏷 Category";
14
+ readonly align: "left";
15
+ }, {
16
+ readonly key: "score";
17
+ readonly label: "⭐ Score";
18
+ }, {
19
+ readonly key: "audits";
20
+ readonly label: "🛡 Audits";
21
+ }];
12
22
  export declare const reportRawOverviewTableHeaders: string[];
13
- export declare const reportMetaTableHeaders: string[];
14
- export declare const pluginMetaTableHeaders: string[];
15
- export declare const detailsTableHeaders: string[];
23
+ export declare const issuesTableHeadings: [{
24
+ readonly key: "severity";
25
+ readonly label: "Severity";
26
+ }, {
27
+ readonly key: "message";
28
+ readonly label: "Message";
29
+ }, {
30
+ readonly key: "file";
31
+ readonly label: "Source file";
32
+ }, {
33
+ readonly key: "line";
34
+ readonly label: "Line(s)";
35
+ }];
@@ -0,0 +1,6 @@
1
+ import { AuditReport, Table } from '@code-pushup/models';
2
+ import { Hierarchy } from '../text-formats';
3
+ export declare function tableSection(tableData: Table, options?: {
4
+ level?: Hierarchy | 0;
5
+ }): string;
6
+ export declare function metaDescription({ docsUrl, description, }: Pick<AuditReport, 'docsUrl' | 'description'>): string;
@@ -0,0 +1,6 @@
1
+ import { AuditReport } from '@code-pushup/models';
2
+ import { ScoredGroup, ScoredReport } from './types';
3
+ export declare function categoriesOverviewSection(report: Pick<ScoredReport, 'categories' | 'plugins'>): string;
4
+ export declare function categoriesDetailsSection(report: Pick<ScoredReport, 'categories' | 'plugins'>): string;
5
+ export declare function categoryRef({ title, score, value, displayValue }: AuditReport, pluginTitle: string): string;
6
+ export declare function categoryGroupItem({ score, title }: ScoredGroup, groupAudits: AuditReport[], pluginTitle: string): string;
@@ -1,2 +1,10 @@
1
+ import { AuditReport, Issue, Report, Table } from '@code-pushup/models';
1
2
  import { ScoredReport } from './types';
3
+ export declare function auditDetailsAuditValue({ score, value, displayValue, }: AuditReport): string;
2
4
  export declare function generateMdReport(report: ScoredReport): string;
5
+ export declare function auditDetailsIssues(issues?: Issue[]): string;
6
+ export declare function auditDetails(audit: AuditReport): string;
7
+ export declare function auditsSection({ plugins, }: Pick<ScoredReport, 'plugins'>): string;
8
+ export declare function aboutSection(report: Omit<ScoredReport, 'packageName'>): string;
9
+ export declare function reportPluginMeta({ plugins }: Pick<Report, 'plugins'>): Table;
10
+ export declare function reportMetaData({ commit, version, duration, plugins, categories, }: Pick<ScoredReport, 'date' | 'duration' | 'version' | 'commit' | 'plugins' | 'categories'>): Table;
@@ -4,13 +4,15 @@ export declare function formatReportScore(score: number): string;
4
4
  export declare function formatScoreWithColor(score: number, options?: {
5
5
  skipBold?: boolean;
6
6
  }): string;
7
- export declare function getRoundScoreMarker(score: number): string;
8
- export declare function getSquaredScoreMarker(score: number): string;
7
+ export type MarkerShape = 'circle' | 'square';
8
+ export type ScoreColors = 'red' | 'yellow' | 'green';
9
+ export declare const MARKERS: Record<MarkerShape, Record<ScoreColors, string>>;
10
+ export declare function scoreMarker(score: number, markerType?: MarkerShape): string;
9
11
  export declare function getDiffMarker(diff: number): string;
10
12
  export declare function colorByScoreDiff(text: string, diff: number): string;
11
13
  export declare function shieldsBadge(text: string, color: string): string;
12
14
  export declare function formatDiffNumber(diff: number): string;
13
- export declare function getSeverityIcon(severity: 'info' | 'warning' | 'error'): string;
15
+ export declare function severityMarker(severity: 'info' | 'warning' | 'error'): string;
14
16
  export declare function calcDuration(start: number, stop?: number): number;
15
17
  export declare function countWeightedRefs(refs: CategoryRef[]): number;
16
18
  export declare function countCategoryAudits(refs: CategoryRef[], plugins: ScoredReport['plugins']): number;
@@ -0,0 +1,3 @@
1
+ export declare function normalizeSemver(semverString: string): string;
2
+ export declare function isSemver(semverString?: string): boolean;
3
+ export declare function sortSemvers(semverStrings: string[]): string[];
@@ -0,0 +1,6 @@
1
+ import { Table, TableAlignment, TableColumnObject, TableColumnPrimitive } from '@code-pushup/models';
2
+ export declare function rowToStringArray({ rows, columns }: Table): string[][];
3
+ export declare function columnsToStringArray({ rows, columns }: Table): string[];
4
+ export declare function getColumnAlignmentForKeyAndIndex(targetKey: string, targetIdx: number, columns?: TableColumnObject[]): TableAlignment;
5
+ export declare function getColumnAlignmentForIndex(targetIdx: number, columns?: TableColumnPrimitive[]): TableAlignment;
6
+ export declare function getColumnAlignments({ rows, columns, }: Table): TableAlignment[];
@@ -0,0 +1,3 @@
1
+ export declare const NEW_LINE = "\n";
2
+ export declare const TAB = " ";
3
+ export declare const SPACE = " ";
@@ -1,7 +1,9 @@
1
1
  /**
2
2
  * <details {open}>
3
3
  * <summary>{title}</summary>
4
+ *
4
5
  * {content}
6
+ *
5
7
  * <details>
6
8
  */
7
9
  export declare function details(title: string, content: string, cfg?: {
@@ -0,0 +1,3 @@
1
+ export declare function bold(text: string): string;
2
+ export declare function italic(text: string): string;
3
+ export declare function code(text: string): string;
@@ -0,0 +1 @@
1
+ export declare function link(href: string, text?: string): string;
@@ -0,0 +1,2 @@
1
+ import { Table } from '@code-pushup/models';
2
+ export declare function table(tableData: Table): string;
@@ -0,0 +1,44 @@
1
+ import { details } from './html/details';
2
+ import { bold as boldHtml, code as codeHtml, italic as italicHtml } from './html/font-style';
3
+ import { link as linkHtml } from './html/link';
4
+ import { table as tableHtml } from './html/table';
5
+ import { bold as boldMd, code as codeMd, italic as italicMd, strikeThrough as strikeThroughMd } from './md/font-style';
6
+ import { h, h1, h2, h3, h4, h5, h6, headline } from './md/headline';
7
+ import { image } from './md/image';
8
+ import { link as linkMd } from './md/link';
9
+ import { indentation, li } from './md/list';
10
+ import { paragraphs } from './md/paragraphs';
11
+ import { lines, section } from './md/section';
12
+ import { table as tableMd } from './md/table';
13
+ export { NEW_LINE, SPACE, TAB } from './constants';
14
+ export { Hierarchy } from './types';
15
+ export declare const md: {
16
+ bold: typeof boldMd;
17
+ italic: typeof italicMd;
18
+ strikeThrough: typeof strikeThroughMd;
19
+ code: typeof codeMd;
20
+ link: typeof linkMd;
21
+ image: typeof image;
22
+ headline: typeof headline;
23
+ h: typeof h;
24
+ h1: typeof h1;
25
+ h2: typeof h2;
26
+ h3: typeof h3;
27
+ h4: typeof h4;
28
+ h5: typeof h5;
29
+ h6: typeof h6;
30
+ indentation: typeof indentation;
31
+ lines: typeof lines;
32
+ li: typeof li;
33
+ section: typeof section;
34
+ paragraphs: typeof paragraphs;
35
+ table: typeof tableMd;
36
+ };
37
+ export declare const html: {
38
+ bold: typeof boldHtml;
39
+ italic: typeof italicHtml;
40
+ code: typeof codeHtml;
41
+ link: typeof linkHtml;
42
+ details: typeof details;
43
+ table: typeof tableHtml;
44
+ };
@@ -0,0 +1,4 @@
1
+ export declare function bold(text: string): string;
2
+ export declare function italic(text: string): string;
3
+ export declare function strikeThrough(text: string): string;
4
+ export declare function code(text: string): string;
@@ -1,4 +1,4 @@
1
- export type Hierarchy = 1 | 2 | 3 | 4 | 5 | 6;
1
+ import { Hierarchy } from '../types';
2
2
  /**
3
3
  * \# {text} // hierarchy set to 1
4
4
  *
@@ -0,0 +1 @@
1
+ export declare function link(href: string, text?: string): string;
@@ -3,3 +3,5 @@ export type Order = 'unordered' | 'checkbox';
3
3
  * - {text}
4
4
  */
5
5
  export declare function li(text: string, order?: Order): string;
6
+ export type Indentations = 1 | 2 | 3;
7
+ export declare function indentation(text: string, level?: Indentations): string;
@@ -0,0 +1,2 @@
1
+ export declare function section(...contents: (string | undefined | boolean)[]): string;
2
+ export declare function lines(...contents: (string | undefined | boolean)[]): string;
@@ -0,0 +1,9 @@
1
+ import { Table } from '@code-pushup/models';
2
+ /**
3
+ * | Table Header 1 | Table Header 2 |
4
+ * | :-------------- | -------------: |
5
+ * | String 1 | 1 |
6
+ * | String 1 | 2 |
7
+ * | String 1 | 3 |
8
+ */
9
+ export declare function table(data: Table): string;
@@ -0,0 +1,6 @@
1
+ import { Table, TableAlignment, TableColumnObject, TableColumnPrimitive } from '@code-pushup/models';
2
+ export declare function rowToStringArray({ rows, columns }: Table): string[][];
3
+ export declare function columnsToStringArray({ rows, columns }: Table): string[];
4
+ export declare function getColumnAlignmentForKeyAndIndex(targetKey: string, targetIdx: number, columns?: TableColumnObject[]): TableAlignment;
5
+ export declare function getColumnAlignmentForIndex(targetIdx: number, columns?: TableColumnPrimitive[]): TableAlignment;
6
+ export declare function getColumnAlignments({ rows, columns, }: Table): TableAlignment[];
@@ -0,0 +1 @@
1
+ export type Hierarchy = 1 | 2 | 3 | 4 | 5 | 6;
@@ -0,0 +1,3 @@
1
+ export type ExcludeNullFromPropertyTypes<T> = {
2
+ [P in keyof T]: Exclude<T[P], null>;
3
+ };
@@ -1,16 +0,0 @@
1
- declare const stylesMap: {
2
- readonly i: "_";
3
- readonly b: "**";
4
- readonly s: "~";
5
- readonly c: "`";
6
- };
7
- export type FontStyle = keyof typeof stylesMap;
8
- /**
9
- * **{text}** // default is bold
10
- *
11
- * _{text}_ // italic - styles set to `['i']`
12
- *
13
- * ~**{text}**~ // bold & stroke-through - styles set to `['b','s']`
14
- */
15
- export declare function style(text: string, styles?: FontStyle[]): string;
16
- export {};
@@ -1,8 +0,0 @@
1
- export * from './details';
2
- export * from './font-style';
3
- export * from './headline';
4
- export * from './image';
5
- export * from './link';
6
- export * from './list';
7
- export * from './paragraphs';
8
- export * from './table';
@@ -1,6 +0,0 @@
1
- /**
2
- * \# {text} // hierarchy set to 1
3
- *
4
- * \## {text} // hierarchy set to 2
5
- */
6
- export declare function link(href: string, text?: string): string;
@@ -1,10 +0,0 @@
1
- export type Alignment = 'l' | 'c' | 'r';
2
- /**
3
- * | Table Header 1 | Table Header 2 |
4
- * | --------------- | -------------- |
5
- * | String 1 | 1 |
6
- * | String 1 | 2 |
7
- * | String 1 | 3 |
8
- */
9
- export declare function tableMd(data: (string | number)[][], align?: Alignment[]): string;
10
- export declare function tableHtml(data: (string | number)[][]): string;
File without changes