@code-pushup/lighthouse-plugin 0.123.0 → 0.124.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/lighthouse-plugin",
3
- "version": "0.123.0",
3
+ "version": "0.124.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.123.0",
40
- "@code-pushup/utils": "0.123.0",
39
+ "@code-pushup/models": "0.124.0",
40
+ "@code-pushup/utils": "0.124.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
@@ -6,3 +6,4 @@ 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 { lighthouseCategories, mergeLighthouseCategories, } from './lib/categories.js';
9
+ export { lighthouseSetupBinding } from './lib/binding.js';
package/src/index.js CHANGED
@@ -5,4 +5,5 @@ export { lighthouseAuditRef, lighthouseAuditRefs, lighthouseGroupRef, lighthouse
5
5
  export { lighthousePlugin } from './lib/lighthouse-plugin.js';
6
6
  export default lighthousePlugin;
7
7
  export { lighthouseCategories, mergeLighthouseCategories, } from './lib/categories.js';
8
+ export { lighthouseSetupBinding } from './lib/binding.js';
8
9
  //# sourceMappingURL=index.js.map
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,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"}
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;AAC7B,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,44 @@
1
+ import type { CategoryCodegenConfig, PluginAnswer } from '@code-pushup/models';
2
+ export declare const lighthouseSetupBinding: {
3
+ slug: string;
4
+ title: string;
5
+ packageName: string;
6
+ prompts: (_targetDir: string) => Promise<({
7
+ key: string;
8
+ message: string;
9
+ type: "input";
10
+ default: string;
11
+ choices?: undefined;
12
+ } | {
13
+ key: string;
14
+ message: string;
15
+ type: "checkbox";
16
+ choices: {
17
+ name: string;
18
+ value: string;
19
+ }[];
20
+ default: string[];
21
+ })[]>;
22
+ generateConfig: (answers: Record<string, PluginAnswer>) => {
23
+ imports: {
24
+ namedImports?: string[] | undefined;
25
+ moduleSpecifier: string;
26
+ defaultImport: string;
27
+ }[];
28
+ pluginInit: string[];
29
+ pluginDeclaration?: undefined;
30
+ categories?: undefined;
31
+ } | {
32
+ imports: {
33
+ namedImports?: string[] | undefined;
34
+ moduleSpecifier: string;
35
+ defaultImport: string;
36
+ }[];
37
+ pluginDeclaration: {
38
+ identifier: string;
39
+ expression: string;
40
+ };
41
+ pluginInit: string[];
42
+ categories: CategoryCodegenConfig[];
43
+ };
44
+ };
@@ -0,0 +1,118 @@
1
+ import { createRequire } from 'node:module';
2
+ import { answerArray, answerNonEmptyArray, singleQuote, } from '@code-pushup/utils';
3
+ import { LIGHTHOUSE_GROUP_SLUGS, LIGHTHOUSE_PLUGIN_SLUG, LIGHTHOUSE_PLUGIN_TITLE, } from './constants.js';
4
+ const { name: PACKAGE_NAME } = createRequire(import.meta.url)('../../package.json');
5
+ const DEFAULT_URL = 'http://localhost:4200';
6
+ const PLUGIN_VAR = 'lhPlugin';
7
+ const CATEGORY_TO_GROUP = {
8
+ performance: 'performance',
9
+ a11y: 'accessibility',
10
+ 'best-practices': 'best-practices',
11
+ seo: 'seo',
12
+ };
13
+ const CATEGORIES = [
14
+ {
15
+ slug: 'performance',
16
+ title: 'Performance',
17
+ description: 'Measure performance and find opportunities to speed up page loads.',
18
+ refsExpression: `lighthouseGroupRefs(${PLUGIN_VAR}, 'performance')`,
19
+ },
20
+ {
21
+ slug: 'a11y',
22
+ title: 'Accessibility',
23
+ description: 'Determine if all users access content and navigate your site effectively.',
24
+ refsExpression: `lighthouseGroupRefs(${PLUGIN_VAR}, 'accessibility')`,
25
+ },
26
+ {
27
+ slug: 'best-practices',
28
+ title: 'Best Practices',
29
+ description: 'Improve code health of your web page following these best practices.',
30
+ refsExpression: `lighthouseGroupRefs(${PLUGIN_VAR}, 'best-practices')`,
31
+ },
32
+ {
33
+ slug: 'seo',
34
+ title: 'SEO',
35
+ description: 'Ensure that your page is optimized for search engine results ranking.',
36
+ refsExpression: `lighthouseGroupRefs(${PLUGIN_VAR}, 'seo')`,
37
+ },
38
+ ];
39
+ const CATEGORY_CHOICES = CATEGORIES.map(({ slug, title }) => ({
40
+ name: title,
41
+ value: slug,
42
+ }));
43
+ const DEFAULT_CATEGORIES = CATEGORIES.map(({ slug }) => slug);
44
+ export const lighthouseSetupBinding = {
45
+ slug: LIGHTHOUSE_PLUGIN_SLUG,
46
+ title: LIGHTHOUSE_PLUGIN_TITLE,
47
+ packageName: PACKAGE_NAME,
48
+ prompts: async (_targetDir) => [
49
+ {
50
+ key: 'lighthouse.urls',
51
+ message: 'Target URL(s) (comma-separated)',
52
+ type: 'input',
53
+ default: DEFAULT_URL,
54
+ },
55
+ {
56
+ key: 'lighthouse.categories',
57
+ message: 'Lighthouse categories',
58
+ type: 'checkbox',
59
+ choices: [...CATEGORY_CHOICES],
60
+ default: [...DEFAULT_CATEGORIES],
61
+ },
62
+ ],
63
+ generateConfig: (answers) => {
64
+ const options = parseAnswers(answers);
65
+ const hasCategories = options.categories.length > 0;
66
+ const imports = [
67
+ {
68
+ moduleSpecifier: PACKAGE_NAME,
69
+ defaultImport: 'lighthousePlugin',
70
+ ...(hasCategories ? { namedImports: ['lighthouseGroupRefs'] } : {}),
71
+ },
72
+ ];
73
+ const pluginCall = formatPluginCall(options);
74
+ if (!hasCategories) {
75
+ return {
76
+ imports,
77
+ pluginInit: [`${pluginCall},`],
78
+ };
79
+ }
80
+ return {
81
+ imports,
82
+ pluginDeclaration: {
83
+ identifier: PLUGIN_VAR,
84
+ expression: pluginCall,
85
+ },
86
+ pluginInit: [`${PLUGIN_VAR},`],
87
+ categories: createCategories(options),
88
+ };
89
+ },
90
+ };
91
+ function parseAnswers(answers) {
92
+ return {
93
+ urls: answerNonEmptyArray(answers, 'lighthouse.urls', DEFAULT_URL),
94
+ categories: answerArray(answers, 'lighthouse.categories'),
95
+ };
96
+ }
97
+ function formatPluginCall({ urls, categories }) {
98
+ const formattedUrls = formatUrls(urls);
99
+ const groups = categories.flatMap(slug => {
100
+ const group = CATEGORY_TO_GROUP[slug];
101
+ return group ? [group] : [];
102
+ });
103
+ if (groups.length === 0 || groups.length === LIGHTHOUSE_GROUP_SLUGS.length) {
104
+ return `lighthousePlugin(${formattedUrls})`;
105
+ }
106
+ const onlyGroups = groups.map(singleQuote).join(', ');
107
+ return `lighthousePlugin(${formattedUrls}, { onlyGroups: [${onlyGroups}] })`;
108
+ }
109
+ function formatUrls([first, ...rest]) {
110
+ if (rest.length === 0) {
111
+ return singleQuote(first);
112
+ }
113
+ return `[${[first, ...rest].map(singleQuote).join(', ')}]`;
114
+ }
115
+ function createCategories({ categories, }) {
116
+ return CATEGORIES.filter(({ slug }) => categories.includes(slug));
117
+ }
118
+ //# sourceMappingURL=binding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binding.js","sourceRoot":"","sources":["../../../src/lib/binding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAM5C,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,gBAAgB,CAAC;AAGxB,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAC3D,oBAAoB,CACkB,CAAC;AAEzC,MAAM,WAAW,GAAG,uBAAuB,CAAC;AAC5C,MAAM,UAAU,GAAG,UAAU,CAAC;AAE9B,MAAM,iBAAiB,GAAwC;IAC7D,WAAW,EAAE,aAAa;IAC1B,IAAI,EAAE,eAAe;IACrB,gBAAgB,EAAE,gBAAgB;IAClC,GAAG,EAAE,KAAK;CACX,CAAC;AAEF,MAAM,UAAU,GAA4B;IAC1C;QACE,IAAI,EA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