grunt-nodemon icon indicating copy to clipboard operation
grunt-nodemon copied to clipboard

Adding nodemon to Gruntfile disables other tasks' ability to catch signals

Open thetaiter opened this issue 9 years ago • 1 comments

I am setting up a nodejs server using grunt as the task runner, so I have many grunt tasks that do various things. Many of them handle signals like SIGINT, SIGQUIT, and SIGTERM. Until I add the line grunt.loadNpmTasks('grunt-nodemon'); to my Gruntfile, all of these signal handlers worked fine. As soon as I add that line, other grunt tasks, unrelated to nodemon, no longer handle signals properly.

For reproducing the issue, make sure the line I indicated above is commented out in your Gruntfile. You do not need to remove the initConfig info, or uninstall grunt-nodemon from node_modules. Then create a simple grunt task that handles SIGINT like so:

var done = this.async();

process.on('SIGINT', function() {
    console.log('Caught SIGINT');
    done();
});

Run that task, then press Ctrl-C to send the SIGINT signal to the process, and you should see that the task exits properly, displaying the desired text before exiting.

Now if you uncomment grunt.loadNpmTasks('grunt-nodemon'); in the Gruntfile and try to run the example task again, you will see that it no longer handles the signal properly.

Why would having grunt-nodemon affect other unrelated grunt tasks?

thetaiter avatar Jun 02 '15 03:06 thetaiter

I think that is 'by design' (hard to explain though). A workaround for this is to use grunt-concurrent, e.g. you can see an example of usage here. Haven't tried it - so it might not be applicable for your case.

oshybystyi avatar Jun 18 '15 20:06 oshybystyi