Skip to content

Commit

Permalink
core: convert core d.ts files to modules (#12880)
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankenny authored Aug 9, 2021
1 parent 8230ff5 commit 4c03c6d
Show file tree
Hide file tree
Showing 15 changed files with 1,643 additions and 1,617 deletions.
1,628 changes: 811 additions & 817 deletions types/artifacts.d.ts

Large diffs are not rendered by default.

18 changes: 11 additions & 7 deletions types/audit-details.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

import {IcuMessage} from './i18n';
import Treemap from './treemap';
import {Artifacts} from './artifacts';

type Details =
Details.CriticalRequestChain |
Details.DebugData |
Expand Down Expand Up @@ -79,7 +83,7 @@ declare module Details {
* and the locations of interesting nodes.
* Used by element screenshots renderer.
*/
interface FullPageScreenshot extends LH.Artifacts.FullPageScreenshot {
interface FullPageScreenshot extends Artifacts.FullPageScreenshot {
type: 'full-page-screenshot';
}

Expand Down Expand Up @@ -111,14 +115,14 @@ declare module Details {

interface TreemapData {
type: 'treemap-data';
nodes: LH.Treemap.Node[];
nodes: Treemap.Node[];
}

/** String enum of possible types of values found within table items. */
type ItemValueType = 'bytes' | 'code' | 'link' | 'ms' | 'multi' | 'node' | 'source-location' | 'numeric' | 'text' | 'thumbnail' | 'timespanMs' | 'url';

/** Possible types of values found within table items. */
type ItemValue = string | number | boolean | DebugData | NodeValue | SourceLocationValue | LinkValue | UrlValue | CodeValue | NumericValue | LH.IcuMessage | TableSubItems;
type ItemValue = string | number | boolean | DebugData | NodeValue | SourceLocationValue | LinkValue | UrlValue | CodeValue | NumericValue | IcuMessage | TableSubItems;

// TODO: drop TableColumnHeading, rename OpportunityColumnHeading to TableColumnHeading and
// use that for all table-like audit details.
Expand All @@ -132,7 +136,7 @@ declare module Details {
*/
key: string|null;
/** Readable text label of the field. */
text: LH.IcuMessage | string;
text: IcuMessage | string;
/**
* The data format of the column of values being described. Usually
* those values will be primitives rendered as this type, but the values
Expand Down Expand Up @@ -164,7 +168,7 @@ declare module Details {
*/
key: string|null;
/** Readable text label of the field. */
label: LH.IcuMessage | string;
label: IcuMessage | string;
/**
* The data format of the column of values being described. Usually
* those values will be primitives rendered as this type, but the values
Expand Down Expand Up @@ -198,7 +202,7 @@ declare module Details {
*/
interface CodeValue {
type: 'code';
value: LH.IcuMessage | string;
value: IcuMessage | string;
}

/**
Expand All @@ -222,7 +226,7 @@ declare module Details {
lhId?: string;
path?: string;
selector?: string;
boundingRect?: LH.Artifacts.Rect;
boundingRect?: Artifacts.Rect;
/** An HTML snippet used to identify the node. */
snippet?: string;
/** A human-friendly text descriptor that's used to identify the node more quickly. */
Expand Down
37 changes: 21 additions & 16 deletions types/audit.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,26 @@
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

import ArbitraryEqualityMap = require('../lighthouse-core/lib/arbitrary-equality-map.js');
import {Artifacts} from './artifacts';
import AuditDetails from './audit-details';
import Config from './config';
import Gatherer from './gatherer';
import {FormattedIcu, IcuMessage} from './i18n';

declare module Audit {
export import Details = AuditDetails;

type Context = Immutable<{
/** audit options */
options: Record<string, any>;
settings: LH.Config.Settings;
settings: Config.Settings;
/**
* Nested cache for already-computed computed artifacts. Keyed first on
* the computed artifact's `name` property, then on input artifact(s).
* Values are Promises resolving to the computedArtifact result.
*/
computedCache: Map<string, LH.ArbitraryEqualityMap>;
computedCache: Map<string, ArbitraryEqualityMap>;
}>;

interface ScoreOptions {
Expand Down Expand Up @@ -47,19 +52,19 @@ declare module Audit {
/** The string identifier of the audit, in kebab case. */
id: string;
/** Short, user-visible title for the audit when successful. */
title: string | LH.IcuMessage;
title: string | IcuMessage;
/** Short, user-visible title for the audit when failing. */
failureTitle?: string | LH.IcuMessage;
failureTitle?: string | IcuMessage;
/** A more detailed description that describes why the audit is important and links to Lighthouse documentation on the audit; markdown links supported. */
description: string | LH.IcuMessage;
description: string | IcuMessage;
/** A list of the members of LH.Artifacts that must be present for the audit to execute. */
requiredArtifacts: Array<keyof LH.Artifacts>;
requiredArtifacts: Array<keyof Artifacts>;
/** A list of the members of LH.Artifacts that augment the audit, but aren't necessary. For internal use only with experimental-config. */
__internalOptionalArtifacts?: Array<keyof LH.Artifacts>;
__internalOptionalArtifacts?: Array<keyof Artifacts>;
/** A string identifying how the score should be interpreted for display. */
scoreDisplayMode?: Audit.ScoreDisplayMode;
/** A list of gather modes that this audit is applicable to. */
supportedModes?: LH.Gatherer.GatherMode[],
supportedModes?: Gatherer.GatherMode[],
}

interface ByteEfficiencyItem extends AuditDetails.OpportunityItem {
Expand All @@ -76,18 +81,18 @@ declare module Audit {
/** The scored value of the audit, provided in the range `0-1`, or null if `scoreDisplayMode` indicates not scored. */
score: number | null;
/** The i18n'd string value that the audit wishes to display for its results. This value is not necessarily the string version of the `numericValue`. */
displayValue?: string | LH.IcuMessage;
displayValue?: string | IcuMessage;
/** An explanation of why the audit failed on the test page. */
explanation?: string | LH.IcuMessage;
explanation?: string | IcuMessage;
/** Error message from any exception thrown while running this audit. */
errorMessage?: string | LH.IcuMessage;
warnings?: Array<string | LH.IcuMessage>;
errorMessage?: string | IcuMessage;
warnings?: Array<string | IcuMessage>;
/** Overrides scoreDisplayMode with notApplicable if set to true */
notApplicable?: boolean;
/** Extra information about the page provided by some types of audits, in one of several possible forms that can be rendered in the HTML report. */
details?: AuditDetails;
/** If an audit encounters unusual execution circumstances, strings can be put in this optional array to add top-level warnings to the LHR. */
runWarnings?: Array<LH.IcuMessage>;
runWarnings?: Array<IcuMessage>;
}

/** The Audit.Product type for audits that do not return a `numericValue`. */
Expand Down Expand Up @@ -137,15 +142,15 @@ declare module Audit {
/** The unit of `numericValue`, used when the consumer wishes to convert numericValue to a display string. */
numericUnit?: string;
/** Extra information about the page provided by some types of audits, in one of several possible forms that can be rendered in the HTML report. */
details?: LH.FormattedIcu<AuditDetails>;
details?: FormattedIcu<AuditDetails>;
}

interface Results {
[metric: string]: Result;
}

type MultiCheckAuditP1 = Partial<Record<LH.Artifacts.ManifestValueCheckID, boolean>>;
type MultiCheckAuditP2 = Partial<LH.Artifacts.ManifestValues>;
type MultiCheckAuditP1 = Partial<Record<Artifacts.ManifestValueCheckID, boolean>>;
type MultiCheckAuditP2 = Partial<Artifacts.ManifestValues>;
interface MultiCheckAuditP3 {
failures: Array<string>;
manifestValues?: undefined;
Expand Down
99 changes: 47 additions & 52 deletions types/budget.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,57 @@
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

declare global {
module LH {
/**
* The performance budget interface.
* More info: https://github.com/GoogleChrome/budget.json
*/
export interface Budget {
/** Budget options */
options?: Budget.Options;
/**
* Indicates which pages a budget applies to. Uses the robots.txt format.
* If it is not supplied, the budget applies to all pages.
* More info on robots.txt: https://developers.google.com/search/reference/robots_txt#url-matching-based-on-path-values
*/
path?: string;
/** Budgets based on resource count. */
resourceCounts?: Array<Budget.ResourceBudget>;
/** Budgets based on resource size. */
resourceSizes?: Array<Budget.ResourceBudget>;
/** Budgets based on timing metrics. */
timings?: Array<Budget.TimingBudget>;
}
/**
* The performance budget interface.
* More info: https://github.com/GoogleChrome/budget.json
*/
interface Budget {
/** Budget options */
options?: Budget.Options;
/**
* Indicates which pages a budget applies to. Uses the robots.txt format.
* If it is not supplied, the budget applies to all pages.
* More info on robots.txt: https://developers.google.com/search/reference/robots_txt#url-matching-based-on-path-values
*/
path?: string;
/** Budgets based on resource count. */
resourceCounts?: Array<Budget.ResourceBudget>;
/** Budgets based on resource size. */
resourceSizes?: Array<Budget.ResourceBudget>;
/** Budgets based on timing metrics. */
timings?: Array<Budget.TimingBudget>;
}

module Budget {
export interface ResourceBudget {
/** The resource type that a budget applies to. */
resourceType: ResourceType;
/** Budget for resource. Depending on context, this is either the count or size (KiB) of a resource. */
budget: number;
}
declare module Budget {
interface ResourceBudget {
/** The resource type that a budget applies to. */
resourceType: ResourceType;
/** Budget for resource. Depending on context, this is either the count or size (KiB) of a resource. */
budget: number;
}

export interface TimingBudget {
/** The type of timing metric. */
metric: TimingMetric;
/** Budget for timing measurement, in milliseconds. */
budget: number;
}
interface TimingBudget {
/** The type of timing metric. */
metric: TimingMetric;
/** Budget for timing measurement, in milliseconds. */
budget: number;
}

export interface Options {
/**
* List of hostnames used to classify resources as 1st or 3rd party.
* Wildcards can optionally be used to match a hostname and all of its subdomains.
* For example e.g.: "*.news.gov.uk" matches both "news.gov.uk" and "en.news.gov.uk"
* If this property is not set, the root domain and all its subdomains are considered first party.
*/
firstPartyHostnames?: Array<string>;
}
interface Options {
/**
* List of hostnames used to classify resources as 1st or 3rd party.
* Wildcards can optionally be used to match a hostname and all of its subdomains.
* For example e.g.: "*.news.gov.uk" matches both "news.gov.uk" and "en.news.gov.uk"
* If this property is not set, the root domain and all its subdomains are considered first party.
*/
firstPartyHostnames?: Array<string>;
}

/** Supported timing metrics. */
export type TimingMetric = 'first-contentful-paint' | 'interactive' | 'first-meaningful-paint' | 'max-potential-fid' | 'total-blocking-time' | 'speed-index' | 'largest-contentful-paint' | 'cumulative-layout-shift';
/** Supported timing metrics. */
type TimingMetric = 'first-contentful-paint' | 'interactive' | 'first-meaningful-paint' | 'max-potential-fid' | 'total-blocking-time' | 'speed-index' | 'largest-contentful-paint' | 'cumulative-layout-shift';

/** Supported values for the resourceType property of a ResourceBudget. */
export type ResourceType = 'stylesheet' | 'image' | 'media' | 'font' | 'script' | 'document' | 'other' | 'total' | 'third-party';
}
}
/** Supported values for the resourceType property of a ResourceBudget. */
type ResourceType = 'stylesheet' | 'image' | 'media' | 'font' | 'script' | 'document' | 'other' | 'total' | 'third-party';
}

// empty export to keep file a module
export {}
export default Budget;
Loading

0 comments on commit 4c03c6d

Please sign in to comment.