@code-pushup/lighthouse-plugin 0.86.0 → 0.87.1
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 +3 -3
- package/src/index.d.ts +1 -1
- package/src/index.js.map +1 -1
- package/src/lib/lighthouse-plugin.d.ts +3 -3
- package/src/lib/lighthouse-plugin.js +2 -1
- package/src/lib/lighthouse-plugin.js.map +1 -1
- package/src/lib/merge-categories.d.ts +4 -7
- package/src/lib/merge-categories.js +7 -46
- package/src/lib/merge-categories.js.map +1 -1
- package/src/lib/processing.d.ts +0 -12
- package/src/lib/processing.js +2 -62
- package/src/lib/processing.js.map +1 -1
- package/src/lib/runner/runner.js +2 -3
- package/src/lib/runner/runner.js.map +1 -1
- package/src/lib/types.d.ts +0 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@code-pushup/lighthouse-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.87.1",
|
|
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.87.1",
|
|
40
|
+
"@code-pushup/utils": "0.87.1",
|
|
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
|
@@ -2,7 +2,7 @@ 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
4
|
export { lighthouseAuditRef, lighthouseGroupRef } from './lib/utils.js';
|
|
5
|
-
export type { LighthouseGroupSlug, LighthouseOptions
|
|
5
|
+
export type { LighthouseGroupSlug, LighthouseOptions } from './lib/types.js';
|
|
6
6
|
export { lighthousePlugin } from './lib/lighthouse-plugin.js';
|
|
7
7
|
export default lighthousePlugin;
|
|
8
8
|
export { mergeLighthouseCategories } from './lib/merge-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,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;
|
|
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,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAExE,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,eAAe,gBAAgB,CAAC;AAChC,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { PluginConfig } from '@code-pushup/models';
|
|
2
|
-
import type { LighthouseOptions
|
|
3
|
-
export declare function lighthousePlugin(urls:
|
|
1
|
+
import type { PluginConfig, PluginUrls } from '@code-pushup/models';
|
|
2
|
+
import type { LighthouseOptions } from './types.js';
|
|
3
|
+
export declare function lighthousePlugin(urls: PluginUrls, flags?: LighthouseOptions): PluginConfig;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
|
+
import { normalizeUrlInput } from '@code-pushup/utils';
|
|
2
3
|
import { LIGHTHOUSE_PLUGIN_SLUG } from './constants.js';
|
|
3
4
|
import { normalizeFlags } from './normalize-flags.js';
|
|
4
|
-
import {
|
|
5
|
+
import { processAuditsAndGroups } from './processing.js';
|
|
5
6
|
import { createRunnerFunction } from './runner/runner.js';
|
|
6
7
|
export function lighthousePlugin(urls, flags) {
|
|
7
8
|
const { skipAudits, onlyAudits, onlyCategories, scoreTargets, ...unparsedFlags } = normalizeFlags(flags ?? {});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lighthouse-plugin.js","sourceRoot":"","sources":["../../../src/lib/lighthouse-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"lighthouse-plugin.js","sourceRoot":"","sources":["../../../src/lib/lighthouse-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAG1D,MAAM,UAAU,gBAAgB,CAC9B,IAAgB,EAChB,KAAyB;IAEzB,MAAM,EACJ,UAAU,EACV,UAAU,EACV,cAAc,EACd,YAAY,EACZ,GAAG,aAAa,EACjB,GAAG,cAAc,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;IAEhC,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAElE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,sBAAsB,CAAC,cAAc,EAAE;QAChE,UAAU;QACV,UAAU;QACV,cAAc;KACf,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAChD,oBAAoB,CACkB,CAAC;IAEzC,OAAO;QACL,IAAI,EAAE,sBAAsB;QAC5B,WAAW,EAAE,WAAW,CAAC,IAAI;QAC7B,OAAO,EAAE,WAAW,CAAC,OAAO;QAC5B,KAAK,EAAE,YAAY;QACnB,IAAI,EAAE,YAAY;QAClB,MAAM;QACN,MAAM;QACN,MAAM,EAAE,oBAAoB,CAAC,cAAc,EAAE;YAC3C,UAAU;YACV,UAAU;YACV,cAAc;YACd,GAAG,aAAa;SACjB,CAAC;QACF,OAAO;QACP,GAAG,CAAC,YAAY,IAAI,EAAE,YAAY,EAAE,CAAC;KACtC,CAAC;AACJ,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { CategoryConfig, Group, PluginConfig } from '@code-pushup/models';
|
|
2
|
-
import
|
|
2
|
+
import { type PluginUrlContext } from '@code-pushup/utils';
|
|
3
|
+
import type { LighthouseGroupSlug } from './types.js';
|
|
3
4
|
/**
|
|
4
5
|
* Expands and aggregates categories for multi-URL Lighthouse runs.
|
|
5
6
|
*
|
|
@@ -24,18 +25,14 @@ export declare function mergeLighthouseCategories(plugin: Pick<PluginConfig, 'gr
|
|
|
24
25
|
* Creates a category config for a Lighthouse group, expanding it for each URL.
|
|
25
26
|
* Only used when user categories are not provided.
|
|
26
27
|
*/
|
|
27
|
-
export declare function createAggregatedCategory(groupSlug: LighthouseGroupSlug, context:
|
|
28
|
+
export declare function createAggregatedCategory(groupSlug: LighthouseGroupSlug, context: PluginUrlContext): CategoryConfig;
|
|
28
29
|
/**
|
|
29
30
|
* Expands all refs (groups and audits) in a user-defined category for each URL.
|
|
30
31
|
* Used when user categories are provided.
|
|
31
32
|
*/
|
|
32
|
-
export declare function expandAggregatedCategory(category: CategoryConfig, context:
|
|
33
|
+
export declare function expandAggregatedCategory(category: CategoryConfig, context: PluginUrlContext): CategoryConfig;
|
|
33
34
|
/**
|
|
34
35
|
* Extracts unique, unsuffixed group slugs from a list of groups.
|
|
35
36
|
* Useful for deduplicating and normalizing group slugs when generating categories.
|
|
36
37
|
*/
|
|
37
38
|
export declare function extractGroupSlugs(groups: Group[]): LighthouseGroupSlug[];
|
|
38
|
-
export declare class ContextValidationError extends Error {
|
|
39
|
-
constructor(message: string);
|
|
40
|
-
}
|
|
41
|
-
export declare function validateContext(context: PluginConfig['context']): asserts context is LighthouseContext;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { createCategoryRefs, expandCategoryRefs, removeIndex, shouldExpandForUrls, validateUrlContext, } from '@code-pushup/utils';
|
|
1
2
|
import { LIGHTHOUSE_GROUP_SLUGS, LIGHTHOUSE_PLUGIN_SLUG } from './constants.js';
|
|
2
|
-
import { orderSlug, shouldExpandForUrls } from './processing.js';
|
|
3
3
|
import { LIGHTHOUSE_GROUPS } from './runner/constants.js';
|
|
4
4
|
import { isLighthouseGroupSlug } from './utils.js';
|
|
5
5
|
/**
|
|
@@ -25,7 +25,7 @@ export function mergeLighthouseCategories(plugin, categories) {
|
|
|
25
25
|
if (!plugin.groups || plugin.groups.length === 0) {
|
|
26
26
|
return categories ?? [];
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
validateUrlContext(plugin.context);
|
|
29
29
|
if (!categories) {
|
|
30
30
|
return createCategories(plugin.groups, plugin.context);
|
|
31
31
|
}
|
|
@@ -57,14 +57,7 @@ export function createAggregatedCategory(groupSlug, context) {
|
|
|
57
57
|
slug: group.slug,
|
|
58
58
|
title: group.title,
|
|
59
59
|
...(group.description && { description: group.description }),
|
|
60
|
-
refs:
|
|
61
|
-
plugin: LIGHTHOUSE_PLUGIN_SLUG,
|
|
62
|
-
slug: shouldExpandForUrls(context.urlCount)
|
|
63
|
-
? orderSlug(group.slug, i)
|
|
64
|
-
: group.slug,
|
|
65
|
-
type: 'group',
|
|
66
|
-
weight: resolveWeight(context.weights, i),
|
|
67
|
-
})),
|
|
60
|
+
refs: createCategoryRefs(group.slug, LIGHTHOUSE_PLUGIN_SLUG, context),
|
|
68
61
|
};
|
|
69
62
|
}
|
|
70
63
|
/**
|
|
@@ -74,18 +67,9 @@ export function createAggregatedCategory(groupSlug, context) {
|
|
|
74
67
|
export function expandAggregatedCategory(category, context) {
|
|
75
68
|
return {
|
|
76
69
|
...category,
|
|
77
|
-
refs: category.refs.flatMap(ref =>
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
...ref,
|
|
81
|
-
slug: shouldExpandForUrls(context.urlCount)
|
|
82
|
-
? orderSlug(ref.slug, i)
|
|
83
|
-
: ref.slug,
|
|
84
|
-
weight: resolveWeight(context.weights, i, ref.weight),
|
|
85
|
-
}));
|
|
86
|
-
}
|
|
87
|
-
return [ref];
|
|
88
|
-
}),
|
|
70
|
+
refs: category.refs.flatMap(ref => ref.plugin === LIGHTHOUSE_PLUGIN_SLUG
|
|
71
|
+
? expandCategoryRefs(ref, context)
|
|
72
|
+
: [ref]),
|
|
89
73
|
};
|
|
90
74
|
}
|
|
91
75
|
/**
|
|
@@ -93,30 +77,7 @@ export function expandAggregatedCategory(category, context) {
|
|
|
93
77
|
* Useful for deduplicating and normalizing group slugs when generating categories.
|
|
94
78
|
*/
|
|
95
79
|
export function extractGroupSlugs(groups) {
|
|
96
|
-
const slugs = groups.map(({ slug }) => slug
|
|
80
|
+
const slugs = groups.map(({ slug }) => removeIndex(slug));
|
|
97
81
|
return [...new Set(slugs)].filter(isLighthouseGroupSlug);
|
|
98
82
|
}
|
|
99
|
-
export class ContextValidationError extends Error {
|
|
100
|
-
constructor(message) {
|
|
101
|
-
super(`Invalid Lighthouse context: ${message}`);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
export function validateContext(context) {
|
|
105
|
-
if (!context || typeof context !== 'object') {
|
|
106
|
-
throw new ContextValidationError('must be an object');
|
|
107
|
-
}
|
|
108
|
-
const { urlCount, weights } = context;
|
|
109
|
-
if (typeof urlCount !== 'number' || urlCount < 0) {
|
|
110
|
-
throw new ContextValidationError('urlCount must be a non-negative number');
|
|
111
|
-
}
|
|
112
|
-
if (!weights || typeof weights !== 'object') {
|
|
113
|
-
throw new ContextValidationError('weights must be an object');
|
|
114
|
-
}
|
|
115
|
-
if (Object.keys(weights).length !== urlCount) {
|
|
116
|
-
throw new ContextValidationError('weights count must match urlCount');
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
function resolveWeight(weights, index, userDefinedWeight) {
|
|
120
|
-
return weights[index + 1] ?? userDefinedWeight ?? 1;
|
|
121
|
-
}
|
|
122
83
|
//# sourceMappingURL=merge-categories.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge-categories.js","sourceRoot":"","sources":["../../../src/lib/merge-categories.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"merge-categories.js","sourceRoot":"","sources":["../../../src/lib/merge-categories.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,kBAAkB,EAClB,kBAAkB,EAClB,WAAW,EACX,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,E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AAC3D,CAAC"}
|
package/src/lib/processing.d.ts
CHANGED
|
@@ -1,17 +1,5 @@
|
|
|
1
1
|
import type { Audit, Group } from '@code-pushup/models';
|
|
2
|
-
import type { LighthouseContext, LighthouseUrls } from './types.js';
|
|
3
2
|
import { type FilterOptions } from './utils.js';
|
|
4
|
-
export declare function orderSlug(slug: string, index: number): string;
|
|
5
|
-
export declare function shouldExpandForUrls(urlCount: number): boolean;
|
|
6
|
-
export declare function normalizeUrlInput(input: LighthouseUrls): {
|
|
7
|
-
urls: string[];
|
|
8
|
-
context: LighthouseContext;
|
|
9
|
-
};
|
|
10
|
-
export declare function extractUrls(input: LighthouseUrls): string[];
|
|
11
|
-
export declare function getWeightForUrl(input: LighthouseUrls, url: string): number;
|
|
12
|
-
export declare function getUrlIdentifier(url: string): string;
|
|
13
|
-
export declare function expandAuditsForUrls(audits: Audit[], urls: string[]): Audit[];
|
|
14
|
-
export declare function expandGroupsForUrls(groups: Group[], urls: string[]): Group[];
|
|
15
3
|
export declare function expandOptionsForUrls(options: FilterOptions, urlCount: number): FilterOptions;
|
|
16
4
|
export declare function processAuditsAndGroups(urls: string[], options: FilterOptions): {
|
|
17
5
|
audits: Audit[];
|
package/src/lib/processing.js
CHANGED
|
@@ -1,71 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { addIndex, expandAuditsForUrls, expandGroupsForUrls, shouldExpandForUrls, } from '@code-pushup/utils';
|
|
2
2
|
import { LIGHTHOUSE_GROUPS, LIGHTHOUSE_NAVIGATION_AUDITS, } from './runner/constants.js';
|
|
3
3
|
import { markSkippedAuditsAndGroups } from './utils.js';
|
|
4
|
-
export function orderSlug(slug, index) {
|
|
5
|
-
return `${slug}-${index + 1}`;
|
|
6
|
-
}
|
|
7
|
-
export function shouldExpandForUrls(urlCount) {
|
|
8
|
-
return urlCount > SINGLE_URL_THRESHOLD;
|
|
9
|
-
}
|
|
10
|
-
export function normalizeUrlInput(input) {
|
|
11
|
-
const urls = extractUrls(input);
|
|
12
|
-
const weights = Object.fromEntries(urls.map((url, index) => [index + 1, getWeightForUrl(input, url)]));
|
|
13
|
-
return {
|
|
14
|
-
urls,
|
|
15
|
-
context: {
|
|
16
|
-
urlCount: urls.length,
|
|
17
|
-
weights,
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
export function extractUrls(input) {
|
|
22
|
-
if (Array.isArray(input)) {
|
|
23
|
-
return input;
|
|
24
|
-
}
|
|
25
|
-
if (typeof input === 'string') {
|
|
26
|
-
return [input];
|
|
27
|
-
}
|
|
28
|
-
return Object.keys(input);
|
|
29
|
-
}
|
|
30
|
-
export function getWeightForUrl(input, url) {
|
|
31
|
-
if (typeof input === 'object' && !Array.isArray(input)) {
|
|
32
|
-
return input[url] ?? 1;
|
|
33
|
-
}
|
|
34
|
-
return 1;
|
|
35
|
-
}
|
|
36
|
-
export function getUrlIdentifier(url) {
|
|
37
|
-
try {
|
|
38
|
-
const { host, pathname } = new URL(url);
|
|
39
|
-
const path = pathname === '/' ? '' : pathname;
|
|
40
|
-
return `${host}${path}`;
|
|
41
|
-
}
|
|
42
|
-
catch {
|
|
43
|
-
return url;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
export function expandAuditsForUrls(audits, urls) {
|
|
47
|
-
return urls.flatMap((url, index) => audits.map(audit => ({
|
|
48
|
-
...audit,
|
|
49
|
-
slug: orderSlug(audit.slug, index),
|
|
50
|
-
title: `${audit.title} (${getUrlIdentifier(url)})`,
|
|
51
|
-
})));
|
|
52
|
-
}
|
|
53
|
-
export function expandGroupsForUrls(groups, urls) {
|
|
54
|
-
return urls.flatMap((url, index) => groups.map(group => ({
|
|
55
|
-
...group,
|
|
56
|
-
slug: orderSlug(group.slug, index),
|
|
57
|
-
title: `${group.title} (${getUrlIdentifier(url)})`,
|
|
58
|
-
refs: group.refs.map(ref => ({
|
|
59
|
-
...ref,
|
|
60
|
-
slug: orderSlug(ref.slug, index),
|
|
61
|
-
})),
|
|
62
|
-
})));
|
|
63
|
-
}
|
|
64
4
|
export function expandOptionsForUrls(options, urlCount) {
|
|
65
5
|
return Object.fromEntries(Object.entries(options).map(([key, value]) => [
|
|
66
6
|
key,
|
|
67
7
|
Array.isArray(value)
|
|
68
|
-
? value.flatMap(slug => Array.from({ length: urlCount }, (_, i) =>
|
|
8
|
+
? value.flatMap(slug => Array.from({ length: urlCount }, (_, i) => addIndex(slug, i)))
|
|
69
9
|
: value,
|
|
70
10
|
]));
|
|
71
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processing.js","sourceRoot":"","sources":["../../../src/lib/processing.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"processing.js","sourceRoot":"","sources":["../../../src/lib/processing.ts"],"names":[],"mappings":"AACA,OAAO,EACL,QAAQ,EACR,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,iBAAiB,EACjB,4BAA4B,GAC7B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAsB,0BAA0B,EAAE,MAAM,YAAY,CAAC;AAE5E,MAAM,UAAU,oBAAoB,CAClC,OAAsB,EACtB,QAAgB;IAEhB,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC;QAC5C,GAAG;QACH,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;YAClB,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CACnB,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAC9D;YACH,CAAC,CAAC,KAAK;KACV,CAAC,CACH,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,IAAc,EAAE,OAAsB;IAC3E,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACtC,OAAO,0BAA0B,CAC/B,4BAA4B,EAC5B,iBAAiB,EACjB,OAAO,CACR,CAAC;IACJ,CAAC;IACD,MAAM,cAAc,GAAG,mBAAmB,CACxC,4BAA4B,EAC5B,IAAI,CACL,CAAC;IACF,MAAM,cAAc,GAAG,mBAAmB,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;IACpE,MAAM,eAAe,GAAG,oBAAoB,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACnE,OAAO,0BAA0B,CAC/B,cAAc,EACd,cAAc,EACd,eAAe,CAChB,CAAC;AACJ,CAAC"}
|
package/src/lib/runner/runner.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { runLighthouse } from 'lighthouse/cli/run.js';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { ensureDirectoryExists, link, logger, stringifyError, } from '@code-pushup/utils';
|
|
4
|
-
import { orderSlug, shouldExpandForUrls } from '../processing.js';
|
|
3
|
+
import { addIndex, ensureDirectoryExists, link, logger, shouldExpandForUrls, stringifyError, ui, } from '@code-pushup/utils';
|
|
5
4
|
import { DEFAULT_CLI_FLAGS } from './constants.js';
|
|
6
5
|
import { enrichFlags, getConfig, normalizeAuditOutputs, toAuditOutputs, withLocalTmpDir, } from './utils.js';
|
|
7
6
|
export function createRunnerFunction(urls, flags = DEFAULT_CLI_FLAGS) {
|
|
@@ -20,7 +19,7 @@ export function createRunnerFunction(urls, flags = DEFAULT_CLI_FLAGS) {
|
|
|
20
19
|
? auditOutputs
|
|
21
20
|
: auditOutputs.map(audit => ({
|
|
22
21
|
...audit,
|
|
23
|
-
slug:
|
|
22
|
+
slug: addIndex(audit.slug, index),
|
|
24
23
|
}));
|
|
25
24
|
return [...acc, ...processedOutputs];
|
|
26
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../../../src/lib/runner/runner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EACL,qBAAqB,EACrB,IAAI,EACJ,MAAM,EACN,
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../../../src/lib/runner/runner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EACL,QAAQ,EACR,qBAAqB,EACrB,IAAI,EACJ,MAAM,EACN,mBAAmB,EACnB,cAAc,EACd,EAAE,GACH,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD,OAAO,EACL,WAAW,EACX,SAAS,EACT,qBAAqB,EACrB,cAAc,EACd,eAAe,GAChB,MAAM,YAAY,CAAC;AAEpB,MAAM,UAAU,oBAAoB,CAClC,IAAc,EACd,QAA4B,iBAAiB;IAE7C,OAAO,eAAe,CAAC,KAAK,IAA2B,EAAE;QACvD,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,KAAK,CAAC,CAAC;QACtC,MAAM,kBAAkB,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;QAC9C,MAAM,WAAW,GAAG,CAAC,mBAAmB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAEtD,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;YAC9D,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC;YACvB,IAAI,CAAC;gBACH,MAAM,aAAa,GAAG,WAAW;oBAC/B,CAAC,CAAC,kBAAkB;oB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AAI,YAAY,IAAI,IAAI,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACb,gDAAgD,IAAI,CAAC,GAAG,CAAC,EAAE,CAC5D,CAAC;IACJ,CAAC;IAED,MAAM,EAAE,GAAG,EAAE,GAAG,YAA4B,CAAC;IAE7C,OAAO,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC;AAC1D,CAAC"}
|
package/src/lib/types.d.ts
CHANGED
|
@@ -9,9 +9,3 @@ export type LighthouseOptions = ExcludeNullableProps<Partial<Omit<CliFlags, '_'
|
|
|
9
9
|
scoreTargets?: PluginScoreTargets;
|
|
10
10
|
};
|
|
11
11
|
export type LighthouseGroupSlug = (typeof LIGHTHOUSE_GROUP_SLUGS)[number];
|
|
12
|
-
export type WeightedUrl = Record<string, number>;
|
|
13
|
-
export type LighthouseUrls = string | string[] | WeightedUrl;
|
|
14
|
-
export type LighthouseContext = {
|
|
15
|
-
urlCount: number;
|
|
16
|
-
weights: Record<number, number>;
|
|
17
|
-
};
|