-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Conversation
@@ -10,22 +10,11 @@ const Connection = require('./connection.js'); | |||
/* eslint-disable no-unused-vars */ | |||
|
|||
/** | |||
* @interface |
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
@@ -1,29 +0,0 @@ | |||
/** |
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.
I don't think anyone uses this, correct? Just came with the extension generator :)
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.
i do sometimes but dont most of the time. happy to get rid of it.
@@ -12,8 +12,7 @@ | |||
"default_locale": "en", | |||
"background": { | |||
"scripts": [ | |||
"scripts/chromereload.js", |
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.
should we just delete this are we using manifest canary?
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
ill delete canary extension now
edit: done.
ok, yeah, that's way better without the file renames :) will propose that in a future PR |
let lighthouseIsRunning = false; | ||
let latestStatusLog = []; | ||
|
||
// /** |
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.
this was disabled in February 2017. I don't think we need to leave it in anymore just in case :)
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.
HERO
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.
seems mostly good to me! 👍
}; | ||
} | ||
|
||
if (typeof module !== 'undefined' && module.exports) { |
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.
can we just comment that this is for browserify and that it's not really executed in node? this threw me a bit :)
* @param {ParentNode} context | ||
* @return {HTMLElement} | ||
*/ | ||
function find(query, context) { |
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.
we seem to always use document
, do we need context?
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.
added default of document
. WDYT?
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.
sure that sg 👍
*/ | ||
function lighthouse(url, flags = {}, configJSON) { |
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.
this is a breaking change for lighthouse('http://example.com')
in node, do we really need to do this?
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.
do we support fully optional flags
? I hadn't dug into it so I didn't pursue it ({}
isn't currently castable to LH.Flags
which is why I dropped it), but if so, agreed we should support that here.
I can add a manual cast of a {}
here, maybe, and then follow up with solidifying the flags
pipeline in a follow up?
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.
would Partial<LH.Flags>
cut it? I guess we could differentiate LH.Flags from LH.CLIFlags which is basically what's defined now
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.
would Partial<LH.Flags> cut it? I guess we could differentiate LH.Flags from LH.CLIFlags which is basically what's defined now
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 {}
default?
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.
👍
const runnerResult = await background.runLighthouseForConnection(connection, url, options, | ||
categoryIDs, updateBadgeUI); | ||
if (runnerResult) { | ||
// For now, should always be a runnerResult as the extension can't do `gatherMode` |
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.
should we throw if no runner result? seems like a fatal condition
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.
SG
chrome.runtime.onInstalled.addListener(details => { | ||
if (details.previousVersion) { | ||
// eslint-disable-next-line no-console | ||
console.log('previousVersion', details.previousVersion); | ||
} | ||
}); | ||
} | ||
|
||
if (typeof module !== 'undefined' && module.exports) { | ||
// We don't want tsc to infer an index type, so use exports intest of module.exports. |
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.
who consumes this via require
?
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.
who consumes this via require?
popup.js imports this for a typedef only. Added a comment to explain
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.
oh just for typedefs gotcha 👍 yeah comment is good
@@ -1,29 +0,0 @@ | |||
/** |
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.
i do sometimes but dont most of the time. happy to get rid of it.
let lighthouseIsRunning = false; | ||
let latestStatusLog = []; | ||
|
||
// /** |
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.
HERO
}; | ||
} | ||
|
||
if (typeof module !== 'undefined' && module.exports) { |
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.
really dig this. thanks.
return window.runLighthouseForConnection(connection, url, options, categoryIDs) | ||
.then(results => { | ||
const endTime = Date.now(); | ||
results.timing = {total: endTime - startTime}; |
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.
currently LR continues to expect a .timing.total prop.
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.
currently LR continues to expect a .timing.total prop.
this is added in runner now, so doesn't need to be done here
} else { | ||
hideRunningSubpage(); | ||
async function initPopup() { | ||
chrome.tabs.query({active: true, lastFocusedWindow: true}, function(tabs) { |
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.
is changing the order here deliberate?
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.
is changing the order here deliberate?
yeah, it used to fire off the promise to retrieve the background page and immediately run this query in parallel. Since I switched the promise.then
to await
, the query wouldn't run until after the background page had been found and the rest of the init stuff had run. Since at least siteURL
is used for the pre-populated github message in case of a thrown error, it made sense to make sure it was set before the stuff
👍 to a file-rename PR afterwards. :) |
@patrickhulce second (third?) look? |
to do this, needed to do a little import/export doctoring.
lighthouse-background.js
window
if not in node (this is how devtools uses it), otherwise exports function as a node modulelighthouse-ext-background.js
lighthouse-background.js
in module form, allowing cross-file references to work in type checking and IDE navigation. Browserify handles the require normally (before it was still required but not as a module, but wrote its exports towindow
so they were available there)window
, since this file is only ever used where there is a window, but also to a module sopopup.js
can access for type checkingpopup.js
lighthouse-ext-background.js
only for types, so still works as before, but now types of calls to the background page are checked and IDE nav, etc worksgit isn't picking up thatreverted file renaming for nowlighthouse-ext-background.js
moved toextension-background.js
, so it's treating it as a totally new file. Sorry about that. I can revert the move and do that afterwards if that's easier to review.