This repository was archived by the owner on Feb 18, 2022. It is now read-only.
Make non-async if there's no need for awaits #181
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This makes postcss-custom-properties act as a synchronous plugin (i.e. so users don't need to
await
the result ofpostcss(..).process()
), if and only if nothing is imported nor exported.Some background: we're trying to use postcss-custom-properties in a server setup where user-written CSS is compiled down. For many practical reasons, making the entire pipeline asynchronous is prohibitively hard, and given that we don't use any importing/exporting, we found ourselves wishing postcss-custom-properties was just a synchronous thing altogether. Well, now it is :-)
Given that some of the existing tests don't import or export things, the new code is automatically covered. So I've not added any tests.
I don't have an extremely detailed understanding of the internals of postcss, but if I understand it right, plugins can either return or promise or not, and postcss papers over the difference pretty transparently. Notably, I believe that you can
await
a postcss pipeline even if all plugins happened to have run synchronously - that would be pretty important for this change to be backward compatible. My limited manual testing shows that this is indeed the case but I might have missed some edge case.