Related to: https://github.com/ajaxorg/cloud9/pull/1874
Prefer watchFile over watch
A commit log should not only explain what it changes but also why... why is watchFile > watch?
(EDIT: I wager it's because fs.watch() doesn't work with NFS mounts but that's speculation on my side.)
@bnoordhuis The issue was the frequency at which watch events were dispatched, and the vagueness of the events dispatched. This forced the callee to do a stat on the file anyway and find out what changed.
It also may have been the cause for some very, very odd behavior. We would be watching a file "/path/to/file.md" and after the first time the contents of the file were modified and an event was dispatched (oddly enough with the event type "rename") it would subsequently emit "rename" events on the parent directory every time there was a change and at seemingly random intervals.
We were baffled by this mystery but I had used watchFile with success before. It worked here without any of the aforementioned issues.
I realize the consistency of watchFile is greater because it stats on a regular interval but the consequences of using this technique are low. Even on c9.io this is not an issue because each workspace is in its own container.
I'm fine with this change. Who else is using this API? Isn't @cadorn using it for something?
@creationix Yes: https://github.com/c9/c9local/issues/220
That's where this whole issue started from. File watching appeared broken on Cloud9 Local, but was actually broken on Cloud9 OSS. The change here works for both repos.
Published to npm as email@example.com