@code-pushup/lighthouse-plugin 0.105.0 → 0.107.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/README.md +63 -26
- package/package.json +3 -3
- package/src/index.d.ts +1 -1
- package/src/index.js +1 -1
- package/src/index.js.map +1 -1
- package/src/lib/categories.d.ts +13 -21
- package/src/lib/categories.js +23 -32
- package/src/lib/categories.js.map +1 -1
- package/src/lib/utils.d.ts +26 -1
- package/src/lib/utils.js +54 -1
- package/src/lib/utils.js.map +1 -1
package/README.md
CHANGED
|
@@ -211,65 +211,92 @@ For a complete guide on Lighthouse configuration read the [official documentatio
|
|
|
211
211
|
|
|
212
212
|
The plugin provides helpers to integrate Lighthouse results into your categories.
|
|
213
213
|
|
|
214
|
-
###
|
|
214
|
+
### Building categories with ref helpers
|
|
215
215
|
|
|
216
|
-
Use `
|
|
216
|
+
Use `lighthouseGroupRefs` and `lighthouseAuditRefs` to build categories. These helpers automatically handle multi-URL expansion:
|
|
217
217
|
|
|
218
218
|
```ts
|
|
219
|
-
import lighthousePlugin, {
|
|
219
|
+
import lighthousePlugin, { lighthouseGroupRefs } from '@code-pushup/lighthouse-plugin';
|
|
220
220
|
|
|
221
221
|
const lighthouse = await lighthousePlugin('https://example.com');
|
|
222
222
|
|
|
223
223
|
export default {
|
|
224
224
|
plugins: [lighthouse],
|
|
225
|
-
categories:
|
|
225
|
+
categories: [
|
|
226
|
+
{
|
|
227
|
+
slug: 'performance',
|
|
228
|
+
title: 'Performance',
|
|
229
|
+
refs: lighthouseGroupRefs(lighthouse, 'performance'),
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
slug: 'seo',
|
|
233
|
+
title: 'SEO',
|
|
234
|
+
refs: lighthouseGroupRefs(lighthouse, 'seo'),
|
|
235
|
+
},
|
|
236
|
+
],
|
|
226
237
|
};
|
|
227
238
|
```
|
|
228
239
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
### Custom categories
|
|
232
|
-
|
|
233
|
-
For fine-grained control, provide your own categories. You can reference groups (Lighthouse's native categories) or individual audits:
|
|
240
|
+
For multi-URL setups, refs are automatically expanded for each URL with appropriate weights:
|
|
234
241
|
|
|
235
242
|
```ts
|
|
236
|
-
import lighthousePlugin, {
|
|
243
|
+
import lighthousePlugin, { lighthouseAuditRefs, lighthouseGroupRefs } from '@code-pushup/lighthouse-plugin';
|
|
237
244
|
|
|
238
|
-
const lighthouse = await lighthousePlugin(
|
|
245
|
+
const lighthouse = await lighthousePlugin({
|
|
246
|
+
'https://example.com': 2,
|
|
247
|
+
'https://example.com/about': 1,
|
|
248
|
+
});
|
|
239
249
|
|
|
240
250
|
export default {
|
|
241
251
|
plugins: [lighthouse],
|
|
242
|
-
categories:
|
|
252
|
+
categories: [
|
|
243
253
|
{
|
|
244
254
|
slug: 'performance',
|
|
245
255
|
title: 'Performance',
|
|
246
|
-
refs:
|
|
256
|
+
refs: lighthouseGroupRefs(lighthouse, 'performance'),
|
|
247
257
|
},
|
|
248
258
|
{
|
|
249
259
|
slug: 'core-web-vitals',
|
|
250
260
|
title: 'Core Web Vitals',
|
|
251
|
-
refs: [
|
|
261
|
+
refs: [...lighthouseAuditRefs(lighthouse, 'largest-contentful-paint', 3), ...lighthouseAuditRefs(lighthouse, 'cumulative-layout-shift', 2), ...lighthouseAuditRefs(lighthouse, 'first-contentful-paint', 1)],
|
|
252
262
|
},
|
|
253
|
-
]
|
|
263
|
+
],
|
|
254
264
|
};
|
|
255
265
|
```
|
|
256
266
|
|
|
257
|
-
|
|
258
|
-
> Referencing individual audits offers more granularity but increases maintenance costs. Use `npx code-pushup print-config --onlyPlugins=lighthouse` to list all available audits and groups.
|
|
267
|
+
### Get all groups
|
|
259
268
|
|
|
260
|
-
|
|
261
|
-
> Weights determine each ref's influence on the category score. Use weight `0` to include a ref as info only, without affecting the score.
|
|
269
|
+
Call `lighthouseGroupRefs` without a slug to get refs for all Lighthouse groups:
|
|
262
270
|
|
|
263
|
-
|
|
264
|
-
|
|
271
|
+
```ts
|
|
272
|
+
import lighthousePlugin, { lighthouseGroupRefs } from '@code-pushup/lighthouse-plugin';
|
|
273
|
+
|
|
274
|
+
const lighthouse = await lighthousePlugin('https://example.com');
|
|
275
|
+
|
|
276
|
+
export default {
|
|
277
|
+
plugins: [lighthouse],
|
|
278
|
+
categories: [
|
|
279
|
+
{
|
|
280
|
+
slug: 'lighthouse',
|
|
281
|
+
title: 'Lighthouse',
|
|
282
|
+
refs: lighthouseGroupRefs(lighthouse), // all groups
|
|
283
|
+
},
|
|
284
|
+
],
|
|
285
|
+
};
|
|
286
|
+
```
|
|
265
287
|
|
|
266
288
|
### Helper functions
|
|
267
289
|
|
|
268
|
-
| Function
|
|
269
|
-
|
|
|
270
|
-
| `
|
|
271
|
-
| `
|
|
272
|
-
|
|
290
|
+
| Function | Description |
|
|
291
|
+
| --------------------- | --------------------------------------------------------------- |
|
|
292
|
+
| `lighthouseGroupRefs` | Creates category refs to Lighthouse group(s), handles multi-URL |
|
|
293
|
+
| `lighthouseAuditRefs` | Creates category refs to Lighthouse audit(s), handles multi-URL |
|
|
294
|
+
|
|
295
|
+
> [!NOTE]
|
|
296
|
+
> Referencing individual audits offers more granularity but increases maintenance costs. Use `npx code-pushup print-config --onlyPlugins=lighthouse` to list all available audits and groups.
|
|
297
|
+
|
|
298
|
+
> [!TIP]
|
|
299
|
+
> Weights determine each ref's influence on the category score. Use weight `0` to include a ref as info only, without affecting the score.
|
|
273
300
|
|
|
274
301
|
### Type safety
|
|
275
302
|
|
|
@@ -281,4 +308,14 @@ import type { LighthouseGroupSlug } from '@code-pushup/lighthouse-plugin';
|
|
|
281
308
|
const group: LighthouseGroupSlug = 'performance';
|
|
282
309
|
```
|
|
283
310
|
|
|
311
|
+
### Deprecated helpers
|
|
312
|
+
|
|
313
|
+
The following helpers are deprecated and will be removed in a future version:
|
|
314
|
+
|
|
315
|
+
| Function | Replacement |
|
|
316
|
+
| ---------------------- | -------------------------------------------------------- |
|
|
317
|
+
| `lighthouseCategories` | Build categories manually with `lighthouseGroupRefs` |
|
|
318
|
+
| `lighthouseGroupRef` | Use `lighthouseGroupRefs` (plural) for multi-URL support |
|
|
319
|
+
| `lighthouseAuditRef` | Use `lighthouseAuditRefs` (plural) for multi-URL support |
|
|
320
|
+
|
|
284
321
|
If you want to contribute, please refer to [CONTRIBUTING.md](./CONTRIBUTING.md).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@code-pushup/lighthouse-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.107.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Code PushUp plugin for measuring web performance and quality with Lighthouse 🔥",
|
|
6
6
|
"homepage": "https://github.com/code-pushup/cli/tree/main/packages/plugin-lighthouse#readme",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
},
|
|
37
37
|
"type": "module",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@code-pushup/models": "0.
|
|
40
|
-
"@code-pushup/utils": "0.
|
|
39
|
+
"@code-pushup/models": "0.107.0",
|
|
40
|
+
"@code-pushup/utils": "0.107.0",
|
|
41
41
|
"ansis": "^3.3.0",
|
|
42
42
|
"chrome-launcher": "^1.1.1",
|
|
43
43
|
"lighthouse": "^12.0.0",
|
package/src/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { lighthousePlugin } from './lib/lighthouse-plugin.js';
|
|
2
2
|
export { LIGHTHOUSE_REPORT_NAME } from './lib/runner/constants.js';
|
|
3
3
|
export { DEFAULT_CHROME_FLAGS, LIGHTHOUSE_PLUGIN_SLUG, LIGHTHOUSE_OUTPUT_PATH, } from './lib/constants.js';
|
|
4
|
-
export { lighthouseAuditRef, lighthouseGroupRef } from './lib/utils.js';
|
|
4
|
+
export { lighthouseAuditRef, lighthouseAuditRefs, lighthouseGroupRef, lighthouseGroupRefs, } from './lib/utils.js';
|
|
5
5
|
export type { LighthouseGroupSlug, LighthouseOptions } from './lib/types.js';
|
|
6
6
|
export { lighthousePlugin } from './lib/lighthouse-plugin.js';
|
|
7
7
|
export default lighthousePlugin;
|
package/src/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { lighthousePlugin } from './lib/lighthouse-plugin.js';
|
|
2
2
|
export { LIGHTHOUSE_REPORT_NAME } from './lib/runner/constants.js';
|
|
3
3
|
export { DEFAULT_CHROME_FLAGS, LIGHTHOUSE_PLUGIN_SLUG, LIGHTHOUSE_OUTPUT_PATH, } from './lib/constants.js';
|
|
4
|
-
export { lighthouseAuditRef, lighthouseGroupRef } from './lib/utils.js';
|
|
4
|
+
export { lighthouseAuditRef, lighthouseAuditRefs, lighthouseGroupRef, lighthouseGroupRefs, } from './lib/utils.js';
|
|
5
5
|
export { lighthousePlugin } from './lib/lighthouse-plugin.js';
|
|
6
6
|
export default lighthousePlugin;
|
|
7
7
|
export { lighthouseCategories, mergeLighthouseCategories, } from './lib/categories.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,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,eAAe,gBAAgB,CAAC;AAChC,OAAO,EACL,oBAAoB,EACpB,yBAAyB,GAC1B,MAAM,qBAAqB,CAAC"}
|
package/src/lib/categories.d.ts
CHANGED
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type CategoryConfig, type PluginConfig } from '@code-pushup/models';
|
|
2
2
|
import { type PluginUrlContext } from '@code-pushup/utils';
|
|
3
3
|
import type { LighthouseGroupSlug } from './types.js';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* - If user categories are provided, expands all refs (groups and audits) for each URL.
|
|
8
|
-
* - If not, generates categories from plugin groups only.
|
|
9
|
-
* - Assigns per-URL weights with correct precedence.
|
|
10
|
-
*
|
|
11
|
-
* @public
|
|
12
|
-
* @param plugin - {@link PluginConfig} object with groups and context
|
|
13
|
-
* @param categories - {@link CategoryConfig} optional user-defined categories
|
|
14
|
-
* @returns {CategoryConfig[]} - expanded and agregated categories
|
|
5
|
+
* @deprecated Use `lighthouseGroupRefs` to build categories manually instead.
|
|
15
6
|
*
|
|
16
7
|
* @example
|
|
17
|
-
*
|
|
18
|
-
* const
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
8
|
+
* // Instead of:
|
|
9
|
+
* const categories = lighthouseCategories(lhPlugin);
|
|
10
|
+
*
|
|
11
|
+
* // Use:
|
|
12
|
+
* const categories = [
|
|
13
|
+
* {
|
|
14
|
+
* slug: 'performance',
|
|
15
|
+
* title: 'Performance',
|
|
16
|
+
* refs: lighthouseGroupRefs(lhPlugin, 'performance'),
|
|
17
|
+
* },
|
|
18
|
+
* ];
|
|
22
19
|
*/
|
|
23
20
|
export declare function lighthouseCategories(plugin: Pick<PluginConfig, 'groups' | 'context'>, categories?: CategoryConfig[]): CategoryConfig[];
|
|
24
21
|
/**
|
|
@@ -36,8 +33,3 @@ export declare function createAggregatedCategory(groupSlug: LighthouseGroupSlug,
|
|
|
36
33
|
* Used when user categories are provided.
|
|
37
34
|
*/
|
|
38
35
|
export declare function expandAggregatedCategory(category: CategoryConfig, context: PluginUrlContext): CategoryConfig;
|
|
39
|
-
/**
|
|
40
|
-
* Extracts unique, unsuffixed group slugs from a list of groups.
|
|
41
|
-
* Useful for deduplicating and normalizing group slugs when generating categories.
|
|
42
|
-
*/
|
|
43
|
-
export declare function extractGroupSlugs(groups: Group[]): LighthouseGroupSlug[];
|
package/src/lib/categories.js
CHANGED
|
@@ -1,45 +1,44 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { validate, } from '@code-pushup/models';
|
|
2
|
+
import { expandCategoryRefs, pluginUrlContextSchema, shouldExpandForUrls, } from '@code-pushup/utils';
|
|
2
3
|
import { LIGHTHOUSE_GROUP_SLUGS, LIGHTHOUSE_PLUGIN_SLUG } from './constants.js';
|
|
3
4
|
import { LIGHTHOUSE_GROUPS } from './runner/constants.js';
|
|
4
|
-
import {
|
|
5
|
+
import { lighthouseGroupSlugs } from './utils.js';
|
|
5
6
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* - If user categories are provided, expands all refs (groups and audits) for each URL.
|
|
9
|
-
* - If not, generates categories from plugin groups only.
|
|
10
|
-
* - Assigns per-URL weights with correct precedence.
|
|
11
|
-
*
|
|
12
|
-
* @public
|
|
13
|
-
* @param plugin - {@link PluginConfig} object with groups and context
|
|
14
|
-
* @param categories - {@link CategoryConfig} optional user-defined categories
|
|
15
|
-
* @returns {CategoryConfig[]} - expanded and agregated categories
|
|
7
|
+
* @deprecated Use `lighthouseGroupRefs` to build categories manually instead.
|
|
16
8
|
*
|
|
17
9
|
* @example
|
|
18
|
-
*
|
|
19
|
-
* const
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
10
|
+
* // Instead of:
|
|
11
|
+
* const categories = lighthouseCategories(lhPlugin);
|
|
12
|
+
*
|
|
13
|
+
* // Use:
|
|
14
|
+
* const categories = [
|
|
15
|
+
* {
|
|
16
|
+
* slug: 'performance',
|
|
17
|
+
* title: 'Performance',
|
|
18
|
+
* refs: lighthouseGroupRefs(lhPlugin, 'performance'),
|
|
19
|
+
* },
|
|
20
|
+
* ];
|
|
23
21
|
*/
|
|
24
22
|
export function lighthouseCategories(plugin, categories) {
|
|
25
23
|
if (!plugin.groups || plugin.groups.length === 0) {
|
|
26
24
|
return categories ?? [];
|
|
27
25
|
}
|
|
28
|
-
validateUrlContext(plugin.context);
|
|
29
26
|
if (!categories) {
|
|
30
|
-
return createCategories(plugin
|
|
27
|
+
return createCategories(plugin);
|
|
31
28
|
}
|
|
32
|
-
return expandCategories(
|
|
29
|
+
return expandCategories(plugin, categories);
|
|
33
30
|
}
|
|
34
31
|
/**
|
|
35
32
|
* @deprecated
|
|
36
33
|
* Helper is renamed, please use `lighthouseCategories` function instead.
|
|
37
34
|
*/
|
|
38
35
|
export const mergeLighthouseCategories = lighthouseCategories;
|
|
39
|
-
function createCategories(
|
|
40
|
-
|
|
36
|
+
function createCategories(plugin) {
|
|
37
|
+
const context = validate(pluginUrlContextSchema, plugin.context);
|
|
38
|
+
return lighthouseGroupSlugs(plugin).map(slug => createAggregatedCategory(slug, context));
|
|
41
39
|
}
|
|
42
|
-
function expandCategories(
|
|
40
|
+
function expandCategories(plugin, categories) {
|
|
41
|
+
const context = validate(pluginUrlContextSchema, plugin.context);
|
|
43
42
|
if (!shouldExpandForUrls(context.urlCount)) {
|
|
44
43
|
return categories;
|
|
45
44
|
}
|
|
@@ -59,7 +58,7 @@ export function createAggregatedCategory(groupSlug, context) {
|
|
|
59
58
|
slug: group.slug,
|
|
60
59
|
title: group.title,
|
|
61
60
|
...(group.description && { description: group.description }),
|
|
62
|
-
refs:
|
|
61
|
+
refs: expandCategoryRefs({ plugin: LIGHTHOUSE_PLUGIN_SLUG, slug: group.slug, type: 'group' }, context),
|
|
63
62
|
};
|
|
64
63
|
}
|
|
65
64
|
/**
|
|
@@ -74,12 +73,4 @@ export function expandAggregatedCategory(category, context) {
|
|
|
74
73
|
: [ref]),
|
|
75
74
|
};
|
|
76
75
|
}
|
|
77
|
-
/**
|
|
78
|
-
* Extracts unique, unsuffixed group slugs from a list of groups.
|
|
79
|
-
* Useful for deduplicating and normalizing group slugs when generating categories.
|
|
80
|
-
*/
|
|
81
|
-
export function extractGroupSlugs(groups) {
|
|
82
|
-
const slugs = groups.map(({ slug }) => removeIndex(slug));
|
|
83
|
-
return [...new Set(slugs)].filter(isLighthouseGroupSlug);
|
|
84
|
-
}
|
|
85
76
|
//# sourceMappingURL=categories.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"categories.js","sourceRoot":"","sources":["../../../src/lib/categories.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"categories.js","sourceRoot":"","sources":["../../../src/lib/categories.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,QAAQ,GACT,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAEL,kBAAkB,EAClB,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAChF,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAgD,EAChD,UAA6B;IAE7B,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACjD,OAAO,UAAU,IAAI,EAAE,CAAC;IAC1B,CAAC;IACD,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO,gBAAgB,CAAC,MAA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AK,CAAC,KAAK;QAClB,GAAG,CAAC,KAAK,CAAC,WAAW,IAAI,EAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC;QAC5D,IAAI,EAAE,kBAAkB,CACtB,EAAE,MAAM,EAAE,sBAAsB,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,EACnE,OAAO,CACR;KACF,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CACtC,QAAwB,EACxB,OAAyB;IAEzB,OAAO;QACL,GAAG,QAAQ;QACX,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAChC,GAAG,CAAC,MAAM,KAAK,sBAAsB;YACnC,CAAC,CAAC,kBAAkB,CAAC,GAAG,EAAE,OAAO,CAAC;YAClC,CAAC,CAAC,CAAC,GAAG,CAAC,CACV;KACF,CAAC;AACJ,CAAC"}
|
package/src/lib/utils.d.ts
CHANGED
|
@@ -1,8 +1,33 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Audit, type CategoryRef, type Group, type PluginConfig } from '@code-pushup/models';
|
|
2
2
|
import type { LighthouseCliFlags } from './runner/types.js';
|
|
3
3
|
import type { LighthouseGroupSlug } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated Use `lighthouseGroupRefs` instead for multi-URL support.
|
|
6
|
+
*/
|
|
4
7
|
export declare function lighthouseGroupRef(groupSlug: LighthouseGroupSlug, weight?: number): CategoryRef;
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated Use `lighthouseAuditRefs` instead for multi-URL support.
|
|
10
|
+
*/
|
|
5
11
|
export declare function lighthouseAuditRef(auditSlug: string, weight?: number): CategoryRef;
|
|
12
|
+
/**
|
|
13
|
+
* Creates category refs for Lighthouse groups with multi-URL support.
|
|
14
|
+
*
|
|
15
|
+
* @param plugin - Lighthouse plugin instance
|
|
16
|
+
* @param groupSlug - Optional group slug; if omitted, includes all groups
|
|
17
|
+
* @param groupWeight - Optional weight for the ref(s)
|
|
18
|
+
* @returns Array of category refs, expanded for each URL in multi-URL configs
|
|
19
|
+
*/
|
|
20
|
+
export declare function lighthouseGroupRefs(plugin: Pick<PluginConfig, 'groups' | 'context'>, groupSlug?: LighthouseGroupSlug, groupWeight?: number): CategoryRef[];
|
|
21
|
+
/**
|
|
22
|
+
* Creates category refs for Lighthouse audits with multi-URL support.
|
|
23
|
+
*
|
|
24
|
+
* @param plugin - Lighthouse plugin instance
|
|
25
|
+
* @param auditSlug - Optional audit slug; if omitted, includes all audits
|
|
26
|
+
* @param auditWeight - Optional weight for the ref(s)
|
|
27
|
+
* @returns Array of category refs, expanded for each URL in multi-URL configs
|
|
28
|
+
*/
|
|
29
|
+
export declare function lighthouseAuditRefs(plugin: Pick<PluginConfig, 'audits' | 'context'>, auditSlug?: string, auditWeight?: number): CategoryRef[];
|
|
30
|
+
export declare function lighthouseGroupSlugs(plugin: Pick<PluginConfig, 'groups'>): LighthouseGroupSlug[];
|
|
6
31
|
export declare function validateAudits(audits: Audit[], onlyAudits: string[]): boolean;
|
|
7
32
|
export declare function validateOnlyCategories(groups: Group[], onlyCategories: string | string[]): boolean;
|
|
8
33
|
export type FilterOptions = Partial<Pick<LighthouseCliFlags, 'onlyAudits' | 'onlyCategories' | 'skipAudits'>>;
|
package/src/lib/utils.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { validate, } from '@code-pushup/models';
|
|
2
|
+
import { expandCategoryRefs, extractGroupSlugs, pluginUrlContextSchema, toArray, } from '@code-pushup/utils';
|
|
2
3
|
import { LIGHTHOUSE_GROUP_SLUGS, LIGHTHOUSE_PLUGIN_SLUG } from './constants.js';
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated Use `lighthouseGroupRefs` instead for multi-URL support.
|
|
6
|
+
*/
|
|
3
7
|
export function lighthouseGroupRef(groupSlug, weight = 1) {
|
|
4
8
|
return {
|
|
5
9
|
plugin: LIGHTHOUSE_PLUGIN_SLUG,
|
|
@@ -8,6 +12,9 @@ export function lighthouseGroupRef(groupSlug, weight = 1) {
|
|
|
8
12
|
weight,
|
|
9
13
|
};
|
|
10
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated Use `lighthouseAuditRefs` instead for multi-URL support.
|
|
17
|
+
*/
|
|
11
18
|
export function lighthouseAuditRef(auditSlug, weight = 1) {
|
|
12
19
|
return {
|
|
13
20
|
plugin: LIGHTHOUSE_PLUGIN_SLUG,
|
|
@@ -16,6 +23,52 @@ export function lighthouseAuditRef(auditSlug, weight = 1) {
|
|
|
16
23
|
weight,
|
|
17
24
|
};
|
|
18
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates category refs for Lighthouse groups with multi-URL support.
|
|
28
|
+
*
|
|
29
|
+
* @param plugin - Lighthouse plugin instance
|
|
30
|
+
* @param groupSlug - Optional group slug; if omitted, includes all groups
|
|
31
|
+
* @param groupWeight - Optional weight for the ref(s)
|
|
32
|
+
* @returns Array of category refs, expanded for each URL in multi-URL configs
|
|
33
|
+
*/
|
|
34
|
+
export function lighthouseGroupRefs(plugin, groupSlug, groupWeight) {
|
|
35
|
+
const context = validate(pluginUrlContextSchema, plugin.context);
|
|
36
|
+
if (groupSlug) {
|
|
37
|
+
return expandCategoryRefs({
|
|
38
|
+
plugin: LIGHTHOUSE_PLUGIN_SLUG,
|
|
39
|
+
slug: groupSlug,
|
|
40
|
+
type: 'group',
|
|
41
|
+
weight: groupWeight,
|
|
42
|
+
}, context);
|
|
43
|
+
}
|
|
44
|
+
return lighthouseGroupSlugs(plugin).flatMap(slug => expandCategoryRefs({ plugin: LIGHTHOUSE_PLUGIN_SLUG, slug, type: 'group' }, context));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Creates category refs for Lighthouse audits with multi-URL support.
|
|
48
|
+
*
|
|
49
|
+
* @param plugin - Lighthouse plugin instance
|
|
50
|
+
* @param auditSlug - Optional audit slug; if omitted, includes all audits
|
|
51
|
+
* @param auditWeight - Optional weight for the ref(s)
|
|
52
|
+
* @returns Array of category refs, expanded for each URL in multi-URL configs
|
|
53
|
+
*/
|
|
54
|
+
export function lighthouseAuditRefs(plugin, auditSlug, auditWeight) {
|
|
55
|
+
const context = validate(pluginUrlContextSchema, plugin.context);
|
|
56
|
+
if (auditSlug) {
|
|
57
|
+
return expandCategoryRefs({
|
|
58
|
+
plugin: LIGHTHOUSE_PLUGIN_SLUG,
|
|
59
|
+
slug: auditSlug,
|
|
60
|
+
type: 'audit',
|
|
61
|
+
weight: auditWeight,
|
|
62
|
+
}, context);
|
|
63
|
+
}
|
|
64
|
+
return plugin.audits.flatMap(({ slug }) => expandCategoryRefs({ plugin: LIGHTHOUSE_PLUGIN_SLUG, slug, type: 'audit' }, context));
|
|
65
|
+
}
|
|
66
|
+
export function lighthouseGroupSlugs(plugin) {
|
|
67
|
+
if (!plugin.groups) {
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
return extractGroupSlugs(plugin.groups).filter(isLighthouseGroupSlug);
|
|
71
|
+
}
|
|
19
72
|
class NotImplementedError extends Error {
|
|
20
73
|
constructor(plural, slugs) {
|
|
21
74
|
const formattedSlugs = slugs.map(slug => `"${slug}"`).join(', ');
|
package/src/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/lib/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,QAAQ,GACT,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,sBAAsB,EACtB,OAAO,GACR,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAIhF;;GAEG;AAC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