Why Gaze watches all directories if I watch only a single file? #174

Closed
alexilyaev opened this Issue Jan 18, 2015 · 3 comments

Projects

None yet

2 participants

@alexilyaev

Related to #45.

Test case
Using grunt-contrib-watch to watch a single file.

Gruntfile.js:

module.exports = function (grunt) {

    grunt.initConfig({
        watch: {
            index: {
                files: 'index.html'
            }
        }
    });

    grunt.registerTask('default', ['serve']);
};

Executing:
grunt --verbose

Result:

Running "watch" task
Waiting...
Verifying property watch exists in config...OK
Verifying property watch.index.files exists in config...OK
Watching index.html for changes.
Watching .git for changes.
Watching css for changes.
Watching js for changes.
Watching lib for changes.
Watching node_modules for changes.

As mentioned in #45, Gaze.prototype._addToWatched is adding all those dirs to the this._watched array for some reason, even though I'm watching only a single file.

I"ve tried changing the pattern to './index.html' but it didn't work as well.

So, what is the purpose of adding all of those dirs?
Is it a bug? If not, how to restrict the watch list?

It sure isn't the expected behavior.

@shama
Owner
shama commented Jan 18, 2015

Since grunt-contrib-watch and gaze work based on file patterns rather than files, that is the expected behavior. In order to anticipate added files it needs to watch folders behind the scenes where it thinks a file could be added. In the current version is doesn't distinguish between internal/external watched files; you just get all watched. But they are safe to ignore.

@shama shama closed this Jan 18, 2015
@alexilyaev

@shama So when it says it's watching those directories, what exactly is it watching? And what will it trigger if a file in those directories is aded/updated?

I'm just getting some "too many watched files" kind of messages when I run several projects simultaneously and I though it might be related.

Also, is there a way to tell it to watch just that one file without all those directories?

@shama
Owner
shama commented Jan 20, 2015

It should only watch each folder, not all files within the folder. If you're on OSX, the default open file limit is very low, 256. I recommend increasing it with ulimit -n 1024 or more permanent methods.

The version of gaze packaged with grunt-contrib-watch uses a combination of native and stat polling. So if you're getting EMFILE, it's likely one of your projects might be watching node_modules or another big folder accidentally. Check for open patterns like **/*as it doesn't ignore the node_modules folder by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment