diff --git a/package.json b/package.json index f0577056f0c9..9ffefcec24ff 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "9.2.0", "description": "Automated auditing, performance metrics, and best practices for the web.", "main": "./lighthouse-core/index.js", + "types": "./types/lighthouse.js", "bin": { "lighthouse": "./lighthouse-cli/index.js", "chrome-debug": "./lighthouse-core/scripts/manual-chrome-launcher.js", diff --git a/types/lighthouse.d.ts b/types/lighthouse.d.ts new file mode 100644 index 000000000000..d3d5b3f89be1 --- /dev/null +++ b/types/lighthouse.d.ts @@ -0,0 +1,60 @@ +/// + +export = lighthouse; +/** + * Run Lighthouse. + * @param {string=} url The URL to test. Optional if running in auditMode. + * @param {LH.Flags=} flags Optional settings for the Lighthouse run. If present, + * they will override any settings in the config. + * @param {LH.Config.Json=} configJSON Configuration for the Lighthouse run. If + * not present, the default config is used. + * @param {Connection=} userConnection + * @return {Promise} + */ +declare function lighthouse(url?: string, flags?: LH.Flags, configJSON?: LH.Config.Json, userConnection?: Connection): Promise; +declare namespace lighthouse { + export { generateConfig, getAuditList, traceCategories, Audit, Gatherer, NetworkRecords, Connection }; +} +/** + * Generate a Lighthouse Config. + * @param {LH.Config.Json=} configJson Configuration for the Lighthouse run. If + * not present, the default config is used. + * @param {LH.Flags=} flags Optional settings for the Lighthouse run. If present, + * they will override any settings in the config. + * @return {Config} + */ +declare function generateConfig(configJson?: LH.Config.Json, flags?: LH.Flags): LH.Config.Json; +declare function getAuditList(): string[]; +declare function traceCategories(): string[]; +declare var Audit: typeof LH.Audit; +declare var Gatherer: LH.Gatherer.GathererInstance; + +declare class Connection { + constructor(); + // Not implemented, will throw currently + connect(): Promise; + disconnect(): Promise; + wsEndpoint(): Promise; + + sendCommand( + method: C, + sessionId: string | undefined, + paramArgs: LH.CrdpCommands[C]['paramsType'] + ): Promise; + on(eventName: 'protocolevent', cb: (arg0: LH.Protocol.RawEventMessage) => void): void; + off(eventName: 'protocolevent', cb: (arg0: LH.Protocol.RawEventMessage) => void): void; + protected sendRawMessage(message: string): void; + protected handleRawMessage(message: string): void; + emitProtocolEvent(eventMessage: LH.Protocol.RawEventMessage): void; + protected dispose(): void; +} + +type NetworkRecords_Return = Promise>; +declare class NetworkRecords_ { + static compute_(devtoolsLog: LH.DevtoolsLog): NetworkRecords_Return +} + +declare var NetworkRecords: NetworkRecords_ & { + request: (dependencies: LH.DevtoolsLog, context: LH.Artifacts.ComputedContext) + => NetworkRecords_Return +} \ No newline at end of file