Fix: make file reloading handle file name changes #236
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.
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, theassets
andsvelte
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: