glebmachine / postcss-easysprites

Easy sprites for postcss. Just append `#spritename` to the end of image url. No complicated mechanism or strict folder structure.
MIT License
61 stars 8 forks source link

Sometimes it hits the cache when the files are not on disk #264

Open emirotin opened 2 years ago

emirotin commented 2 years ago

Hi

This tool is nice and convenient, thanks. But recently I started getting a very strange Shroedingbug. Quite often if I clear the previously generated sprites and then run the build, it would report that the files were not changed, and skip writing them to disk. This ultimately leads to the build failure. I wasn't able to reproduce it in debug mode, so it can be some kind of the race condition.

For now, I have commented these lines in my locally patched copy of the plugin:

diff --git a/node_modules/postcss-easysprites/lib/sprites.js b/node_modules/postcss-easysprites/lib/sprites.js
index c143a18..1ed7126 100644
--- a/node_modules/postcss-easysprites/lib/sprites.js
+++ b/node_modules/postcss-easysprites/lib/sprites.js
@@ -52,11 +52,11 @@ async function saveSpriteFile(spriteElement) {
   // Build the full path the sprite file should be saved to.
   sprite.path = path.resolve(opts.spritePath, `${sprite.groups}.png`);

-  // If the sprite is being pulled from the cache, don't save a new version.
-  if (sprite.isFromCache) {
-    log('Easysprites:', ansi.green(sprite.path), 'unchanged.');
-    return sprite;
-  }
+  // // If the sprite is being pulled from the cache, don't save a new version.
+  // if (sprite.isFromCache) {
+  //   log('Easysprites:', ansi.green(sprite.path), 'unchanged.');
+  //   return sprite;
+  // }

   // Save new version of the sprite image file.
   await writeFileAsync(sprite.path, Buffer.from(sprite.image, 'binary'));