Hacker News new | ask | show | jobs
by adambratt 4084 days ago
The problem is that a lot of these js tools that are being built are being built on top of other hobbyist js libraries that are built on top of others that creates this weird chain of dependency that appears to arise from nothing other than the author's coding style preference.

Take a look at just one of gulp's dependencies (and arguably one of the most important) vinyl-fs which it uses for file watching. This is the actual chain of abstractions for the file watching functionality in gulp.

vinyl-fs < glob-watcher < gaze < graceful-fs

    * gulp.watch uses vfs.watch provided by vinyl-fs

    * vfs.watch is actually just glob-watcher (lol)

    * glob-watcher is a simple 20 line wrapper around gaze watch

    * gaze uses graceful-fs to watch full paths
4 levels of library abstraction for file watching. Something that the built-in fs.watch handles natively.

Here's the actual description of the gaze library "A globbing fs.watch wrapper built from the best parts of other fine watch libs."

Yet apparently that wasn't enough as the gulp authors had to toss in 2 more layers on top of it. And at the end of the day gulp still sucks for watching files on linux.

I understand that there are other pieces of vfs that are being used by gulp...but it still doesn't make any sense to me how there can be SOOO many accepted libraries dealing with just file watching. And instead of making a pull request for new features on existing libraries, developers are just building other libraries around them to do what they want.

There's so much fragmentation in the JS world and no one can seem to ever agree to work together on anything. In comparison, in the Python world there's pretty much one agreed upon library for something like file watching "watchdog". There are alternatives but it stands out above all the rest.

3 comments

fs.watch actually doesn't work just fine, not sure what gave you that impression. We went with the best file watcher that was around at the time because we didn't feel the need to write our own. The layers of abstraction are there so other people can make use of them as modules. We are (and have been) evaluating other solutions for file watching but gaze is still the best option for us to use under the hood.
I've been stuck in file watching hell before... CHOKIDAR!!!!!

I actually had a really interesting conversation with Bert Belder about some of the lower level problem with file watching. It came up that perhaps there could be a working group around fixing this issue.

The problem with file watching in JS land isn't the libraries, its node. I'll point you at the documentation [1]. fs.watch is inconsistent, unreliable, unperformant on certain platforms, and a layer too low for most applications. For that matter, npm is worlds better than python which is why you don't tend to see crazy dependency graphs in python.

[1] https://nodejs.org/api/fs.html#fs_caveats

I think the deep dependency graphs enabled by npm and a community rigorously embracing semver are fantastically exciting. I'm of the opinion that it is one of the platform's biggest strengths.