/* eslint-disable strict */ /** * @license * Copyright 2018 Google LLC * SPDX-License-Identifier: Apache-2.0 */ import {Audit} from '../core/audits/audit.js'; import {SharedFlagsSettings, ConfigSettings} from './lhr/settings.js'; import Gatherer from './gatherer.js'; import {IcuMessage} from './lhr/i18n.js'; import Result from './lhr/lhr.js'; interface ClassOf { new (): T; } /** * The Lighthouse Config format. */ interface Config { extends?: 'lighthouse:default' | string; settings?: SharedFlagsSettings; artifacts?: Config.ArtifactJson[] | null; audits?: Config.AuditJson[] | null; categories?: Record | null; groups?: Record | null; plugins?: Array; } declare module Config { /** * The normalized and fully resolved config. */ interface ResolvedConfig { settings: Settings; artifacts: AnyArtifactDefn[] | null; audits: AuditDefn[] | null; categories: Record | null; groups: Record | null; } interface ArtifactJson { id: string; gatherer: GathererJson; } type GathererJson = { path: string; } | { implementation: ClassOf; } | { instance: Gatherer.GathererInstance; } | Gatherer.GathererInstance | ClassOf | string; interface CategoryJson { title: string | IcuMessage; auditRefs: AuditRefJson[]; description?: string | IcuMessage; manualDescription?: string | IcuMessage; supportedModes?: Gatherer.GatherMode[]; } interface GroupJson { title: string | IcuMessage; description?: string | IcuMessage; } type AuditJson = { path: string, options?: {}; } | { implementation: typeof Audit; options?: {}; } | typeof Audit | string; /** * Reference to an audit member of a category and how its score should be * weighted and how its results grouped with other members. */ interface AuditRefJson { id: string; weight: number; group?: string; acronym?: string; } type Settings = ConfigSettings; interface ArtifactDefn { id: string; gatherer: GathererDefn; dependencies?: TDependencies extends Gatherer.DefaultDependenciesKey ? undefined : Record, {id: string}>; } type ArtifactDefnExpander = // Lack of brackets intentional here to convert to the union of all individual dependencies. TDependencies extends Gatherer.DefaultDependenciesKey ? ArtifactDefn : ArtifactDefn type AnyArtifactDefn = ArtifactDefnExpander|ArtifactDefnExpander interface GathererDefn { implementation?: ClassOf>; instance: Gatherer.GathererInstance; path?: string; } type GathererDefnExpander = // Lack of brackets intentional here to convert to the union of all individual dependencies. TDependencies extends Gatherer.DefaultDependenciesKey ? GathererDefn : GathererDefn type AnyGathererDefn = GathererDefnExpander|GathererDefnExpander interface AuditDefn { implementation: typeof Audit; path?: string; options: {}; } // TODO: For now, these are unchanged from JSON and Result versions. Need to harmonize. interface AuditRef extends AuditRefJson {} interface Category extends CategoryJson { auditRefs: AuditRef[]; } interface Group extends GroupJson {} interface Plugin { /** Optionally provide more audits to run in addition to those specified by the base config. */ audits?: Array<{path: string}>; /** Provide a category to display the plugin results in the report. */ category: Config.Category; /** Optionally provide more groups in addition to those specified by the base config. */ groups?: Record; } type Merge = { , U extends Record>(base: T|null|undefined, extension: U, overwriteArrays?: boolean): T & U; , U extends Array>(base: T|null|undefined, extension: T, overwriteArrays?: boolean): T & U; } } export default Config;