You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cmda.apache.org by xi...@apache.org on 2015/10/17 01:11:44 UTC
[10/51] [partial] incubator-cmda git commit: Update ApacheCMDA_1.0
http://git-wip-us.apache.org/repos/asf/incubator-cmda/blob/a9a83675/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/config.js
----------------------------------------------------------------------
diff --git a/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/config.js b/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/config.js
new file mode 100644
index 0000000..7d97763
--- /dev/null
+++ b/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/config.js
@@ -0,0 +1,285 @@
+
+module.exports = config
+
+config.usage = "npm config set <key> <value>"
+ + "\nnpm config get [<key>]"
+ + "\nnpm config delete <key>"
+ + "\nnpm config list"
+ + "\nnpm config edit"
+ + "\nnpm set <key> <value>"
+ + "\nnpm get [<key>]"
+
+var log = require("npmlog")
+ , npm = require("./npm.js")
+ , spawn = require("child_process").spawn
+ , fs = require("graceful-fs")
+ , npmconf = require("npmconf")
+ , types = npmconf.defs.types
+ , ini = require("ini")
+ , editor = require("editor")
+ , os = require("os")
+
+config.completion = function (opts, cb) {
+ var argv = opts.conf.argv.remain
+ if (argv[1] !== "config") argv.unshift("config")
+ if (argv.length === 2) {
+ var cmds = ["get", "set", "delete", "ls", "rm", "edit"]
+ if (opts.partialWord !== "l") cmds.push("list")
+ return cb(null, cmds)
+ }
+
+ var action = argv[2]
+ switch (action) {
+ case "set":
+ // todo: complete with valid values, if possible.
+ if (argv.length > 3) return cb(null, [])
+ // fallthrough
+ case "get":
+ case "delete":
+ case "rm":
+ return cb(null, Object.keys(types))
+ case "edit":
+ case "list": case "ls":
+ return cb(null, [])
+ default: return cb(null, [])
+ }
+}
+
+// npm config set key value
+// npm config get key
+// npm config list
+function config (args, cb) {
+ var action = args.shift()
+ switch (action) {
+ case "set": return set(args[0], args[1], cb)
+ case "get": return get(args[0], cb)
+ case "delete": case "rm": case "del": return del(args[0], cb)
+ case "list": case "ls": return list(cb)
+ case "edit": return edit(cb)
+ default: return unknown(action, cb)
+ }
+}
+
+function edit (cb) {
+ var e = npm.config.get("editor")
+ , which = npm.config.get("global") ? "global" : "user"
+ , f = npm.config.get(which + "config")
+ if (!e) return cb(new Error("No EDITOR config or environ set."))
+ npm.config.save(which, function (er) {
+ if (er) return cb(er)
+ fs.readFile(f, "utf8", function (er, data) {
+ if (er) data = ""
+ data = [ ";;;;"
+ , "; npm "+(npm.config.get("global") ?
+ "globalconfig" : "userconfig")+" file"
+ , "; this is a simple ini-formatted file"
+ , "; lines that start with semi-colons are comments."
+ , "; read `npm help config` for help on the various options"
+ , ";;;;"
+ , ""
+ , data
+ ].concat( [ ";;;;"
+ , "; all options with default values"
+ , ";;;;"
+ ]
+ )
+ .concat(Object.keys(npmconf.defaults).reduce(function (arr, key) {
+ var obj = {};
+ obj[key] = npmconf.defaults[key]
+ if (key === "logstream") return arr
+ return arr.concat(
+ ini.stringify(obj)
+ .replace(/\n$/m, '')
+ .replace(/^/g, '; ')
+ .replace(/\n/g, '\n; ')
+ .split('\n'))
+ }, []))
+ .concat([""])
+ .join(os.EOL)
+ fs.writeFile
+ ( f
+ , data
+ , "utf8"
+ , function (er) {
+ if (er) return cb(er)
+ editor(f, { editor: e }, cb)
+ }
+ )
+ })
+ })
+}
+
+function del (key, cb) {
+ if (!key) return cb(new Error("no key provided"))
+ var where = npm.config.get("global") ? "global" : "user"
+ npm.config.del(key, where)
+ npm.config.save(where, cb)
+}
+
+function set (key, val, cb) {
+ if (key === undefined) {
+ return unknown("", cb)
+ }
+ if (val === undefined) {
+ if (key.indexOf("=") !== -1) {
+ var k = key.split("=")
+ key = k.shift()
+ val = k.join("=")
+ } else {
+ val = ""
+ }
+ }
+ key = key.trim()
+ val = val.trim()
+ log.info("config", "set %j %j", key, val)
+ var where = npm.config.get("global") ? "global" : "user"
+ npm.config.set(key, val, where)
+ npm.config.save(where, cb)
+}
+
+function get (key, cb) {
+ if (!key) return list(cb)
+ if (key.charAt(0) === "_") {
+ return cb(new Error("---sekretz---"))
+ }
+ console.log(npm.config.get(key))
+ cb()
+}
+
+function sort (a, b) {
+ return a > b ? 1 : -1
+}
+
+function reverse (a, b) {
+ return a > b ? -1 : 1
+}
+
+function public (k) {
+ return !(k.charAt(0) === "_" || types[k] !== types[k])
+}
+
+function getKeys (data) {
+ return Object.keys(data).filter(public).sort(sort)
+}
+
+function list (cb) {
+ var msg = ""
+ , long = npm.config.get("long")
+
+ var cli = npm.config.sources.cli.data
+ , cliKeys = getKeys(cli)
+ if (cliKeys.length) {
+ msg += "; cli configs\n"
+ cliKeys.forEach(function (k) {
+ if (cli[k] && typeof cli[k] === "object") return
+ if (k === "argv") return
+ msg += k + " = " + JSON.stringify(cli[k]) + "\n"
+ })
+ msg += "\n"
+ }
+
+ // env configs
+ var env = npm.config.sources.env.data
+ , envKeys = getKeys(env)
+ if (envKeys.length) {
+ msg += "; environment configs\n"
+ envKeys.forEach(function (k) {
+ if (env[k] !== npm.config.get(k)) {
+ if (!long) return
+ msg += "; " + k + " = " + JSON.stringify(env[k])
+ + " (overridden)\n"
+ } else msg += k + " = " + JSON.stringify(env[k]) + "\n"
+ })
+ msg += "\n"
+ }
+
+ // user config file
+ var uconf = npm.config.sources.user.data
+ , uconfKeys = getKeys(uconf)
+ if (uconfKeys.length) {
+ msg += "; userconfig " + npm.config.get("userconfig") + "\n"
+ uconfKeys.forEach(function (k) {
+ var val = (k.charAt(0) === "_")
+ ? "---sekretz---"
+ : JSON.stringify(uconf[k])
+ if (uconf[k] !== npm.config.get(k)) {
+ if (!long) return
+ msg += "; " + k + " = " + val
+ + " (overridden)\n"
+ } else msg += k + " = " + val + "\n"
+ })
+ msg += "\n"
+ }
+
+ // global config file
+ var gconf = npm.config.sources.global.data
+ , gconfKeys = getKeys(gconf)
+ if (gconfKeys.length) {
+ msg += "; globalconfig " + npm.config.get("globalconfig") + "\n"
+ gconfKeys.forEach(function (k) {
+ var val = (k.charAt(0) === "_")
+ ? "---sekretz---"
+ : JSON.stringify(gconf[k])
+ if (gconf[k] !== npm.config.get(k)) {
+ if (!long) return
+ msg += "; " + k + " = " + val
+ + " (overridden)\n"
+ } else msg += k + " = " + val + "\n"
+ })
+ msg += "\n"
+ }
+
+ // builtin config file
+ var builtin = npm.config.sources.builtin || {}
+ if (builtin && builtin.data) {
+ var bconf = builtin.data
+ , bpath = builtin.path
+ , bconfKeys = getKeys(bconf)
+ if (bconfKeys.length) {
+ var path = require("path")
+ msg += "; builtin config " + bpath + "\n"
+ bconfKeys.forEach(function (k) {
+ var val = (k.charAt(0) === "_")
+ ? "---sekretz---"
+ : JSON.stringify(bconf[k])
+ if (bconf[k] !== npm.config.get(k)) {
+ if (!long) return
+ msg += "; " + k + " = " + val
+ + " (overridden)\n"
+ } else msg += k + " = " + val + "\n"
+ })
+ msg += "\n"
+ }
+ }
+
+ // only show defaults if --long
+ if (!long) {
+ msg += "; node bin location = " + process.execPath + "\n"
+ + "; cwd = " + process.cwd() + "\n"
+ + "; HOME = " + process.env.HOME + "\n"
+ + "; 'npm config ls -l' to show all defaults.\n"
+
+ console.log(msg)
+ return cb()
+ }
+
+ var defaults = npmconf.defaults
+ , defKeys = getKeys(defaults)
+ msg += "; default values\n"
+ defKeys.forEach(function (k) {
+ if (defaults[k] && typeof defaults[k] === "object") return
+ var val = JSON.stringify(defaults[k])
+ if (defaults[k] !== npm.config.get(k)) {
+ msg += "; " + k + " = " + val
+ + " (overridden)\n"
+ } else msg += k + " = " + val + "\n"
+ })
+ msg += "\n"
+
+ console.log(msg)
+ return cb()
+}
+
+function unknown (action, cb) {
+ cb("Usage:\n" + config.usage)
+}
http://git-wip-us.apache.org/repos/asf/incubator-cmda/blob/a9a83675/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/dedupe.js
----------------------------------------------------------------------
diff --git a/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/dedupe.js b/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/dedupe.js
new file mode 100644
index 0000000..ce161a4
--- /dev/null
+++ b/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/dedupe.js
@@ -0,0 +1,353 @@
+// traverse the node_modules/package.json tree
+// looking for duplicates. If any duplicates are found,
+// then move them up to the highest level necessary
+// in order to make them no longer duplicated.
+//
+// This is kind of ugly, and really highlights the need for
+// much better "put pkg X at folder Y" abstraction. Oh well,
+// whatever. Perfect enemy of the good, and all that.
+
+var fs = require("fs")
+var asyncMap = require("slide").asyncMap
+var path = require("path")
+var readJson = require("read-package-json")
+var archy = require("archy")
+var util = require("util")
+var RegClient = require("npm-registry-client")
+var npmconf = require("npmconf")
+var semver = require("semver")
+var rimraf = require("rimraf")
+var log = require("npmlog")
+var npm = require("./npm.js")
+
+module.exports = dedupe
+
+dedupe.usage = "npm dedupe [pkg pkg...]"
+
+function dedupe (args, silent, cb) {
+ if (typeof silent === "function") cb = silent, silent = false
+ var dryrun = false
+ if (npm.command.match(/^find/)) dryrun = true
+ return dedupe_(npm.prefix, args, {}, dryrun, silent, cb)
+}
+
+function dedupe_ (dir, filter, unavoidable, dryrun, silent, cb) {
+ readInstalled(path.resolve(dir), {}, null, function (er, data, counter) {
+ if (er) {
+ return cb(er)
+ }
+
+ if (!data) {
+ return cb()
+ }
+
+ // find out which things are dupes
+ var dupes = Object.keys(counter || {}).filter(function (k) {
+ if (filter.length && -1 === filter.indexOf(k)) return false
+ return counter[k] > 1 && !unavoidable[k]
+ }).reduce(function (s, k) {
+ s[k] = []
+ return s
+ }, {})
+
+ // any that are unavoidable need to remain as they are. don't even
+ // try to touch them or figure it out. Maybe some day, we can do
+ // something a bit more clever here, but for now, just skip over it,
+ // and all its children.
+ ;(function U (obj) {
+ if (unavoidable[obj.name]) {
+ obj.unavoidable = true
+ }
+ if (obj.parent && obj.parent.unavoidable) {
+ obj.unavoidable = true
+ }
+ Object.keys(obj.children).forEach(function (k) {
+ U(obj.children[k])
+ })
+ })
+
+ // then collect them up and figure out who needs them
+ ;(function C (obj) {
+ if (dupes[obj.name] && !obj.unavoidable) {
+ dupes[obj.name].push(obj)
+ obj.duplicate = true
+ }
+ obj.dependents = whoDepends(obj)
+ Object.keys(obj.children).forEach(function (k) {
+ C(obj.children[k])
+ })
+ })(data)
+
+ if (dryrun) {
+ var k = Object.keys(dupes)
+ if (!k.length) return cb()
+ return npm.commands.ls(k, silent, cb)
+ }
+
+ var summary = Object.keys(dupes).map(function (n) {
+ return [n, dupes[n].filter(function (d) {
+ return d && d.parent && !d.parent.duplicate && !d.unavoidable
+ }).map(function M (d) {
+ return [d.path, d.version, d.dependents.map(function (k) {
+ return [k.path, k.version, k.dependencies[d.name] || ""]
+ })]
+ })]
+ }).map(function (item) {
+ var name = item[0]
+ var set = item[1]
+
+ var ranges = set.map(function (i) {
+ return i[2].map(function (d) {
+ return d[2]
+ })
+ }).reduce(function (l, r) {
+ return l.concat(r)
+ }, []).map(function (v, i, set) {
+ if (set.indexOf(v) !== i) return false
+ return v
+ }).filter(function (v) {
+ return v !== false
+ })
+
+ var locs = set.map(function (i) {
+ return i[0]
+ })
+
+ var versions = set.map(function (i) {
+ return i[1]
+ }).filter(function (v, i, set) {
+ return set.indexOf(v) === i
+ })
+
+ var has = set.map(function (i) {
+ return [i[0], i[1]]
+ }).reduce(function (set, kv) {
+ set[kv[0]] = kv[1]
+ return set
+ }, {})
+
+ var loc = locs.length ? locs.reduce(function (a, b) {
+ // a=/path/to/node_modules/foo/node_modules/bar
+ // b=/path/to/node_modules/elk/node_modules/bar
+ // ==/path/to/node_modules/bar
+ var nmReg = new RegExp("\\" + path.sep + "node_modules\\" + path.sep)
+ a = a.split(nmReg)
+ b = b.split(nmReg)
+ var name = a.pop()
+ b.pop()
+ // find the longest chain that both A and B share.
+ // then push the name back on it, and join by /node_modules/
+ var res = []
+ for (var i = 0, al = a.length, bl = b.length; i < al && i < bl && a[i] === b[i]; i++);
+ return a.slice(0, i).concat(name).join(path.sep + "node_modules" + path.sep)
+ }) : undefined
+
+ return [item[0], { item: item
+ , ranges: ranges
+ , locs: locs
+ , loc: loc
+ , has: has
+ , versions: versions
+ }]
+ }).filter(function (i) {
+ return i[1].loc
+ })
+
+ findVersions(npm, summary, function (er, set) {
+ if (er) return cb(er)
+ if (!set.length) return cb()
+ installAndRetest(set, filter, dir, unavoidable, silent, cb)
+ })
+ })
+}
+
+function installAndRetest (set, filter, dir, unavoidable, silent, cb) {
+ //return cb(null, set)
+ var remove = []
+
+ asyncMap(set, function (item, cb) {
+ // [name, has, loc, locMatch, regMatch, others]
+ var name = item[0]
+ var has = item[1]
+ var where = item[2]
+ var locMatch = item[3]
+ var regMatch = item[4]
+ var others = item[5]
+
+ // nothing to be done here. oh well. just a conflict.
+ if (!locMatch && !regMatch) {
+ log.warn("unavoidable conflict", item[0], item[1])
+ log.warn("unavoidable conflict", "Not de-duplicating")
+ unavoidable[item[0]] = true
+ return cb()
+ }
+
+ // nothing to do except to clean up the extraneous deps
+ if (locMatch && has[where] === locMatch) {
+ remove.push.apply(remove, others)
+ return cb()
+ }
+
+ if (regMatch) {
+ var what = name + "@" + regMatch
+ // where is /path/to/node_modules/foo/node_modules/bar
+ // for package "bar", but we need it to be just
+ // /path/to/node_modules/foo
+ var nmReg = new RegExp("\\" + path.sep + "node_modules\\" + path.sep)
+ where = where.split(nmReg)
+ where.pop()
+ where = where.join(path.sep + "node_modules" + path.sep)
+ remove.push.apply(remove, others)
+
+ return npm.commands.install(where, what, cb)
+ }
+
+ // hrm?
+ return cb(new Error("danger zone\n" + name + " " +
+ + regMatch + " " + locMatch))
+
+ }, function (er, installed) {
+ if (er) return cb(er)
+ asyncMap(remove, rimraf, function (er) {
+ if (er) return cb(er)
+ remove.forEach(function (r) {
+ log.info("rm", r)
+ })
+ dedupe_(dir, filter, unavoidable, false, silent, cb)
+ })
+ })
+}
+
+function findVersions (npm, summary, cb) {
+ // now, for each item in the summary, try to find the maximum version
+ // that will satisfy all the ranges. next step is to install it at
+ // the specified location.
+ asyncMap(summary, function (item, cb) {
+ var name = item[0]
+ var data = item[1]
+ var loc = data.loc
+ var locs = data.locs.filter(function (l) {
+ return l !== loc
+ })
+
+ // not actually a dupe, or perhaps all the other copies were
+ // children of a dupe, so this'll maybe be picked up later.
+ if (locs.length === 0) {
+ return cb(null, [])
+ }
+
+ // { <folder>: <version> }
+ var has = data.has
+
+ // the versions that we already have.
+ // if one of these is ok, then prefer to use that.
+ // otherwise, try fetching from the registry.
+ var versions = data.versions
+
+ var ranges = data.ranges
+ npm.registry.get(name, function (er, data) {
+ var regVersions = er ? [] : Object.keys(data.versions)
+ var locMatch = bestMatch(versions, ranges)
+ var regMatch;
+ var tag = npm.config.get("tag");
+ var distTags = data["dist-tags"];
+ if (distTags && distTags[tag] && data.versions[distTags[tag]]) {
+ regMatch = distTags[tag]
+ } else {
+ regMatch = bestMatch(regVersions, ranges)
+ }
+
+ cb(null, [[name, has, loc, locMatch, regMatch, locs]])
+ })
+ }, cb)
+}
+
+function bestMatch (versions, ranges) {
+ return versions.filter(function (v) {
+ return !ranges.some(function (r) {
+ return !semver.satisfies(v, r, true)
+ })
+ }).sort(semver.compareLoose).pop()
+}
+
+
+function readInstalled (dir, counter, parent, cb) {
+ var pkg, children, realpath
+
+ fs.realpath(dir, function (er, rp) {
+ realpath = rp
+ next()
+ })
+
+ readJson(path.resolve(dir, "package.json"), function (er, data) {
+ if (er && er.code !== "ENOENT" && er.code !== "ENOTDIR") return cb(er)
+ if (er) return cb() // not a package, probably.
+ counter[data.name] = counter[data.name] || 0
+ counter[data.name]++
+ pkg =
+ { _id: data._id
+ , name: data.name
+ , version: data.version
+ , dependencies: data.dependencies || {}
+ , optionalDependencies: data.optionalDependencies || {}
+ , devDependencies: data.devDependencies || {}
+ , bundledDependencies: data.bundledDependencies || []
+ , path: dir
+ , realPath: dir
+ , children: {}
+ , parent: parent
+ , family: Object.create(parent ? parent.family : null)
+ , unavoidable: false
+ , duplicate: false
+ }
+ if (parent) {
+ parent.children[data.name] = pkg
+ parent.family[data.name] = pkg
+ }
+ next()
+ })
+
+ fs.readdir(path.resolve(dir, "node_modules"), function (er, c) {
+ children = c || [] // error is ok, just means no children.
+ children = children.filter(function (p) {
+ return !p.match(/^[\._-]/)
+ })
+ next()
+ })
+
+ function next () {
+ if (!children || !pkg || !realpath) return
+
+ // ignore devDependencies. Just leave them where they are.
+ children = children.filter(function (c) {
+ return !pkg.devDependencies.hasOwnProperty(c)
+ })
+
+ pkg.realPath = realpath
+ if (pkg.realPath !== pkg.path) children = []
+ var d = path.resolve(dir, "node_modules")
+ asyncMap(children, function (child, cb) {
+ readInstalled(path.resolve(d, child), counter, pkg, cb)
+ }, function (er) {
+ cb(er, pkg, counter)
+ })
+ }
+}
+
+function whoDepends (pkg) {
+ var start = pkg.parent || pkg
+ return whoDepends_(pkg, [], start)
+}
+
+function whoDepends_ (pkg, who, test) {
+ if (test !== pkg &&
+ test.dependencies[pkg.name] &&
+ test.family[pkg.name] === pkg) {
+ who.push(test)
+ }
+ Object.keys(test.children).forEach(function (n) {
+ whoDepends_(pkg, who, test.children[n])
+ })
+ return who
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-cmda/blob/a9a83675/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/deprecate.js
----------------------------------------------------------------------
diff --git a/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/deprecate.js b/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/deprecate.js
new file mode 100644
index 0000000..7d0b41a
--- /dev/null
+++ b/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/deprecate.js
@@ -0,0 +1,47 @@
+
+module.exports = deprecate
+
+deprecate.usage = "npm deprecate <pkg>[@<version>] <message>"
+
+deprecate.completion = function (opts, cb) {
+ // first, get a list of remote packages this user owns.
+ // once we have a user account, then don't complete anything.
+ var un = npm.config.get("username")
+ if (!npm.config.get("username")) return cb()
+ if (opts.conf.argv.remain.length > 2) return cb()
+ // get the list of packages by user
+ var uri = "/-/by-user/"+encodeURIComponent(un)
+ registry.get(uri, null, 60000, function (er, list) {
+ if (er) return cb()
+ console.error(list)
+ return cb(null, list[un])
+ })
+}
+
+var semver = require("semver")
+ , npm = require("./npm.js")
+ , registry = npm.registry
+
+function deprecate (args, cb) {
+ var pkg = args[0]
+ , msg = args[1]
+ if (msg === undefined) return cb("Usage: " + deprecate.usage)
+ // fetch the data and make sure it exists.
+ pkg = pkg.split(/@/)
+ var name = pkg.shift()
+ , ver = pkg.join("@")
+ if (semver.validRange(ver) === null) {
+ return cb(new Error("invalid version range: "+ver))
+ }
+ registry.get(name, function (er, data) {
+ if (er) return cb(er)
+ // filter all the versions that match
+ Object.keys(data.versions).filter(function (v) {
+ return semver.satisfies(v, ver, true)
+ }).forEach(function (v) {
+ data.versions[v].deprecated = msg
+ })
+ // now update the doc on the registry
+ registry.request('PUT', data._id, data, cb)
+ })
+}
http://git-wip-us.apache.org/repos/asf/incubator-cmda/blob/a9a83675/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/docs.js
----------------------------------------------------------------------
diff --git a/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/docs.js b/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/docs.js
new file mode 100644
index 0000000..2abbd62
--- /dev/null
+++ b/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/docs.js
@@ -0,0 +1,62 @@
+module.exports = docs
+
+docs.usage = "npm docs <pkgname>"
+docs.usage += "\n"
+docs.usage += "npm docs ."
+
+docs.completion = function (opts, cb) {
+ registry.get("/-/short", 60000, function (er, list) {
+ return cb(null, list || [])
+ })
+}
+
+var npm = require("./npm.js")
+ , registry = npm.registry
+ , opener = require("opener")
+ , path = require('path')
+ , log = require('npmlog')
+
+function url (json) {
+ return json.homepage ? json.homepage : "https://npmjs.org/package/" + json.name
+}
+
+function docs (args, cb) {
+ args = args || []
+ var pending = args.length
+ if (!pending) return getDoc('.', cb)
+ args.forEach(function(proj) {
+ getDoc(proj, function(err) {
+ if (err) return cb(err)
+ --pending || cb()
+ })
+ })
+}
+
+function getDoc (project, cb) {
+ project = project || '.'
+ var package = path.resolve(process.cwd(), "package.json")
+
+ if (project === '.' || project === './') {
+ try {
+ var json = require(package)
+ if (!json.name) throw new Error('package.json does not have a valid "name" property')
+ project = json.name
+ } catch (e) {
+ log.error(e.message)
+ return cb(docs.usage)
+ }
+
+ return opener(url(json), { command: npm.config.get("browser") }, cb)
+ }
+
+ registry.get(project + "/latest", 3600, function (er, json) {
+ var github = "https://github.com/" + project + "#readme"
+
+ if (er) {
+ if (project.split("/").length !== 2) return cb(er)
+ return opener(github, { command: npm.config.get("browser") }, cb)
+ }
+
+ return opener(url(json), { command: npm.config.get("browser") }, cb)
+ })
+}
http://git-wip-us.apache.org/repos/asf/incubator-cmda/blob/a9a83675/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/edit.js
----------------------------------------------------------------------
diff --git a/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/edit.js b/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/edit.js
new file mode 100644
index 0000000..791dc60
--- /dev/null
+++ b/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/edit.js
@@ -0,0 +1,32 @@
+// npm edit <pkg>[@<version>]
+// open the package folder in the $EDITOR
+
+module.exports = edit
+edit.usage = "npm edit <pkg>"
+
+edit.completion = require("./utils/completion/installed-shallow.js")
+
+var npm = require("./npm.js")
+ , spawn = require("child_process").spawn
+ , path = require("path")
+ , fs = require("graceful-fs")
+ , editor = require("editor")
+
+function edit (args, cb) {
+ var p = args[0]
+ if (args.length !== 1 || !p) return cb(edit.usage)
+ var e = npm.config.get("editor")
+ if (!e) return cb(new Error(
+ "No editor set. Set the 'editor' config, or $EDITOR environ."))
+ p = p.split("/")
+ .join("/node_modules/")
+ .replace(/(\/node_modules)+/, "/node_modules")
+ var f = path.resolve(npm.dir, p)
+ fs.lstat(f, function (er) {
+ if (er) return cb(er)
+ editor(f, { editor: e }, function (er) {
+ if (er) return cb(er)
+ npm.commands.rebuild(args, cb)
+ })
+ })
+}
http://git-wip-us.apache.org/repos/asf/incubator-cmda/blob/a9a83675/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/explore.js
----------------------------------------------------------------------
diff --git a/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/explore.js b/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/explore.js
new file mode 100644
index 0000000..8b55115
--- /dev/null
+++ b/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/explore.js
@@ -0,0 +1,36 @@
+// npm explore <pkg>[@<version>]
+// open a subshell to the package folder.
+
+module.exports = explore
+explore.usage = "npm explore <pkg> [ -- <cmd>]"
+explore.completion = require("./utils/completion/installed-shallow.js")
+
+var npm = require("./npm.js")
+ , spawn = require("child_process").spawn
+ , path = require("path")
+ , fs = require("graceful-fs")
+
+function explore (args, cb) {
+ if (args.length < 1 || !args[0]) return cb(explore.usage)
+ var p = args.shift()
+ args = args.join(" ").trim()
+ if (args) args = ["-c", args]
+ else args = []
+
+ var cwd = path.resolve(npm.dir, p)
+ var sh = npm.config.get("shell")
+ fs.stat(cwd, function (er, s) {
+ if (er || !s.isDirectory()) return cb(new Error(
+ "It doesn't look like "+p+" is installed."))
+ if (!args.length) console.log(
+ "\nExploring "+cwd+"\n"+
+ "Type 'exit' or ^D when finished\n")
+
+ var shell = spawn(sh, args, { cwd: cwd, customFds: [0, 1, 2] })
+ shell.on("close", function (er) {
+ // only fail if non-interactive.
+ if (!args.length) return cb()
+ cb(er)
+ })
+ })
+}
http://git-wip-us.apache.org/repos/asf/incubator-cmda/blob/a9a83675/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/faq.js
----------------------------------------------------------------------
diff --git a/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/faq.js b/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/faq.js
new file mode 100644
index 0000000..912db00
--- /dev/null
+++ b/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/faq.js
@@ -0,0 +1,8 @@
+
+module.exports = faq
+
+faq.usage = "npm faq"
+
+var npm = require("./npm.js")
+
+function faq (args, cb) { npm.commands.help(["faq"], cb) }
http://git-wip-us.apache.org/repos/asf/incubator-cmda/blob/a9a83675/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/get.js
----------------------------------------------------------------------
diff --git a/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/get.js b/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/get.js
new file mode 100644
index 0000000..aa05800
--- /dev/null
+++ b/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/get.js
@@ -0,0 +1,12 @@
+
+module.exports = get
+
+get.usage = "npm get <key> <value> (See `npm config`)"
+
+var npm = require("./npm.js")
+
+get.completion = npm.commands.config.completion
+
+function get (args, cb) {
+ npm.commands.config(["get"].concat(args), cb)
+}
http://git-wip-us.apache.org/repos/asf/incubator-cmda/blob/a9a83675/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/help-search.js
----------------------------------------------------------------------
diff --git a/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/help-search.js b/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/help-search.js
new file mode 100644
index 0000000..027f14c
--- /dev/null
+++ b/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/help-search.js
@@ -0,0 +1,218 @@
+
+module.exports = helpSearch
+
+var fs = require("graceful-fs")
+ , path = require("path")
+ , asyncMap = require("slide").asyncMap
+ , cliDocsPath = path.join(__dirname, "..", "doc", "cli")
+ , apiDocsPath = path.join(__dirname, "..", "doc", "api")
+ , log = require("npmlog")
+ , npm = require("./npm.js")
+ , glob = require("glob")
+
+helpSearch.usage = "npm help-search <text>"
+
+function helpSearch (args, silent, cb) {
+ if (typeof cb !== "function") cb = silent, silent = false
+ if (!args.length) return cb(helpSearch.usage)
+
+ // see if we're actually searching the api docs.
+ var argv = npm.config.get("argv").cooked
+
+ var docPath = path.resolve(__dirname, "..", "doc")
+ return glob(docPath + "/*/*.md", function (er, files) {
+ if (er)
+ return cb(er)
+ readFiles(files, function (er, data) {
+ if (er)
+ return cb(er)
+ searchFiles(args, data, function (er, results) {
+ if (er)
+ return cb(er)
+ formatResults(args, results, cb)
+ })
+ })
+ })
+}
+
+function readFiles (files, cb) {
+ var res = {}
+ asyncMap(files, function (file, cb) {
+ fs.readFile(file, 'utf8', function (er, data) {
+ res[file] = data
+ return cb(er)
+ })
+ }, function (er) {
+ return cb(er, res)
+ })
+}
+
+function searchFiles (args, files, cb) {
+ var results = []
+ Object.keys(files).forEach(function (file) {
+ var data = files[file]
+
+ // skip if no matches at all
+ for (var a = 0, l = args.length; a < l && !match; a++) {
+ var match = data.toLowerCase().indexOf(args[a].toLowerCase()) !== -1
+ }
+ if (!match)
+ return
+
+ var lines = data.split(/\n+/)
+ var context = []
+
+ // if a line has a search term, then skip it and the next line.
+ // if the next line has a search term, then skip all 3
+ // otherwise, set the line to null. then remove the nulls.
+ for (var i = 0, l = lines.length; i < l; i ++) {
+ var line = lines[i]
+ , nextLine = lines[i + 1]
+ , match = false
+ if (nextLine) {
+ for (var a = 0, ll = args.length; a < ll && !match; a ++) {
+ match = nextLine.toLowerCase()
+ .indexOf(args[a].toLowerCase()) !== -1
+ }
+ if (match) {
+ // skip over the next line, and the line after it.
+ i += 2
+ continue
+ }
+ }
+
+ match = false
+ for (var a = 0, ll = args.length; a < ll && !match; a ++) {
+ match = line.toLowerCase().indexOf(args[a].toLowerCase()) !== -1
+ }
+ if (match) {
+ // skip over the next line
+ i ++
+ continue
+ }
+
+ lines[i] = null
+ }
+
+ // now squish any string of nulls into a single null
+ lines = lines.reduce(function (l, r) {
+ if (!(r === null && l[l.length-1] === null)) l.push(r)
+ return l
+ }, [])
+
+ if (lines[lines.length - 1] === null) lines.pop()
+ if (lines[0] === null) lines.shift()
+
+ // now see how many args were found at all.
+ var found = {}
+ , totalHits = 0
+ lines.forEach(function (line) {
+ args.forEach(function (arg) {
+ var hit = (line || "").toLowerCase()
+ .split(arg.toLowerCase()).length - 1
+ if (hit > 0) {
+ found[arg] = (found[arg] || 0) + hit
+ totalHits += hit
+ }
+ })
+ })
+
+ var cmd = "npm help "
+ if (path.basename(path.dirname(file)) === "api") {
+ cmd = "npm apihelp "
+ }
+ cmd += path.basename(file, ".md").replace(/^npm-/, "")
+ results.push({ file: file
+ , cmd: cmd
+ , lines: lines
+ , found: Object.keys(found)
+ , hits: found
+ , totalHits: totalHits
+ })
+ })
+
+ // if only one result, then just show that help section.
+ if (results.length === 1) {
+ return npm.commands.help([results[0].file.replace(/\.md$/, "")], cb)
+ }
+
+ if (results.length === 0) {
+ console.log("No results for " + args.map(JSON.stringify).join(" "))
+ return cb()
+ }
+
+ // sort results by number of results found, then by number of hits
+ // then by number of matching lines
+ results = results.sort(function (a, b) {
+ return a.found.length > b.found.length ? -1
+ : a.found.length < b.found.length ? 1
+ : a.totalHits > b.totalHits ? -1
+ : a.totalHits < b.totalHits ? 1
+ : a.lines.length > b.lines.length ? -1
+ : a.lines.length < b.lines.length ? 1
+ : 0
+ })
+
+ cb(null, results)
+}
+
+function formatResults (args, results, cb) {
+ if (!results) return cb(null)
+
+ var cols = Math.min(process.stdout.columns || Infinity, 80) + 1
+
+ var out = results.map(function (res, i, results) {
+ var out = res.cmd
+ , r = Object.keys(res.hits).map(function (k) {
+ return k + ":" + res.hits[k]
+ }).sort(function (a, b) {
+ return a > b ? 1 : -1
+ }).join(" ")
+
+ out += ((new Array(Math.max(1, cols - out.length - r.length)))
+ .join (" ")) + r
+
+ if (!npm.config.get("long")) return out
+
+ var out = "\n\n" + out
+ + "\n" + (new Array(cols)).join("—") + "\n"
+ + res.lines.map(function (line, i) {
+ if (line === null || i > 3) return ""
+ for (var out = line, a = 0, l = args.length; a < l; a ++) {
+ var finder = out.toLowerCase().split(args[a].toLowerCase())
+ , newOut = []
+ , p = 0
+ finder.forEach(function (f) {
+ newOut.push( out.substr(p, f.length)
+ , "\1"
+ , out.substr(p + f.length, args[a].length)
+ , "\2" )
+ p += f.length + args[a].length
+ })
+ out = newOut.join("")
+ }
+ if (npm.color) {
+ var color = "\033[31;40m"
+ , reset = "\033[0m"
+ } else {
+ var color = ""
+ , reset = ""
+ }
+ out = out.split("\1").join(color)
+ .split("\2").join(reset)
+ return out
+ }).join("\n").trim()
+ return out
+ }).join("\n")
+
+ if (results.length && !npm.config.get("long")) {
+ out = "Top hits for "+(args.map(JSON.stringify).join(" "))
+ + "\n" + (new Array(cols)).join("—") + "\n"
+ + out
+ + "\n" + (new Array(cols)).join("—") + "\n"
+ + "(run with -l or --long to see more context)"
+ }
+
+ console.log(out.trim())
+ cb(null, results)
+}
http://git-wip-us.apache.org/repos/asf/incubator-cmda/blob/a9a83675/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/help.js
----------------------------------------------------------------------
diff --git a/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/help.js b/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/help.js
new file mode 100644
index 0000000..ea3970b
--- /dev/null
+++ b/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/help.js
@@ -0,0 +1,231 @@
+
+module.exports = help
+
+help.completion = function (opts, cb) {
+ if (opts.conf.argv.remain.length > 2) return cb(null, [])
+ getSections(cb)
+}
+
+var fs = require("graceful-fs")
+ , path = require("path")
+ , spawn = require("child_process").spawn
+ , npm = require("./npm.js")
+ , log = require("npmlog")
+ , opener = require("opener")
+ , glob = require("glob")
+
+function help (args, cb) {
+ var argv = npm.config.get("argv").cooked
+
+ var argnum = 0
+ if (args.length === 2 && ~~args[0]) {
+ argnum = ~~args.shift()
+ }
+
+ // npm help foo bar baz: search topics
+ if (args.length > 1 && args[0]) {
+ return npm.commands["help-search"](args, argnum, cb)
+ }
+
+ var section = npm.deref(args[0]) || args[0]
+
+ // npm help <noargs>: show basic usage
+ if (!section)
+ return npmUsage(cb)
+
+ // npm <cmd> -h: show command usage
+ if ( npm.config.get("usage")
+ && npm.commands[section]
+ && npm.commands[section].usage
+ ) {
+ npm.config.set("loglevel", "silent")
+ log.level = "silent"
+ console.log(npm.commands[section].usage)
+ return cb()
+ }
+
+ // npm apihelp <section>: Prefer section 3 over section 1
+ var apihelp = argv.length && -1 !== argv[0].indexOf("api")
+ var pref = apihelp ? [3, 1, 5, 7] : [1, 3, 5, 7]
+ if (argnum)
+ pref = [ argnum ].concat(pref.filter(function (n) {
+ return n !== argnum
+ }))
+
+ // npm help <section>: Try to find the path
+ var manroot = path.resolve(__dirname, "..", "man")
+ var htmlroot = path.resolve(__dirname, "..", "html", "doc")
+
+ // legacy
+ if (section === "global")
+ section = "folders"
+ else if (section === "json")
+ section = "package.json"
+
+ // find either /section.n or /npm-section.n
+ var f = "+(npm-" + section + "|" + section + ").[0-9]"
+ return glob(manroot + "/*/" + f, function (er, mans) {
+ if (er)
+ return cb(er)
+
+ if (!mans.length)
+ return npm.commands["help-search"](args, cb)
+
+ viewMan(pickMan(mans, pref), cb)
+ })
+}
+
+function pickMan (mans, pref_) {
+ var nre = /([0-9]+)$/
+ var pref = {}
+ pref_.forEach(function (sect, i) {
+ pref[sect] = i
+ })
+ mans = mans.sort(function (a, b) {
+ var an = a.match(nre)[1]
+ var bn = b.match(nre)[1]
+ return an === bn ? (a > b ? -1 : 1)
+ : pref[an] < pref[bn] ? -1
+ : 1
+ })
+ return mans[0]
+}
+
+function viewMan (man, cb) {
+ var nre = /([0-9]+)$/
+ var num = man.match(nre)[1]
+ var section = path.basename(man, "." + num)
+
+ // at this point, we know that the specified man page exists
+ var manpath = path.join(__dirname, "..", "man")
+ , env = {}
+ Object.keys(process.env).forEach(function (i) {
+ env[i] = process.env[i]
+ })
+ env.MANPATH = manpath
+ var viewer = npm.config.get("viewer")
+
+ switch (viewer) {
+ case "woman":
+ var a = ["-e", "(woman-find-file \"" + man + "\")"]
+ var conf = { env: env, customFds: [ 0, 1, 2] }
+ var woman = spawn("emacsclient", a, conf)
+ woman.on("close", cb)
+ break
+
+ case "browser":
+ opener(htmlMan(man), { command: npm.config.get("browser") }, cb)
+ break
+
+ default:
+ var conf = { env: env, customFds: [ 0, 1, 2] }
+ var man = spawn("man", [num, section], conf)
+ man.on("close", cb)
+ break
+ }
+}
+
+function htmlMan (man) {
+ var sect = +man.match(/([0-9]+)$/)[1]
+ var f = path.basename(man).replace(/([0-9]+)$/, "html")
+ switch (sect) {
+ case 1:
+ sect = "cli"
+ break
+ case 3:
+ sect = "api"
+ break
+ case 5:
+ sect = "files"
+ break
+ case 7:
+ sect = "misc"
+ break
+ default:
+ throw new Error("invalid man section: " + sect)
+ }
+ return path.resolve(__dirname, "..", "html", "doc", sect, f)
+}
+
+function npmUsage (cb) {
+ npm.config.set("loglevel", "silent")
+ log.level = "silent"
+ console.log
+ ( ["\nUsage: npm <command>"
+ , ""
+ , "where <command> is one of:"
+ , npm.config.get("long") ? usages()
+ : " " + wrap(Object.keys(npm.commands))
+ , ""
+ , "npm <cmd> -h quick help on <cmd>"
+ , "npm -l display full usage info"
+ , "npm faq commonly asked questions"
+ , "npm help <term> search for help on <term>"
+ , "npm help npm involved overview"
+ , ""
+ , "Specify configs in the ini-formatted file:"
+ , " " + npm.config.get("userconfig")
+ , "or on the command line via: npm <command> --key value"
+ , "Config info can be viewed via: npm help config"
+ , ""
+ , "npm@" + npm.version + " " + path.dirname(__dirname)
+ ].join("\n"))
+ cb()
+}
+
+function usages () {
+ // return a string of <cmd>: <usage>
+ var maxLen = 0
+ return Object.keys(npm.commands).filter(function (c) {
+ return c === npm.deref(c)
+ }).reduce(function (set, c) {
+ set.push([c, npm.commands[c].usage || ""])
+ maxLen = Math.max(maxLen, c.length)
+ return set
+ }, []).map(function (item) {
+ var c = item[0]
+ , usage = item[1]
+ return "\n " + c + (new Array(maxLen - c.length + 2).join(" "))
+ + (usage.split("\n")
+ .join("\n" + (new Array(maxLen + 6).join(" "))))
+ }).join("\n")
+ return out
+}
+
+
+function wrap (arr) {
+ var out = ['']
+ , l = 0
+ , line
+
+ line = process.stdout.columns
+ if (!line)
+ line = 60
+ else
+ line = Math.min(60, Math.max(line - 16, 24))
+
+ arr.sort(function (a,b) { return a<b?-1:1 })
+ .forEach(function (c) {
+ if (out[l].length + c.length + 2 < line) {
+ out[l] += ', '+c
+ } else {
+ out[l++] += ','
+ out[l] = c
+ }
+ })
+ return out.join("\n ").substr(2)
+}
+
+function getSections (cb) {
+ var g = path.resolve(__dirname, "../man/man[0-9]/*.[0-9]")
+ glob(g, function (er, files) {
+ if (er)
+ return cb(er)
+ cb(null, Object.keys(files.reduce(function (acc, file) {
+ file = path.basename(file).replace(/\.[0-9]+$/, "")
+ file = file.replace(/^npm-/, "")
+ acc[file] = true
+ return acc
+ }, { help: true })))
+ })
+}
http://git-wip-us.apache.org/repos/asf/incubator-cmda/blob/a9a83675/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/init.js
----------------------------------------------------------------------
diff --git a/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/init.js b/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/init.js
new file mode 100644
index 0000000..d064ae8
--- /dev/null
+++ b/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/init.js
@@ -0,0 +1,36 @@
+
+// initialize a package.json file
+
+module.exports = init
+
+var log = require("npmlog")
+ , npm = require("./npm.js")
+ , initJson = require("init-package-json")
+
+init.usage = "npm init"
+
+function init (args, cb) {
+ var dir = process.cwd()
+ log.pause()
+ var initFile = npm.config.get('init-module')
+
+ console.log(
+ ["This utility will walk you through creating a package.json file."
+ ,"It only covers the most common items, and tries to guess sane defaults."
+ ,""
+ ,"See `npm help json` for definitive documentation on these fields"
+ ,"and exactly what they do."
+ ,""
+ ,"Use `npm install <pkg> --save` afterwards to install a package and"
+ ,"save it as a dependency in the package.json file."
+ ,""
+ ,"Press ^C at any time to quit."
+ ].join("\n"))
+
+ initJson(dir, initFile, npm.config, function (er, data) {
+ log.resume()
+ log.silly('package data', data)
+ log.info('init', 'written successfully')
+ cb(er, data)
+ })
+}
http://git-wip-us.apache.org/repos/asf/incubator-cmda/blob/a9a83675/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/install.js
----------------------------------------------------------------------
diff --git a/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/install.js b/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/install.js
new file mode 100644
index 0000000..9270303
--- /dev/null
+++ b/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/install.js
@@ -0,0 +1,1114 @@
+// npm install <pkg> <pkg> <pkg>
+//
+// See doc/install.md for more description
+
+// Managing contexts...
+// there's a lot of state associated with an "install" operation, including
+// packages that are already installed, parent packages, current shrinkwrap, and
+// so on. We maintain this state in a "context" object that gets passed around.
+// every time we dive into a deeper node_modules folder, the "family" list that
+// gets passed along uses the previous "family" list as its __proto__. Any
+// "resolved precise dependency" things that aren't already on this object get
+// added, and then that's passed to the next generation of installation.
+
+module.exports = install
+
+install.usage = "npm install"
+ + "\nnpm install <pkg>"
+ + "\nnpm install <pkg>@<tag>"
+ + "\nnpm install <pkg>@<version>"
+ + "\nnpm install <pkg>@<version range>"
+ + "\nnpm install <folder>"
+ + "\nnpm install <tarball file>"
+ + "\nnpm install <tarball url>"
+ + "\nnpm install <git:// url>"
+ + "\nnpm install <github username>/<github project>"
+ + "\n\nCan specify one or more: npm install ./foo.tgz bar@stable /some/folder"
+ + "\nIf no argument is supplied and ./npm-shrinkwrap.json is "
+ + "\npresent, installs dependencies specified in the shrinkwrap."
+ + "\nOtherwise, installs dependencies from ./package.json."
+
+install.completion = function (opts, cb) {
+ // install can complete to a folder with a package.json, or any package.
+ // if it has a slash, then it's gotta be a folder
+ // if it starts with https?://, then just give up, because it's a url
+ // for now, not yet implemented.
+ var registry = npm.registry
+ registry.get("/-/short", function (er, pkgs) {
+ if (er) return cb()
+ if (!opts.partialWord) return cb(null, pkgs)
+
+ var name = opts.partialWord.split("@").shift()
+ pkgs = pkgs.filter(function (p) {
+ return p.indexOf(name) === 0
+ })
+
+ if (pkgs.length !== 1 && opts.partialWord === name) {
+ return cb(null, pkgs)
+ }
+
+ registry.get(pkgs[0], function (er, d) {
+ if (er) return cb()
+ return cb(null, Object.keys(d["dist-tags"] || {})
+ .concat(Object.keys(d.versions || {}))
+ .map(function (t) {
+ return pkgs[0] + "@" + t
+ }))
+ })
+ })
+}
+
+var npm = require("./npm.js")
+ , semver = require("semver")
+ , readJson = require("read-package-json")
+ , readInstalled = require("read-installed")
+ , log = require("npmlog")
+ , path = require("path")
+ , fs = require("graceful-fs")
+ , cache = require("./cache.js")
+ , asyncMap = require("slide").asyncMap
+ , chain = require("slide").chain
+ , url = require("url")
+ , mkdir = require("mkdirp")
+ , lifecycle = require("./utils/lifecycle.js")
+ , archy = require("archy")
+ , isGitUrl = require("./utils/is-git-url.js")
+
+function install (args, cb_) {
+ var hasArguments = !!args.length
+
+ function cb (er, installed) {
+ if (er) return cb_(er)
+
+ findPeerInvalid(where, function (er, problem) {
+ if (er) return cb_(er)
+
+ if (problem) {
+ var peerInvalidError = new Error("The package " + problem.name +
+ " does not satisfy its siblings' peerDependencies requirements!")
+ peerInvalidError.code = "EPEERINVALID"
+ peerInvalidError.packageName = problem.name
+ peerInvalidError.peersDepending = problem.peersDepending
+ return cb(peerInvalidError)
+ }
+
+ var tree = treeify(installed || [])
+ , pretty = prettify(tree, installed).trim()
+
+ if (pretty) console.log(pretty)
+ save(where, installed, tree, pretty, hasArguments, cb_)
+ })
+ }
+
+ // the /path/to/node_modules/..
+ var where = path.resolve(npm.dir, "..")
+
+ // internal api: install(where, what, cb)
+ if (arguments.length === 3) {
+ where = args
+ args = [].concat(cb_) // pass in [] to do default dep-install
+ cb_ = arguments[2]
+ log.verbose("install", "where,what", [where, args])
+ }
+
+ if (!npm.config.get("global")) {
+ args = args.filter(function (a) {
+ return path.resolve(a) !== where
+ })
+ }
+
+ mkdir(where, function (er, made) {
+ if (er) return cb(er)
+ // install dependencies locally by default,
+ // or install current folder globally
+ if (!args.length) {
+ var opt = { dev: npm.config.get("dev") || !npm.config.get("production") }
+
+ if (npm.config.get("global")) args = ["."]
+ else return readDependencies(null, where, opt, function (er, data) {
+ if (er) {
+ log.error("install", "Couldn't read dependencies")
+ return cb(er)
+ }
+ var deps = Object.keys(data.dependencies || {})
+ log.verbose("install", "where, deps", [where, deps])
+ var context = { family: {}
+ , ancestors: {}
+ , explicit: false
+ , parent: data
+ , root: true
+ , wrap: null }
+
+ if (data.name === path.basename(where) &&
+ path.basename(path.dirname(where)) === "node_modules") {
+ // Only include in ancestry if it can actually be required.
+ // Otherwise, it does not count.
+ context.family[data.name] =
+ context.ancestors[data.name] = data.version
+ }
+
+ installManyTop(deps.map(function (dep) {
+ var target = data.dependencies[dep]
+ , parsed = url.parse(target.replace(/^git\+/, "git"))
+ target = dep + "@" + target
+ return target
+ }), where, context, function(er, results) {
+ if (er) return cb(er, results)
+ lifecycle(data, "prepublish", where, function(er) {
+ return cb(er, results)
+ })
+ })
+ })
+ }
+
+ // initial "family" is the name:version of the root, if it's got
+ // a package.json file.
+ var jsonFile = path.resolve(where, "package.json")
+ readJson(jsonFile, log.warn, function (er, data) {
+ if (er
+ && er.code !== "ENOENT"
+ && er.code !== "ENOTDIR") return cb(er)
+ if (er) data = null
+ var context = { family: {}
+ , ancestors: {}
+ , explicit: true
+ , parent: data
+ , root: true
+ , wrap: null }
+ if (data && data.name === path.basename(where) &&
+ path.basename(path.dirname(where)) === "node_modules") {
+ context.family[data.name] = context.ancestors[data.name] = data.version
+ }
+ var fn = npm.config.get("global") ? installMany : installManyTop
+ fn(args, where, context, cb)
+ })
+ })
+}
+
+function findPeerInvalid (where, cb) {
+ readInstalled(where, log.warn, function (er, data) {
+ if (er) return cb(er)
+
+ cb(null, findPeerInvalid_(data.dependencies, []))
+ })
+}
+
+function findPeerInvalid_ (packageMap, fpiList) {
+ if (fpiList.indexOf(packageMap) !== -1)
+ return
+
+ fpiList.push(packageMap)
+
+ for (var packageName in packageMap) {
+ var pkg = packageMap[packageName]
+
+ if (pkg.peerInvalid) {
+ var peersDepending = {};
+ for (peerName in packageMap) {
+ var peer = packageMap[peerName]
+ if (peer.peerDependencies && peer.peerDependencies[packageName]) {
+ peersDepending[peer.name + "@" + peer.version] =
+ peer.peerDependencies[packageName]
+ }
+ }
+ return { name: pkg.name, peersDepending: peersDepending }
+ }
+
+ if (pkg.dependencies) {
+ var invalid = findPeerInvalid_(pkg.dependencies, fpiList)
+ if (invalid)
+ return invalid
+ }
+ }
+
+ return null
+}
+
+// reads dependencies for the package at "where". There are several cases,
+// depending on our current state and the package's configuration:
+//
+// 1. If "context" is specified, then we examine the context to see if there's a
+// shrinkwrap there. In that case, dependencies are read from the shrinkwrap.
+// 2. Otherwise, if an npm-shrinkwrap.json file is present, dependencies are
+// read from there.
+// 3. Otherwise, dependencies come from package.json.
+//
+// Regardless of which case we fall into, "cb" is invoked with a first argument
+// describing the full package (as though readJson had been used) but with
+// "dependencies" read as described above. The second argument to "cb" is the
+// shrinkwrap to use in processing this package's dependencies, which may be
+// "wrap" (in case 1) or a new shrinkwrap (in case 2).
+function readDependencies (context, where, opts, cb) {
+ var wrap = context ? context.wrap : null
+
+ readJson( path.resolve(where, "package.json")
+ , log.warn
+ , function (er, data) {
+ if (er && er.code === "ENOENT") er.code = "ENOPACKAGEJSON"
+ if (er) return cb(er)
+
+ if (opts && opts.dev) {
+ if (!data.dependencies) data.dependencies = {}
+ Object.keys(data.devDependencies || {}).forEach(function (k) {
+ data.dependencies[k] = data.devDependencies[k]
+ })
+ }
+
+ if (!npm.config.get("optional") && data.optionalDependencies) {
+ Object.keys(data.optionalDependencies).forEach(function (d) {
+ delete data.dependencies[d]
+ })
+ }
+
+ // User has opted out of shrinkwraps entirely
+ if (npm.config.get("shrinkwrap") === false)
+ return cb(null, data, null)
+
+ if (wrap) {
+ log.verbose("readDependencies: using existing wrap", [where, wrap])
+ var rv = {}
+ Object.keys(data).forEach(function (key) {
+ rv[key] = data[key]
+ })
+ rv.dependencies = {}
+ Object.keys(wrap).forEach(function (key) {
+ log.verbose("from wrap", [key, wrap[key]])
+ rv.dependencies[key] = readWrap(wrap[key])
+ })
+ log.verbose("readDependencies returned deps", rv.dependencies)
+ return cb(null, rv, wrap)
+ }
+
+ var wrapfile = path.resolve(where, "npm-shrinkwrap.json")
+
+ fs.readFile(wrapfile, "utf8", function (er, wrapjson) {
+ if (er) {
+ log.verbose("readDependencies", "using package.json deps")
+ return cb(null, data, null)
+ }
+
+ try {
+ var newwrap = JSON.parse(wrapjson)
+ } catch (ex) {
+ return cb(ex)
+ }
+
+ log.info("shrinkwrap", "file %j", wrapfile)
+ var rv = {}
+ Object.keys(data).forEach(function (key) {
+ rv[key] = data[key]
+ })
+ rv.dependencies = {}
+ Object.keys(newwrap.dependencies || {}).forEach(function (key) {
+ rv.dependencies[key] = readWrap(newwrap.dependencies[key])
+ })
+
+ // fold in devDependencies if not already present, at top level
+ if (opts && opts.dev) {
+ Object.keys(data.devDependencies || {}).forEach(function (k) {
+ rv.dependencies[k] = rv.dependencies[k] || data.devDependencies[k]
+ })
+ }
+
+ log.verbose("readDependencies returned deps", rv.dependencies)
+ return cb(null, rv, newwrap.dependencies)
+ })
+ })
+}
+
+function readWrap (w) {
+ return (w.resolved) ? w.resolved
+ : (w.from && url.parse(w.from).protocol) ? w.from
+ : w.version
+}
+
+// if the -S|--save option is specified, then write installed packages
+// as dependencies to a package.json file.
+// This is experimental.
+function save (where, installed, tree, pretty, hasArguments, cb) {
+ if (!hasArguments ||
+ !npm.config.get("save") &&
+ !npm.config.get("save-dev") &&
+ !npm.config.get("save-optional") ||
+ npm.config.get("global")) {
+ return cb(null, installed, tree, pretty)
+ }
+
+ var saveBundle = npm.config.get('save-bundle')
+
+ // each item in the tree is a top-level thing that should be saved
+ // to the package.json file.
+ // The relevant tree shape is { <folder>: {what:<pkg>} }
+ var saveTarget = path.resolve(where, "package.json")
+ , things = Object.keys(tree).map(function (k) {
+ // if "what" was a url, then save that instead.
+ var t = tree[k]
+ , u = url.parse(t.from)
+ , w = t.what.split("@")
+ if (u && u.protocol) w[1] = t.from
+ return w
+ }).reduce(function (set, k) {
+ var rangeDescriptor = semver.valid(k[1], true) &&
+ semver.gte(k[1], "0.1.0", true)
+ ? "~" : ""
+ set[k[0]] = rangeDescriptor + k[1]
+ return set
+ }, {})
+
+ // don't use readJson, because we don't want to do all the other
+ // tricky npm-specific stuff that's in there.
+ fs.readFile(saveTarget, function (er, data) {
+ // ignore errors here, just don't save it.
+ try {
+ data = JSON.parse(data.toString("utf8"))
+ } catch (ex) {
+ er = ex
+ }
+
+ if (er) {
+ return cb(null, installed, tree, pretty)
+ }
+
+ var deps = npm.config.get("save-optional") ? "optionalDependencies"
+ : npm.config.get("save-dev") ? "devDependencies"
+ : "dependencies"
+
+ if (saveBundle) {
+ var bundle = data.bundleDependencies || data.bundledDependencies
+ delete data.bundledDependencies
+ if (!Array.isArray(bundle)) bundle = []
+ data.bundleDependencies = bundle
+ }
+
+ log.verbose('saving', things)
+ data[deps] = data[deps] || {}
+ Object.keys(things).forEach(function (t) {
+ data[deps][t] = things[t]
+ if (saveBundle) {
+ var i = bundle.indexOf(t)
+ if (i === -1) bundle.push(t)
+ }
+ })
+
+ data = JSON.stringify(data, null, 2) + "\n"
+ fs.writeFile(saveTarget, data, function (er) {
+ cb(er, installed, tree, pretty)
+ })
+ })
+}
+
+
+// Outputting *all* the installed modules is a bit confusing,
+// because the length of the path does not make it clear
+// that the submodules are not immediately require()able.
+// TODO: Show the complete tree, ls-style, but only if --long is provided
+function prettify (tree, installed) {
+ if (npm.config.get("json")) {
+ function red (set, kv) {
+ set[kv[0]] = kv[1]
+ return set
+ }
+
+ tree = Object.keys(tree).map(function (p) {
+ if (!tree[p]) return null
+ var what = tree[p].what.split("@")
+ , name = what.shift()
+ , version = what.join("@")
+ , o = { name: name, version: version, from: tree[p].from }
+ o.dependencies = tree[p].children.map(function P (dep) {
+ var what = dep.what.split("@")
+ , name = what.shift()
+ , version = what.join("@")
+ , o = { version: version, from: dep.from }
+ o.dependencies = dep.children.map(P).reduce(red, {})
+ return [name, o]
+ }).reduce(red, {})
+ return o
+ })
+
+ return JSON.stringify(tree, null, 2)
+ }
+ if (npm.config.get("parseable")) return parseable(installed)
+
+ return Object.keys(tree).map(function (p) {
+ return archy({ label: tree[p].what + " " + p
+ , nodes: (tree[p].children || []).map(function P (c) {
+ if (npm.config.get("long")) {
+ return { label: c.what, nodes: c.children.map(P) }
+ }
+ var g = c.children.map(function (g) {
+ return g.what
+ }).join(", ")
+ if (g) g = " (" + g + ")"
+ return c.what + g
+ })
+ })
+ }).join("\n")
+}
+
+function parseable (installed) {
+ var long = npm.config.get("long")
+ , cwd = process.cwd()
+ return installed.map(function (item) {
+ return path.resolve(cwd, item[1]) +
+ ( long ? ":" + item[0] : "" )
+ }).join("\n")
+}
+
+function treeify (installed) {
+ // each item is [what, where, parent, parentDir]
+ // If no parent, then report it.
+ // otherwise, tack it into the parent's children list.
+ // If the parent isn't a top-level then ignore it.
+ var whatWhere = installed.reduce(function (l, r) {
+ var parentDir = r[3]
+ , parent = r[2]
+ , where = r[1]
+ , what = r[0]
+ , from = r[4]
+ l[where] = { parentDir: parentDir
+ , parent: parent
+ , children: []
+ , where: where
+ , what: what
+ , from: from }
+ return l
+ }, {})
+
+ // log.warn("install", whatWhere, "whatWhere")
+ return Object.keys(whatWhere).reduce(function (l, r) {
+ var ww = whatWhere[r]
+ //log.warn("r, ww", [r, ww])
+ if (!ww.parent) {
+ l[r] = ww
+ } else {
+ var p = whatWhere[ww.parentDir]
+ if (p) p.children.push(ww)
+ else l[r] = ww
+ }
+ return l
+ }, {})
+}
+
+
+// just like installMany, but also add the existing packages in
+// where/node_modules to the family object.
+function installManyTop (what, where, context, cb_) {
+ function cb (er, d) {
+ if (context.explicit || er) return cb_(er, d)
+ // since this wasn't an explicit install, let's build the top
+ // folder, so that `npm install` also runs the lifecycle scripts.
+ npm.commands.build([where], false, true, function (er) {
+ return cb_(er, d)
+ })
+ }
+
+ if (context.explicit) return next()
+
+ readJson(path.join(where, "package.json"), log.warn, function (er, data) {
+ if (er) return next(er)
+ lifecycle(data, "preinstall", where, next)
+ })
+
+ function next (er) {
+ if (er) return cb(er)
+ installManyTop_(what, where, context, cb)
+ }
+}
+
+function installManyTop_ (what, where, context, cb) {
+ var nm = path.resolve(where, "node_modules")
+ , names = context.explicit
+ ? what.map(function (w) { return w.split(/@/).shift() })
+ : []
+
+ fs.readdir(nm, function (er, pkgs) {
+ if (er) return installMany(what, where, context, cb)
+ pkgs = pkgs.filter(function (p) {
+ return !p.match(/^[\._-]/)
+ })
+ asyncMap(pkgs.map(function (p) {
+ return path.resolve(nm, p, "package.json")
+ }), function (jsonfile, cb) {
+ readJson(jsonfile, log.warn, function (er, data) {
+ if (er && er.code !== "ENOENT" && er.code !== "ENOTDIR") return cb(er)
+ if (er) return cb(null, [])
+ return cb(null, [[data.name, data.version]])
+ })
+ }, function (er, packages) {
+ // if there's nothing in node_modules, then don't freak out.
+ if (er) packages = []
+ // add all the existing packages to the family list.
+ // however, do not add to the ancestors list.
+ packages.forEach(function (p) {
+ context.family[p[0]] = p[1]
+ })
+ return installMany(what, where, context, cb)
+ })
+ })
+}
+
+function installMany (what, where, context, cb) {
+ // readDependencies takes care of figuring out whether the list of
+ // dependencies we'll iterate below comes from an existing shrinkwrap from a
+ // parent level, a new shrinkwrap at this level, or package.json at this
+ // level, as well as which shrinkwrap (if any) our dependencies should use.
+ var opt = { dev: npm.config.get("dev") }
+ readDependencies(context, where, opt, function (er, data, wrap) {
+ if (er) data = {}
+
+ var parent = data
+
+ var d = data.dependencies || {}
+
+ // if we're explicitly installing "what" into "where", then the shrinkwrap
+ // for "where" doesn't apply. This would be the case if someone were adding
+ // a new package to a shrinkwrapped package. (data.dependencies will not be
+ // used here except to indicate what packages are already present, so
+ // there's no harm in using that.)
+ if (context.explicit) wrap = null
+
+ // what is a list of things.
+ // resolve each one.
+ asyncMap( what
+ , targetResolver(where, context, d)
+ , function (er, targets) {
+
+ if (er) return cb(er)
+
+ // each target will be a data object corresponding
+ // to a package, folder, or whatever that is in the cache now.
+ var newPrev = Object.create(context.family)
+ , newAnc = Object.create(context.ancestors)
+
+ if (!context.root) {
+ newAnc[data.name] = data.version
+ }
+ targets.forEach(function (t) {
+ newPrev[t.name] = t.version
+ })
+ log.silly("resolved", targets)
+ targets.filter(function (t) { return t }).forEach(function (t) {
+ log.info("install", "%s into %s", t._id, where)
+ })
+ asyncMap(targets, function (target, cb) {
+ log.info("installOne", target._id)
+ var wrapData = wrap ? wrap[target.name] : null
+ var newWrap = wrapData && wrapData.dependencies
+ ? wrap[target.name].dependencies || {}
+ : null
+ var newContext = { family: newPrev
+ , ancestors: newAnc
+ , parent: parent
+ , explicit: false
+ , wrap: newWrap }
+ installOne(target, where, newContext, cb)
+ }, cb)
+ })
+ })
+}
+
+function targetResolver (where, context, deps) {
+ var alreadyInstalledManually = context.explicit ? [] : null
+ , nm = path.resolve(where, "node_modules")
+ , parent = context.parent
+ , wrap = context.wrap
+
+ if (!context.explicit) fs.readdir(nm, function (er, inst) {
+ if (er) return alreadyInstalledManually = []
+
+ // don't even mess with non-package looking things
+ inst = inst.filter(function (p) {
+ return !p.match(/^[\._-]/)
+ })
+
+ asyncMap(inst, function (pkg, cb) {
+ readJson(path.resolve(nm, pkg, "package.json"), log.warn, function (er, d) {
+ if (er && er.code !== "ENOENT" && er.code !== "ENOTDIR") return cb(er)
+ // error means it's not a package, most likely.
+ if (er) return cb(null, [])
+
+ // if it's a bundled dep, then assume that anything there is valid.
+ // otherwise, make sure that it's a semver match with what we want.
+ var bd = parent.bundleDependencies
+ if (bd && bd.indexOf(d.name) !== -1 ||
+ semver.satisfies(d.version, deps[d.name] || "*", true) ||
+ deps[d.name] === d._resolved) {
+ return cb(null, d.name)
+ }
+
+ // see if the package had been previously linked
+ fs.lstat(path.resolve(nm, pkg), function(err, s) {
+ if (err) return cb(null, [])
+ if (s.isSymbolicLink()) {
+ return cb(null, d.name)
+ }
+
+ // something is there, but it's not satisfactory. Clobber it.
+ return cb(null, [])
+ })
+ })
+ }, function (er, inst) {
+ // this is the list of things that are valid and should be ignored.
+ alreadyInstalledManually = inst
+ })
+ })
+
+ var to = 0
+ return function resolver (what, cb) {
+ if (!alreadyInstalledManually) return setTimeout(function () {
+ resolver(what, cb)
+ }, to++)
+
+ // now we know what's been installed here manually,
+ // or tampered with in some way that npm doesn't want to overwrite.
+ if (alreadyInstalledManually.indexOf(what.split("@").shift()) !== -1) {
+ log.verbose("already installed", "skipping %s %s", what, where)
+ return cb(null, [])
+ }
+
+ // check for a version installed higher in the tree.
+ // If installing from a shrinkwrap, it must match exactly.
+ if (context.family[what]) {
+ if (wrap && wrap[what].version === context.family[what]) {
+ log.verbose("shrinkwrap", "use existing", what)
+ return cb(null, [])
+ }
+ }
+
+ // if it's identical to its parent, then it's probably someone
+ // doing `npm install foo` inside of the foo project. Print
+ // a warning, and skip it.
+ if (parent && parent.name === what && !npm.config.get("force")) {
+ log.warn("install", "Refusing to install %s as a dependency of itself"
+ , what)
+ return cb(null, [])
+ }
+
+ if (wrap) {
+ var name = what.split(/@/).shift()
+ if (wrap[name]) {
+ var wrapTarget = readWrap(wrap[name])
+ what = name + "@" + wrapTarget
+ } else {
+ log.verbose("shrinkwrap", "skipping %s (not in shrinkwrap)", what)
+ }
+ } else if (deps[what]) {
+ what = what + "@" + deps[what]
+ }
+
+ // This is where we actually fetch the package, if it's not already
+ // in the cache.
+ // If it's a git repo, then we want to install it, even if the parent
+ // already has a matching copy.
+ // If it's not a git repo, and the parent already has that pkg, then
+ // we can skip installing it again.
+ cache.add(what, function (er, data) {
+ if (er && parent && parent.optionalDependencies &&
+ parent.optionalDependencies.hasOwnProperty(what.split("@")[0])) {
+ log.warn("optional dep failed, continuing", what)
+ log.verbose("optional dep failed, continuing", [what, er])
+ return cb(null, [])
+ }
+
+ var isGit = false
+ , maybeGit = what.split("@").slice(1).join()
+
+ if (maybeGit)
+ isGit = isGitUrl(url.parse(maybeGit))
+
+ if (!er &&
+ data &&
+ !context.explicit &&
+ context.family[data.name] === data.version &&
+ !npm.config.get("force") &&
+ !isGit) {
+ log.info("already installed", data.name + "@" + data.version)
+ return cb(null, [])
+ }
+
+ if (data && !data._from) data._from = what
+ if (er && parent && parent.name) er.parent = parent.name
+ return cb(er, data || [])
+ })
+ }
+}
+
+// we've already decided to install this. if anything's in the way,
+// then uninstall it first.
+function installOne (target, where, context, cb) {
+ // the --link flag makes this a "link" command if it's at the
+ // the top level.
+ if (where === npm.prefix && npm.config.get("link")
+ && !npm.config.get("global")) {
+ return localLink(target, where, context, cb)
+ }
+ installOne_(target, where, context, function (er, installedWhat) {
+
+ // check if this one is optional to its parent.
+ if (er && context.parent && context.parent.optionalDependencies &&
+ context.parent.optionalDependencies.hasOwnProperty(target.name)) {
+ log.warn("optional dep failed, continuing", target._id)
+ log.verbose("optional dep failed, continuing", [target._id, er])
+ er = null
+ }
+
+ cb(er, installedWhat)
+ })
+
+}
+
+function localLink (target, where, context, cb) {
+ log.verbose("localLink", target._id)
+ var jsonFile = path.resolve( npm.globalDir, target.name
+ , "package.json" )
+ , parent = context.parent
+
+ readJson(jsonFile, log.warn, function (er, data) {
+ if (er && er.code !== "ENOENT" && er.code !== "ENOTDIR") return cb(er)
+ if (er || data._id === target._id) {
+ if (er) {
+ install( path.resolve(npm.globalDir, "..")
+ , target._id
+ , function (er) {
+ if (er) return cb(er, [])
+ thenLink()
+ })
+ } else thenLink()
+
+ function thenLink () {
+ npm.commands.link([target.name], function (er, d) {
+ log.silly("localLink", "back from link", [er, d])
+ cb(er, [resultList(target, where, parent && parent._id)])
+ })
+ }
+
+ } else {
+ log.verbose("localLink", "install locally (no link)", target._id)
+ installOne_(target, where, context, cb)
+ }
+ })
+}
+
+function resultList (target, where, parentId) {
+ var nm = path.resolve(where, "node_modules")
+ , targetFolder = path.resolve(nm, target.name)
+ , prettyWhere = where
+
+ if (!npm.config.get("global")) {
+ prettyWhere = path.relative(process.cwd(), where)
+ }
+
+ if (prettyWhere === ".") prettyWhere = null
+
+ if (!npm.config.get("global")) {
+ // print out the folder relative to where we are right now.
+ targetFolder = path.relative(process.cwd(), targetFolder)
+ }
+
+ return [ target._id
+ , targetFolder
+ , prettyWhere && parentId
+ , parentId && prettyWhere
+ , target._from ]
+}
+
+// name => install locations
+var installOnesInProgress = Object.create(null)
+
+function isIncompatibleInstallOneInProgress(target, where) {
+ return target.name in installOnesInProgress &&
+ installOnesInProgress[target.name].indexOf(where) !== -1
+}
+
+function installOne_ (target, where, context, cb) {
+ var nm = path.resolve(where, "node_modules")
+ , targetFolder = path.resolve(nm, target.name)
+ , prettyWhere = path.relative(process.cwd(), where)
+ , parent = context.parent
+
+ if (prettyWhere === ".") prettyWhere = null
+
+ if (isIncompatibleInstallOneInProgress(target, where)) {
+ var prettyTarget = path.relative(process.cwd(), targetFolder)
+
+ // just call back, with no error. the error will be detected in the
+ // final check for peer-invalid dependencies
+ return cb()
+ }
+
+ if (!(target.name in installOnesInProgress)) {
+ installOnesInProgress[target.name] = []
+ }
+ installOnesInProgress[target.name].push(where)
+ var indexOfIOIP = installOnesInProgress[target.name].length - 1
+
+ chain
+ ( [ [checkEngine, target]
+ , [checkPlatform, target]
+ , [checkCycle, target, context.ancestors]
+ , [checkGit, targetFolder]
+ , [write, target, targetFolder, context] ]
+ , function (er, d) {
+ installOnesInProgress[target.name].splice(indexOfIOIP, 1)
+
+ if (er) return cb(er)
+
+ d.push(resultList(target, where, parent && parent._id))
+ cb(er, d)
+ }
+ )
+}
+
+function checkEngine (target, cb) {
+ var npmv = npm.version
+ , force = npm.config.get("force")
+ , nodev = force ? null : npm.config.get("node-version")
+ , strict = npm.config.get("engine-strict") || target.engineStrict
+ , eng = target.engines
+ if (!eng) return cb()
+ if (nodev && eng.node && !semver.satisfies(nodev, eng.node)
+ || eng.npm && !semver.satisfies(npmv, eng.npm)) {
+ if (strict) {
+ var er = new Error("Unsupported")
+ er.code = "ENOTSUP"
+ er.required = eng
+ er.pkgid = target._id
+ return cb(er)
+ } else {
+ log.warn( "engine", "%s: wanted: %j (current: %j)"
+ , target._id, eng, {node: nodev, npm: npm.version} )
+ }
+ }
+ return cb()
+}
+
+function checkPlatform (target, cb) {
+ var platform = process.platform
+ , arch = process.arch
+ , osOk = true
+ , cpuOk = true
+ , force = npm.config.get("force")
+
+ if (force) {
+ return cb()
+ }
+
+ if (target.os) {
+ osOk = checkList(platform, target.os)
+ }
+ if (target.cpu) {
+ cpuOk = checkList(arch, target.cpu)
+ }
+ if (!osOk || !cpuOk) {
+ var er = new Error("Unsupported")
+ er.code = "EBADPLATFORM"
+ er.os = target.os || ['any']
+ er.cpu = target.cpu || ['any']
+ er.pkgid = target._id
+ return cb(er)
+ }
+ return cb()
+}
+
+function checkList (value, list) {
+ var tmp
+ , match = false
+ , blc = 0
+ if (typeof list === "string") {
+ list = [list]
+ }
+ if (list.length === 1 && list[0] === "any") {
+ return true
+ }
+ for (var i = 0; i < list.length; ++i) {
+ tmp = list[i]
+ if (tmp[0] === '!') {
+ tmp = tmp.slice(1)
+ if (tmp === value) {
+ return false
+ }
+ ++blc
+ } else {
+ match = match || tmp === value
+ }
+ }
+ return match || blc === list.length
+}
+
+function checkCycle (target, ancestors, cb) {
+ // there are some very rare and pathological edge-cases where
+ // a cycle can cause npm to try to install a never-ending tree
+ // of stuff.
+ // Simplest:
+ //
+ // A -> B -> A' -> B' -> A -> B -> A' -> B' -> A -> ...
+ //
+ // Solution: Simply flat-out refuse to install any name@version
+ // that is already in the prototype tree of the ancestors object.
+ // A more correct, but more complex, solution would be to symlink
+ // the deeper thing into the new location.
+ // Will do that if anyone whines about this irl.
+ //
+ // Note: `npm install foo` inside of the `foo` package will abort
+ // earlier if `--force` is not set. However, if it IS set, then
+ // we need to still fail here, but just skip the first level. Of
+ // course, it'll still fail eventually if it's a true cycle, and
+ // leave things in an undefined state, but that's what is to be
+ // expected when `--force` is used. That is why getPrototypeOf
+ // is used *twice* here: to skip the first level of repetition.
+
+ var p = Object.getPrototypeOf(Object.getPrototypeOf(ancestors))
+ , name = target.name
+ , version = target.version
+ while (p && p !== Object.prototype && p[name] !== version) {
+ p = Object.getPrototypeOf(p)
+ }
+ if (p[name] !== version) return cb()
+
+ var er = new Error("Unresolvable cycle detected")
+ var tree = [target._id, JSON.parse(JSON.stringify(ancestors))]
+ , t = Object.getPrototypeOf(ancestors)
+ while (t && t !== Object.prototype) {
+ if (t === p) t.THIS_IS_P = true
+ tree.push(JSON.parse(JSON.stringify(t)))
+ t = Object.getPrototypeOf(t)
+ }
+ log.verbose("unresolvable dependency tree", tree)
+ er.pkgid = target._id
+ er.code = "ECYCLE"
+ return cb(er)
+}
+
+function checkGit (folder, cb) {
+ // if it's a git repo then don't touch it!
+ fs.lstat(folder, function (er, s) {
+ if (er || !s.isDirectory()) return cb()
+ else checkGit_(folder, cb)
+ })
+}
+
+function checkGit_ (folder, cb) {
+ fs.stat(path.resolve(folder, ".git"), function (er, s) {
+ if (!er && s.isDirectory()) {
+ var e = new Error("Appears to be a git repo or submodule.")
+ e.path = folder
+ e.code = "EISGIT"
+ return cb(e)
+ }
+ cb()
+ })
+}
+
+function write (target, targetFolder, context, cb_) {
+ var up = npm.config.get("unsafe-perm")
+ , user = up ? null : npm.config.get("user")
+ , group = up ? null : npm.config.get("group")
+ , family = context.family
+
+ function cb (er, data) {
+ // cache.unpack returns the data object, and all we care about
+ // is the list of installed packages from that last thing.
+ if (!er) return cb_(er, data)
+
+ if (false === npm.config.get("rollback")) return cb_(er)
+ npm.commands.unbuild([targetFolder], true, function (er2) {
+ if (er2) log.error("error rolling back", target._id, er2)
+ return cb_(er, data)
+ })
+ }
+
+ var bundled = []
+
+ chain
+ ( [ [ cache.unpack, target.name, target.version, targetFolder
+ , null, null, user, group ]
+ , [ fs, "writeFile"
+ , path.resolve(targetFolder, "package.json")
+ , JSON.stringify(target, null, 2) + "\n" ]
+ , [ lifecycle, target, "preinstall", targetFolder ]
+ , function (cb) {
+ if (!target.bundleDependencies) return cb()
+
+ var bd = path.resolve(targetFolder, "node_modules")
+ fs.readdir(bd, function (er, b) {
+ // nothing bundled, maybe
+ if (er) return cb()
+ bundled = b || []
+ cb()
+ })
+ } ]
+
+ // nest the chain so that we can throw away the results returned
+ // up until this point, since we really don't care about it.
+ , function X (er) {
+ if (er) return cb(er)
+
+ // before continuing to installing dependencies, check for a shrinkwrap.
+ var opt = { dev: npm.config.get("dev") }
+ readDependencies(context, targetFolder, opt, function (er, data, wrap) {
+ var deps = prepareForInstallMany(data, "dependencies", bundled, wrap,
+ family)
+ var depsTargetFolder = targetFolder
+ var depsContext = { family: family
+ , ancestors: context.ancestors
+ , parent: target
+ , explicit: false
+ , wrap: wrap }
+
+ var peerDeps = prepareForInstallMany(data, "peerDependencies", bundled,
+ wrap, family)
+ var pdTargetFolder = path.resolve(targetFolder, "..", "..")
+ var pdContext = context
+
+ var actions =
+ [ [ installManyAndBuild, deps, depsTargetFolder, depsContext ] ]
+
+ if (peerDeps.length > 0) {
+ actions.push(
+ [ installMany, peerDeps, pdTargetFolder, pdContext ]
+ )
+ }
+
+ chain(actions, cb)
+ })
+ })
+}
+
+function installManyAndBuild (deps, targetFolder, context, cb) {
+ installMany(deps, targetFolder, context, function (er, d) {
+ log.verbose("about to build", targetFolder)
+ if (er) return cb(er)
+ npm.commands.build( [targetFolder]
+ , npm.config.get("global")
+ , true
+ , function (er) { return cb(er, d) })
+ })
+}
+
+function prepareForInstallMany (packageData, depsKey, bundled, wrap, family) {
+ var deps = Object.keys(packageData[depsKey] || {})
+
+ // don't install bundleDependencies, unless they're missing.
+ if (packageData.bundleDependencies) {
+ deps = deps.filter(function (d) {
+ return packageData.bundleDependencies.indexOf(d) === -1 ||
+ bundled.indexOf(d) === -1
+ })
+ }
+
+ return deps.filter(function (d) {
+ // prefer to not install things that are satisfied by
+ // something in the "family" list, unless we're installing
+ // from a shrinkwrap.
+ if (wrap) return wrap
+ if (semver.validRange(family[d], true))
+ return !semver.satisfies(family[d], packageData[depsKey][d], true)
+ return true
+ }).map(function (d) {
+ var t = packageData[depsKey][d]
+ , parsed = url.parse(t.replace(/^git\+/, "git"))
+ t = d + "@" + t
+ return t
+ })
+}
http://git-wip-us.apache.org/repos/asf/incubator-cmda/blob/a9a83675/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/link.js
----------------------------------------------------------------------
diff --git a/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/link.js b/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/link.js
new file mode 100644
index 0000000..4ecd64a
--- /dev/null
+++ b/ApacheCMDA_Backend_1.0/project/target/node-modules/webjars/npm/lib/link.js
@@ -0,0 +1,169 @@
+// link with no args: symlink the folder to the global location
+// link with package arg: symlink the global to the local
+
+var npm = require("./npm.js")
+ , symlink = require("./utils/link.js")
+ , fs = require("graceful-fs")
+ , log = require("npmlog")
+ , asyncMap = require("slide").asyncMap
+ , chain = require("slide").chain
+ , path = require("path")
+ , rm = require("rimraf")
+ , build = require("./build.js")
+
+module.exports = link
+
+link.usage = "npm link (in package dir)"
+ + "\nnpm link <pkg> (link global into local)"
+
+link.completion = function (opts, cb) {
+ var dir = npm.globalDir
+ fs.readdir(dir, function (er, files) {
+ cb(er, files.filter(function (f) {
+ return !f.match(/^[\._-]/)
+ }))
+ })
+}
+
+function link (args, cb) {
+ if (process.platform === "win32") {
+ var semver = require("semver")
+ if (!semver.satisfies(process.version, ">=0.7.9")) {
+ var msg = "npm link not supported on windows prior to node 0.7.9"
+ , e = new Error(msg)
+ e.code = "ENOTSUP"
+ e.errno = require("constants").ENOTSUP
+ return cb(e)
+ }
+ }
+
+ if (npm.config.get("global")) {
+ return cb(new Error("link should never be --global.\n"
+ +"Please re-run this command with --local"))
+ }
+
+ if (args.length === 1 && args[0] === ".") args = []
+ if (args.length) return linkInstall(args, cb)
+ linkPkg(npm.prefix, cb)
+}
+
+function linkInstall (pkgs, cb) {
+ asyncMap(pkgs, function (pkg, cb) {
+ function n (er, data) {
+ if (er) return cb(er, data)
+ // install returns [ [folder, pkgId], ... ]
+ // but we definitely installed just one thing.
+ var d = data.filter(function (d) { return !d[3] })
+ pp = d[0][1]
+ pkg = path.basename(pp)
+ target = path.resolve(npm.dir, pkg)
+ next()
+ }
+
+ var t = path.resolve(npm.globalDir, "..")
+ , pp = path.resolve(npm.globalDir, pkg)
+ , rp = null
+ , target = path.resolve(npm.dir, pkg)
+
+ // if it's a folder or a random not-installed thing, then
+ // link or install it first
+ if (pkg.indexOf("/") !== -1 || pkg.indexOf("\\") !== -1) {
+ return fs.lstat(path.resolve(pkg), function (er, st) {
+ if (er || !st.isDirectory()) {
+ npm.commands.install(t, pkg, n)
+ } else {
+ rp = path.resolve(pkg)
+ linkPkg(rp, n)
+ }
+ })
+ }
+
+ fs.lstat(pp, function (er, st) {
+ if (er) {
+ rp = pp
+ return npm.commands.install(t, pkg, n)
+ } else if (!st.isSymbolicLink()) {
+ rp = pp
+ next()
+ } else {
+ return fs.realpath(pp, function (er, real) {
+ if (er) log.warn("invalid symbolic link", pkg)
+ else rp = real
+ next()
+ })
+ }
+ })
+
+ function next () {
+ chain
+ ( [ [npm.commands, "unbuild", [target]]
+ , [function (cb) {
+ log.verbose("link", "symlinking %s to %s", pp, target)
+ cb()
+ }]
+ , [symlink, pp, target]
+ // do run lifecycle scripts - full build here.
+ , rp && [build, [target]]
+ , [ resultPrinter, pkg, pp, target, rp ] ]
+ , cb )
+ }
+ }, cb)
+}
+
+function linkPkg (folder, cb_) {
+ var me = folder || npm.prefix
+ , readJson = require("read-package-json")
+
+ log.verbose("linkPkg", folder)
+
+ readJson(path.resolve(me, "package.json"), function (er, d) {
+ function cb (er) {
+ return cb_(er, [[d && d._id, target, null, null]])
+ }
+ if (er) return cb(er)
+ var target = path.resolve(npm.globalDir, d.name)
+ rm(target, function (er) {
+ if (er) return cb(er)
+ symlink(me, target, function (er) {
+ if (er) return cb(er)
+ log.verbose("link", "build target", target)
+ // also install missing dependencies.
+ npm.commands.install(me, [], function (er, installed) {
+ if (er) return cb(er)
+ // build the global stuff. Don't run *any* scripts, because
+ // install command already will have done that.
+ build([target], true, build._noLC, true, function (er) {
+ if (er) return cb(er)
+ resultPrinter(path.basename(me), me, target, cb)
+ })
+ })
+ })
+ })
+ })
+}
+
+function resultPrinter (pkg, src, dest, rp, cb) {
+ if (typeof cb !== "function") cb = rp, rp = null
+ var where = dest
+ rp = (rp || "").trim()
+ src = (src || "").trim()
+ // XXX If --json is set, then look up the data from the package.json
+ if (npm.config.get("parseable")) {
+ return parseableOutput(dest, rp || src, cb)
+ }
+ if (rp === src) rp = null
+ console.log(where + " -> " + src + (rp ? " -> " + rp: ""))
+ cb()
+}
+
+function parseableOutput (dest, rp, cb) {
+ // XXX this should match ls --parseable and install --parseable
+ // look up the data from package.json, format it the same way.
+ //
+ // link is always effectively "long", since it doesn't help much to
+ // *just* print the target folder.
+ // However, we don't actually ever read the version number, so
+ // the second field is always blank.
+ console.log(dest + "::" + rp)
+ cb()
+}