Skip to content

Commit 00293a9

Browse files
committed
feat(utils): replace @isaacs/cliui for printing audits to stdout
1 parent 7673051 commit 00293a9

File tree

12 files changed

+163
-233
lines changed

12 files changed

+163
-233
lines changed

e2e/plugin-lighthouse-e2e/tests/collect.e2e.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
E2E_ENVIRONMENTS_DIR,
88
TEST_OUTPUT_DIR,
99
omitVariableReportData,
10-
removeColorCodes,
1110
restoreNxIgnoredFiles,
1211
teardownTestFolder,
1312
} from '@code-pushup/test-utils';
@@ -42,8 +41,7 @@ describe('PLUGIN collect report with lighthouse-plugin NPM package', () => {
4241
});
4342

4443
expect(code).toBe(0);
45-
const cleanStdout = removeColorCodes(stdout);
46-
expect(cleanStdout).toContain('● Largest Contentful Paint');
44+
expect(stdout).toContain('Largest Contentful Paint');
4745

4846
const report = await readJsonFile(
4947
path.join(defaultSetupDir, '.code-pushup', 'report.json'),

package-lock.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"dependencies": {
2222
"@axe-core/playwright": "^4.11.0",
2323
"@code-pushup/portal-client": "^0.16.0",
24-
"@isaacs/cliui": "^8.0.2",
2524
"@nx/devkit": "21.4.1",
2625
"@poppinss/cliui": "6.4.1",
2726
"@swc/helpers": "0.5.13",

packages/utils/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
},
2929
"dependencies": {
3030
"@code-pushup/models": "0.87.2",
31-
"@isaacs/cliui": "^8.0.2",
3231
"@poppinss/cliui": "^6.4.0",
3332
"ansis": "^3.3.0",
3433
"build-md": "^0.4.2",

packages/utils/src/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,8 @@ export {
8888
export { interpolate } from './lib/interpolate.js';
8989
export { logMultipleResults } from './lib/log-results.js';
9090
export { Logger, logger } from './lib/logger.js';
91-
export { link, ui, type CliUi, type Column } from './lib/logging.js';
91+
export { link, ui, type CliUi } from './lib/logging.js';
9292
export { mergeConfigs } from './lib/merge-configs.js';
93-
export {
94-
getUrlIdentifier,
95-
normalizeUrlInput,
96-
type PluginUrlContext,
97-
} from './lib/plugin-url-config.js';
9893
export {
9994
addIndex,
10095
ContextValidationError,
@@ -106,6 +101,11 @@ export {
106101
shouldExpandForUrls,
107102
validateUrlContext,
108103
} from './lib/plugin-url-aggregation.js';
104+
export {
105+
getUrlIdentifier,
106+
normalizeUrlInput,
107+
type PluginUrlContext,
108+
} from './lib/plugin-url-config.js';
109109
export { getProgressBar, type ProgressBar } from './lib/progress.js';
110110
export {
111111
asyncSequential,

packages/utils/src/lib/logging.ts

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,16 @@
1-
import isaacs_cliui from '@isaacs/cliui';
21
import { cliui } from '@poppinss/cliui';
32
import ansis from 'ansis';
4-
import { TERMINAL_WIDTH } from './text-formats/constants.js';
53

64
// TODO: remove once logger is used everywhere
75

8-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
9-
type ArgumentsType<T> = T extends (...args: infer U) => any ? U : never;
10-
export type CliUiBase = ReturnType<typeof cliui>;
11-
type UI = ReturnType<typeof isaacs_cliui>;
12-
type CliExtension = {
13-
row: (r: ArgumentsType<UI['div']>) => void;
14-
};
15-
export type Column = {
16-
text: string;
17-
width?: number;
18-
align?: 'right' | 'left' | 'center';
19-
padding: number[];
20-
border?: boolean;
21-
};
22-
export type CliUi = CliUiBase & CliExtension;
6+
export type CliUi = ReturnType<typeof cliui>;
237

248
// eslint-disable-next-line functional/no-let
25-
let cliUISingleton: CliUiBase | undefined;
26-
// eslint-disable-next-line functional/no-let
27-
let cliUIExtendedSingleton: CliUi | undefined;
9+
let cliUISingleton: CliUi | undefined;
2810

2911
export function ui(): CliUi {
30-
if (cliUISingleton === undefined) {
31-
cliUISingleton = cliui();
32-
}
33-
if (!cliUIExtendedSingleton) {
34-
cliUIExtendedSingleton = {
35-
...cliUISingleton,
36-
row: args => {
37-
logListItem(args);
38-
},
39-
};
40-
}
41-
42-
return cliUIExtendedSingleton;
43-
}
44-
45-
// eslint-disable-next-line functional/no-let
46-
let singletonisaacUi: UI | undefined;
47-
export function logListItem(args: ArgumentsType<UI['div']>) {
48-
if (singletonisaacUi === undefined) {
49-
singletonisaacUi = isaacs_cliui({ width: TERMINAL_WIDTH });
50-
}
51-
singletonisaacUi.div(...args);
52-
const content = singletonisaacUi.toString();
53-
// eslint-disable-next-line functional/immutable-data
54-
singletonisaacUi.rows = [];
55-
cliUIExtendedSingleton?.logger.log(content);
12+
cliUISingleton ??= cliui();
13+
return cliUISingleton;
5614
}
5715

5816
export function link(text: string) {

packages/utils/src/lib/reports/__snapshots__/report-stdout-all-perfect-scores.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@ Code PushUp Report - @code-pushup/core@0.0.1
33

44
ESLint audits
55

6-
● ... All 47 audits have perfect scores ...
6+
... All 47 audits have perfect scores ...
77

88

99
Lighthouse audits
1010

11-
● Minimize third-party usage Third-party code
12-
blocked the main
13-
thread for 6,850 ms
14-
● First Contentful Paint 1.2 s
15-
● Largest Contentful Paint 1.5 s
16-
● Speed Index 1.2 s
17-
● ... 2 audits with perfect scores omitted for brevity ...
11+
● Minimize third-party usage Third-party code blocked the main
12+
thread for 6,850 ms
13+
● First Contentful Paint 1.2 s
14+
● Largest Contentful Paint 1.5 s
15+
● Speed Index 1.2 s
16+
● ... + 2 audits with perfect scores ...
1817

1918
Categories
2019

@@ -29,3 +28,4 @@ Categories
2928
└─────────────────────────────────────────────────────────┴─────────┴──────────┘
3029

3130
Made with ❤ by code-pushup.dev
31+

packages/utils/src/lib/reports/__snapshots__/report-stdout-no-categories.txt

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,31 @@ Code PushUp Report - @code-pushup/core@0.0.1
33

44
ESLint audits
55

6-
● Disallow missing props validation in a React component 6 warnings
7-
definition
8-
● Disallow variable declarations from shadowing variables 3 warnings
9-
declared in the outer scope
10-
● Require or disallow method and property shorthand 3 warnings
11-
syntax for object literals
12-
● verifies the list of dependencies for Hooks like 2 warnings
13-
useEffect and similar
14-
● Disallow missing `key` props in iterators/collection 1 warning
15-
literals
16-
● Disallow unused variables 1 warning
17-
● Enforce a maximum number of lines of code in a function 1 warning
18-
● Require `const` declarations for variables that are 1 warning
19-
never reassigned after declared
20-
● Require braces around arrow function bodies 1 warning
21-
● Require the use of `===` and `!==` 1 warning
22-
● ... 37 audits with perfect scores omitted for brevity ...
6+
● Disallow missing props validation in a React component definition 6 warnings
7+
● Disallow variable declarations from shadowing variables declared 3 warnings
8+
in the outer scope
9+
● Require or disallow method and property shorthand syntax for 3 warnings
10+
object literals
11+
● verifies the list of dependencies for Hooks like useEffect and 2 warnings
12+
similar
13+
● Disallow missing `key` props in iterators/collection literals 1 warning
14+
● Disallow unused variables 1 warning
15+
● Enforce a maximum number of lines of code in a function 1 warning
16+
● Require `const` declarations for variables that are never 1 warning
17+
reassigned after declared
18+
● Require braces around arrow function bodies 1 warning
19+
● Require the use of `===` and `!==` 1 warning
20+
● ... + 37 audits with perfect scores ...
2321

2422

2523
Lighthouse audits
2624

27-
● Minimize third-party usage Third-party code
28-
blocked the main
29-
thread for 6,850 ms
30-
● First Contentful Paint 1.2 s
31-
● Largest Contentful Paint 1.5 s
32-
● Speed Index 1.2 s
33-
● ... 2 audits with perfect scores omitted for brevity ...
25+
● Minimize third-party usage Third-party code blocked the main
26+
thread for 6,850 ms
27+
● First Contentful Paint 1.2 s
28+
● Largest Contentful Paint 1.5 s
29+
● Speed Index 1.2 s
30+
● ... + 2 audits with perfect scores ...
3431

3532
Made with ❤ by code-pushup.dev
33+

packages/utils/src/lib/reports/__snapshots__/report-stdout-verbose.txt

Lines changed: 64 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -3,87 +3,73 @@ Code PushUp Report - @code-pushup/core@0.0.1
33

44
ESLint audits
55

6-
● Disallow missing props validation in a React component 6 warnings
7-
definition
8-
● Disallow variable declarations from shadowing variables 3 warnings
9-
declared in the outer scope
10-
● Require or disallow method and property shorthand 3 warnings
11-
syntax for object literals
12-
● verifies the list of dependencies for Hooks like 2 warnings
13-
useEffect and similar
14-
● Disallow missing `key` props in iterators/collection 1 warning
15-
literals
16-
● Disallow unused variables 1 warning
17-
● Enforce a maximum number of lines of code in a function 1 warning
18-
● Require `const` declarations for variables that are 1 warning
19-
never reassigned after declared
20-
● Require braces around arrow function bodies 1 warning
21-
● Require the use of `===` and `!==` 1 warning
22-
● Disallow `target="_blank"` attribute without passed
23-
`rel="noreferrer"`
24-
● Disallow assignment operators in conditional passed
25-
expressions
26-
● Disallow comments from being inserted as text nodes passed
27-
● Disallow direct mutation of this.state passed
28-
● Disallow duplicate properties in JSX passed
29-
● Disallow invalid regular expression strings in `RegExp` passed
30-
constructors
31-
● Disallow loops with a body that allows only one passed
32-
iteration
33-
● Disallow missing displayName in a React component passed
34-
definition
35-
● Disallow missing React when using JSX passed
36-
● Disallow negating the left operand of relational passed
37-
operators
38-
● Disallow passing of children as props passed
39-
● Disallow React to be incorrectly marked as unused passed
40-
● Disallow reassigning `const` variables passed
41-
● Disallow the use of `debugger` passed
42-
● Disallow the use of undeclared variables unless passed
43-
mentioned in `/*global */` comments
44-
● Disallow undeclared variables in JSX passed
45-
● Disallow unescaped HTML entities from appearing in passed
46-
markup
47-
● Disallow usage of deprecated methods passed
48-
● Disallow usage of findDOMNode passed
49-
● Disallow usage of isMounted passed
50-
● Disallow usage of the return value of ReactDOM.render passed
51-
● Disallow usage of unknown DOM property passed
52-
● Disallow use of optional chaining in contexts where the passed
53-
`undefined` value is not allowed
54-
● Disallow using Object.assign with an object literal as passed
55-
the first argument and prefer the use of object spread
56-
instead
57-
● Disallow using string references passed
58-
● Disallow variables used in JSX to be incorrectly marked passed
59-
as unused
60-
● Disallow when a DOM element is using both children and passed
61-
dangerouslySetInnerHTML
62-
● Enforce a maximum number of lines per file passed
63-
● Enforce camelcase naming convention passed
64-
● Enforce comparing `typeof` expressions against valid passed
65-
strings
66-
● Enforce consistent brace style for all control passed
67-
statements
68-
● Enforce ES5 or ES6 class for returning value in render passed
69-
function
70-
● enforces the Rules of Hooks passed
71-
● Require `let` or `const` instead of `var` passed
72-
● Require calls to `isNaN()` when checking for `NaN` passed
73-
● Require or disallow "Yoda" conditions passed
74-
● Require using arrow functions for callbacks passed
6+
● Disallow missing props validation in a React component definition 6 warnings
7+
● Disallow variable declarations from shadowing variables declared 3 warnings
8+
in the outer scope
9+
● Require or disallow method and property shorthand syntax for 3 warnings
10+
object literals
11+
● verifies the list of dependencies for Hooks like useEffect and 2 warnings
12+
similar
13+
● Disallow missing `key` props in iterators/collection literals 1 warning
14+
● Disallow unused variables 1 warning
15+
● Enforce a maximum number of lines of code in a function 1 warning
16+
● Require `const` declarations for variables that are never 1 warning
17+
reassigned after declared
18+
● Require braces around arrow function bodies 1 warning
19+
● Require the use of `===` and `!==` 1 warning
20+
● Disallow `target="_blank"` attribute without `rel="noreferrer"` passed
21+
● Disallow assignment operators in conditional expressions passed
22+
● Disallow comments from being inserted as text nodes passed
23+
● Disallow direct mutation of this.state passed
24+
● Disallow duplicate properties in JSX passed
25+
● Disallow invalid regular expression strings in `RegExp` passed
26+
constructors
27+
● Disallow loops with a body that allows only one iteration passed
28+
● Disallow missing displayName in a React component definition passed
29+
● Disallow missing React when using JSX passed
30+
● Disallow negating the left operand of relational operators passed
31+
● Disallow passing of children as props passed
32+
● Disallow React to be incorrectly marked as unused passed
33+
● Disallow reassigning `const` variables passed
34+
● Disallow the use of `debugger` passed
35+
● Disallow the use of undeclared variables unless mentioned in passed
36+
`/*global */` comments
37+
● Disallow undeclared variables in JSX passed
38+
● Disallow unescaped HTML entities from appearing in markup passed
39+
● Disallow usage of deprecated methods passed
40+
● Disallow usage of findDOMNode passed
41+
● Disallow usage of isMounted passed
42+
● Disallow usage of the return value of ReactDOM.render passed
43+
● Disallow usage of unknown DOM property passed
44+
● Disallow use of optional chaining in contexts where the passed
45+
`undefined` value is not allowed
46+
● Disallow using Object.assign with an object literal as the first passed
47+
argument and prefer the use of object spread instead
48+
● Disallow using string references passed
49+
● Disallow variables used in JSX to be incorrectly marked as unused passed
50+
● Disallow when a DOM element is using both children and passed
51+
dangerouslySetInnerHTML
52+
● Enforce a maximum number of lines per file passed
53+
● Enforce camelcase naming convention passed
54+
● Enforce comparing `typeof` expressions against valid strings passed
55+
● Enforce consistent brace style for all control statements passed
56+
● Enforce ES5 or ES6 class for returning value in render function passed
57+
● enforces the Rules of Hooks passed
58+
● Require `let` or `const` instead of `var` passed
59+
● Require calls to `isNaN()` when checking for `NaN` passed
60+
● Require or disallow "Yoda" conditions passed
61+
● Require using arrow functions for callbacks passed
7562

7663

7764
Lighthouse audits
7865

79-
● Minimize third-party usage Third-party code
80-
blocked the main
81-
thread for 6,850 ms
82-
● First Contentful Paint 1.2 s
83-
● Largest Contentful Paint 1.5 s
84-
● Speed Index 1.2 s
85-
● Cumulative Layout Shift 0
86-
● Total Blocking Time 0 ms
66+
● Minimize third-party usage Third-party code blocked the main thread for
67+
6,850 ms
68+
● First Contentful Paint 1.2 s
69+
● Largest Contentful Paint 1.5 s
70+
● Speed Index 1.2 s
71+
● Cumulative Layout Shift 0
72+
● Total Blocking Time 0 ms
8773

8874
Categories
8975

@@ -98,3 +84,4 @@ Categories
9884
└─────────────────────────────────────────────────────────┴─────────┴──────────┘
9985

10086
Made with ❤ by code-pushup.dev
87+

0 commit comments

Comments
 (0)