postcss-critical-css icon indicating copy to clipboard operation
postcss-critical-css copied to clipboard

Fix to issue with async output and missing output directory

Open ostowe opened this issue 7 years ago • 7 comments

Sorry for the huge PR. I also switched all the tests to jest, so this should address https://github.com/zgreen/postcss-critical-css/issues/14 as well.

More detail about what I'm fixing here: for a project using webpack in which most CSS imports are happening in JS files, postcss will run once for each import. Due to an improperly handled call to an async fs function (I can't remember which one), this was causing only part of each chunk of critical CSS to get output. To solve this I switch to using fs-extra (which promisifies all fs functions, among other things) and switched to using async/await.

LMK what you want to do with this PR, I'm happy to use my fork until then 🎉

ostowe avatar Jun 12 '18 21:06 ostowe

Alrighty, after testing a bit more I guess this doesn't actually fix my issue. Seems like unless we can figure out some way to open a writable stream, keep it open while webpack is running, then close the stream when it’s done I don’t think we’ll be able to figure this one out. Bummer.

You're welcome to cherry pick the testing updates, though.

ostowe avatar Jun 12 '18 22:06 ostowe

I'd love to get this merged, if only for the testing updates alone. Very rad. Thanks!

Possible to create a failing test case for the use case you describe?

zgreen avatar Jun 13 '18 13:06 zgreen

@zgreen sweet! I actually managed to fix this, though it's probably a little janky. I added bottleneck to rate-limit file writes, preventing the overlap issue.

I'll also see if I can come up with a test for this.

ostowe avatar Jun 13 '18 15:06 ostowe

@zgreen ready for a review when you get a chance (assuming you want to code review it)

ostowe avatar Jun 19 '18 18:06 ostowe

Thanks @ostowe. Was out all last week but will look this week :)

zgreen avatar Jun 25 '18 13:06 zgreen

Sorry for my delay here... will definitely look soon.

zgreen avatar Jul 12 '18 19:07 zgreen

This has lingered too long :/ Still want to get it merged.

My plan is to cherry-pick the jest work so we can get that merged first, and then address the issue raised here, as my sense is that there's more to review/discuss there. Thanks again :)

zgreen avatar Sep 23 '18 19:09 zgreen