Elderjs / elderjs

Elder.js is an opinionated static site generator and web framework for Svelte built with SEO in mind.
https://elderguide.com/tech/elderjs/
MIT License
2.12k stars 53 forks source link

Fix: make file reloading handle file name changes #236

Closed ChristofferKarlsson closed 2 years ago

ChristofferKarlsson commented 2 years ago

Since version 1.5.0, file reloads have not worked correctly if your files are being renamed, such as when using TailwindCSS 3 (or 2 with JIT). The reason for this seems to be a bug in chokidar, that doesn't correctly handle deleting and re-creating a folder that is being directly watched. I've opened two issues in their repo about it: Issue #1207 and Issue #1208.

Before version 1.5.0 this worked, because the entire elderConfig.$$internal.distElder folder was being watched. When a folder was removed (which it seems to be in server restarts) and re-created, chokidar noticed it without problems. But in version 1.5.0, the assets and svelte folders are explicitly being watched, and not their parent directory. Due to the bugs above, they are thus no longer tracked after the first server restart that deletes the folders. See v1.5.0 changes here.

I found a workaround (see comment here) and it seems that it works if you add a trailing slash to the watches. And that is what I have changed in this PR.

For a working example, I forked the template and added TailwindCSS 3, and changed to this fixed version. It handles the CSS renaming and reloads as it should. The repo is found here: https://github.com/ChristofferKarlsson/elderjs-template-tailwind.

I have only tested this on my machine:

codecov-commenter commented 2 years ago

Codecov Report

Merging #236 (0fa6c33) into master (bf528f1) will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #236   +/-   ##
=======================================
  Coverage   82.14%   82.14%           
=======================================
  Files          46       46           
  Lines        1960     1960           
  Branches      465      440   -25     
=======================================
  Hits         1610     1610           
  Misses        348      348           
  Partials        2        2           
Impacted Files Coverage Δ
src/rollup/rollupPlugin.ts 76.13% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update bf528f1...0fa6c33. Read the comment docs.