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

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

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

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

alexilyaev opened this issue Jan 18, 2015 · 3 comments

Comments

@alexilyaev
Copy link

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
Copy link
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 as completed Jan 18, 2015
@alexilyaev
Copy link
Author

@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
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants