Closed ammein closed 4 years ago
Hmm. I get why you want to do this but want to make sure we do it in a forwards-compatible way. Should it be only chokidar events? "on" is a very general term. Should it tie us to chokidar forever by making it part of the official developer interface? (I'd say we should avoid that.)
I think it might be more appropriate to just add support for verbose logging in monitor.js itself when APOS_MONITOR_LOG=1 is in the environment; when you see that env var, log stuff to console.debug, etc.
That doesn't tie us to a developer interface.
What do you think?
I think to emit on chokidar events is a good approach. But when I dive into the code. There are several if else statement that already done that filters only on specific module changes or added. Using apostrophe events or any kind of events tied but only filtered on specific changes or re-added would be extremely helpful.
I think I should tell you my specific use case on why I'm doing this is because my local development site is kept responding to change even I'm not saving my editor. I wanted to know, which files that are triggering changes without my consent. That is why I made a custom function that listens to file changes but NOT ALL. (Means exclude unnecessary files, only wanted to know my saved file changes only). Also, my local dev site is taking too long to restarting. By this solution, I could see file changes easily and avoid "Don't make me wait" kind of experience.
I hope you get the idea 😄
Sure. I think adding a simple "log" function in monitor.js that you call with anything that is interesting to log, with an if statement in it to check for an env var, would achieve this without creating a new developer interface that exposes chokidar forever as part of the API.
Going to close this because we decided it makes more sense to introduce a verbose logging option in apostrophe-monitor itself, so that we are not embracing chokidar forever by directly exposing it (leaky abstraction). But that PR for the verbose logging would be quite welcome. Thanks for contributing as always.
I make an external function that extends from
monitor-config.js
for better log file changes usingapos.utils.log
. It is useful to debug or to watch which files are changes and also to make sureaddIgnore
works when restarting the site. This is extremely useful for me to see my site works perfectly and see the progress while restarting. I hope this would be beneficial too to other devs. For example :