core(config): add support for audit/gatherer options#4394
Conversation
| } | ||
|
|
||
| const auditIds = audits.map(audit => audit.meta.name); | ||
| const auditIds = audits.map(audit => audit.implementation.meta.name); |
There was a problem hiding this comment.
I find implementation such a weird name I wanted to call it instance but I see below that it's indeed the implementation but still find it weird 😛 but maybe that's because i'm no native speaker.
|
I really like this PR! not much to say about it. I haven't tested any of it but the approach looks good. I only think we need to document the option parameter a bit. We don't want it to be used as an escape hatch to smuggle custom settings in. |
paulirish
left a comment
There was a problem hiding this comment.
Thanks for all the renames. It's great to have these things called more accurately.
A few questions below but first.. This is correct yah?
- implementation: the class of a gatherer/audit
- instance: an instance of that class/implementation
- defn: whatever is resolved into the implementation.
- Can you show me what one looks like? a gathererDefn and an auditDefn?
| return gathererDefn; | ||
| } | ||
|
|
||
| if (typeof gathererDefn.beforePass === 'function') { |
There was a problem hiding this comment.
this is for backwards compat? if so can you add a comment with the case this covers?
| return gatherers.reduce((chain, gathererDefn) => { | ||
| return chain.then(_ => { | ||
| const artifactPromise = Promise.resolve().then(_ => gatherer.pass(options)); | ||
| const gatherer = gathererDefn.instance; |
There was a problem hiding this comment.
feels like pass/beforePass shouldn't have to do this resolving on their own. can we provide instantiated gatherers instead of the config.gatherers or something?
There was a problem hiding this comment.
resolved in person, outcome: gather-runner will still need access to .instance and .options but will be oblivious to everything else
| return new GathererClass(); | ||
| const gathererPath = typeof gathererDefn === 'string' ? gathererDefn : gathererDefn.path; | ||
| const GathererClass = GatherRunner.getGathererClass( | ||
| gathererDefn.implementation || gathererPath, rootPath); |
There was a problem hiding this comment.
should we move all this into config.js? seems like it spiritually belongs over there.
There's also a lot of cases (6+?) being served by these lines:
lighthouse/lighthouse-core/gather/gather-runner.js
Lines 505 to 516 in c2652e6
I'm hoping by moving it into config, we're going to end up with something simpler. Open to ideas.
There was a problem hiding this comment.
yeah just lots of test changes 😢 I'm on it though
| return chain.then(_ => { | ||
| const artifactPromise = Promise.resolve().then(_ => gatherer.pass(options)); | ||
| const gatherer = gathererDefn.instance; | ||
| context.options = gathererDefn.options || {}; |
There was a problem hiding this comment.
at the very least let's comment that this is terrible. :)
There was a problem hiding this comment.
I'll create a new context so it won't be terrible :)
| @@ -491,14 +501,21 @@ class GatherRunner { | |||
|
|
|||
| static instantiateGatherers(passes, rootPath) { | |||
There was a problem hiding this comment.
let's do instantiateGatherers back in config so by the time gatherrunner.run is called, everything has an instance.
this'll require updating some tests. sorry 'bout that.
paulirish
left a comment
There was a problem hiding this comment.
this is gtg, though I think we should land it after we cut the 2.9.1. sgty?
| const gatherer = gathererDefn.instance; | ||
| // Abuse the passContext to pass through gatherer options | ||
| passContext.options = gathererDefn.options || {}; | ||
| const artifactPromise = Promise.resolve().then(_ => gatherer.beforePass(passContext)); |
There was a problem hiding this comment.
wdyt about a followup PR to rename options in all the gatherers to passContext?
yeah good plan |
big change coming in! closes #4206
introduces support for audit and gatherer options while maintaining backcompat with existing config options, internally all audits and gatherers are mapped to the new format
additionally, the very poorly named
optionsinput to gatherers I'm now callingcontextas it more roughly captures what's being passed in, also we avoidoptions.options:)feedback very very welcome while it's still early please! :D
Usage - before
Usage - after