grunt-contrib-watch icon indicating copy to clipboard operation
grunt-contrib-watch copied to clipboard

Not detecting newly added files

Open pensierinmusica opened this issue 10 years ago • 46 comments

If I understand correctly, grunt-contrib-watch should detect any added, modified, or deleted file that matches the patters specified in the Grunt configuration file.

On the other hand, I noticed that in my case it doesn't detect newly added files at all. Here's an example of my Grunt configuration:

  grunt.initConfig({
    watch: {
      options: {
        livereload: true
      },
      styles: {
        files: ['<%= yeoman.app %>/styles/sections/*.styl'],
        tasks: ['stylus', 'autoprefixer'],
        options: {livereload: false}
      },
      iconfont: {
        files: ['<%= yeoman.app %>/images/icons/*.svg'],
        tasks: ['webfont', 'stylus'],
      }

grunt-contrib-watch perfectly detects modifications to existing files, but for example if I add a new .styl file in the specified folder nothing happens. I'm using Node 0.10.24 on OSX Mavericks.

Any advice on what might be causing the problem?

Thanks :)

pensierinmusica avatar Jan 18 '14 19:01 pensierinmusica

Strange, I don't think it's because of the hyphens. I work with file names with hyphens in them on a daily basis without any issues. What node.js version? What OS and version? What are the actual file names? Are you sure they are matching? Try grunt watch --verbose.

shama avatar Jan 19 '14 00:01 shama

Hi @shama , thanks for the quick reply, I've checked and you're perfectly right: in fact the problem is not related to file names, but inability to detect newly added files (sorry for the confusion).

I've just updated the original issue here above with all details.

Do you have any advice on how to get the problem fixed?

Thanks! :)

pensierinmusica avatar Jan 21 '14 01:01 pensierinmusica

What is the path of <%= yeoman.app %>?

Also, just a personal request, in the future would you mind adding a new comment or opening a new issue instead of editing your existing one? Just to avoid confusion with someone else coming across the same issue reading the thread. Thanks!

shama avatar Jan 21 '14 03:01 shama

Hi @shama, sure no worries I'll make sure to open new issues in the future :) In this case, after I understood the problem better I just realized the original issue was useless, and that's why I modified it.

Regarding your question, for this specific project where I have the problem, the path of <%= yeoman.app %> is ., or else the current directory. You can see a copy of the configuration here below:

var yeomanConfig = {
  app: '.',
  dist: 'dist'
};

Any thoughts? Thanks :)

pensierinmusica avatar Jan 21 '14 13:01 pensierinmusica

Hmm that could be it. The cwd is always implied so a ./ never needs to be prepended. It could be related to this issue when ./ is prepended, it breaks some of the events: shama/gaze#66

shama avatar Jan 21 '14 16:01 shama

I see, thanks for pointing that out! Removing the <%= yeoman.app %> prefix (and consequently the .), together with the first / at the beginning of the path, fixed the problem :)

On the other hand, as a general approach I actually liked having a variable defined once in the yeomanConfig object, and then referred to elsewhere in the Grunt config file. This way, if one needs to change the folder structure or location at any point, the value has to be updated in one place only.

So, I still think it would be cool to be able to use . and have grunt-contrib-watch detect newly added files. Is there any chance that the bug could be fixed in Gaze, or does this make any sense to you at all?

Cheers!

pensierinmusica avatar Jan 21 '14 21:01 pensierinmusica

Yep, it's fixed the next version of gaze. :) Which will land here as soon I as get safe writes solid for linux (last failing test on that branch).

shama avatar Jan 21 '14 21:01 shama

A-w-e-s-o-m-e!!

Thanks a lot, great job ;)

pensierinmusica avatar Jan 21 '14 22:01 pensierinmusica

Still experiencing that issue with no "." in my cwd; weird

spacenick avatar Jan 30 '14 17:01 spacenick

Had this problem and removing ./ from the beginning of my files options fixed it for me. :thumbsup:

dannyfritz avatar Mar 22 '14 01:03 dannyfritz

Still having this issue with things like files: ['src/**/*.hbs'] when adding a file in a new empty folder.

@shama Having the feeling this issue keeps rising from the dead. #166 What can we do to help you on this?

JSteunou avatar Jun 04 '14 12:06 JSteunou

+1

sshmyg avatar Sep 22 '14 14:09 sshmyg

Same than @JSteunou

spacenick avatar Sep 22 '14 14:09 spacenick

Is this plugin supported, yet?

sshmyg avatar Sep 22 '14 14:09 sshmyg

