Permalink
Browse files

Fix EPIPE workaround for Darwin

  • Loading branch information...
1 parent ef0ba6a commit 5effe86f312129963da33a3b506156945c6ac1c2 @mfncooper mfncooper committed with isaacs Sep 8, 2012
Showing with 7 additions and 2 deletions.
  1. +7 −2 lib/completion.js
View
@@ -16,7 +16,8 @@ var npm = require("./npm.js")
})
, shorthandNames = Object.keys(shorthands)
, allConfs = configNames.concat(shorthandNames)
- , npm = require("./npm.js")
+ , once = require("once")
+
completion.completion = function (opts, cb) {
if (opts.w > 3) return cb()
@@ -150,6 +151,10 @@ function dumpScript (cb) {
, path = require("path")
, p = path.resolve(__dirname, "utils/completion.sh")
+ // The Darwin patch below results in callbacks first for the write and then
+ // for the error handler, so make sure we only call our callback once.
+ cb = once(cb)
+
fs.readFile(p, "utf8", function (er, d) {
if (er) return cb(er)
d = d.replace(/^\#\!.*?\n/, "")
@@ -166,7 +171,7 @@ function dumpScript (cb) {
// Really, one should not be tossing away EPIPE errors, or any
// errors, so casually. But, without this, `. <(npm completion)`
// can never ever work on OS X.
- if (er.errno === require("constants").EPIPE) er = null
+ if (er.errno === "EPIPE") er = null
cb(er)
})

0 comments on commit 5effe86

Please sign in to comment.