-
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
core(config): augment settings/passes with defaults #4894
Conversation
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.
lgtm % nits
lighthouse-core/config/constants.js
Outdated
|
||
module.exports = { | ||
throttling, | ||
defaultSettings: { |
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.
might as well extract this obv to a var like the throttling one.
and same with defaultPassConfig.
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 done
lighthouse-cli/bin.js
Outdated
@@ -55,8 +54,6 @@ if (cliFlags.configPath) { | |||
// Resolve the config file path relative to where cli was called. | |||
cliFlags.configPath = path.resolve(process.cwd(), cliFlags.configPath); | |||
config = /** @type {!LH.Config} */ (require(cliFlags.configPath)); | |||
} else if (cliFlags.perf) { |
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.
you're removing --perf ? omg
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 add an alias for --onlyCategories=perf
(is that it?)
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.
yeah added back the flag as an alias for --only-categories=performance
for now, but IMO we should get rid of it for v3 :)
@brendankenny this overall direction look good enough to you for me to change all tests? |
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 some general comments on the current version. Overall, though, I really like just using all the settings from the default config.
Copying over the the default passes and audits seems a lot more complicated, though, at least with our current overriding semantics. It seems easy to express "add these additional things", but much harder to say "I want to run only these new things", unless I'm missing how it works :)
As a result, the onlyCategories: ['mixedContent'],
in mixed-content-config.js
ends up being a pretty subtle line for such non-trivial effects (again, if I'm reading this correctly :)
cpuSlowdownMultiplier: emulation.CPU_THROTTLE_METRICS.rate, | ||
}, | ||
}, | ||
settings: constants.defaultSettings, |
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.
maybe this is still better broken out as an object where the properties are set to individual constants? It would be nice if the shape of default-config.js was still readable in place, even if the actual numeric values require a lookup
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'd be against that since it feels like a small when at the cost of manual/error-prone work to copy properties from one file to the other and muddies the source of truth, the shape of settings is a cmd+click away still :)
Maybe it's just me, @paulirish 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.
at first i was like "yah" but now i'm like "nah"
having the keynames present would be nice, but mostly a tease if the actual values aren't there. might as well be clear that the source of truth is not this file.
so i'm +1 on keeping it as is in the PR
docs/readme.md
Outdated
|
||
```js | ||
const perfConfig: any = require('lighthouse/lighthouse-core/config/perf.json'); | ||
const perfConfig = {settings: {onlyCategories: ['performance']}}; |
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 nice example though is it possible do we want to get rid of perf-config.js
? There are more potential tweaks that could be made there beyond just onlyCategories
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.
yeah just brought it back since you and paul are both against
// ... | ||
launchChromeAndRunLighthouse(url, flags, perfConfig).then( // ... | ||
``` | ||
|
||
You can also craft your own config (e.g. [plots-config.js](https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/config/plots-config.js)) for completely custom runs. Also see the [basic custom audit recipe](https://github.com/GoogleChrome/lighthouse/tree/master/docs/recipes/custom-audit). | ||
You can also craft your own config (e.g. [mixed-content-config.js](https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/config/mixed-content-config.js)) for custom runs. Also see the [basic custom audit recipe](https://github.com/GoogleChrome/lighthouse/tree/master/docs/recipes/custom-audit). |
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.
recipes/custom-audit
does this still work? we should probably have a test for that...
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.
heh, yeah I updated the recipe to nuke the extends property
lighthouse-cli/bin.js
Outdated
@@ -56,7 +55,7 @@ if (cliFlags.configPath) { | |||
cliFlags.configPath = path.resolve(process.cwd(), cliFlags.configPath); | |||
config = /** @type {!LH.Config} */ (require(cliFlags.configPath)); | |||
} else if (cliFlags.perf) { | |||
config = /** @type {!LH.Config} */ (perfOnlyConfig); | |||
cliFlags.onlyCategories = ['performance']; |
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.
does this get weird if they supply a config and specify --perf
? The old overwriting config
completely seems more predictable
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.
yeah just brought it back since you and paul are both against
@@ -3,8 +3,8 @@ | |||
node lighthouse-cli/test/fixtures/static-server.js & | |||
|
|||
sleep 0.5s | |||
|
|||
config="lighthouse-core/config/perf.json" | |||
# TODO: replace this with a smoketest for --only-categories performance and nuke the perf-config |
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.
pull out into a tracking issue (or add to breaking changes umbrella)? Bigger change than just dropping the smoke test :)
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.
nuked since we'll keep the config around
@@ -13,7 +13,7 @@ | |||
|
|||
const Audit = require('./audit'); | |||
const URL = require('../lib/url-shim'); | |||
const Emulation = require('../lib/emulation'); | |||
const mobile3G = require('../config/constants').throttling.mobile3G; |
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.
nit: to keep the more descriptive name, maybe const targetLatencyMs = require('../config/constants').throttling.mobile3G.rttMs
?
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.
done
lighthouse-core/config/config.js
Outdated
|
||
const isEqual = require('lodash.isequal'); |
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 no problem for longtime lodash users, I'm sure, but any chance of calling the local deepEqual
? :)
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.
done
I'm not sure if it's harder to say I want to run only these things since it's still just 1 prop you stick in the config, but I agree the "everything extends default" makes things more confusing as to what will be run. It'd be great to know how anyone not on the Lighthouse team feels about these changes and if the ergonomic win is worth it, @benschwarz @denar90 any reactions to always extend default config? My sneaking suspicion is that |
ok updated all the tests, it actually wasn't that bad. 2 major consequences:
|
A solution in the middle could be to pull over settings from the default config and not passes/audits/categories (or, equivalently, have a base audit with empty passes/audits/categories). I'm not sure how that would work with individual pass settings, though (back to default constants instead of from a base config?) Some of the tests aren't unreasonable cases, like "only run these gatherers, not audits or categories" (and other gatherers?), and having to use This does seem to be trading mental complexity for a nice model of config defaults... |
@@ -6,20 +6,13 @@ | |||
'use strict'; | |||
|
|||
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.
Looks like we don't need our own config anymore 💃
https://github.com/paulirish/pwmetrics/blob/v3.2.0/lib/lh-config.ts
0103ff8
to
aca2ba0
Compare
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.
Nice! Really like the simplifications in config.js
lighthouse-cli/bin.js
Outdated
@@ -15,8 +15,9 @@ const runLighthouse = require('./run').runLighthouse; | |||
|
|||
const log = require('lighthouse-logger'); | |||
// @ts-ignore | |||
const perfOnlyConfig = require('../lighthouse-core/config/perf.json'); | |||
const mixedContentConfig = require('../lighthouse-core/config/mixed-content.js'); | |||
const perfOnlyConfig = require('../lighthouse-core/config/perf-config.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.
does this still need to be @ts-ignore
? I think that was because it always has an error on trying to require a json file, so it shouldn't be an issue with a js file. OTOH it might be any
or hopelessly typed :)
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.
nope, totally unnecessary now good call 👍
WIP, but I'm waiting to fix all the tests and do cleanup until we get some consensus on what this looks like :)updated all the tests!This PR would move all defaults that can be specified in the config to a
config/constants.js
file, enforces that all configs implicitly extend default, and changes the defaults specified across various files to be pulled in from constants. This PR also does some promised hygiene on our config files.Points of discussion with my opinions:
Yes we can now make more assumptions about the config and most valid use cases for truly custom can be achieved through
onlyAudits
/onlyCategories
/skipAudits
/etcYes it will be super convenient for scanning all tunable parameters and it's easy to require the constants file in to all the places we still want to double-default parameters for more convenient testing, etc.
cc @benschwarz in case you're doing any custom config magic we might want to know about :)