According to the latest PostCSS plugin guidelines, plugins should "use asynchronous methods when it is possible". Theres a number of places postcss-url makes blocking FS calls.
|
if (!fs.existsSync(file)) { |
|
var stats = fs.statSync(file) |
|
file = fs.readFileSync(file) |
|
var contents = fs.readFileSync(filePath) |
|
mkdirp.sync(absoluteAssetsPath) |
|
mkdirp.sync(absoluteAssetsPath) |
In order to clean this up, the postcss plugin API will need to return a Promise which will mark it as async forcing consumers to use process(css).then(cb). This would probably be considered a major backwards incompatible change.
But I think it would be worth while to align to the plugin best practices as this plugin is listed under the official @postcss org.
There could be other benefits besides this cleanup. For one, I think it would be great to support async logic in the custom url function.
"postcss-url": {
url: function(url) {
return asyncCallToComputeAssetMD5(url).then(function(md5) {
return url + "?" + md5
})
}
}
I'd be happy to help work on this. But I just wanted to get an idea if this would be a welcome direction.
Thanks!
CC: @MoOx @ai
According to the latest PostCSS plugin guidelines, plugins should "use asynchronous methods when it is possible". Theres a number of places postcss-url makes blocking FS calls.
postcss-url/index.js
Line 239 in 130b43c
postcss-url/index.js
Line 244 in 130b43c
postcss-url/index.js
Line 263 in 130b43c
postcss-url/index.js
Line 306 in 130b43c
postcss-url/index.js
Line 318 in 130b43c
postcss-url/index.js
Line 339 in 130b43c
In order to clean this up, the postcss plugin API will need to return a Promise which will mark it as async forcing consumers to use
process(css).then(cb). This would probably be considered a major backwards incompatible change.But I think it would be worth while to align to the plugin best practices as this plugin is listed under the official @postcss org.
There could be other benefits besides this cleanup. For one, I think it would be great to support async logic in the custom url function.
I'd be happy to help work on this. But I just wanted to get an idea if this would be a welcome direction.
Thanks!
CC: @MoOx @ai