Skip to content
This repository has been archived by the owner on Sep 25, 2020. It is now read-only.

Dont run one postcss instance parallel #122

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

tholewebgods
Copy link

@tholewebgods tholewebgods commented Apr 10, 2019

When configuring multiple files for processing (depending on the plugin) the resulting files might be garbage since they share the same processor instance and do not wait until the processing finished.

Example config when using the processor postcss-preset-env:

files: [{
	src: "input/foo.css",
	dest: "target/foo.css"
},
{
	src: "input/bar.css",
	dest: "target/bar.css"
}]

input/foo.css

:root {
	--foo: #333;
}

.moo {
	color: var(--foo);
}

input/bar.css

:root {
	--foo: #666;
}

target/foo.css

:root {
	--foo: #333;
}

.moo {
	color: #666;
	color: var(--foo);
}

Note the "fallback" "color" style is "#666", originated from the bar.css file.

This is probably due to the fact that an internal variables dictionary changed due to the second file while processing the first was not complete yet.

The current implementation calls process() in a loop while not waiting for their returned promise to fullfill.

The new implementation uses a reducer to chain the promises together.

A warning was added too to inform the developers if they've configured multiple source files with one destination (in place editing), which is not sensible.

Configuring multiple source files with one destination is possible through
the Grunt framework but not sensible in the context of postcss processing.

Warn the developers if they've such a config.
@tholewebgods tholewebgods force-pushed the fix/dont-run-one-postcss-parallel branch from 6c746f1 to ef9afc6 Compare April 10, 2019 14:10
tholewebgods added a commit to tholewebgods/grunt-postcss that referenced this pull request Apr 10, 2019
Note though that this test case

 - is not Node 4 compatible since the plugin is not Node 4 compatible
 - might not be reliably since the regression case depends on postcss'
   and postcss-preset-env's internal workings and might be
   false-positive (false-non-failing) when there's actually an error.
@tholewebgods tholewebgods force-pushed the fix/dont-run-one-postcss-parallel branch from ef9afc6 to 613984f Compare April 10, 2019 14:26
@tholewebgods
Copy link
Author

Note: removed regression test case from the original bugfix commit since it's failing in Node 4 due to missing features and it might not be reliable anyway. See commit ec4087d (from fix/dont-run-one-postcss-parallel-with-basic-tests) and its commit message.

The previous implementation ran process() parallel on one processor instance
which messed up variables when plugins auto generated fallback styles for
CSS variables for example.
tholewebgods added a commit to tholewebgods/grunt-postcss that referenced this pull request Apr 12, 2019
Note though that this test case

 - is not Node 4 compatible since the plugin is not Node 4 compatible
 - might not be reliably since the regression case depends on postcss'
   and postcss-preset-env's internal workings and might be
   false-positive (false-non-failing) when there's actually an error.
@tholewebgods tholewebgods force-pushed the fix/dont-run-one-postcss-parallel branch from 613984f to fe9d4db Compare April 12, 2019 06:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant