Skip to content

Commit f7263a4

Browse files
committed
feat: multi-URL aware helpers for cross-plugin composition
1 parent 9d4a223 commit f7263a4

21 files changed

+988
-603
lines changed

code-pushup.preset.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
/* eslint-disable @nx/enforce-module-boundaries */
22
import { createProjectGraphAsync } from '@nx/devkit';
3-
import type {
4-
CategoryConfig,
5-
CoreConfig,
6-
PluginUrls,
7-
} from './packages/models/src/index.js';
8-
import axePlugin, { axeCategories } from './packages/plugin-axe/src/index.js';
3+
import type { CoreConfig, PluginUrls } from './packages/models/src/index.js';
4+
import axePlugin, { axeGroupRefs } from './packages/plugin-axe/src/index.js';
95
import coveragePlugin, {
106
type CoveragePluginConfig,
117
getNxCoveragePaths,
@@ -16,8 +12,7 @@ import eslintPlugin, {
1612
import jsPackagesPlugin from './packages/plugin-js-packages/src/index.js';
1713
import jsDocsPlugin from './packages/plugin-jsdocs/src/index.js';
1814
import {
19-
lighthouseCategories,
20-
lighthouseGroupRef,
15+
lighthouseGroupRefs,
2116
lighthousePlugin,
2217
} from './packages/plugin-lighthouse/src/index.js';
2318
import typescriptPlugin, {
@@ -195,38 +190,43 @@ export async function configureLighthousePlugin(
195190
urls: PluginUrls,
196191
): Promise<CoreConfig> {
197192
const lhPlugin = await lighthousePlugin(urls);
198-
const lhCategories: CategoryConfig[] = [
199-
{
200-
slug: 'performance',
201-
title: 'Performance',
202-
refs: [lighthouseGroupRef('performance')],
203-
},
204-
{
205-
slug: 'a11y',
206-
title: 'Accessibility',
207-
refs: [lighthouseGroupRef('accessibility')],
208-
},
209-
{
210-
slug: 'best-practices',
211-
title: 'Best Practices',
212-
refs: [lighthouseGroupRef('best-practices')],
213-
},
214-
{
215-
slug: 'seo',
216-
title: 'SEO',
217-
refs: [lighthouseGroupRef('seo')],
218-
},
219-
];
220193
return {
221194
plugins: [lhPlugin],
222-
categories: lighthouseCategories(lhPlugin, lhCategories),
195+
categories: [
196+
{
197+
slug: 'performance',
198+
title: 'Performance',
199+
refs: lighthouseGroupRefs(lhPlugin, 'performance'),
200+
},
201+
{
202+
slug: 'a11y',
203+
title: 'Accessibility',
204+
refs: lighthouseGroupRefs(lhPlugin, 'accessibility'),
205+
},
206+
{
207+
slug: 'best-practices',
208+
title: 'Best Practices',
209+
refs: lighthouseGroupRefs(lhPlugin, 'best-practices'),
210+
},
211+
{
212+
slug: 'seo',
213+
title: 'SEO',
214+
refs: lighthouseGroupRefs(lhPlugin, 'seo'),
215+
},
216+
],
223217
};
224218
}
225219

226220
export function configureAxePlugin(urls: PluginUrls): CoreConfig {
227221
const axe = axePlugin(urls);
228222
return {
229223
plugins: [axe],
230-
categories: axeCategories(axe),
224+
categories: [
225+
{
226+
slug: 'axe-a11y',
227+
title: 'Axe Accessibility',
228+
refs: axeGroupRefs(axe),
229+
},
230+
],
231231
};
232232
}

packages/models/docs/models-reference.md

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ _All properties are optional._
2525

2626
_Object containing the following properties:_
2727

28-
| Property | Description | Type |
29-
| :----------------------- | :----------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
30-
| **`slug`** (\*) | Unique ID (human-readable, URL-safe) | [Slug](#slug) |
31-
| **`title`** (\*) | Descriptive name | `string` (_max length: 256_) |
32-
| `docsUrl` | Documentation site | `string` (_url_) (_optional_) _or_ `''` |
33-
| **`scores`** (\*) | Score comparison | _Object with properties:_<ul><li>**`before`** (\*): [Score](#score) - Value between 0 and 1 (source commit)</li><li>**`after`** (\*): [Score](#score) - Value between 0 and 1 (target commit)</li><li>**`diff`** (\*): `number` (_≥-1, ≤1_) - Score change (`scores.after - scores.before`)</li></ul> |
34-
| **`plugin`** (\*) | Plugin which defines it | _Object with properties:_<ul><li>**`slug`** (\*): [Slug](#slug) - Unique plugin slug within core config</li><li>**`title`** (\*): `string` (_max length: 256_) - Descriptive name</li><li>`docsUrl`: `string` (_url_) (_optional_) _or_ `''` - Plugin documentation site</li></ul> |
35-
| **`values`** (\*) | Audit `value` comparison | _Object with properties:_<ul><li>**`before`** (\*): `number` (_≥0_) - Raw numeric value (source commit)</li><li>**`after`** (\*): `number` (_≥0_) - Raw numeric value (target commit)</li><li>**`diff`** (\*): `number` - Value change (`values.after - values.before`)</li></ul> |
36-
| **`displayValues`** (\*) | Audit `displayValue` comparison | _Object with properties:_<ul><li>`before`: `string` - Formatted value (e.g. '0.9 s', '2.1 MB') (source commit)</li><li>`after`: `string` - Formatted value (e.g. '0.9 s', '2.1 MB') (target commit)</li></ul> |
28+
| Property | Description | Type |
29+
| :----------------------- | :----------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
30+
| **`slug`** (\*) | Unique ID (human-readable, URL-safe) | [Slug](#slug) |
31+
| **`title`** (\*) | Descriptive name | `string` (_max length: 256_) |
32+
| `docsUrl` | Documentation site | `string` (_url_) (_optional_) _or_ `''` |
33+
| **`scores`** (\*) | Score comparison | _Object with properties:_<ul><li>**`before`** (\*): [Score](#score) - Value between 0 and 1 (source commit)</li><li>**`after`** (\*): [Score](#score) - Value between 0 and 1 (target commit)</li><li>**`diff`** (\*): `number` (_≥-1, ≤1_) - Score change (`scores.after - scores.before`)</li></ul> |
34+
| **`plugin`** (\*) | Plugin which defines it | _Object with properties:_<ul><li>**`slug`** (\*): [Slug](#slug) - Unique plugin slug within core config</li><li>**`title`** (\*): `string` (_max length: 256_) - Descriptive name</li><li>`docsUrl`: `string` (_url_) (_optional_) _or_ `''` - Plugin documentation site</li></ul> |
35+
| **`values`** (\*) | Audit `value` comparison | _Object with properties:_<ul><li>**`before`** (\*): [NonnegativeNumber](#nonnegativenumber) - Raw numeric value (source commit)</li><li>**`after`** (\*): [NonnegativeNumber](#nonnegativenumber) - Raw numeric value (target commit)</li><li>**`diff`** (\*): `number` - Value change (`values.after - values.before`)</li></ul> |
36+
| **`displayValues`** (\*) | Audit `displayValue` comparison | _Object with properties:_<ul><li>`before`: `string` - Formatted value (e.g. '0.9 s', '2.1 MB') (source commit)</li><li>`after`: `string` - Formatted value (e.g. '0.9 s', '2.1 MB') (target commit)</li></ul> |
3737

3838
_(\*) Required._
3939

@@ -43,14 +43,14 @@ Audit information
4343

4444
_Object containing the following properties:_
4545

46-
| Property | Description | Type |
47-
| :--------------- | :--------------------------------------- | :---------------------------- |
48-
| **`slug`** (\*) | Reference to audit | [Slug](#slug) |
49-
| `displayValue` | Formatted value (e.g. '0.9 s', '2.1 MB') | `string` |
50-
| **`value`** (\*) | Raw numeric value | `number` (_≥0_) |
51-
| **`score`** (\*) | Value between 0 and 1 | [Score](#score) |
52-
| `scoreTarget` | Pass/fail score threshold (0-1) | `number` (_≥0, ≤1_) |
53-
| `details` | Detailed information | [AuditDetails](#auditdetails) |
46+
| Property | Description | Type |
47+
| :--------------- | :--------------------------------------- | :-------------------------------------- |
48+
| **`slug`** (\*) | Reference to audit | [Slug](#slug) |
49+
| `displayValue` | Formatted value (e.g. '0.9 s', '2.1 MB') | `string` |
50+
| **`value`** (\*) | Raw numeric value | [NonnegativeNumber](#nonnegativenumber) |
51+
| **`score`** (\*) | Value between 0 and 1 | [Score](#score) |
52+
| `scoreTarget` | Pass/fail score threshold (0-1) | `number` (_≥0, ≤1_) |
53+
| `details` | Detailed information | [AuditDetails](#auditdetails) |
5454

5555
_(\*) Required._
5656

@@ -72,7 +72,7 @@ _Object containing the following properties:_
7272
| `docsUrl` | Link to documentation (rationale) | `string` (_url_) (_optional_) _or_ `''` |
7373
| `isSkipped` | Indicates whether the audit is skipped | `boolean` |
7474
| `displayValue` | Formatted value (e.g. '0.9 s', '2.1 MB') | `string` |
75-
| **`value`** (\*) | Raw numeric value | `number` (_≥0_) |
75+
| **`value`** (\*) | Raw numeric value | [NonnegativeNumber](#nonnegativenumber) |
7676
| **`score`** (\*) | Value between 0 and 1 | [Score](#score) |
7777
| `scoreTarget` | Pass/fail score threshold (0-1) | `number` (_≥0, ≤1_) |
7878
| `details` | Detailed information | [AuditDetails](#auditdetails) |
@@ -90,7 +90,7 @@ _Object containing the following properties:_
9090
| `docsUrl` | Documentation site | `string` (_url_) (_optional_) _or_ `''` |
9191
| **`plugin`** (\*) | Plugin which defines it | _Object with properties:_<ul><li>**`slug`** (\*): [Slug](#slug) - Unique plugin slug within core config</li><li>**`title`** (\*): `string` (_max length: 256_) - Descriptive name</li><li>`docsUrl`: `string` (_url_) (_optional_) _or_ `''` - Plugin documentation site</li></ul> |
9292
| **`score`** (\*) | Value between 0 and 1 | [Score](#score) |
93-
| **`value`** (\*) | Raw numeric value | `number` (_≥0_) |
93+
| **`value`** (\*) | Raw numeric value | [NonnegativeNumber](#nonnegativenumber) |
9494
| `displayValue` | Formatted value (e.g. '0.9 s', '2.1 MB') | `string` |
9595

9696
_(\*) Required._
@@ -198,12 +198,12 @@ _(\*) Required._
198198

199199
_Object containing the following properties:_
200200

201-
| Property | Description | Type |
202-
| :---------------- | :----------------------------------------------------------------- | :------------------- |
203-
| **`slug`** (\*) | Slug of an audit or group (depending on `type`) | [Slug](#slug) |
204-
| **`weight`** (\*) | Weight used to calculate score | `number` (_≥0_) |
205-
| **`type`** (\*) | Discriminant for reference kind, affects where `slug` is looked up | `'audit' \| 'group'` |
206-
| **`plugin`** (\*) | Plugin slug (plugin should contain referenced audit or group) | [Slug](#slug) |
201+
| Property | Description | Type |
202+
| :---------------- | :----------------------------------------------------------------- | :-------------------------------------- |
203+
| **`slug`** (\*) | Slug of an audit or group (depending on `type`) | [Slug](#slug) |
204+
| **`weight`** (\*) | Weight used to calculate score | [NonnegativeNumber](#nonnegativenumber) |
205+
| **`type`** (\*) | Discriminant for reference kind, affects where `slug` is looked up | `'audit' \| 'group'` |
206+
| **`plugin`** (\*) | Plugin slug (plugin should contain referenced audit or group) | [Slug](#slug) |
207207

208208
_(\*) Required._
209209

@@ -332,10 +332,10 @@ Weighted reference to a group
332332

333333
_Object containing the following properties:_
334334

335-
| Property | Description | Type |
336-
| :---------------- | :-------------------------------------------------------------- | :-------------- |
337-
| **`slug`** (\*) | Reference slug to a group within this plugin (e.g. 'max-lines') | [Slug](#slug) |
338-
| **`weight`** (\*) | Weight used to calculate score | `number` (_≥0_) |
335+
| Property | Description | Type |
336+
| :---------------- | :-------------------------------------------------------------- | :-------------------------------------- |
337+
| **`slug`** (\*) | Reference slug to a group within this plugin (e.g. 'max-lines') | [Slug](#slug) |
338+
| **`weight`** (\*) | Weight used to calculate score | [NonnegativeNumber](#nonnegativenumber) |
339339

340340
_(\*) Required._
341341

@@ -1262,6 +1262,10 @@ _Enum, one of the following possible values:_
12621262

12631263
</details>
12641264

1265+
## NonnegativeNumber
1266+
1267+
_Number which is greater than or equal to 0._
1268+
12651269
## PersistConfig
12661270

12671271
_Object containing the following properties:_
@@ -1374,7 +1378,7 @@ _Union of the following possible types:_
13741378

13751379
- `string` (_url_)
13761380
- `Array<string (_url_)>`
1377-
- _Object with dynamic keys of type_ `string` (_url_) _and values of type_ `number` (_≥0_)
1381+
- _Object with dynamic keys of type_ `string` (_url_) _and values of type_ [NonnegativeNumber](#nonnegativenumber)
13781382

13791383
## PositiveInt
13801384

@@ -1574,3 +1578,9 @@ _Object containing the following properties:_
15741578
| `timeout` | Request timeout in minutes (default is 5) | `number` (_>0, int_) |
15751579

15761580
_(\*) Required._
1581+
1582+
## Weight
1583+
1584+
Coefficient for the given score (use weight 0 if only for display)
1585+
1586+
_Number which is greater than or equal to 0._

packages/models/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,11 @@ export {
6666
filePathSchema,
6767
globPathSchema,
6868
materialIconSchema,
69+
nonnegativeNumberSchema,
6970
positiveIntSchema,
7071
scoreSchema,
7172
slugSchema,
73+
weightSchema,
7274
type MaterialIcon,
7375
} from './lib/implementation/schemas.js';
7476
export { exists } from './lib/implementation/utils.js';

0 commit comments

Comments
 (0)