diff options
Diffstat (limited to 'deps/npm/node_modules/npmconf/lib')
-rw-r--r-- | deps/npm/node_modules/npmconf/lib/load-cafile.js | 31 | ||||
-rw-r--r-- | deps/npm/node_modules/npmconf/lib/load-prefix.js | 70 | ||||
-rw-r--r-- | deps/npm/node_modules/npmconf/lib/set-user.js | 5 |
3 files changed, 69 insertions, 37 deletions
diff --git a/deps/npm/node_modules/npmconf/lib/load-cafile.js b/deps/npm/node_modules/npmconf/lib/load-cafile.js new file mode 100644 index 0000000000..b8c9fff233 --- /dev/null +++ b/deps/npm/node_modules/npmconf/lib/load-cafile.js @@ -0,0 +1,31 @@ +module.exports = loadCAFile + +var fs = require('fs') + +function loadCAFile(cafilePath, cb) { + if (!cafilePath) + return process.nextTick(cb) + + fs.readFile(cafilePath, 'utf8', afterCARead.bind(this)) + + function afterCARead(er, cadata) { + if (er) + return cb(er) + + var delim = '-----END CERTIFICATE-----' + var output + + output = cadata + .split(delim) + .filter(function(xs) { + return !!xs.trim() + }) + .map(function(xs) { + return xs.trimLeft() + delim + }) + + this.set('ca', output) + cb(null) + } + +} diff --git a/deps/npm/node_modules/npmconf/lib/load-prefix.js b/deps/npm/node_modules/npmconf/lib/load-prefix.js index c161b06495..bb39d9c98d 100644 --- a/deps/npm/node_modules/npmconf/lib/load-prefix.js +++ b/deps/npm/node_modules/npmconf/lib/load-prefix.js @@ -1,51 +1,49 @@ module.exports = loadPrefix var findPrefix = require("./find-prefix.js") -var mkdirp = require("mkdirp") var path = require('path') function loadPrefix (cb) { var cli = this.list[0] - // try to guess at a good node_modules location. - var p - , gp - - if (!Object.prototype.hasOwnProperty.call(cli, "prefix")) { - p = process.cwd() - } else { - p = this.get("prefix") - } - gp = this.get("prefix") - - findPrefix(p, function (er, p) { - Object.defineProperty(this, "localPrefix", - { get : function () { return p } - , set : function (r) { return p = r } - , enumerable : true - }) - // the prefix MUST exist, or else nothing works. - if (!this.get("global")) { - mkdirp(p, next.bind(this)) - } else { - next.bind(this)(er) - } - }.bind(this)) + Object.defineProperty(this, "prefix", + { set : function (prefix) { + var g = this.get("global") + this[g ? 'globalPrefix' : 'localPrefix'] = prefix + }.bind(this) + , get : function () { + var g = this.get("global") + return g ? this.globalPrefix : this.localPrefix + }.bind(this) + , enumerable : true + }) - gp = path.resolve(gp) Object.defineProperty(this, "globalPrefix", - { get : function () { return gp } - , set : function (r) { return gp = r } + { set : function (prefix) { + this.set('prefix', prefix) + }.bind(this) + , get : function () { + return path.resolve(this.get("prefix")) + }.bind(this) , enumerable : true }) - // the prefix MUST exist, or else nothing works. - mkdirp(gp, next.bind(this)) - var i = 2 - var errState = null - function next (er) { - if (errState) return - if (er) return cb(errState = er) - if (--i === 0) return cb() + var p + Object.defineProperty(this, "localPrefix", + { set : function (prefix) { p = prefix }, + get : function () { return p } + , enumerable: true }) + + // try to guess at a good node_modules location. + // If we are *explicitly* given a prefix on the cli, then + // always use that. otherwise, infer local prefix from cwd. + if (Object.prototype.hasOwnProperty.call(cli, "prefix")) { + p = path.resolve(cli.prefix) + process.nextTick(cb) + } else { + findPrefix(process.cwd(), function (er, found) { + p = found + cb(er) + }.bind(this)) } } diff --git a/deps/npm/node_modules/npmconf/lib/set-user.js b/deps/npm/node_modules/npmconf/lib/set-user.js index 2e7774aec3..cf29b1ace2 100644 --- a/deps/npm/node_modules/npmconf/lib/set-user.js +++ b/deps/npm/node_modules/npmconf/lib/set-user.js @@ -1,10 +1,13 @@ module.exports = setUser +var Conf = require('../npmconf.js').Conf +var assert = require('assert') var path = require('path') var fs = require('fs') function setUser (cb) { - var defaultConf = Object.getPrototypeOf(this.root) + var defaultConf = this.root + assert(defaultConf !== Object.prototype) // If global, leave it as-is. // If not global, then set the user to the owner of the prefix folder. |