-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
extension(tsc): add type checking to extension entry points #5346
Changes from 6 commits
c9b8eef
d42535a
fae3482
c3db014
8d5df1d
830a6fe
64b4802
9d83fe9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* 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. | ||
*/ | ||
// @ts-nocheck | ||
'use strict'; | ||
|
||
const Runner = require('./runner'); | ||
|
@@ -30,16 +29,17 @@ const Config = require('./config/config'); | |
* @param {string} url | ||
* @param {LH.Flags} flags | ||
* @param {LH.Config.Json|undefined} configJSON | ||
* @return {Promise<LH.RunnerResult>} | ||
* @return {Promise<LH.RunnerResult|undefined>} | ||
*/ | ||
function lighthouse(url, flags = {}, configJSON) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a breaking change for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we support fully optional I can add a manual cast of a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
yeah, I think that's basically what we need to do. Handy to have output from yargs, but then our optional flags fed into Config is a different beast (and it looks like completely optional is fine). Ok if we do a future "Make Flags Good" PR while leaving this with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
function lighthouse(url, flags, configJSON) { | ||
return Promise.resolve().then(_ => { | ||
// set logging preferences, assume quiet | ||
flags.logLevel = flags.logLevel || 'error'; | ||
log.setLevel(flags.logLevel); | ||
|
||
// Use ConfigParser to generate a valid config file | ||
const config = new Config(configJSON, flags); | ||
// @ts-ignore - TODO(bckenny): type checking for Config | ||
const config = /** @type {LH.Config} */ (new Config(configJSON, flags)); | ||
const connection = new ChromeProtocol(flags.port, flags.hostname); | ||
|
||
// kick off a lighthouse run | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,6 @@ | |
"default_locale": "en", | ||
"background": { | ||
"scripts": [ | ||
"scripts/chromereload.js", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we just delete this are we using manifest canary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm good with deleting, but we should probably delete the actual extension in that case? @paulirish There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ill delete canary extension now |
||
"scripts/lighthouse-ext-background.js" | ||
], | ||
"persistent": false | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,20 +11,24 @@ const Config = require('../../../lighthouse-core/config/config'); | |
const defaultConfig = require('../../../lighthouse-core/config/default-config.js'); | ||
const log = require('lighthouse-logger'); | ||
|
||
/** @typedef {import('../../../lighthouse-core/gather/connections/connection.js')} Connection */ | ||
|
||
/** | ||
* @param {!Connection} connection | ||
* @param {Connection} connection | ||
* @param {string} url | ||
* @param {!Object} options Lighthouse options. | ||
* @param {!Array<string>} categoryIDs Name values of categories to include. | ||
* @return {!Promise} | ||
* @param {{flags: LH.Flags}} options Lighthouse options. | ||
* @param {Array<string>} categoryIDs Name values of categories to include. | ||
* @param {(url?: string) => void} updateBadgeFn | ||
* @return {Promise<LH.RunnerResult|void>} | ||
*/ | ||
window.runLighthouseForConnection = function( | ||
connection, url, options, categoryIDs, | ||
updateBadgeFn = function() { }) { | ||
const config = new Config({ | ||
function runLighthouseForConnection( | ||
connection, url, options, categoryIDs, | ||
updateBadgeFn = function() { }) { | ||
// @ts-ignore - TODO(bckenny): type checking for Config | ||
const config = /** @type {LH.Config} */ (new Config({ | ||
extends: 'lighthouse:default', | ||
settings: {onlyCategories: categoryIDs}, | ||
}, options.flags); | ||
}, options.flags)); | ||
|
||
// Add url and config to fresh options object. | ||
const runOptions = Object.assign({}, options, {url, config}); | ||
|
@@ -39,30 +43,46 @@ window.runLighthouseForConnection = function( | |
updateBadgeFn(); | ||
throw err; | ||
}); | ||
}; | ||
} | ||
|
||
/** | ||
* @param {!RawProtocol.Port} port | ||
* @param {RawProtocol.Port} port | ||
* @param {string} url | ||
* @param {!Object} options Lighthouse options. | ||
* @param {!Array<string>} categoryIDs Name values of categories to include. | ||
* @return {!Promise} | ||
* @param {{flags: LH.Flags}} options Lighthouse options. | ||
* @param {Array<string>} categoryIDs Name values of categories to include. | ||
* @return {Promise<LH.RunnerResult|void>} | ||
*/ | ||
window.runLighthouseInWorker = function(port, url, options, categoryIDs) { | ||
function runLighthouseInWorker(port, url, options, categoryIDs) { | ||
// Default to 'info' logging level. | ||
log.setLevel('info'); | ||
const connection = new RawProtocol(port); | ||
return window.runLighthouseForConnection(connection, url, options, categoryIDs); | ||
}; | ||
return runLighthouseForConnection(connection, url, options, categoryIDs); | ||
} | ||
|
||
/** | ||
* Returns list of top-level categories from the default config. | ||
* @return {!Array<{title: string, id: string}>} | ||
* @return {Array<{title: string, id: string}>} | ||
*/ | ||
window.getDefaultCategories = function() { | ||
function getDefaultCategories() { | ||
return Config.getCategories(defaultConfig); | ||
}; | ||
} | ||
|
||
window.listenForStatus = function(listenCallback) { | ||
/** @param {(status: [string, string, string]) => void} listenCallback */ | ||
function listenForStatus(listenCallback) { | ||
log.events.addListener('status', listenCallback); | ||
}; | ||
} | ||
|
||
if (typeof module !== 'undefined' && module.exports) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. really dig this. thanks. |
||
module.exports = { | ||
runLighthouseForConnection, | ||
runLighthouseInWorker, | ||
getDefaultCategories, | ||
listenForStatus, | ||
}; | ||
} else { | ||
// If not require()d, expose on window for devtools, other consumers of file. | ||
// @ts-ignore | ||
window.runLighthouseInWorker = runLighthouseInWorker; | ||
// @ts-ignore | ||
window.listenForStatus = listenForStatus; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
turns out this was never working as an interface for tsc (@interface has closure support only). Making a typedef so can be imported elsewhere