Permalink
Browse files

don't require a cb to specify stream to write to

  • Loading branch information...
1 parent f6938bb commit db1d55f45c74693d45dd9e2f4e1a36de68e4e222 @isaacs isaacs committed Mar 22, 2011
Showing with 12 additions and 5 deletions.
  1. +12 −5 lib/utils/output.js
View
@@ -25,12 +25,18 @@ function isatty (stream) {
}
function write (args, stream, lf, cb) {
- if (typeof cb !== "function") cb = lf, lf = null
- if (typeof cb !== "function") cb = stream, stream = npm.config.get("outfd")
+ if (typeof cb !== "function" && typeof lf === "function") {
+ cb = lf
+ lf = null
+ }
+ if (typeof cb !== "function" && typeof stream === "function") {
+ cb = stream
+ stream = npm.config.get("outfd")
+ }
stream = getStream(stream)
if (lf == null) lf = isatty(stream)
- if (!stream) return cb && cb()
+ if (!stream) return cb && cb(), false
if (!Array.isArray(args)) args = [args]
var msg = ""
@@ -47,7 +53,7 @@ function write (args, stream, lf, cb) {
// listen to the "output" event to cancel/modify/redirect
npm.output = {stream:stream, message:msg}
npm.emit("output", npm.output)
- if (!npm.output) return cb(), false // cancelled
+ if (!npm.output) return cb && cb(), false // cancelled
stream = npm.output.stream
msg = npm.output.message
@@ -60,11 +66,12 @@ function write (args, stream, lf, cb) {
return true
}
var flushed = stream.write(msg)
- if (flushed) {
+ if (flushed && cb) {
process.nextTick(cb)
} else {
stream.on("drain", cb)
}
+ return flushed
}
function getStream (fd) {

0 comments on commit db1d55f

Please sign in to comment.