gruntjs / grunt-contrib-watch

Run tasks whenever watched files change.
http://gruntjs.com/
MIT License
1.98k stars 356 forks source link

Add file ignored by watch if folder does not already contain a file matching the files pattern #436

Open andidev opened 9 years ago

andidev commented 9 years ago

Add file ignored by watch if folder does not already contain a file matching the files pattern when running grunt watch.

Gruntfile.js

/*global module:false*/
module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    // Task configuration.
    jshint: {
      all: {
        src: ['src/**/*.js']
      }
    },
    watch: {
      lib_test: {
        files: 'src/**/*.js',
        tasks: ['jshint:all']
      }
    }
  });

  // These plugins provide necessary tasks.
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-watch');

};

package.json

{
  "engines": {
    "node": ">= 0.10.0"
  },
  "devDependencies": {
    "grunt": "0.4.5",
    "grunt-contrib-jshint": "0.10.0",
    "grunt-contrib-watch": "0.6.1"
  }
}

Using

Reproduced by

  1. git clone https://github.com/andidev/grunt-contrib-watch-add-file-bug-example-project
  2. cd grunt-contrib-watch-add-file-bug-example-project
  3. npm install
  4. grunt watch
  5. add a file named jsfile1.js in src folder

The console output so far:

Running "watch" task
Waiting...

i.e. no reaction from the watch task

  1. end the grunt watch task and start it again with grunt watch
  2. add a file named jsfile2.js in src folder

The console output now looks a bit better, grunt watch works!

Running "watch" task
Waiting...
>> File "src/jsfile2.js" added.
Running "jshint:all" (jshint) task
>> 2 files lint free.

Done, without errors.
Completed in 0.579s at Sun May 17 2015 13:13:03 GMT+0200 (CEST) - Waiting...

once again thats great! but wait a minute...

  1. end the grunt watch task remove the jsfile1.js and jsfile2.js file from the src folder and then start it again with grunt watch
  2. add a file named jsfile3.js in src folder

The console output now looks a bit sad, grunt watch does not work again.

Running "watch" task
Waiting...

i.e. no reaction from the watch task since there where no files matching the files pattern when grunt watch was started

andidev commented 9 years ago

This is the same issue described in https://github.com/gruntjs/grunt-contrib-watch/issues/166#issuecomment-21432390