Skip to content

feat: allow extension of default config#1731

Merged
paulirish merged 3 commits intomasterfrom
config_extenstions
Feb 17, 2017
Merged

feat: allow extension of default config#1731
paulirish merged 3 commits intomasterfrom
config_extenstions

Conversation

@patrickhulce
Copy link
Copy Markdown
Collaborator

@patrickhulce patrickhulce commented Feb 16, 2017

would address part of #1730, it's rather out there so comments and thoughts welcome on other possible approaches

usage

{
  extends: true,
  passes: [
    {passName: "defaultPass", gatherers: [MyCustomGatherer]
  ],
  audits: [MyCustomAudit]
}

@ebidel
Copy link
Copy Markdown
Contributor

ebidel commented Feb 16, 2017

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.

return value;
} else {
return extension;
}
Copy link
Copy Markdown
Contributor

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;?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread lighthouse-core/config/config.js Outdated
configJSON.audits = Array.from(inputConfig.audits);
}

// Extend the default config is specified
Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

validatePasses(configJSON.passes, this._audits, this._configDir);
}

static extendConfigJSON(baseJSON, extendJSON) {
Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@ebidel
Copy link
Copy Markdown
Contributor

ebidel commented Feb 16, 2017

Can you add documentation to the README? In the "creating custom configs" section.

Copy link
Copy Markdown
Member

@paulirish paulirish left a 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.

Comment thread lighthouse-core/config/config.js Outdated
return artifacts;
}

function merge(value, extension) {
Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread 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}`);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

array => object?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woops, done

Comment thread lighthouse-core/config/config.js Outdated
delete extendJSON.passes;
}

Object.keys(extendJSON).forEach(key => {
Copy link
Copy Markdown
Member

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) ?

Copy link
Copy Markdown
Collaborator Author

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

@patrickhulce patrickhulce changed the title Proposal: Allow extension of default config feat: allow extension of default config Feb 16, 2017
@patrickhulce
Copy link
Copy Markdown
Collaborator Author

@ebidel added a readme entry PTAL :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants