diff options
author | Forrest L Norvell <forrest@npmjs.com> | 2014-05-02 04:18:40 +0400 |
---|---|---|
committer | Forrest L Norvell <forrest@npmjs.com> | 2014-05-08 05:00:51 +0400 |
commit | 83d68b675f3ba7c095030b84b60e9a4566874d19 (patch) | |
tree | 9f3bf2b04fe5e18e70c63ebd8930d7c168648b4c | |
parent | a469a56e820f95b9031176dfdec8ec961717129f (diff) |
devariadify cache.*
-rw-r--r-- | lib/cache.js | 16 | ||||
-rw-r--r-- | lib/cache/add-local-tarball.js | 2 | ||||
-rw-r--r-- | lib/cache/add-local.js | 5 | ||||
-rw-r--r-- | lib/cache/add-named.js | 5 | ||||
-rw-r--r-- | lib/install.js | 2 | ||||
-rw-r--r-- | lib/outdated.js | 2 | ||||
-rw-r--r-- | lib/pack.js | 2 | ||||
-rw-r--r-- | lib/publish.js | 2 | ||||
-rw-r--r-- | lib/submodule.js | 2 |
9 files changed, 20 insertions, 18 deletions
diff --git a/lib/cache.js b/lib/cache.js index c269ffe86..108ffe4c7 100644 --- a/lib/cache.js +++ b/lib/cache.js @@ -58,6 +58,7 @@ cache.unpack = unpack var npm = require("./npm.js") , fs = require("graceful-fs") + , assert = require("assert") , rm = require("./utils/gently-rm.js") , readJson = require("read-package-json") , log = require("npmlog") @@ -118,7 +119,11 @@ 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) { - if (typeof cb !== "function") cb = forceBypass, forceBypass = true + 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 jsonFile = path.join(npm.cache, name, ver, "package", "package.json") function c (er, data) { if (data) deprCheck(data) @@ -163,8 +168,10 @@ function ls_ (req, depth, cb) { // npm cache clean [<path>] function clean (args, cb) { - if (!cb) cb = args, args = [] + assert(typeof cb === "function", "must include callback") + if (!args) args = [] + args = args.join("/").split("@").join("/") if (args.substr(-1) === "/") args = args.substr(0, args.length - 1) var f = path.join(npm.cache, path.normalize(args)) @@ -186,8 +193,9 @@ function clean (args, cb) { // npm cache add <tarball> // npm cache add <folder> cache.add = function (pkg, ver, scrub, cb) { - if (typeof cb !== "function") cb = scrub, scrub = false - if (typeof cb !== "function") cb = ver, ver = null + assert(typeof pkg === "string", "must include name of package to install") + assert(typeof cb === "function", "must include callback") + if (scrub) { return clean([], function (er) { if (er) return cb(er) diff --git a/lib/cache/add-local-tarball.js b/lib/cache/add-local-tarball.js index 167972e3e..a26debd8b 100644 --- a/lib/cache/add-local-tarball.js +++ b/lib/cache/add-local-tarball.js @@ -110,7 +110,7 @@ function addPlacedTarball (p, name, shasum, cb) { // a set of arguments like it does now, but then also a destination // folder. // -// cache.add('foo@bar', '/path/node_modules/foo', cb) +// cache.add('foo@bar', '/path/node_modules/foo', false, cb) // // 1. Resolve 'foo@bar' to some specific: // - git url diff --git a/lib/cache/add-local.js b/lib/cache/add-local.js index b6f9c75f3..1bb6a6dbe 100644 --- a/lib/cache/add-local.js +++ b/lib/cache/add-local.js @@ -56,7 +56,7 @@ function addLocal (p, name, cb_) { } return cb(er) } - if (s.isDirectory()) addLocalDirectory(p, name, cb) + if (s.isDirectory()) addLocalDirectory(p, name, null, cb) else addLocalTarball(p, name, cb) }) }) @@ -65,8 +65,7 @@ function addLocal (p, name, cb_) { // At this point, if shasum is set, it's something that we've already // read and checked. Just stashing it in the data at this point. function addLocalDirectory (p, name, shasum, cb) { - if (typeof cb !== "function") cb = shasum, shasum = "" - if (typeof cb !== "function") cb = name, name = "" + assert(typeof cb === "function", "must have callback") // if it's a folder, then read the package.json, // tar it to the proper place, and add the cache tar if (pathIsInside(p, npm.cache)) return cb(new Error( diff --git a/lib/cache/add-named.js b/lib/cache/add-named.js index 25e4d6802..2ef06eda1 100644 --- a/lib/cache/add-named.js +++ b/lib/cache/add-named.js @@ -51,7 +51,6 @@ function addNamed (name, version, data, cb_) { } function addNameTag (name, tag, data, cb_) { - if (typeof cb_ !== "function") cb_ = data, data = null log.info("addNameTag", [name, tag]) var explicit = true if (!tag) { @@ -107,8 +106,6 @@ function engineFilter (data) { } function addNameVersion (name, v, data, cb) { - if (typeof cb !== "function") cb = data, data = null - var ver = semver.valid(v, true) if (!ver) return cb(new Error("Invalid version: "+v)) @@ -197,8 +194,6 @@ function addNameVersion (name, v, data, cb) { } function addNameRange (name, range, data, cb) { - if (typeof cb !== "function") cb = data, data = null - range = semver.validRange(range, true) if (range === null) return cb(new Error( "Invalid version range: "+range)) diff --git a/lib/install.js b/lib/install.js index 3e319fa67..3b7e1c444 100644 --- a/lib/install.js +++ b/lib/install.js @@ -709,7 +709,7 @@ function targetResolver (where, context, deps) { // 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) { + cache.add(what, null, false, function (er, data) { if (er && parent && parent.optionalDependencies && parent.optionalDependencies.hasOwnProperty(what.split("@")[0])) { log.warn("optional dep failed, continuing", what) diff --git a/lib/outdated.js b/lib/outdated.js index 6ca348726..fd409bd59 100644 --- a/lib/outdated.js +++ b/lib/outdated.js @@ -273,7 +273,7 @@ function shouldUpdate (args, dir, dep, has, req, depth, cb) { } // We didn't find the version in the doc. See if cache can find it. - cache.add(dep, req, onCacheAdd) + cache.add(dep, req, false, onCacheAdd) function onCacheAdd(er, d) { // if this fails, then it means we can't update this thing. diff --git a/lib/pack.js b/lib/pack.js index 302aa81f2..ea94dd154 100644 --- a/lib/pack.js +++ b/lib/pack.js @@ -40,7 +40,7 @@ function printFiles (files, cb) { // add to cache, then cp to the cwd function pack_ (pkg, cb) { - cache.add(pkg, function (er, data) { + cache.add(pkg, null, false, function (er, data) { if (er) return cb(er) var fname = path.resolve(data._id.replace(/@/g, "-") + ".tgz") , cached = path.resolve( npm.cache diff --git a/lib/publish.js b/lib/publish.js index cede9ff0a..01d66b407 100644 --- a/lib/publish.js +++ b/lib/publish.js @@ -49,7 +49,7 @@ function publish (args, isRetry, cb) { // That means that we can run publish/postpublish in the dir, rather than // in the cache dir. function cacheAddPublish (dir, didPre, isRetry, cb) { - npm.commands.cache.add(dir, function (er, data) { + npm.commands.cache.add(dir, null, false, function (er, data) { if (er) return cb(er) log.silly("publish", data) var cachedir = path.resolve( npm.cache diff --git a/lib/submodule.js b/lib/submodule.js index 42e6c1eb5..5ea5a4f46 100644 --- a/lib/submodule.js +++ b/lib/submodule.js @@ -23,7 +23,7 @@ function submodule (args, cb) { if (args.length === 0) return cb(submodule.usage) asyncMap(args, function (arg, cb) { - cache.add(arg, cb) + cache.add(arg, null, false, cb) }, function (er, pkgs) { if (er) return cb(er) chain(pkgs.map(function (pkg) { return function (cb) { |