This is the dramatic refactor which was alluded to in ed004e0. 1. All output goes through a central module. 2. Callbacks are called when data is flushed, but only ever called once 3. Set "outfd" and "logfd" to direct output and error to different places, or set to a writable stream when using npm programmatically. 4. Clean up the many varied ways to write data to the console. 5. Set colors smarter, and allow overriding by setting the "color" config.
Log statements are written to the file descriptor or stream object passed in as the "logfd" configuration param. For bonus points, if it's not a tty, it doesn't get colorised. So, if someone does this: npm install npm --logfd 1 | pbcopy then it'll actually be a log that can be pasted into an email without a bunch of tty color code noise.
Building more upon the patch from Charlie Robbins (d7c6982), these changes remove any way of npm actually triggering a program exit than by being called by the cli. - Move the "exit" option off the opts object and onto a proper config setting. Why not? - Use \r\n for most output, so that it'll look correct in the repl, or other places where \n may not be enough. - Add a comment about loading npm programmatically.