postcss / postcss-use

Enable PostCSS plugins directly in your stylesheet.
MIT License
153 stars 11 forks source link

Add option to specify default plugin options (closes #11) #21

Closed rexxars closed 8 years ago

rexxars commented 8 years ago

As outlined in #11, it would be useful to be able to provide default options for plugins.

This implements that. I couldn't see any good way to merge non-object options, such as arrays - it's unclear whether it's meant to override or merge them when this is the case.

coveralls commented 8 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling 2e3920eef172f0922ce5b9e6b2386d39a2aa3b24 on sanity-io:default-plugin-options into abe815d6dee0004e6d8e924a8ad68285a7e77a00 on postcss:master.

rexxars commented 8 years ago

Sorry, I didn't test this under Node 0.12. Added some code to work around Object.assign not being present there.

coveralls commented 8 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling 0f4e97f4de354f55b9e6c3f84d4a09767448a801 on sanity-io:default-plugin-options into abe815d6dee0004e6d8e924a8ad68285a7e77a00 on postcss:master.

coveralls commented 8 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling 0f4e97f4de354f55b9e6c3f84d4a09767448a801 on sanity-io:default-plugin-options into abe815d6dee0004e6d8e924a8ad68285a7e77a00 on postcss:master.

ben-eb commented 8 years ago

Hi @rexxars, thanks for the pull request!

Do we need the isPlainObject checking? Any time that I've been using options objects, it's always been obvious that we should supply a plain object, that is pretty much a standard pattern across most if not all JS modules.

Also, I think it would be nice if you could remove the polyfill and let Babel polyfill it for 0.12, via object spread. So we can get rid of a lot of code by swapping out;

return assign({}, defaultOpts, specifiedOpts);

with

return {
  ...defaultOpts,
  ...specifiedOpts,
};

Also, defaultPluginOptions is a little verbose. Perhaps simply options is a better name for this?

rexxars commented 8 years ago

Thanks for the feedback, @ben-eb

The reason why I added the object check was that there is already handling of non-object options in the codebase (postcss-discard-font-face can receive an array, for instance). Be happy to remove it if you think it's not necessary.

Updated PR based on your feedback, awaiting reply regarding object check.

coveralls commented 8 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling 1ec5f1489f2af9241da4a179c58e1f12da591be3 on sanity-io:default-plugin-options into 74d8f52939ea41740a7609502c296338cfd1aeb8 on postcss:master.

ben-eb commented 8 years ago

Ah, OK. That makes sense to me. 👍

ben-eb commented 8 years ago

Merged and released on npm in v2.3.0. Thanks again! 🎉