Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inotify support #255

Closed
blueyed opened this issue Dec 4, 2013 · 4 comments
Closed

inotify support #255

blueyed opened this issue Dec 4, 2013 · 4 comments

Comments

@blueyed
Copy link

blueyed commented Dec 4, 2013

I have setup grunt and use grunt-contrib-watch to watch a whole directory.

Unfortunately, it appears to constantly stat all the files in there. I would have expected that something like inotify would get used on Linux.

Am I missing something?

Would it make sense to use https://github.com/bevry/watchr to abstract the actual watching process?

@shama
Copy link
Member

shama commented Dec 4, 2013

We use gaze which does use inotify for some files on linux. Gaze watches the way it does for a few reasons: it handles Grunt compatible file patterns, it handles safe rewrites among other use cases raised by our users over the year+, still supports node v0.8 to maintain compatibility with Grunt (which still supports v0.8) and is cross-platform compatible.

fs.watch gets better with newer versions of node and we're looking into progressively applying those by detecting the version of node. The primary goal of gaze is to maintain compatibility with Grunt and continue to support the use cases collected and put in the tests. Unfortunately switching to a pure fs.watch watch, even with the latest version of node, wont pass our tests. It is still marked as an unstable API (and very much is so): http://nodejs.org/api/fs.html#fs_fs_watch_filename_options_listener

Also, please correct me if Im wrong, but watchr doesn't appear to support file patterns and doesn't use fs.watch but only stat polls.

You can use fs.watch directly with Grunt if you think that will work for you:

grunt.registerTask('mywatch', function() {
  var done = this.async();
  require('fs').watch('somedir', function(event, filename) {
    grunt.task.run(['jshint', 'mywatch']);
    done();
  });
});

I really wished the above worked for everyone else though. Maybe in node 1.0.0 :)

@shama shama closed this as completed Dec 4, 2013
@blueyed
Copy link
Author

blueyed commented Dec 7, 2013

@shama
Thanks for your explanation and example code.

How can I "pause" the watch for the time the callback is running? E.g. if the "jshint" task itself would trigger a filesystem change in "somedir".

In my case, the task is a shell process creating a ctags file, and while I can ignore changes to the tags file itself, I do not want to have multiple ctags processes running in parallel in any case.

@shama
Copy link
Member

shama commented Dec 8, 2013

You can't (at least not easily) atm. That is something I'd like to support in the future though: shama/gaze#29

@blueyed
Copy link
Author

blueyed commented Dec 14, 2013

@shama

We use gaze which does use inotify for some files on linux

Is this documented somewhere? I find that it does not use inotify even for a single file?!

Is it possible to require/use fs.watch directly through the loaded NpmTask (in grunt.initConfig)? I wanted to use this for the livereload feature, but without inotify it's not much fun.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants