summaryrefslogtreecommitdiff
path: root/deps/npm/lib
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2014-01-19 21:13:20 -0800
committerisaacs <i@izs.me>2014-01-19 21:13:20 -0800
commitf645c40fcd92ca929e03e65d8a8f4ebb05e2cea2 (patch)
tree5e8ba8fcd49f3989c8dd71de106e43a7679c644b /deps/npm/lib
parent1d57a5caa4dc2994906c2160eaa31ca700dff39c (diff)
downloadandroid-node-v8-f645c40fcd92ca929e03e65d8a8f4ebb05e2cea2.tar.gz
android-node-v8-f645c40fcd92ca929e03e65d8a8f4ebb05e2cea2.tar.bz2
android-node-v8-f645c40fcd92ca929e03e65d8a8f4ebb05e2cea2.zip
npm: Upgrade to v1.3.24
Diffstat (limited to 'deps/npm/lib')
-rw-r--r--deps/npm/lib/adduser.js6
-rw-r--r--deps/npm/lib/docs.js17
-rw-r--r--deps/npm/lib/install.js21
-rw-r--r--deps/npm/lib/prune.js14
-rw-r--r--deps/npm/lib/search.js167
-rw-r--r--deps/npm/lib/utils/lifecycle.js17
6 files changed, 135 insertions, 107 deletions
diff --git a/deps/npm/lib/adduser.js b/deps/npm/lib/adduser.js
index efb0691966..739f14243f 100644
--- a/deps/npm/lib/adduser.js
+++ b/deps/npm/lib/adduser.js
@@ -37,7 +37,7 @@ function adduser (args, cb) {
function readUsername (c, u, cb) {
var v = userValidate.username
- read({prompt: "Username: ", default: c.u}, function (er, un) {
+ read({prompt: "Username: ", default: c.u || ""}, function (er, un) {
if (er) {
return cb(er.message === "cancelled" ? er.message : er)
}
@@ -92,8 +92,8 @@ function readPassword (c, u, cb) {
function readEmail (c, u, cb) {
var v = userValidate.email
-
- read({prompt: "Email: (this IS public) ", default: c.e}, function (er, em) {
+ var r = { prompt: "Email: (this IS public) ", default: c.e || "" }
+ read(r, function (er, em) {
if (er) {
return cb(er.message === "cancelled" ? er.message : er)
}
diff --git a/deps/npm/lib/docs.js b/deps/npm/lib/docs.js
index 0f59572ac8..2abbd62f26 100644
--- a/deps/npm/lib/docs.js
+++ b/deps/npm/lib/docs.js
@@ -5,7 +5,6 @@ docs.usage += "\n"
docs.usage += "npm docs ."
docs.completion = function (opts, cb) {
- if (opts.conf.argv.remain.length > 2) return cb()
registry.get("/-/short", 60000, function (er, list) {
return cb(null, list || [])
})
@@ -22,8 +21,20 @@ function url (json) {
}
function docs (args, cb) {
- var project = args[0] || '.'
- , package = path.resolve(process.cwd(), "package.json")
+ 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 {
diff --git a/deps/npm/lib/install.js b/deps/npm/lib/install.js
index 790879d0d7..9270303a65 100644
--- a/deps/npm/lib/install.js
+++ b/deps/npm/lib/install.js
@@ -637,8 +637,16 @@ function targetResolver (where, context, deps) {
return cb(null, d.name)
}
- // something is there, but it's not satisfactory. Clobber it.
- return cb(null, [])
+ // 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.
@@ -689,6 +697,12 @@ function targetResolver (where, context, deps) {
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])) {
@@ -697,9 +711,8 @@ function targetResolver (where, context, deps) {
return cb(null, [])
}
- // if the target is a git repository, we always want to fetch it
var isGit = false
- , maybeGit = what.split("@").pop()
+ , maybeGit = what.split("@").slice(1).join()
if (maybeGit)
isGit = isGitUrl(url.parse(maybeGit))
diff --git a/deps/npm/lib/prune.js b/deps/npm/lib/prune.js
index dbe8790b9d..0e13da13be 100644
--- a/deps/npm/lib/prune.js
+++ b/deps/npm/lib/prune.js
@@ -13,19 +13,19 @@ var readInstalled = require("read-installed")
prune.completion = require("./utils/completion/installed-deep.js")
function prune (args, cb) {
+ //check if is a valid package.json file
var jsonFile = path.resolve(npm.dir, "..", "package.json" )
- readJson(jsonFile, log.warn, function (er, packageData) {
+ readJson(jsonFile, log.warn, function (er, data) {
if (er) return cb(er)
+ next()
+ })
+
+ function next() {
readInstalled(npm.prefix, npm.config.get("depth"), function (er, data) {
if (er) return cb(er)
- if (npm.config.get("production")) {
- Object.keys(packageData.devDependencies || {}).forEach(function (k) {
- if (data.dependencies[k]) data.dependencies[k].extraneous = true
- })
- }
prune_(args, data, cb)
})
- })
+ }
}
function prune_ (args, data, cb) {
diff --git a/deps/npm/lib/search.js b/deps/npm/lib/search.js
index fdc1c8b07d..21b6ab2794 100644
--- a/deps/npm/lib/search.js
+++ b/deps/npm/lib/search.js
@@ -3,6 +3,7 @@ module.exports = exports = search
var npm = require("./npm.js")
, registry = npm.registry
+ , columnify = require('columnify')
search.usage = "npm search [some search terms ...]"
@@ -91,7 +92,8 @@ function stripData (data) {
&& (new Date(data.time.modified).toISOString()
.split("T").join(" ")
.replace(/:[0-9]{2}\.[0-9]{3}Z$/, ""))
- || "(prehistoric)"
+ .slice(0, -5) // remove time
+ || "prehistoric"
}
}
@@ -129,102 +131,77 @@ function match (words, arg) {
}
function prettify (data, args) {
- try {
- var tty = require("tty")
- , stdout = process.stdout
- , cols = !tty.isatty(stdout.fd) ? Infinity
- : process.stdout.getWindowSize()[0]
- cols = (cols == 0) ? Infinity : cols
- } catch (ex) { cols = Infinity }
-
- // name, desc, author, keywords
- var longest = []
- , spaces
- , maxLen = npm.config.get("description")
- ? [20, 60, 20, 20, 10, Infinity]
- : [20, 20, 20, 10, Infinity]
- , headings = npm.config.get("description")
- ? ["NAME", "DESCRIPTION", "AUTHOR", "DATE", "VERSION", "KEYWORDS"]
- : ["NAME", "AUTHOR", "DATE", "VERSION", "KEYWORDS"]
- , lines
- , searchsort = (npm.config.get("searchsort") || "NAME").toLowerCase()
- , sortFields = { name: 0
- , description: 1
- , author: 2
- , date: 3
- , version: 4
- , keywords: 5 }
+ var searchsort = (npm.config.get("searchsort") || "NAME").toLowerCase()
+ , sortField = searchsort.replace(/^\-+/, "")
, searchRev = searchsort.charAt(0) === "-"
- , sortField = sortFields[searchsort.replace(/^\-+/, "")]
+ , truncate = !npm.config.get("long")
+
+ if (Object.keys(data).length === 0) {
+ return "No match found for "+(args.map(JSON.stringify).join(" "))
+ }
- lines = Object.keys(data).map(function (d) {
+ var lines = Object.keys(data).map(function (d) {
+ // strip keyname
return data[d]
- }).map(function (data) {
- // turn a pkg data into a string
- // [name,who,desc,targets,keywords] tuple
- // also set longest to the longest name
- if (typeof data.keywords === "string") {
- data.keywords = data.keywords.split(/[,\s]+/)
+ }).map(function(dat) {
+ dat.author = dat.maintainers
+ delete dat.maintainers
+ dat.date = dat.time
+ delete dat.time
+ return dat
+ }).map(function(dat) {
+ // split keywords on whitespace or ,
+ if (typeof dat.keywords === "string") {
+ dat.keywords = dat.keywords.split(/[,\s]+/)
}
- if (!Array.isArray(data.keywords)) data.keywords = []
- var l = [ data.name
- , data.description || ""
- , data.maintainers.join(" ")
- , data.time
- , data.version || ""
- , (data.keywords || []).join(" ")
- ]
- l.forEach(function (s, i) {
- var len = s.length
- longest[i] = Math.min(maxLen[i] || Infinity
- ,Math.max(longest[i] || 0, len))
- if (len > longest[i]) {
- l._undent = l._undent || []
- l._undent[i] = len - longest[i]
- }
- l[i] = ('' + l[i]).replace(/\s+/g, " ")
- })
- return l
- }).sort(function (a, b) {
- // a and b are "line" objects of [name, desc, maint, time, kw]
+ if (Array.isArray(dat.keywords)) {
+ dat.keywords = dat.keywords.join(' ')
+ }
+
+ // split author on whitespace or ,
+ if (typeof dat.author === "string") {
+ dat.author = dat.author.split(/[,\s]+/)
+ }
+ if (Array.isArray(dat.author)) {
+ dat.author = dat.author.join(' ')
+ }
+ return dat
+ })
+
+ lines.sort(function(a, b) {
var aa = a[sortField].toLowerCase()
, bb = b[sortField].toLowerCase()
return aa === bb ? 0
- : aa < bb ? (searchRev ? 1 : -1)
- : (searchRev ? -1 : 1)
- }).map(function (line) {
- return line.map(function (s, i) {
- spaces = spaces || longest.map(function (n) {
- return new Array(n + 2).join(" ")
- })
- var len = s.length
- if (line._undent && line._undent[i - 1]) {
- len += line._undent[i - 1] - 1
- }
- return s + spaces[i].substr(len)
- }).join(" ").substr(0, cols).trim()
- }).map(function (line) {
- // colorize!
- args.forEach(function (arg, i) {
- line = addColorMarker(line, arg, i)
- })
- return colorize(line).trim()
+ : aa < bb ? -1 : 1
})
- if (lines.length === 0) {
- return "No match found for "+(args.map(JSON.stringify).join(" "))
- }
+ if (searchRev) lines.reverse()
- // build the heading padded to the longest in each field
- return headings.map(function (h, i) {
- var space = Math.max(2, 3 + (longest[i] || 0) - h.length)
- return h + (new Array(space).join(" "))
- }).join("").substr(0, cols).trim() + "\n" + lines.join("\n")
+ var columns = npm.config.get("description")
+ ? ["name", "description", "author", "date", "version", "keywords"]
+ : ["name", "author", "date", "version", "keywords"]
+
+ var output = columnify(lines, {
+ include: columns
+ , truncate: truncate
+ , config: {
+ name: { maxWidth: 40, truncate: false, truncateMarker: '' }
+ , description: { maxWidth: 60 }
+ , author: { maxWidth: 20 }
+ , date: { maxWidth: 11 }
+ , version: { maxWidth: 11 }
+ , keywords: { maxWidth: Infinity }
+ }
+ })
+ output = trimToMaxWidth(output)
+ output = highlightSearchTerms(output, args)
+ return output
}
var colors = [31, 33, 32, 36, 34, 35 ]
, cl = colors.length
+
function addColorMarker (str, arg, i) {
var m = i % cl + 1
, markStart = String.fromCharCode(m)
@@ -260,3 +237,29 @@ function colorize (line) {
var uncolor = npm.color ? "\033[0m" : ""
return line.split("\u0000").join(uncolor)
}
+
+function getMaxWidth() {
+ try {
+ var tty = require("tty")
+ , stdout = process.stdout
+ , cols = !tty.isatty(stdout.fd) ? Infinity
+ : process.stdout.getWindowSize()[0]
+ cols = (cols == 0) ? Infinity : cols
+ } catch (ex) { cols = Infinity }
+ return cols
+}
+
+function trimToMaxWidth(str) {
+ var maxWidth = getMaxWidth()
+ return str.split('\n').map(function(line) {
+ return line.slice(0, maxWidth)
+ }).join('\n')
+}
+
+function highlightSearchTerms(str, terms) {
+ terms.forEach(function (arg, i) {
+ str = addColorMarker(str, arg, i)
+ })
+
+ return colorize(str).trim()
+}
diff --git a/deps/npm/lib/utils/lifecycle.js b/deps/npm/lib/utils/lifecycle.js
index ffa6484fa8..e6ef925b30 100644
--- a/deps/npm/lib/utils/lifecycle.js
+++ b/deps/npm/lib/utils/lifecycle.js
@@ -185,14 +185,6 @@ function runCmd_ (cmd, pkg, env, wd, stage, unsafe, uid, gid, cb_) {
process.nextTick(dequeue)
}
- var sh = "sh"
- var shFlag = "-c"
-
- if (process.platform === "win32") {
- sh = "cmd"
- shFlag = "/c"
- }
-
var conf = { cwd: wd
, env: env
, stdio: [ 0, 1, 2 ]
@@ -203,6 +195,15 @@ function runCmd_ (cmd, pkg, env, wd, stage, unsafe, uid, gid, cb_) {
conf.gid = gid ^ 0
}
+ var sh = "sh"
+ var shFlag = "-c"
+
+ if (process.platform === "win32") {
+ sh = "cmd"
+ shFlag = "/c"
+ conf.windowsVerbatimArguments = true
+ }
+
var proc = spawn(sh, [shFlag, cmd], conf)
proc.on("close", function (code, signal) {
if (signal) {