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

alexilyaev opened this issue Jan 18, 2015 · 3 comments

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

alexilyaev opened this issue Jan 18, 2015 · 3 comments


Copy link

@alexilyaev alexilyaev commented Jan 18, 2015

Related to #45.

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


module.exports = function (grunt) {

        watch: {
            index: {
                files: 'index.html'

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

grunt --verbose


Running "watch" task
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.

Copy link

@shama 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
Copy link

@alexilyaev alexilyaev commented Jan 20, 2015

@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?

Copy link

@shama 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
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.