aboutsummaryrefslogtreecommitdiff
path: root/deps/npm/lib/cache.js
diff options
context:
space:
mode:
authorRebecca Turner <me@re-becca.org>2015-10-09 23:13:57 -0700
committerJeremiah Senkpiel <fishrock123@rocketmail.com>2015-10-22 13:56:09 -0400
commit41923c0c0795cfa6c465821387fca88fe8811367 (patch)
tree853587bc888fde98f714d72050edceb4785145de /deps/npm/lib/cache.js
parent9b8886446dd183cee26adf9c603f8e1cd5da74bd (diff)
downloadandroid-node-v8-41923c0c0795cfa6c465821387fca88fe8811367.tar.gz
android-node-v8-41923c0c0795cfa6c465821387fca88fe8811367.tar.bz2
android-node-v8-41923c0c0795cfa6c465821387fca88fe8811367.zip
deps: upgrade npm to 3.3.6
PR-URL: https://github.com/nodejs/node/pull/3310 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Diffstat (limited to 'deps/npm/lib/cache.js')
-rw-r--r--deps/npm/lib/cache.js257
1 files changed, 135 insertions, 122 deletions
diff --git a/deps/npm/lib/cache.js b/deps/npm/lib/cache.js
index 2e11be32f8..b4b04819c9 100644
--- a/deps/npm/lib/cache.js
+++ b/deps/npm/lib/cache.js
@@ -60,54 +60,54 @@ cache.unpack = unpack
cache.clean = clean
cache.read = read
-var npm = require("./npm.js")
- , fs = require("graceful-fs")
- , writeFileAtomic = require("write-file-atomic")
- , assert = require("assert")
- , rm = require("./utils/gently-rm.js")
- , readJson = require("read-package-json")
- , log = require("npmlog")
- , path = require("path")
- , asyncMap = require("slide").asyncMap
- , tar = require("./utils/tar.js")
- , fileCompletion = require("./utils/completion/file-completion.js")
- , deprCheck = require("./utils/depr-check.js")
- , addNamed = require("./cache/add-named.js")
- , addLocal = require("./cache/add-local.js")
- , addRemoteTarball = require("./cache/add-remote-tarball.js")
- , addRemoteGit = require("./cache/add-remote-git.js")
- , inflight = require("inflight")
- , realizePackageSpecifier = require("realize-package-specifier")
- , npa = require("npm-package-arg")
- , getStat = require("./cache/get-stat.js")
- , cachedPackageRoot = require("./cache/cached-package-root.js")
- , mapToRegistry = require("./utils/map-to-registry.js")
-
-cache.usage = "npm cache add <tarball file>"
- + "\nnpm cache add <folder>"
- + "\nnpm cache add <tarball url>"
- + "\nnpm cache add <git url>"
- + "\nnpm cache add <name>@<version>"
- + "\nnpm cache ls [<path>]"
- + "\nnpm cache clean [<pkg>[@<version>]]"
+var npm = require('./npm.js')
+var fs = require('graceful-fs')
+var writeFileAtomic = require('write-file-atomic')
+var assert = require('assert')
+var rm = require('./utils/gently-rm.js')
+var readJson = require('read-package-json')
+var log = require('npmlog')
+var path = require('path')
+var asyncMap = require('slide').asyncMap
+var tar = require('./utils/tar.js')
+var fileCompletion = require('./utils/completion/file-completion.js')
+var deprCheck = require('./utils/depr-check.js')
+var addNamed = require('./cache/add-named.js')
+var addLocal = require('./cache/add-local.js')
+var addRemoteTarball = require('./cache/add-remote-tarball.js')
+var addRemoteGit = require('./cache/add-remote-git.js')
+var inflight = require('inflight')
+var realizePackageSpecifier = require('realize-package-specifier')
+var npa = require('npm-package-arg')
+var getStat = require('./cache/get-stat.js')
+var cachedPackageRoot = require('./cache/cached-package-root.js')
+var mapToRegistry = require('./utils/map-to-registry.js')
+
+cache.usage = 'npm cache add <tarball file>' +
+ '\nnpm cache add <folder>' +
+ '\nnpm cache add <tarball url>' +
+ '\nnpm cache add <git url>' +
+ '\nnpm cache add <name>@<version>' +
+ '\nnpm cache ls [<path>]' +
+ '\nnpm cache clean [<pkg>[@<version>]]'
cache.completion = function (opts, cb) {
var argv = opts.conf.argv.remain
if (argv.length === 2) {
- return cb(null, ["add", "ls", "clean"])
+ return cb(null, ['add', 'ls', 'clean'])
}
switch (argv[2]) {
- case "clean":
- case "ls":
+ case 'clean':
+ case 'ls':
// cache and ls are easy, because the completion is
// what ls_ returns anyway.
// just get the partial words, minus the last path part
- var p = path.dirname(opts.partialWords.slice(3).join("/"))
- if (p === ".") p = ""
+ var p = path.dirname(opts.partialWords.slice(3).join('/'))
+ if (p === '.') p = ''
return ls_(p, 2, cb)
- case "add":
+ case 'add':
// Same semantics as install and publish.
return npm.commands.install.completion(opts, cb)
}
@@ -116,10 +116,10 @@ cache.completion = function (opts, cb) {
function cache (args, cb) {
var cmd = args.shift()
switch (cmd) {
- case "rm": case "clear": case "clean": return clean(args, cb)
- case "list": case "sl": case "ls": return ls(args, cb)
- case "add": return add(args, npm.prefix, cb)
- default: return cb("Usage: "+cache.usage)
+ case 'rm': case 'clear': case 'clean': return clean(args, cb)
+ case 'list': case 'sl': case 'ls': return ls(args, cb)
+ case 'add': return add(args, npm.prefix, cb)
+ default: return cb('Usage: ' + cache.usage)
}
}
@@ -127,30 +127,30 @@ function cache (args, cb) {
// just do a readJson and return.
// if they're not, then fetch them from the registry.
function read (name, ver, forceBypass, cb) {
- assert(typeof name === "string", "must include name of module to install")
- assert(typeof cb === "function", "must include callback")
+ assert(typeof name === 'string', 'must include name of module to install')
+ assert(typeof cb === 'function', 'must include callback')
if (forceBypass === undefined || forceBypass === null) forceBypass = true
- var root = cachedPackageRoot({name : name, version : ver})
+ var root = cachedPackageRoot({name: name, version: ver})
function c (er, data) {
- if (er) log.verbose("cache", "addNamed error for", name+"@"+ver, er)
+ if (er) log.verbose('cache', 'addNamed error for', name + '@' + ver, er)
if (data) deprCheck(data)
return cb(er, data)
}
- if (forceBypass && npm.config.get("force")) {
- log.verbose("using force", "skipping cache")
+ if (forceBypass && npm.config.get('force')) {
+ log.verbose('using force', 'skipping cache')
return addNamed(name, ver, null, c)
}
- readJson(path.join(root, "package", "package.json"), function (er, data) {
- if (er && er.code !== "ENOENT" && er.code !== "ENOTDIR") return cb(er)
+ readJson(path.join(root, 'package', 'package.json'), function (er, data) {
+ if (er && er.code !== 'ENOENT' && er.code !== 'ENOTDIR') return cb(er)
if (data) {
- if (!data.name) return cb(new Error("No name provided"))
- if (!data.version) return cb(new Error("No version provided"))
+ if (!data.name) return cb(new Error('No name provided'))
+ if (!data.version) return cb(new Error('No version provided'))
}
if (er) return addNamed(name, ver, null, c)
@@ -159,33 +159,33 @@ function read (name, ver, forceBypass, cb) {
}
function normalize (args) {
- var normalized = ""
+ var normalized = ''
if (args.length > 0) {
var a = npa(args[0])
if (a.name) normalized = a.name
- if (a.rawSpec) normalized = [normalized, a.rawSpec].join("/")
- if (args.length > 1) normalized = [normalized].concat(args.slice(1)).join("/")
+ if (a.rawSpec) normalized = [normalized, a.rawSpec].join('/')
+ if (args.length > 1) normalized = [normalized].concat(args.slice(1)).join('/')
}
- if (normalized.substr(-1) === "/") {
+ if (normalized.substr(-1) === '/') {
normalized = normalized.substr(0, normalized.length - 1)
}
normalized = path.normalize(normalized)
- log.silly("ls", "normalized", normalized)
+ log.silly('ls', 'normalized', normalized)
return normalized
}
// npm cache ls [<path>]
function ls (args, cb) {
- var prefix = npm.config.get("cache")
+ var prefix = npm.config.get('cache')
if (prefix.indexOf(process.env.HOME) === 0) {
- prefix = "~" + prefix.substr(process.env.HOME.length)
+ prefix = '~' + prefix.substr(process.env.HOME.length)
}
- ls_(normalize(args), npm.config.get("depth"), function (er, files) {
+ ls_(normalize(args), npm.config.get('depth'), function (er, files) {
console.log(files.map(function (f) {
return path.join(prefix, f)
- }).join("\n").trim())
+ }).join('\n').trim())
cb(er, files)
})
}
@@ -197,7 +197,7 @@ function ls_ (req, depth, cb) {
// npm cache clean [<path>]
function clean (args, cb) {
- assert(typeof cb === "function", "must include callback")
+ assert(typeof cb === 'function', 'must include callback')
if (!args) args = []
@@ -205,15 +205,17 @@ function clean (args, cb) {
if (f === npm.cache) {
fs.readdir(npm.cache, function (er, files) {
if (er) return cb()
- asyncMap( files.filter(function (f) {
- return npm.config.get("force") || f !== "-"
- }).map(function (f) {
- return path.join(npm.cache, f)
- })
- , rm, cb )
+ asyncMap(
+ files.filter(function (f) {
+ return npm.config.get('force') || f !== '-'
+ }).map(function (f) {
+ return path.join(npm.cache, f)
+ }),
+ rm,
+ cb
+ )
})
- }
- else {
+ } else {
rm(f, cb)
}
}
@@ -223,8 +225,8 @@ function clean (args, cb) {
// npm cache add <tarball>
// npm cache add <folder>
cache.add = function (pkg, ver, where, scrub, cb) {
- assert(typeof pkg === "string", "must include name of package to install")
- assert(typeof cb === "function", "must include callback")
+ assert(typeof pkg === 'string', 'must include name of package to install')
+ assert(typeof cb === 'function', 'must include callback')
if (scrub) {
return clean([], function (er) {
@@ -235,67 +237,63 @@ cache.add = function (pkg, ver, where, scrub, cb) {
return add([pkg, ver], where, cb)
}
-
var adding = 0
function add (args, where, cb) {
// this is hot code. almost everything passes through here.
// the args can be any of:
- // ["url"]
- // ["pkg", "version"]
- // ["pkg@version"]
- // ["pkg", "url"]
+ // ['url']
+ // ['pkg', 'version']
+ // ['pkg@version']
+ // ['pkg', 'url']
// This is tricky, because urls can contain @
// Also, in some cases we get [name, null] rather
// that just a single argument.
- var usage = "Usage:\n"
- + " npm cache add <tarball-url>\n"
- + " npm cache add <pkg>@<ver>\n"
- + " npm cache add <tarball>\n"
- + " npm cache add <folder>\n"
- , spec
+ var usage = 'Usage:\n' +
+ ' npm cache add <tarball-url>\n' +
+ ' npm cache add <pkg>@<ver>\n' +
+ ' npm cache add <tarball>\n' +
+ ' npm cache add <folder>\n'
+ var spec
- log.silly("cache add", "args", args)
+ log.silly('cache add', 'args', args)
if (args[1] === undefined) args[1] = null
// at this point the args length must ==2
if (args[1] !== null) {
- spec = args[0]+"@"+args[1]
+ spec = args[0] + '@' + args[1]
} else if (args.length === 2) {
spec = args[0]
}
- log.verbose("cache add", "spec", spec)
+ log.verbose('cache add', 'spec', spec)
if (!spec) return cb(usage)
- if (adding <= 0) {
- npm.spinner.start()
- }
adding++
cb = afterAdd(cb)
realizePackageSpecifier(spec, where, function (err, p) {
if (err) return cb(err)
- log.silly("cache add", "parsed spec", p)
+ log.silly('cache add', 'parsed spec', p)
switch (p.type) {
- case "local":
- case "directory":
+ case 'local':
+ case 'directory':
addLocal(p, null, cb)
break
- case "remote":
+ case 'remote':
// get auth, if possible
mapToRegistry(spec, npm.config, function (err, uri, auth) {
if (err) return cb(err)
- addRemoteTarball(p.spec, {name : p.name}, null, auth, cb)
+ addRemoteTarball(p.spec, { name: p.name }, null, auth, cb)
})
break
- case "git":
- case "hosted":
+ case 'git':
+ case 'hosted':
addRemoteGit(p.rawSpec, cb)
break
default:
@@ -307,47 +305,62 @@ function add (args, where, cb) {
}
function unpack (pkg, ver, unpackTarget, dMode, fMode, uid, gid, cb) {
- if (typeof cb !== "function") cb = gid, gid = null
- if (typeof cb !== "function") cb = uid, uid = null
- if (typeof cb !== "function") cb = fMode, fMode = null
- if (typeof cb !== "function") cb = dMode, dMode = null
+ if (typeof cb !== 'function') {
+ cb = gid
+ gid = null
+ }
+ if (typeof cb !== 'function') {
+ cb = uid
+ uid = null
+ }
+ if (typeof cb !== 'function') {
+ cb = fMode
+ fMode = null
+ }
+ if (typeof cb !== 'function') {
+ cb = dMode
+ dMode = null
+ }
read(pkg, ver, false, function (er) {
if (er) {
- log.error("unpack", "Could not read data for %s", pkg + "@" + ver)
+ log.error('unpack', 'Could not read data for %s', pkg + '@' + ver)
return cb(er)
}
npm.commands.unbuild([unpackTarget], true, function (er) {
if (er) return cb(er)
- tar.unpack( path.join(cachedPackageRoot({name : pkg, version : ver}), "package.tgz")
- , unpackTarget
- , dMode, fMode
- , uid, gid
- , cb )
+ tar.unpack(
+ path.join(cachedPackageRoot({ name: pkg, version: ver }), 'package.tgz'),
+ unpackTarget,
+ dMode, fMode,
+ uid, gid,
+ cb
+ )
})
})
}
-function afterAdd (cb) { return function (er, data) {
- adding--
- if (adding <= 0) npm.spinner.stop()
+function afterAdd (cb) {
+ return function (er, data) {
+ adding--
- if (er || !data || !data.name || !data.version) return cb(er, data)
- log.silly("cache", "afterAdd", data.name+"@"+data.version)
+ if (er || !data || !data.name || !data.version) return cb(er, data)
+ log.silly('cache', 'afterAdd', data.name + '@' + data.version)
- // Save the resolved, shasum, etc. into the data so that the next
- // time we load from this cached data, we have all the same info.
- var pj = path.join(cachedPackageRoot(data), "package", "package.json")
+ // Save the resolved, shasum, etc. into the data so that the next
+ // time we load from this cached data, we have all the same info.
+ var pj = path.join(cachedPackageRoot(data), 'package', 'package.json')
- var done = inflight(pj, cb)
- if (!done) return log.verbose("afterAdd", pj, "already in flight; not writing")
- log.verbose("afterAdd", pj, "not in flight; writing")
+ var done = inflight(pj, cb)
+ if (!done) return log.verbose('afterAdd', pj, 'already in flight; not writing')
+ log.verbose('afterAdd', pj, 'not in flight; writing')
- getStat(function (er, cs) {
- if (er) return done(er)
- writeFileAtomic(pj, JSON.stringify(data), {chown : cs}, function (er) {
- if (!er) log.verbose("afterAdd", pj, "written")
- return done(er, data)
+ getStat(function (er, cs) {
+ if (er) return done(er)
+ writeFileAtomic(pj, JSON.stringify(data), { chown: cs }, function (er) {
+ if (!er) log.verbose('afterAdd', pj, 'written')
+ return done(er, data)
+ })
})
- })
-}}
+ }
+}