I found bug in my Gruntfile. Don't use './' before file path. Watcher doesn't work on file add, with this.

sshmyg avatar Sep 25 '14 05:09 sshmyg

Remove of './' works for new files of non-empty folders, but I have an issue when adding a files in a new empty folder.

romamatusevich avatar Oct 17 '14 09:10 romamatusevich

+1 I'm having the same issue on empty folders and newly created folders.

codezninja avatar Oct 23 '14 13:10 codezninja

Same problem here, nfi why

foxx avatar Nov 06 '14 19:11 foxx

The same problem is here. Adding new folder and then adding new file into does not detected by watch task (OS: Windows 7 x64).

isadovskiy avatar Nov 21 '14 16:11 isadovskiy

Recked on OS X 10.9.5. Works fine.

romamatusevich avatar Nov 22 '14 13:11 romamatusevich

I can confirm that "adding a new folder and then adding a new file into it is not detected by the watch task (OS: Windows 7 x64)". In my case, I'm adding the folder from a symbolic link, which may or may not explain the issue.

FremyCompany avatar Nov 24 '14 11:11 FremyCompany

In case it might help someone else, I had the same problem (OS: Windows 8.1 x64) until I set:

options: {
  event: ['changed', 'added', 'deleted']
}

After I set that under options it appears to fix my issue of not detecting new files / folders. Not sure why the default of event: 'all' didn't work.

Dreytac avatar Nov 25 '14 17:11 Dreytac

I experienced the same problem when I had "./" at the beginning of the search path. I removed it and it now it does detect newly added files in non-empty directories. I can confirm that it still doesn't detect new files in an empty directory. Applying @Denney's suggestion didn't seem to help. I also tried setting the cwd property in the options to the base search path and it didn't help.

(node 0.12, grunt: 0.4.5, grunt-contrib-watch: 0.6.1 on Windows 7 64bit)

As this issue has been unresolved for more than a year now (and more than year and a half for related ones such as #166 and shama/gaze#177 and shama/gaze#167). Being the most popular (and one of the most useful) grunt plugins I find it strange no solution has been found yet and considering either fixing it myself or looking for an alternative plugin.

Edit: After further searching I've found this pull request for a related test: https://github.com/shama/gaze/pull/103 . It seems there is an alternative to gaze called https://github.com/shama/navelgazer that's in development and may not have this problem. It may eventually be used in grunt-watch. I will look further into it.

rotemdan avatar Mar 12 '15 08:03 rotemdan

:+1:

dominikwilkowski avatar Mar 20 '15 02:03 dominikwilkowski

https://github.com/unbalanced/grunt-simple-watch Fix problem for me

UnknownHero avatar Mar 23 '15 07:03 UnknownHero

I think this may be related to Vagrant shared folders (due to lack of inotify?)

foxx avatar Apr 27 '15 13:04 foxx

FWIW, this task also does not work for added (or deleted, I think) files if the file paths are absolute.

tandrewnichols avatar Jun 25 '15 14:06 tandrewnichols

https://github.com/unbalanced/grunt-simple-watch fixed the problem for me also!

roNn23 avatar Jul 01 '15 11:07 roNn23

@UnknownHero It's works for me, this issue waste me 2 days, OMG.

leedorian avatar Nov 11 '15 05:11 leedorian

Having the same issue where newly created less files aren't watched.

I've managed to reproduce this with a minimal example Gruntfile.js:

module.exports = function (grunt) {
    grunt.loadNpmTasks('grunt-contrib-watch');

    var config = {
        watch: {
            less: {
                files: ['src/**/*.less'],
                tasks: ['listfiles:less']
            },
            js: {
                files: ['src/**/*.js'],
                tasks: ['listfiles:js']
            }
        },
        listfiles: {
            js: {
                src: ['src/**/*.js']
            },
            less: {
                src: ['src/**/*.less']
            }
        }
    };

    grunt.initConfig(config);

    grunt.registerMultiTask('listfiles', 'List files matched', function () {
        console.log(this.filesSrc);
    });
};

Now if we create a src/test.js and then launch grunt watch:

  • Creating a src/test2.js triggers the watch
  • Creating a src/test.less does not trigger the watch.

What seems to be happening is that the absence of at least one matching file in the directory prevents watch from triggering on subsequent changes in that directory (for a given pattern). This is why empty directories are completely ignored, but also non-empty directories that don't have any matching files.

Hope this can help bring about a solution.

ezk84 avatar Nov 11 '15 23:11 ezk84