gajus / turbowatch

Extremely fast file change detector and task orchestrator for Node.js.
Other
938 stars 23 forks source link

Allow customising watchers via options. #46

Closed jesushernandez closed 1 year ago

jesushernandez commented 1 year ago

Hey, this is a great tool! We've recently moved our repo to turborepo and are just configuring turbowatch to retain some of the good DX we used to have (typecheck, lint watch..)

However, we found that when turbowatch starts, chokidar begins indexing files and, due to how our monorepo is set up and the dependencies between packages (there might be a cycle somewhere), chokidar never stops indexing the files inside node_modules. It keeps following symlinks recursively. You can see in the logs how the number of indexed files grows infinitely to the millions.

chokidar specifically allows you to provide some glob patterns of files that will be ignored (via the ignored param). Is this something the library could support? Currently we're working around this by providing a custom Watcher which is exactly the same as your ChokidarWatcher but it creates the chokidar instance with an additional ignored parameter:

An alternative to this would be to adapt the glob expression provided to turbowatch to the ignored glob chokidar accepts, which would be more efficient than scanning all files to then 'discard' most of them.

this.chokidar = chokidar.watch(project, {
      ignored: ['**/node_modules/**'],
      awaitWriteFinish: false,
      followSymlinks: true,
    });

We can stick to this but it'd be great if we were able to just pass some of WatchOptions (from chokidar) instead of a whole new WatcherConstructable.

What do you think? I'm happy to contribute.

gajus commented 1 year ago

Using chokidar is going to be an uphill battle no matter what you do.

If you have an option to update to Node v19 your issues would go away as Turbowatch will switch to fs.watch that is a lot more resource efficient.

jesushernandez commented 1 year ago

Ok, we will keep an eye on the project then. We can stay with our current approach, as upgrading to v19 is not an option right now. Cheers!