@code-pushup/utils 0.80.2 → 0.81.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-pushup/utils",
3
- "version": "0.80.2",
3
+ "version": "0.81.0",
4
4
  "description": "Low-level utilities (helper functions, etc.) used by Code PushUp CLI",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/code-pushup/cli/tree/main/packages/utils#readme",
@@ -27,7 +27,7 @@
27
27
  "node": ">=17.0.0"
28
28
  },
29
29
  "dependencies": {
30
- "@code-pushup/models": "0.80.2",
30
+ "@code-pushup/models": "0.81.0",
31
31
  "@isaacs/cliui": "^8.0.2",
32
32
  "@poppinss/cliui": "^6.4.0",
33
33
  "ansis": "^3.3.0",
@@ -37,7 +37,8 @@
37
37
  "multi-progress-bars": "^5.0.3",
38
38
  "semver": "^7.6.0",
39
39
  "simple-git": "^3.20.0",
40
- "zod": "^4.0.5"
40
+ "zod": "^4.0.5",
41
+ "ora": "^9.0.0"
41
42
  },
42
43
  "files": [
43
44
  "src",
package/src/index.d.ts CHANGED
@@ -2,22 +2,24 @@ export { exists } from '@code-pushup/models';
2
2
  export { camelCaseToKebabCase, capitalize, kebabCaseToCamelCase, lowercase, toSentenceCase, toTitleCase, uppercase, } from './lib/case-conversions.js';
3
3
  export { filesCoverageToTree, type FileCoverage } from './lib/coverage-tree.js';
4
4
  export { createRunnerFiles } from './lib/create-runner-files.js';
5
+ export { dateToUnixTimestamp } from './lib/dates.js';
5
6
  export { comparePairs, matchArrayItemsByKey, type Diff } from './lib/diff.js';
6
7
  export { coerceBooleanValue, isCI, isEnvVarEnabled, isVerbose, runnerArgsFromEnv, runnerArgsToEnv, } from './lib/env.js';
7
8
  export { stringifyError } from './lib/errors.js';
8
9
  export { executeProcess, ProcessError, type ProcessConfig, type ProcessObserver, type ProcessResult, } from './lib/execute-process.js';
9
10
  export { crawlFileSystem, createReportPath, directoryExists, ensureDirectoryExists, fileExists, filePathToCliArg, findLineNumberInText, findNearestFile, importModule, logMultipleFileResults, pluginWorkDir, projectToFilename, readJsonFile, readTextFile, removeDirectoryIfExists, type CrawlFileSystemOptions, type FileResult, type MultipleFileResults, } from './lib/file-system.js';
10
11
  export { filterItemRefsBy } from './lib/filter.js';
11
- export { formatBytes, formatDuration, pluralize, pluralizeToken, slugify, truncateDescription, truncateIssueMessage, truncateText, truncateTitle, } from './lib/formatting.js';
12
+ export { formatBytes, formatDuration, indentLines, pluralize, pluralizeToken, roundDecimals, slugify, transformLines, truncateDescription, truncateIssueMessage, truncateText, truncateTitle, } from './lib/formatting.js';
12
13
  export { getCurrentBranchOrTag, getHashes, getHashFromTag, getLatestCommit, getSemverTags, type LogResult, } from './lib/git/git.commits-and-tags.js';
13
14
  export { formatGitPath, getGitRoot, guardAgainstLocalChanges, safeCheckout, toGitPath, } from './lib/git/git.js';
14
15
  export { hasNoNullableProps, isPromiseFulfilledResult, isPromiseRejectedResult, } from './lib/guards.js';
15
16
  export { interpolate } from './lib/interpolate.js';
16
17
  export { logMultipleResults } from './lib/log-results.js';
18
+ export { Logger, logger } from './lib/logger.js';
17
19
  export { link, ui, type CliUi, type Column } from './lib/logging.js';
18
20
  export { mergeConfigs } from './lib/merge-configs.js';
19
21
  export { getProgressBar, type ProgressBar } from './lib/progress.js';
20
- export { asyncSequential, groupByStatus } from './lib/promises.js';
22
+ export { asyncSequential, groupByStatus, settlePromise, } from './lib/promises.js';
21
23
  export { generateRandomId } from './lib/random.js';
22
24
  export { CODE_PUSHUP_DOMAIN, CODE_PUSHUP_UNICODE_LOGO, FOOTER_PREFIX, README_LINK, TERMINAL_WIDTH, } from './lib/reports/constants.js';
23
25
  export { listAuditsFromAllPlugins, listGroupsFromAllPlugins, } from './lib/reports/flatten-plugins.js';
package/src/index.js CHANGED
@@ -2,22 +2,24 @@ export { exists } from '@code-pushup/models';
2
2
  export { camelCaseToKebabCase, capitalize, kebabCaseToCamelCase, lowercase, toSentenceCase, toTitleCase, uppercase, } from './lib/case-conversions.js';
3
3
  export { filesCoverageToTree } from './lib/coverage-tree.js';
4
4
  export { createRunnerFiles } from './lib/create-runner-files.js';
5
+ export { dateToUnixTimestamp } from './lib/dates.js';
5
6
  export { comparePairs, matchArrayItemsByKey } from './lib/diff.js';
6
7
  export { coerceBooleanValue, isCI, isEnvVarEnabled, isVerbose, runnerArgsFromEnv, runnerArgsToEnv, } from './lib/env.js';
7
8
  export { stringifyError } from './lib/errors.js';
8
9
  export { executeProcess, ProcessError, } from './lib/execute-process.js';
9
10
  export { crawlFileSystem, createReportPath, directoryExists, ensureDirectoryExists, fileExists, filePathToCliArg, findLineNumberInText, findNearestFile, importModule, logMultipleFileResults, pluginWorkDir, projectToFilename, readJsonFile, readTextFile, removeDirectoryIfExists, } from './lib/file-system.js';
10
11
  export { filterItemRefsBy } from './lib/filter.js';
11
- export { formatBytes, formatDuration, pluralize, pluralizeToken, slugify, truncateDescription, truncateIssueMessage, truncateText, truncateTitle, } from './lib/formatting.js';
12
+ export { formatBytes, formatDuration, indentLines, pluralize, pluralizeToken, roundDecimals, slugify, transformLines, truncateDescription, truncateIssueMessage, truncateText, truncateTitle, } from './lib/formatting.js';
12
13
  export { getCurrentBranchOrTag, getHashes, getHashFromTag, getLatestCommit, getSemverTags, } from './lib/git/git.commits-and-tags.js';
13
14
  export { formatGitPath, getGitRoot, guardAgainstLocalChanges, safeCheckout, toGitPath, } from './lib/git/git.js';
14
15
  export { hasNoNullableProps, isPromiseFulfilledResult, isPromiseRejectedResult, } from './lib/guards.js';
15
16
  export { interpolate } from './lib/interpolate.js';
16
17
  export { logMultipleResults } from './lib/log-results.js';
18
+ export { Logger, logger } from './lib/logger.js';
17
19
  export { link, ui } from './lib/logging.js';
18
20
  export { mergeConfigs } from './lib/merge-configs.js';
19
21
  export { getProgressBar } from './lib/progress.js';
20
- export { asyncSequential, groupByStatus } from './lib/promises.js';
22
+ export { asyncSequential, groupByStatus, settlePromise, } from './lib/promises.js';
21
23
  export { generateRandomId } from './lib/random.js';
22
24
  export { CODE_PUSHUP_DOMAIN, CODE_PUSHUP_UNICODE_LOGO, FOOTER_PREFIX, README_LINK, TERMINAL_WIDTH, } from './lib/reports/constants.js';
23
25
  export { listAuditsFromAllPlugins, listGroupsFromAllPlugins, } from './lib/reports/flatten-plugins.js';
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EACL,oBAAoB,EACpB,UAAU,EACV,oBAAoB,EACpB,SAAS,EACT,cAAc,EACd,WAAW,EACX,SAAS,GACV,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,mBAAmB,EAAqB,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAa,MAAM,eAAe,CAAC;AAC9E,OAAO,EACL,kBAAkB,EAClB,IAAI,EACJ,eAAe,EACf,SAAS,EACT,iBAAiB,EACjB,eAAe,GAChB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EACL,cAAc,EACd,YAAY,GAIb,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,qBAAqB,EACrB,UAAU,EACV,gBAAgB,EAChB,oBAAoB,EACpB,eAAe,EACf,YAAY,EACZ,sBAAsB,EACtB,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,uBAAuB,GAIxB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EACL,WAAW,EACX,cAAc,EACd,SAAS,EACT,cAAc,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AC;AACpC,OAAO,EACL,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EACL,qBAAqB,EACrB,gCAAgC,GACjC,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAMtD,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACzE,cAAc,6BAA6B,CAAC;AAC5C,OAAO,EACL,gBAAgB,EAChB,QAAQ,EACR,QAAQ,EACR,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,YAAY,EACZ,4BAA4B,EAC5B,OAAO,EACP,WAAW,EACX,iBAAiB,EACjB,SAAS,EACT,cAAc,EACd,UAAU,GAEX,MAAM,oBAAoB,CAAC;AAW5B,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function dateToUnixTimestamp(date: Date): number;
@@ -0,0 +1,4 @@
1
+ export function dateToUnixTimestamp(date) {
2
+ return Math.round(date.getTime() / 1000);
3
+ }
4
+ //# sourceMappingURL=dates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dates.js","sourceRoot":"","sources":["../../../src/lib/dates.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,mBAAmB,CAAC,IAAU;IAC5C,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;AAC3C,CAAC"}
@@ -1,8 +1,9 @@
1
+ export declare function roundDecimals(value: number, maxDecimals: number): number;
1
2
  export declare function slugify(text: string): string;
2
3
  export declare function pluralize(text: string, amount?: number): string;
3
4
  export declare function formatBytes(bytes: number, decimals?: number): string;
4
5
  export declare function pluralizeToken(token: string, times: number): string;
5
- export declare function formatDuration(duration: number, granularity?: number): string;
6
+ export declare function formatDuration(ms: number, maxDecimals?: number): string;
6
7
  export declare function formatDate(date: Date): string;
7
8
  export declare function truncateText(text: string, options: number | {
8
9
  maxChars: number;
@@ -12,3 +13,5 @@ export declare function truncateText(text: string, options: number | {
12
13
  export declare function truncateTitle(text: string): string;
13
14
  export declare function truncateDescription(text: string): string;
14
15
  export declare function truncateIssueMessage(text: string): string;
16
+ export declare function transformLines(text: string, fn: (line: string) => string): string;
17
+ export declare function indentLines(text: string, identation: number): string;
@@ -1,4 +1,8 @@
1
1
  import { MAX_DESCRIPTION_LENGTH, MAX_ISSUE_MESSAGE_LENGTH, MAX_TITLE_LENGTH, } from '@code-pushup/models';
2
+ export function roundDecimals(value, maxDecimals) {
3
+ const multiplier = Math.pow(10, maxDecimals);
4
+ return Math.round(value * multiplier) / multiplier;
5
+ }
2
6
  export function slugify(text) {
3
7
  return text
4
8
  .trim()
@@ -28,16 +32,16 @@ export function formatBytes(bytes, decimals = 2) {
28
32
  const dm = Math.max(decimals, 0);
29
33
  const sizes = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
30
34
  const i = Math.floor(Math.log(positiveBytes) / Math.log(k));
31
- return `${Number.parseFloat((positiveBytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
35
+ return `${roundDecimals(positiveBytes / Math.pow(k, i), dm)} ${sizes[i]}`;
32
36
  }
33
37
  export function pluralizeToken(token, times) {
34
38
  return `${times} ${Math.abs(times) === 1 ? token : pluralize(token)}`;
35
39
  }
36
- export function formatDuration(duration, granularity = 0) {
37
- if (duration < 1000) {
38
- return `${granularity ? duration.toFixed(granularity) : duration} ms`;
40
+ export function formatDuration(ms, maxDecimals = 2) {
41
+ if (ms < 1000) {
42
+ return `${Math.round(ms)} ms`;
39
43
  }
40
- return `${(duration / 1000).toFixed(2)} s`;
44
+ return `${roundDecimals(ms / 1000, maxDecimals)} s`;
41
45
  }
42
46
  export function formatDate(date) {
43
47
  const locale = 'en-US'; // fixed locale to ensure consistency across local defaults execution
@@ -80,4 +84,10 @@ export function truncateDescription(text) {
80
84
  export function truncateIssueMessage(text) {
81
85
  return truncateText(text, MAX_ISSUE_MESSAGE_LENGTH);
82
86
  }
87
+ export function transformLines(text, fn) {
88
+ return text.split(/\r?\n/).map(fn).join('\n');
89
+ }
90
+ export function indentLines(text, identation) {
91
+ return transformLines(text, line => `${' '.repeat(identation)}${line}`);
92
+ }
83
93
  //# sourceMappingURL=formatting.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"formatting.js","sourceRoot":"","sources":["../../../src/lib/formatting.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EACxB,gBAAgB,GACjB,MAAM,qBAAqB,CAAC;AAE7B,MAAM,UAAU,OAAO,CAAC,IAAY;IAClC,OAAO,IAAI;SACR,IAAI,EAAE;SACN,WAAW,EAAE;SACb,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC;SACvB,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,MAAe;IACrD,IAAI,MAAM,IAAI,IAAI,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACvB,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;IAC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OAAO,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC;AAC1E,CAAC"}
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Rich logging implementation for Code PushUp CLI, plugins, etc.
3
+ *
4
+ * Use {@link logger} singleton.
5
+ */
6
+ export declare class Logger {
7
+ #private;
8
+ /**
9
+ * Logs an error to the console (red).
10
+ *
11
+ * Automatically adapts to logger state if called within {@link task}, {@link group}, etc.
12
+ *
13
+ * @example
14
+ * logger.error('Config file is invalid');
15
+ *
16
+ * @param message Error text
17
+ */
18
+ error(message: string): void;
19
+ /**
20
+ * Logs a warning to the console (yellow).
21
+ *
22
+ * Automatically adapts to logger state if called within {@link task}, {@link group}, etc.
23
+ *
24
+ * @example
25
+ * logger.warn('Skipping invalid audits');
26
+ *
27
+ * @param message Warning text
28
+ */
29
+ warn(message: string): void;
30
+ /**
31
+ * Logs an informational message to the console (unstyled).
32
+ *
33
+ * Automatically adapts to logger state if called within {@link task}, {@link group}, etc.
34
+ *
35
+ * @example
36
+ * logger.info('Code PushUp CLI v0.80.2');
37
+ *
38
+ * @param message Info text
39
+ */
40
+ info(message: string): void;
41
+ /**
42
+ * Logs a debug message to the console (gray), but **only if verbose** flag is set (see {@link isVerbose}).
43
+ *
44
+ * Automatically adapts to logger state if called within {@link task}, {@link group}, etc.
45
+ *
46
+ * @example
47
+ * logger.debug('Running ESLint version 9.16.0');
48
+ *
49
+ * @param message Debug text
50
+ */
51
+ debug(message: string): void;
52
+ /**
53
+ * Print a blank line to the console, used to separate logs for readability.
54
+ *
55
+ * Automatically adapts to logger state if called within {@link task}, {@link group}, etc.
56
+ *
57
+ * @example
58
+ * logger.newline();
59
+ */
60
+ newline(): void;
61
+ /**
62
+ * Is verbose flag set?
63
+ *
64
+ * Verbosity is configured by {@link setVerbose} call or `CP_VERBOSE` environment variable.
65
+ *
66
+ * @example
67
+ * if (logger.isVerbose()) {
68
+ * // ...
69
+ * }
70
+ */
71
+ isVerbose(): boolean;
72
+ /**
73
+ * Sets verbose flag for this logger.
74
+ *
75
+ * Also sets the `CP_VERBOSE` environment variable.
76
+ * This means any future {@link Logger} instantiations (including child processes) will use the same verbosity level.
77
+ *
78
+ * @example
79
+ * logger.setVerbose(process.argv.includes('--verbose'));
80
+ *
81
+ * @param isVerbose Verbosity level
82
+ */
83
+ setVerbose(isVerbose: boolean): void;
84
+ /**
85
+ * Animates asynchronous work using a spinner.
86
+ *
87
+ * Basic logs are supported within the worker function, they will be printed with indentation once the spinner completes.
88
+ *
89
+ * In CI environments, the spinner animation is disabled, and inner logs are printed immediately.
90
+ *
91
+ * Spinners may be nested within a {@link group} call, in which case line symbols are used instead of dots, as well the group's color.
92
+ *
93
+ * The task's duration is included in the logged output as a suffix.
94
+ *
95
+ * Listens for `SIGINT` event in order to cancel and restore spinner before exiting.
96
+ *
97
+ * Concurrent or nested spinners are not supported, nor can groups be nested in spinners.
98
+ *
99
+ * @example
100
+ * await logger.task('Uploading report to portal', async () => {
101
+ * // ...
102
+ * return 'Uploaded report to portal';
103
+ * });
104
+ *
105
+ * @param title Display text used as pending message.
106
+ * @param worker Asynchronous implementation. Returned promise determines spinner status and final message. Support for inner logs has some limitations (described above).
107
+ */
108
+ task(title: string, worker: () => Promise<string>): Promise<void>;
109
+ /**
110
+ * Similar to {@link task}, but spinner texts are formatted as shell commands.
111
+ *
112
+ * A `$`-prefix is added. Its color indicates the status (blue=pending, green=success, red=failure).
113
+ *
114
+ * @example
115
+ * await logger.command('npx eslint . --format=json', async () => {
116
+ * // ...
117
+ * });
118
+ *
119
+ * @param bin Command string with arguments.
120
+ * @param worker Asynchronous execution of the command (not implemented by the logger).
121
+ */
122
+ command(bin: string, worker: () => Promise<void>): Promise<void>;
123
+ /**
124
+ * Groups many logs into a visually distinct section.
125
+ *
126
+ * Groups alternate prefix colors between cyan and magenta.
127
+ *
128
+ * The group's total duration is included in the logged output.
129
+ *
130
+ * Nested groups are not supported.
131
+ *
132
+ * @example
133
+ * await logger.group('Running plugin "ESLint"', async () => {
134
+ * logger.debug('ESLint version is 9.16.0');
135
+ * await logger.command('npx eslint . --format=json', () => {
136
+ * // ...
137
+ * })
138
+ * logger.info('Found 42 lint errors.');
139
+ * return 'Completed "ESLint" plugin execution';
140
+ * });
141
+ *
142
+ * @param title Display title for the group.
143
+ * @param worker Asynchronous implementation. Returned promise determines group status and ending message. Inner logs are attached to the group.
144
+ */
145
+ group(title: string, worker: () => Promise<string>): Promise<void>;
146
+ }
147
+ /**
148
+ * Shared {@link Logger} instance.
149
+ *
150
+ * @example
151
+ * import { logger } from '@code-pushup/utils';
152
+ *
153
+ * logger.info('Made with ❤️ by Code PushUp');
154
+ */
155
+ export declare const logger: Logger;
@@ -0,0 +1,408 @@
1
+ import ansis, {} from 'ansis';
2
+ import os from 'node:os';
3
+ import ora, {} from 'ora';
4
+ import { dateToUnixTimestamp } from './dates.js';
5
+ import { isEnvVarEnabled } from './env.js';
6
+ import { formatDuration, indentLines, transformLines } from './formatting.js';
7
+ import { settlePromise } from './promises.js';
8
+ const GROUP_COLOR_ENV_VAR_NAME = 'CP_LOGGER_GROUP_COLOR';
9
+ /**
10
+ * Rich logging implementation for Code PushUp CLI, plugins, etc.
11
+ *
12
+ * Use {@link logger} singleton.
13
+ */
14
+ export class Logger {
15
+ #isVerbose = isEnvVarEnabled('CP_VERBOSE');
16
+ #isCI = isEnvVarEnabled('CI');
17
+ #ciPlatform = process.env['GITHUB_ACTIONS'] === 'true'
18
+ ? 'GitHub Actions'
19
+ : process.env['GITLAB_CI'] === 'true'
20
+ ? 'GitLab CI/CD'
21
+ : undefined;
22
+ #groupColor = process.env[GROUP_COLOR_ENV_VAR_NAME] === 'cyan' ||
23
+ process.env[GROUP_COLOR_ENV_VAR_NAME] === 'magenta'
24
+ ? process.env[GROUP_COLOR_ENV_VAR_NAME]
25
+ : undefined;
26
+ #groupsCount = 0;
27
+ #activeSpinner;
28
+ #activeSpinnerLogs = [];
29
+ #endsWithBlankLine = false;
30
+ #groupSymbols = {
31
+ start: '❯',
32
+ middle: '│',
33
+ end: '└',
34
+ };
35
+ #sigintListener = () => {
36
+ if (this.#activeSpinner != null) {
37
+ const text = `${this.#activeSpinner.text} ${ansis.red.bold('[SIGINT]')}`;
38
+ if (this.#groupColor) {
39
+ this.#activeSpinner.stopAndPersist({
40
+ text,
41
+ symbol: this.#colorize(this.#groupSymbols.end, this.#groupColor),
42
+ });
43
+ this.#setGroupColor(undefined);
44
+ }
45
+ else {
46
+ this.#activeSpinner.fail(text);
47
+ }
48
+ this.#activeSpinner = undefined;
49
+ }
50
+ this.newline();
51
+ this.error(ansis.bold('Cancelled by SIGINT'));
52
+ process.exit(os.platform() === 'win32' ? 2 : 130);
53
+ };
54
+ /**
55
+ * Logs an error to the console (red).
56
+ *
57
+ * Automatically adapts to logger state if called within {@link task}, {@link group}, etc.
58
+ *
59
+ * @example
60
+ * logger.error('Config file is invalid');
61
+ *
62
+ * @param message Error text
63
+ */
64
+ error(message) {
65
+ this.#log(message, 'red');
66
+ }
67
+ /**
68
+ * Logs a warning to the console (yellow).
69
+ *
70
+ * Automatically adapts to logger state if called within {@link task}, {@link group}, etc.
71
+ *
72
+ * @example
73
+ * logger.warn('Skipping invalid audits');
74
+ *
75
+ * @param message Warning text
76
+ */
77
+ warn(message) {
78
+ this.#log(message, 'yellow');
79
+ }
80
+ /**
81
+ * Logs an informational message to the console (unstyled).
82
+ *
83
+ * Automatically adapts to logger state if called within {@link task}, {@link group}, etc.
84
+ *
85
+ * @example
86
+ * logger.info('Code PushUp CLI v0.80.2');
87
+ *
88
+ * @param message Info text
89
+ */
90
+ info(message) {
91
+ this.#log(message);
92
+ }
93
+ /**
94
+ * Logs a debug message to the console (gray), but **only if verbose** flag is set (see {@link isVerbose}).
95
+ *
96
+ * Automatically adapts to logger state if called within {@link task}, {@link group}, etc.
97
+ *
98
+ * @example
99
+ * logger.debug('Running ESLint version 9.16.0');
100
+ *
101
+ * @param message Debug text
102
+ */
103
+ debug(message) {
104
+ if (this.#isVerbose) {
105
+ this.#log(message, 'gray');
106
+ }
107
+ }
108
+ /**
109
+ * Print a blank line to the console, used to separate logs for readability.
110
+ *
111
+ * Automatically adapts to logger state if called within {@link task}, {@link group}, etc.
112
+ *
113
+ * @example
114
+ * logger.newline();
115
+ */
116
+ newline() {
117
+ this.#log('');
118
+ }
119
+ /**
120
+ * Is verbose flag set?
121
+ *
122
+ * Verbosity is configured by {@link setVerbose} call or `CP_VERBOSE` environment variable.
123
+ *
124
+ * @example
125
+ * if (logger.isVerbose()) {
126
+ * // ...
127
+ * }
128
+ */
129
+ isVerbose() {
130
+ return this.#isVerbose;
131
+ }
132
+ /**
133
+ * Sets verbose flag for this logger.
134
+ *
135
+ * Also sets the `CP_VERBOSE` environment variable.
136
+ * This means any future {@link Logger} instantiations (including child processes) will use the same verbosity level.
137
+ *
138
+ * @example
139
+ * logger.setVerbose(process.argv.includes('--verbose'));
140
+ *
141
+ * @param isVerbose Verbosity level
142
+ */
143
+ setVerbose(isVerbose) {
144
+ process.env['CP_VERBOSE'] = `${isVerbose}`;
145
+ this.#isVerbose = isVerbose;
146
+ }
147
+ /**
148
+ * Animates asynchronous work using a spinner.
149
+ *
150
+ * Basic logs are supported within the worker function, they will be printed with indentation once the spinner completes.
151
+ *
152
+ * In CI environments, the spinner animation is disabled, and inner logs are printed immediately.
153
+ *
154
+ * Spinners may be nested within a {@link group} call, in which case line symbols are used instead of dots, as well the group's color.
155
+ *
156
+ * The task's duration is included in the logged output as a suffix.
157
+ *
158
+ * Listens for `SIGINT` event in order to cancel and restore spinner before exiting.
159
+ *
160
+ * Concurrent or nested spinners are not supported, nor can groups be nested in spinners.
161
+ *
162
+ * @example
163
+ * await logger.task('Uploading report to portal', async () => {
164
+ * // ...
165
+ * return 'Uploaded report to portal';
166
+ * });
167
+ *
168
+ * @param title Display text used as pending message.
169
+ * @param worker Asynchronous implementation. Returned promise determines spinner status and final message. Support for inner logs has some limitations (described above).
170
+ */
171
+ task(title, worker) {
172
+ return this.#spinner(worker, {
173
+ pending: title,
174
+ success: value => value,
175
+ failure: error => `${title} → ${ansis.red(`${error}`)}`,
176
+ });
177
+ }
178
+ /**
179
+ * Similar to {@link task}, but spinner texts are formatted as shell commands.
180
+ *
181
+ * A `$`-prefix is added. Its color indicates the status (blue=pending, green=success, red=failure).
182
+ *
183
+ * @example
184
+ * await logger.command('npx eslint . --format=json', async () => {
185
+ * // ...
186
+ * });
187
+ *
188
+ * @param bin Command string with arguments.
189
+ * @param worker Asynchronous execution of the command (not implemented by the logger).
190
+ */
191
+ command(bin, worker) {
192
+ return this.#spinner(worker, {
193
+ pending: `${ansis.blue('$')} ${bin}`,
194
+ success: () => `${ansis.green('$')} ${bin}`,
195
+ failure: () => `${ansis.red('$')} ${bin}`,
196
+ });
197
+ }
198
+ /**
199
+ * Groups many logs into a visually distinct section.
200
+ *
201
+ * Groups alternate prefix colors between cyan and magenta.
202
+ *
203
+ * The group's total duration is included in the logged output.
204
+ *
205
+ * Nested groups are not supported.
206
+ *
207
+ * @example
208
+ * await logger.group('Running plugin "ESLint"', async () => {
209
+ * logger.debug('ESLint version is 9.16.0');
210
+ * await logger.command('npx eslint . --format=json', () => {
211
+ * // ...
212
+ * })
213
+ * logger.info('Found 42 lint errors.');
214
+ * return 'Completed "ESLint" plugin execution';
215
+ * });
216
+ *
217
+ * @param title Display title for the group.
218
+ * @param worker Asynchronous implementation. Returned promise determines group status and ending message. Inner logs are attached to the group.
219
+ */
220
+ async group(title, worker) {
221
+ if (this.#groupColor) {
222
+ throw new Error('Internal Logger error - nested groups are not supported');
223
+ }
224
+ if (this.#activeSpinner) {
225
+ throw new Error('Internal Logger error - creating group in active spinner is not supported');
226
+ }
227
+ if (!this.#endsWithBlankLine) {
228
+ this.newline();
229
+ }
230
+ this.#setGroupColor(this.#groupsCount % 2 === 0 ? 'cyan' : 'magenta');
231
+ this.#groupsCount++;
232
+ const groupMarkers = this.#createGroupMarkers();
233
+ console.log(groupMarkers.start(title));
234
+ const start = performance.now();
235
+ const result = await settlePromise(worker());
236
+ const end = performance.now();
237
+ if (result.status === 'fulfilled') {
238
+ console.log([
239
+ this.#colorize(this.#groupSymbols.end, this.#groupColor),
240
+ this.#colorize(result.value, 'green'),
241
+ this.#formatDurationSuffix({ start, end }),
242
+ ].join(' '));
243
+ }
244
+ else {
245
+ console.log([
246
+ this.#colorize(this.#groupSymbols.end, this.#groupColor),
247
+ this.#colorize(`${result.reason}`, 'red'),
248
+ ].join(' '));
249
+ }
250
+ const endMarker = groupMarkers.end();
251
+ if (endMarker) {
252
+ console.log(endMarker);
253
+ }
254
+ this.#setGroupColor(undefined);
255
+ this.newline();
256
+ if (result.status === 'rejected') {
257
+ throw result.reason;
258
+ }
259
+ }
260
+ #createGroupMarkers() {
261
+ switch (this.#ciPlatform) {
262
+ case 'GitHub Actions':
263
+ // https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-commands#grouping-log-lines
264
+ return {
265
+ start: title => `::group::${this.#formatGroupTitle(title, { prefix: false })}`,
266
+ end: () => '::endgroup::',
267
+ };
268
+ case 'GitLab CI/CD':
269
+ // https://docs.gitlab.com/ci/jobs/job_logs/#custom-collapsible-sections
270
+ const ansiEscCode = '\x1b[0K'; // '\e' ESC character only works for `echo -e`, Node console must use '\x1b'
271
+ const id = Math.random().toString(16).slice(2);
272
+ const sectionId = `code_pushup_logs_group_${id}`;
273
+ return {
274
+ start: title => {
275
+ const sectionHeader = this.#formatGroupTitle(title, {
276
+ prefix: true,
277
+ });
278
+ const options = this.#isVerbose ? '' : '[collapsed=true]';
279
+ // return `${ansiEscCode}section_start:${dateToUnixTimestamp(new Date())}:${sectionId}${options}${ansiEscCode}${sectionHeader}`;
280
+ return `${ansiEscCode}section_start:${dateToUnixTimestamp(new Date())}:${sectionId}${options}\r${ansiEscCode}${sectionHeader}`;
281
+ },
282
+ end: () =>
283
+ // `${ansiEscCode}section_end:${dateToUnixTimestamp(new Date())}:${sectionId}${ansiEscCode}`,
284
+ `${ansiEscCode}section_end:${dateToUnixTimestamp(new Date())}:${sectionId}\r${ansiEscCode}`,
285
+ };
286
+ case undefined:
287
+ return {
288
+ start: title => this.#formatGroupTitle(title, { prefix: true }),
289
+ end: () => '',
290
+ };
291
+ }
292
+ }
293
+ #formatGroupTitle(title, symbols) {
294
+ const text = symbols.prefix
295
+ ? `${this.#groupSymbols.start} ${title}`
296
+ : title;
297
+ return ansis.bold(this.#colorize(text, this.#groupColor));
298
+ }
299
+ #setGroupColor(groupColor) {
300
+ this.#groupColor = groupColor;
301
+ if (groupColor) {
302
+ process.env[GROUP_COLOR_ENV_VAR_NAME] = groupColor;
303
+ }
304
+ else {
305
+ delete process.env[GROUP_COLOR_ENV_VAR_NAME];
306
+ }
307
+ }
308
+ async #spinner(worker, messages) {
309
+ if (this.#activeSpinner) {
310
+ throw new Error('Internal Logger error - concurrent spinners are not supported');
311
+ }
312
+ process.removeListener('SIGINT', this.#sigintListener);
313
+ process.addListener('SIGINT', this.#sigintListener);
314
+ if (this.#groupColor) {
315
+ this.#activeSpinner = ora({
316
+ text: messages.pending,
317
+ spinner: 'line',
318
+ color: this.#groupColor,
319
+ });
320
+ if (this.#isCI) {
321
+ console.log(this.#format(messages.pending, undefined));
322
+ }
323
+ else {
324
+ this.#activeSpinner.start();
325
+ }
326
+ }
327
+ else {
328
+ this.#activeSpinner = ora(messages.pending);
329
+ this.#activeSpinner.start();
330
+ }
331
+ this.#endsWithBlankLine = false;
332
+ const start = performance.now();
333
+ const result = await settlePromise(worker());
334
+ const end = performance.now();
335
+ const text = result.status === 'fulfilled'
336
+ ? [
337
+ messages.success(result.value),
338
+ this.#formatDurationSuffix({ start, end }),
339
+ ].join(' ')
340
+ : messages.failure(result.reason);
341
+ if (this.#activeSpinner) {
342
+ if (this.#groupColor) {
343
+ this.#activeSpinner.stopAndPersist({
344
+ text,
345
+ symbol: this.#colorize(this.#groupSymbols.middle, this.#groupColor),
346
+ });
347
+ }
348
+ else {
349
+ if (result.status === 'fulfilled') {
350
+ this.#activeSpinner.succeed(text);
351
+ }
352
+ else {
353
+ this.#activeSpinner.fail(text);
354
+ }
355
+ }
356
+ this.#endsWithBlankLine = false;
357
+ }
358
+ this.#activeSpinner = undefined;
359
+ this.#activeSpinnerLogs.forEach(message => {
360
+ this.#log(indentLines(message, 2));
361
+ });
362
+ this.#activeSpinnerLogs = [];
363
+ process.removeListener('SIGINT', this.#sigintListener);
364
+ if (result.status === 'rejected') {
365
+ throw result.reason;
366
+ }
367
+ }
368
+ #log(message, color) {
369
+ if (this.#activeSpinner) {
370
+ if (this.#activeSpinner.isSpinning) {
371
+ this.#activeSpinnerLogs.push(this.#format(message, color));
372
+ }
373
+ else {
374
+ console.log(this.#format(indentLines(message, 2), color));
375
+ }
376
+ }
377
+ else {
378
+ console.log(this.#format(message, color));
379
+ }
380
+ this.#endsWithBlankLine = !message || message.endsWith('\n');
381
+ }
382
+ #format(message, color) {
383
+ if (!this.#groupColor || this.#activeSpinner?.isSpinning) {
384
+ return this.#colorize(message, color);
385
+ }
386
+ return transformLines(message, line => `${this.#colorize('│', this.#groupColor)} ${this.#colorize(line, color)}`);
387
+ }
388
+ #colorize(text, color) {
389
+ if (!color) {
390
+ return text;
391
+ }
392
+ return ansis[color](text);
393
+ }
394
+ #formatDurationSuffix({ start, end, }) {
395
+ const duration = formatDuration(end - start);
396
+ return ansis.gray(`(${duration})`);
397
+ }
398
+ }
399
+ /**
400
+ * Shared {@link Logger} instance.
401
+ *
402
+ * @example
403
+ * import { logger } from '@code-pushup/utils';
404
+ *
405
+ * logger.info('Made with ❤️ by Code PushUp');
406
+ */
407
+ export const logger = new Logger();
408
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/lib/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAmB,MAAM,OAAO,CAAC;AAC/C,OAA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AG,cAAc,CAAC,GAAG,GAAG,KAAK,CAAC,CAAC;QAC7C,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,QAAQ,GAAG,CAAC,CAAC;IACrC,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC"}
@@ -3,3 +3,4 @@ export declare function groupByStatus<T>(results: PromiseSettledResult<T>[]): {
3
3
  rejected: PromiseRejectedResult[];
4
4
  };
5
5
  export declare function asyncSequential<TInput, TOutput>(items: TInput[], work: (item: TInput) => Promise<TOutput>): Promise<TOutput[]>;
6
+ export declare function settlePromise<T>(promise: Promise<T>): Promise<PromiseSettledResult<T>>;
@@ -14,4 +14,13 @@ export async function asyncSequential(items, work) {
14
14
  }
15
15
  return results;
16
16
  }
17
+ export async function settlePromise(promise) {
18
+ try {
19
+ const value = await promise;
20
+ return { status: 'fulfilled', value };
21
+ }
22
+ catch (error) {
23
+ return { status: 'rejected', reason: error };
24
+ }
25
+ }
17
26
  //# sourceMappingURL=promises.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"promises.js","sourceRoot":"","sources":["../../../src/lib/promises.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,aAAa,CAAI,OAAkC;IAIjE,OAAO,OAAO,CAAC,MAAM,CAInB,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,CACd,MAAM,CAAC,MAAM,KAAK,WAAW;QAC3B,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,SAAS,EAAE,CAAC,GAAG,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,EAAE;QACnD,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,QAAQ,EAAE,CAAC,GAAG,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,EACrD,EAAE,SAAS,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,CAChC,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,eAAe,CACn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