Plugin#process change #929

Open
jonathantneal opened this Issue Dec 8, 2016 · 1 comment

Projects

None yet

3 participants

@jonathantneal
Contributor
jonathantneal commented Dec 8, 2016 edited

In the next major version, may we please separate plugin options from process options?

plugin.process(cssString, pluginOptions, processOptions)

Right now, the Plugin#process method mixes both the process options and plugin options. This makes accurate stand-alone testing impossible.

plugin.process(cssString, Object.assign(pluginOptions, processOptions))

Because the options are mixed, plugin options cannot use the same names as process options (see processOptions). I ran into this problem when testing plugins (like svg fragments, import) that rely on source.input.file; because it required I pass in a plugin option named from to test the plugin accurately. I ran into a side-effect problem when testing plugins (like postcss-pseudo-class-any) that passed the processOptions to the plugin (in this case, it prevented me from stand-alone testing a plugin without options).

For now, this is my workaround.

// override plugin#process
module.exports.process = function (cssString, pluginOptions, processOptions) {
	return postcss([
		1 in arguments ? module.exports(pluginOptions) : module.exports()
	]).process(cssString, processOptions);
};

Thanks @ben-eb for catching that oversight. It has been corrected.

@ai ai added the enhancement label Dec 8, 2016
@ai ai added this to the 6.0 milestone Dec 8, 2016
@ben-eb
Member
ben-eb commented Dec 8, 2016

This method signature is lacking the css input, it should be:

plugin.process(cssString, pluginOptions, processOptions);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment