gruntjs / grunt-contrib-watch

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

Watch exits with "Done, without errors" while only watching for sass #463

Open doivosevic opened 9 years ago

doivosevic commented 9 years ago

So once every 100 successful builds the watch just stops after printing "Done, without errors" although it never exits usually.

module.exports = function(grunt) {

  require('load-grunt-tasks')(grunt); // npm install --save-dev load-grunt-tasks

    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-sass');

    grunt.initConfig({
        sass: {
            options: {
                sourceMap: true
            },
            dist: {
                files: {
                    'Content/css/styles/styles.css': 'Content/css/styles/styles.scss'
                }
            }
        },
        watch: {
          scripts: {
            files: 'Content/css/styles/**/*.scss',
            tasks: ['sass'],
            options: {
              spawn: false,
              interrupt: true
            },
          },
        }
    });

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

};

console log:

Running "sass:dist" (sass) task

Running "watch" task
Completed in 2.553s at Mon Sep 28 2015 09:22:48 GMT+0200 (Central European Dayli
ght Time) - Waiting...
>> File "\Content\css\styles\components\calendar\_calendar.scss" change
d.

Running "sass:dist" (sass) task

Running "watch" task
Completed in 2.512s at Mon Sep 28 2015 09:23:51 GMT+0200 (Central European Dayli
ght Time) - Waiting...
>> File "\Content\css\styles\components\calendar\_calendar.scss" change
d.

Running "sass:dist" (sass) task

Running "watch" task
Completed in 2.658s at Mon Sep 28 2015 09:24:26 GMT+0200 (Central European Dayli
ght Time) - Waiting...
>> File "\Content\css\styles\components\calendar\_calendar.scss" change
d.

Running "sass:dist" (sass) task
>> no mixin named justify-content
>>
>> Backtrace:
>>      /Content/css/styles/components/calendar/_calendar.scss:96
>>   Line 96  Column 26  \Content\css\styles\components\calendar\_calen
dar.scss
Warning:
Warning: no mixin named justify-content

Backtrace:
        /Content/css/styles/components/calendar/_calendar.scss:96

Running "watch" task
Waiting...
>> File "\Content\css\styles\components\calendar\_calendar.scss" change
d.

Running "sass:dist" (sass) task

Running "watch" task
Completed in 2.501s at Mon Sep 28 2015 09:26:00 GMT+0200 (Central European Dayli
ght Time) - Waiting...
>> File "\Content\css\styles\components\calendar\_calendar.scss" change
d.

Running "sass:dist" (sass) task

Scheduled tasks have been interrupted...>> File "\Content\css\styles\co
mponents\calendar\_calendar.scss" changed.

Running "sass:dist" (sass) task

Running "watch" task
Completed in 0.911s at Mon Sep 28 2015 09:26:27 GMT+0200 (Central European Dayli
ght Time) - Waiting...

Done, without errors.
mike-bresnahan commented 8 years ago

I observe this on a regular basis. It appears to be a timing issue. If I change a file and then change it again during the correct time window before the end of processing, I observe some similar to watch you have observed.

Scheduled tasks have been interrupted... [...] Done, without errors.

I am using:

Node.js v4.2.1 grunt-contrib-watch 0.6.1 grunt v0.4.5 grunt-cli v0.1.13 Windows 7

doivosevic commented 8 years ago

I have also felt that it is a timing issue

mike-bresnahan commented 8 years ago

I'm not at all familiar with node.js development, but I think see the issue. Experimentation suggests that the existence of a open Gaze object prevents the process from exiting. There is window of time between where all Gaze objects are closed and they are recreated. If the task completes in that time window, the process exits.

    // Close any previously opened watchers
    watchers.forEach(function(watcher) {
        watcher.close();
    });
    watchers = [];

[...]

        // Create watcher per target
        watchers.push(new Gaze(patterns, target.options, function(err) {
mike-bresnahan commented 8 years ago

Never mind my last post. I don't think that is the correct explanation anymore.

I have learned that this is the stack trace when the process exits:

0 process.exit node.js:742:7

1 exit.js:17:15

2 exit.js:34:3

3 grunt.tasks.task.options.done grunt.js:154:14

4 task.js:280:25

5 task.js:227:11

6 node.js:417:9

7 node.js:346:13

grunt.js:

154: util.exit(0);

Grunt is exiting forcefully because it thinks the task has completed. I can make this happen on demand by touching a file, waiting about 1 second, and then touching the file again.

mike-bresnahan commented 8 years ago

I have not been able to determine why grunt exits after an interrupt but I did discover that the problem is isolated to when the option spawn = false. Setting that option to the default (true), fixed the issue. I didn't author the original configuration, so I don't know why spawn was set to false. I'm going to go with the default for now!