gruntjs/grunt — pull request #708 by divdavem (2013-03-05 18:33:46+00:00)
Title: Fixing the exit process

This pull request is a step forward in order to solve #664.

Under some environments (especially cygwin on Windows, but also when piping grunt's output to another program), exiting the process too quickly with ``process.exit`` may hide some errors or warnings logged with console.log but not yet displayed. This problem will apparently not be fixed in node.js itself (note that there was a discussion about this a long time ago [here](https://groups.google.com/forum/?fromgroups=#!topic/nodejs-dev/Tj_HNQbvtZs) and nothing changed).

In Grunt, a ``grunt.util.exit`` method already exists, which waits for the output to be properly processed before exiting. However, there are some places where ``process.exit`` is still used. Moreover ``grunt.util.exit`` is using properties which are not part of the public API of node.js.

This pull request fixes those issues and adds a ``grunt.util.hasExited`` method which returns whether ``grunt.util.exit`` was called. This new method is now called after a task is completed, before trying to do anything more, so that no new task is executed after calling ``grunt.util.exit``.

Please consider integrating this pull request so that Grunt becomes really usable for users who face this issue. Otherwise, it is really painful when errors seem to have probably happened but no detail is displayed.

Thank you in advance. I also take this opportunity to thank you for the good job you have already done with Grunt.