gruntjs/grunt — pull request #664 by istvan-antal (2013-02-13 17:24:54+00:00)
Title: Correctly stdout wait for stdout to drain before exiting

The problem that I experienced was the following:

I ran grunt under Cygwin.

I made something that either failed or made grunt exit with a warning.

grunt outputed only the first line.

What I noticed:

In lib/grunt/fail.js process.exit did not wait for stdout to finish outputting the messages.

There is an event for process.stdout called 'drain' that can be used to fix this problem.

There is a lib/util/exit.js that tried to solve the same problem by accessing private properties.

What I did:

I made lib/grunt/fail.js use exit() from lib/util/exit.js for exiting instead of calling process.exit directly.

In a second commit I made exit() use the documented drain event for process.stdout instead of private APIs.

I did not write tests for this because it fails under specific shell/operating systems and the patches seem trivial enough.