Hi! First of all, sincere thanks for your work on this package.
Problem
The FileSystemLoader uses Directory(path).watch to listen for modify events and load templates again. However, on macOS this crashes on every event. For example, when I make one change to my template, I receive 4 almost identical events.
Unfortunately, only the first one is valid. Subsequent events have path that ends with ~ character. When the method tries to load this template it fails, because there isn't one with that name. I'm getting following error.
Unhandled exception:
Exception: template not found: section.html~
I suppose this is some temporary files that my Android Studio creates.
Fix
The easiest fix is to add following line into the file system event listener.
if (event.path.endsWith('~')) return;
The code would look like this:
@override
void load(Environment env) {
super.load(env);
if (autoReload) {
for (final path in paths) {
Directory(path).watch(recursive: true).listen((event) {
if (event.path.endsWith('~')) return;
// ....
});
}
}
}
Furthermore, we could filter the stream to listen for only the correct events. This would lower the number of events and should improve the performance.
If you wouldn't mind, you could use the watcher package. It's from the Dart teams and doesn't seem to have this issue.
I can create a PR if you don't have the time to make these changes. Let me know.
Ideas
I'm using this for live-reload for my static site generator blake. I already have one file system watcher active. When the user edits a file I trigger rebuild. However, when I set autoReload to true in FileSystemLoader it spawns another watcher. Due to this I'm unable to ensure that the template is already updated at the time I trigger rebuild.
Do you have any ideas for solutions? One solution I have in my mind is to extend the Loader class and add custom method that would take a path for updated template and called env.fromString on it. Could this be correct? Or I could just call env.fromString right in my watcher.
Anyway, sorry for this long post (I tried to cover the whole problem) and thanks for help!
Hi! First of all, sincere thanks for your work on this package.
Problem
The
FileSystemLoader
usesDirectory(path).watch
to listen for modify events and load templates again. However, on macOS this crashes on every event. For example, when I make one change to my template, I receive 4 almost identical events.Unfortunately, only the first one is valid. Subsequent events have path that ends with
~
character. When the method tries to load this template it fails, because there isn't one with that name. I'm getting following error.I suppose this is some temporary files that my Android Studio creates.
Fix
The easiest fix is to add following line into the file system event listener.
The code would look like this:
Furthermore, we could filter the stream to listen for only the correct events. This would lower the number of events and should improve the performance.
If you wouldn't mind, you could use the watcher package. It's from the Dart teams and doesn't seem to have this issue.
I can create a PR if you don't have the time to make these changes. Let me know.
Ideas
I'm using this for live-reload for my static site generator blake. I already have one file system watcher active. When the user edits a file I trigger rebuild. However, when I set
autoReload
to true inFileSystemLoader
it spawns another watcher. Due to this I'm unable to ensure that the template is already updated at the time I trigger rebuild.Do you have any ideas for solutions? One solution I have in my mind is to extend the
Loader
class and add custom method that would take a path for updated template and calledenv.fromString
on it. Could this be correct? Or I could just callenv.fromString
right in my watcher.Anyway, sorry for this long post (I tried to cover the whole problem) and thanks for help!