@@ -8,7 +8,10 @@ import {
88 TYPESCRIPT_PLUGIN_SLUG ,
99} from './constants.js' ;
1010import { normalizeCompilerOptions } from './normalize-compiler-options.js' ;
11- import type { TypescriptPluginOptions } from './types.js' ;
11+ import type {
12+ FilterOptions ,
13+ TypescriptPluginOptions ,
14+ } from './typescript-plugin.js' ;
1215
1316export function filterAuditsBySlug ( slugs ?: string [ ] ) {
1417 return ( { slug } : { slug : string } ) => {
@@ -74,7 +77,7 @@ export function getGroups(
7477
7578export function getAudits (
7679 definitive : CompilerOptions ,
77- options ?: TypescriptPluginOptions ,
80+ options ?: FilterOptions ,
7881) {
7982 return AUDITS . filter (
8083 filterAuditsByCompilerOptions ( definitive , options ?. onlyAudits ) ,
@@ -91,11 +94,16 @@ export async function getCategoryRefsFromGroups(
9194 opt ?: TypescriptPluginOptions ,
9295) : Promise < CategoryRef [ ] > {
9396 const { tsConfigPath } = opt ?? { tsConfigPath : DEFAULT_TS_CONFIG } ;
94- const definitive = await normalizeCompilerOptions ( { ...opt , tsConfigPath } ) ;
97+ // this line is duplicated in the typescriptPlugin function
98+ // to mitigate multiple file access we cache the result
99+ const compilerOptions = await normalizeCompilerOptions ( {
100+ ...opt ,
101+ tsConfigPath,
102+ } ) ;
95103 return GROUPS . map ( group => ( {
96104 ...group ,
97105 refs : group . refs . filter (
98- filterAuditsByCompilerOptions ( definitive , opt ?. onlyAudits ) ,
106+ filterAuditsByCompilerOptions ( compilerOptions , opt ?. onlyAudits ) ,
99107 ) ,
100108 } ) )
101109 . filter ( group => group . refs . length > 0 )
@@ -107,6 +115,31 @@ export async function getCategoryRefsFromGroups(
107115 } ) ) ;
108116}
109117
118+ /**
119+ * Retrieve the category references from the audits.
120+ * @param opt TSPluginOptions
121+ * @returns The array of category references
122+ */
123+ export async function getCategoryRefsFromAudits (
124+ opt ?: TypescriptPluginOptions ,
125+ ) : Promise < CategoryRef [ ] > {
126+ const { tsConfigPath } = opt ?? { tsConfigPath : DEFAULT_TS_CONFIG } ;
127+ // this line is duplicated in the typescriptPlugin function
128+ // to mitigate multiple file access we cache the result
129+ const compilerOptions = await normalizeCompilerOptions ( {
130+ ...opt ,
131+ tsConfigPath,
132+ } ) ;
133+ return AUDITS . filter (
134+ filterAuditsByCompilerOptions ( compilerOptions , opt ?. onlyAudits ) ,
135+ ) . map ( ( { slug } ) => ( {
136+ plugin : TYPESCRIPT_PLUGIN_SLUG ,
137+ slug,
138+ weight : 1 ,
139+ type : 'audit' ,
140+ } ) ) ;
141+ }
142+
110143export function logSkippedAudits ( audits : Audit [ ] ) {
111144 const skippedAudits = AUDITS . filter (
112145 audit => ! audits . some ( filtered => filtered . slug === audit . slug ) ,
0 commit comments