A replacement for process.exit that ensures stdio are fully drained before exiting.
To make a long story short, if process.exit is called on Windows, script output is often truncated when pipe-redirecting stdout or stderr. This module attempts to work around this issue by waiting until those streams have been completely drained before actually calling process.exit.
varexit=require('exit');// These lines should appear in the output, EVEN ON WINDOWS.console.log("omg");console.error("yay");// process.exit(5);exit(5);// These lines shouldn't appear in the output.console.log("wtf");console.error("bro");
Don't believe me? Try it for yourself.
In Windows, clone the repo and cd to the test\fixtures directory. The only difference between log.js and log-broken.js is that the former uses exit while the latter calls process.exit directly.
This test was done using cmd.exe, but you can see the same results using | grep "std" in either PowerShell or git-bash.
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
Release History
2013-11-26 - v0.1.2 - Fixed a bug with hanging processes.
2013-09-26 - v0.1.1 - Fixed some bugs. It seems to actually work now!
2013-09-20 - v0.1.0 - Initial release.
License
Copyright (c) 2013 "Cowboy" Ben Alman
Licensed under the MIT license.