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

Missing file modification

Open oshybystyi opened this issue 9 years ago • 4 comments

It is not rare that watch misses file modification.

My system: Ubuntu 14.04 grunt: v0.4.5 grunt-contrib-watch: 0.6.1

The last time it happened - the application thrown error into stderr, after that watch task printed into output:

Running "watch" task
Completed in 1.093s at Sun May 31 2015 23:07:55 GMT+0300 (EEST) - Waiting...

After that I modified file and:

ls -l controllers/Event.js

Outputs:

-rw-rw-r-- 1 oleksandr oleksandr 1585 тра 31 23:08 controllers/Event.js

As you can see the modification happened after 5 secs from starting watch task. Saving file second time - restarts watch task ok.

This my Gruntfile (the most relevant part, I think):

        watch: {
            express: {
                files: [
                    /** Include **/
                    '**/*.js',

                    /** Exclude **/
                    '!**/node_modules/**',
                    '!**/bower_components/**',
                    '!Gruntfile.js',
                    '!assets/**',
                    '!public/**'
                ],
                tasks: [ 'express:dev' ],
                options: {
                    spawn: false,
                    interrupt: true
                }
            }
        }

There are other watch tasks, but error happens on express task, so I posted it.

I will try to run grunt with --verbose option

oshybystyi avatar May 31 '15 20:05 oshybystyi

running grunt with --verbose helped to notice the possible source of the bug.

Well I've noticed that there is a delay between watch task prints Completed in 1.142s at Mon Jun 01 2015 13:35:11 GMT+0300 (EEST) - Waiting... and printing the list of the files the task is watching (maybe 6-7 secs - depending on the quantity of files). So if file is modified between those two outputs - than task is not restarted.

oshybystyi avatar Jun 01 '15 11:06 oshybystyi

I can confirm this issue happens on windows too. It's because of the way that watch essentially restarts watching everything again after it has executed a task.

I think it only happens for watch configurations that set spawn: false, which makes sense because the task that has to execute is usually in a separate process, but when it isn't watch has to let grunt execute the required task and then return to watch again.

I investigated a potential fix, but really watch should not be resetting all the watchers each time as that's expensive to do for a large directory. Essentially the fix I investigated involves recording the last modified time of every watched file, updating it when change/add is detected and then when the task is restarted comparing the current modified time to the last known modified time and triggering an event for each modified file. It's more of a dirty hack then a good solution imo.

lowkay avatar Jun 03 '15 09:06 lowkay

:+1:

MeoMix avatar Sep 01 '15 02:09 MeoMix

I had a fight with this this afternoon. In the end I set the options to

  interrupt: true,
  spawn: false

and it started working. I realise that this is the opposite of what @lowkay said. I don't claim any expertise in this, I just played around with the settings until I got it to work. I'm on Windows 7 Professional 64bit with node v5.9.0 grunt v0.4.5 grunt-cli v0.1.13

[email protected] [email protected]
[email protected]

TimSmith714 avatar Mar 24 '16 17:03 TimSmith714