@@ -13,60 +13,44 @@ const { audits, categories } = defaultConfig;
1313
1414export const PLUGIN_SLUG = 'lighthouse' ;
1515
16- // Initialize with empty arrays - will be populated by initializeLighthouseConstants()
17- export let LIGHTHOUSE_NAVIGATION_AUDITS : Audit [ ] = [ ] ;
18- export let LIGHTHOUSE_GROUPS : Group [ ] = [ ] ;
16+ const allRawLighthouseAudits = await Promise . all (
17+ ( audits ?? [ ] ) . map ( loadLighthouseAudit ) ,
18+ ) ;
1919
20- // Lazy initialization flag
21- let initialized = false ;
20+ export const LIGHTHOUSE_NAVIGATION_AUDITS : Audit [ ] = allRawLighthouseAudits
21+ // This plugin only supports the "navigation" mode of Lighthouse in the current implementation
22+ // If we don't exclude other audits we throw in the plugin output validation as some of the provided audits are not included in `lighthouse-report.json`
23+ . filter (
24+ audit =>
25+ audit . meta . supportedModes == null ||
26+ ( Array . isArray ( audit . meta . supportedModes ) &&
27+ audit . meta . supportedModes . includes ( 'navigation' ) ) ,
28+ )
29+ . map ( audit => ( {
30+ slug : audit . meta . id ,
31+ title : getMetaString ( audit . meta . title ) ,
32+ description : getMetaString ( audit . meta . description ) ,
33+ } ) ) ;
2234
23- // Call this once before using the constants
24- export async function initializeLighthouseConstants ( ) : Promise < void > {
25- if ( initialized ) {
26- return ;
27- }
28-
29- const allRawLighthouseAudits = await Promise . all (
30- ( audits ?? [ ] ) . map ( loadLighthouseAudit ) ,
31- ) ;
32-
33- LIGHTHOUSE_NAVIGATION_AUDITS = allRawLighthouseAudits
34- // This plugin only supports the "navigation" mode of Lighthouse in the current implementation
35- // If we don't exclude other audits we throw in the plugin output validation as some of the provided audits are not included in `lighthouse-report.json`
36- . filter (
37- audit =>
38- audit . meta . supportedModes == null ||
39- ( Array . isArray ( audit . meta . supportedModes ) &&
40- audit . meta . supportedModes . includes ( 'navigation' ) ) ,
41- )
42- . map ( audit => ( {
43- slug : audit . meta . id ,
44- title : getMetaString ( audit . meta . title ) ,
45- description : getMetaString ( audit . meta . description ) ,
46- } ) ) ;
35+ const navigationAuditSlugs = new Set (
36+ LIGHTHOUSE_NAVIGATION_AUDITS . map ( ( { slug } ) => slug ) ,
37+ ) ;
4738
48- const navigationAuditSlugs = new Set (
49- LIGHTHOUSE_NAVIGATION_AUDITS . map ( ( { slug } ) => slug ) ,
50- ) ;
51-
52- LIGHTHOUSE_GROUPS = Object . entries ( categories ?? { } ) . map (
53- ( [ id , category ] ) => ( {
54- slug : id ,
55- title : getMetaString ( category . title ) ,
56- ...( category . description && {
57- description : getMetaString ( category . description ) ,
58- } ) ,
59- refs : category . auditRefs
60- . filter ( ( { id : auditSlug } ) => navigationAuditSlugs . has ( auditSlug ) )
61- . map ( ref => ( {
62- slug : ref . id ,
63- weight : ref . weight ,
64- } ) ) ,
39+ export const LIGHTHOUSE_GROUPS : Group [ ] = Object . entries ( categories ?? { } ) . map (
40+ ( [ id , category ] ) => ( {
41+ slug : id ,
42+ title : getMetaString ( category . title ) ,
43+ ...( category . description && {
44+ description : getMetaString ( category . description ) ,
6545 } ) ,
66- ) ;
67-
68- initialized = true ;
69- }
46+ refs : category . auditRefs
47+ . filter ( ( { id : auditSlug } ) => navigationAuditSlugs . has ( auditSlug ) )
48+ . map ( ref => ( {
49+ slug : ref . id ,
50+ weight : ref . weight ,
51+ } ) ) ,
52+ } ) ,
53+ ) ;
7054
7155function getMetaString ( value : string | IcuMessage ) : string {
7256 if ( typeof value === 'string' ) {
0 commit comments