Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Notify plugins when a file/asset is deleted #1706

Open
mr-miles opened this issue May 13, 2017 · 2 comments
Open

Notify plugins when a file/asset is deleted #1706

mr-miles opened this issue May 13, 2017 · 2 comments
Labels

Comments

@mr-miles
Copy link

I am writing a brunch plugin which is transforming static files using handlebars and handlebars-layouts.
The plugin is picking up helpers (partials) from files on the filesystem - these are common layout files. They are then used across transforms of all the static files.

I want it to work in "watch" mode. So when a file is deleted, I want to unregister the partials that it corresponds to. Is there a hook for a plugin to be notified when a file is deleted? I've scoured the code but it seems impossible.

Thanks for your help!

@shvaikalesh
Copy link
Contributor

shvaikalesh commented May 15, 2017

Hey @mr-miles, we appreciate the issue. I am on a mission to make Brunch fit more use cases without additional bloat and make it work predictably even on edge cases.

If partials depend on some asset, they can return it's path in dependencies, so they will be recompiled when the file gets removed.

@mr-miles
Copy link
Author

Thanks for the reply. I have it returning the dependencies, and that works nicely - but it doesn't cover this case. Hopefully I can be a bit clearer:

  • when brunch sends the plugin a partial to compile, the partial is compiled and also registered with handlebars
  • then when static assets are compiled, they can reference the partial
  • but if the partial is deleted, there's no hook to find out about it and unregister the partial.
  • this means that assets that used to depend on the partial will still compile ok, even though that partial is no longer there on the file system. the correct behaviour is that they generate errors about missing dependencies.

Maybe I'm not doing this in a very brunch-y way - I'd appreciate any ideas? The alternative would be to find the dependencies of each static asset, and then compile and register all the dependencies each time. That's a bit tedious because then I need to examine each dependency for further dependencies etc, etc.

Here's a link to the plugin code if it is useful (I was going to submit a pull request for it, it works very nicely for static site generation):
https://github.com/mr-miles/handlebars-brunch/tree/handlebars-layouts
You can see what I want to do "on unlink" around line 239

Also, in order to guarantee the partials are registered before any static assets are compiled, I register them all in a pre-compile step the first time round. Is there a better way for a plugin to say it wants to process certain paths first? Or is it expected to queue everything up via promises within the plugin?

Thanks for your help, brunch is great!

@paulmillr paulmillr reopened this Aug 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

3 participants