I am currently working on a JupyterLab extension, and I have been getting through the whole official documentation for days now.
I want to make an extension that watches specific files for changes in JupyterLab's scope.
For example, let's say my JupyterLab scope is /home/me/lab/ which then identifies as / in JupyterLab's tree view.
I should be somehow able to watch the state of, let's say, the /lib/index.js (which on my computer should be located at /home/me/lab/lib/index.js), but I cannot find how to do it.
I tried several solutions already:
using
fs.watch, but it does not work in browser apps such as Jupyter so that's a no.using the
ContentsManagerfrom@jupyterlab/servicesbut I can only watch for changes saved by theContentsManagerinstance that I create. I also tried to get the main one but in vain. I don't even know if it exists. Anyway, I would only be able to listen for changes made by the user in JupyterLab, while I would like to watch for any change on the watched files.ChatGPT also told me about
ChokidarSocketEmitterbut this requires to have a watching service alongside the jupyter service, which I would like to avoid.
I want to know if there is something that exists and that would probably be more efficient than me "making a watchdog based on a repeated timer with a callback to fetch the file(s) every 0.5s or so and manually check for changes".
Does anybody have any clue/guidance to give me?