1 module.exports = loadPrefix
3 var findPrefix = require("./find-prefix.js")
4 var path = require("path")
6 function loadPrefix (cb) {
9 Object.defineProperty(this, "prefix",
10 { set : function (prefix) {
11 var g = this.get("global")
12 this[g ? "globalPrefix" : "localPrefix"] = prefix
15 var g = this.get("global")
16 return g ? this.globalPrefix : this.localPrefix
21 Object.defineProperty(this, "globalPrefix",
22 { set : function (prefix) {
23 this.set("prefix", prefix)
26 return path.resolve(this.get("prefix"))
32 Object.defineProperty(this, "localPrefix",
33 { set : function (prefix) { p = prefix },
34 get : function () { return p }
37 // try to guess at a good node_modules location.
38 // If we are *explicitly* given a prefix on the cli, then
39 // always use that. otherwise, infer local prefix from cwd.
40 if (Object.prototype.hasOwnProperty.call(cli, "prefix")) {
41 p = path.resolve(cli.prefix)
44 findPrefix(process.cwd(), function (er, found) {