-
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
feat: allow extension of default config #1731
Conversation
This looks useful. I dreamed of similar things in #887. Our single gigantic config is being unwieldy. This will also help consumers of LH more easily create custom configs. |
lighthouse-core/config/config.js
Outdated
return value; | ||
} else { | ||
return extension; | ||
} |
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: ditch else
and just return extension;
?
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
@@ -262,6 +284,12 @@ class Config { | |||
if (Array.isArray(inputConfig.audits)) { | |||
configJSON.audits = Array.from(inputConfig.audits); | |||
} | |||
|
|||
// Extend the default config is specified |
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.
// Extend the default config if specified.
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
@@ -280,6 +308,27 @@ class Config { | |||
validatePasses(configJSON.passes, this._audits, this._configDir); | |||
} | |||
|
|||
static extendConfigJSON(baseJSON, extendJSON) { |
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 want to add jsdocs, even though it's fairly obvious what everything is.
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
Can you add documentation to the README? In the "creating custom configs" section. |
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.
yup generally like this approach and think itll be more flexible than passing options from CLI for everything. nice.
lighthouse-core/config/config.js
Outdated
@@ -233,6 +233,27 @@ function expandArtifacts(artifacts) { | |||
return artifacts; | |||
} | |||
|
|||
function merge(value, extension) { |
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.
how about s/value/base/. communicates a little better which is being mutated, and in line with your extendConfigJSON
below
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
if (!Array.isArray(value)) throw new TypeError(`Expected array but got ${typeof value}`); | ||
return value.concat(extension); | ||
} else if (typeof extension === 'object') { | ||
if (typeof value !== 'object') throw new TypeError(`Expected array but got ${typeof value}`); |
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.
array => object?
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.
woops, done
lighthouse-core/config/config.js
Outdated
delete extendJSON.passes; | ||
} | ||
|
||
Object.keys(extendJSON).forEach(key => { |
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.
couldn't these three lines be replaced with merge(baseJSON, extendJSON)
?
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.
yep! artifact of earlier implementation, done
@ebidel added a readme entry PTAL :) |
would address part of #1730, it's rather out there so comments and thoughts welcome on other possible approaches
usage