npm-registry-client
Advanced tools
Comparing version 0.4.12 to 1.0.0
@@ -9,2 +9,3 @@ // utilities for working with the js-registry site. | ||
, npmlog | ||
, cacheFile = require('npm-cache-filename') | ||
@@ -49,3 +50,6 @@ try { | ||
this.registry = registry | ||
if (!conf.get('cache')) throw new Error("Cache dir is required") | ||
this.cacheFile = cacheFile(this.conf.get('cache')) | ||
this.log = conf.log || conf.get('log') || npmlog | ||
@@ -52,0 +56,0 @@ } |
@@ -24,2 +24,4 @@ | ||
var cache = this.cacheFile(this.registry + uri) + "/.cache.json" | ||
// /-/all is special. | ||
@@ -29,10 +31,5 @@ // It uses timestamp-based caching and partial updates, | ||
if (uri === "/-/all") { | ||
return requestAll.call(this, cb) | ||
return requestAll.call(this, cache, cb) | ||
} | ||
var cacheUri = uri | ||
// on windows ":" is not an allowed character in a foldername | ||
cacheUri = cacheUri.replace(/:/g, '_').replace(/\?write=true$/, '') | ||
var cache = path.join(this.conf.get('cache'), cacheUri, ".cache.json") | ||
// If the GET is part of a write operation (PUT or DELETE), then | ||
@@ -54,9 +51,6 @@ // skip past the cache entirely, but still save the results. | ||
function requestAll (cb) { | ||
var cache = path.join(this.conf.get('cache'), "/-/all", ".cache.json") | ||
mkdir(path.join(this.conf.get('cache'), "-", "all"), function (er) { | ||
if (er) return cb(er) | ||
function requestAll (cache, cb) { | ||
mkdir(path.dirname(cache), function (er) { | ||
fs.readFile(cache, function (er, data) { | ||
if (er) return requestAll_.call(this, 0, {}, cb) | ||
if (er) return requestAll_.call(this, 0, {}, cache, cb) | ||
try { | ||
@@ -67,7 +61,7 @@ data = JSON.parse(data) | ||
if (er) return cb(new Error("Broken cache.")) | ||
return requestAll_.call(this, 0, {}, cb) | ||
return requestAll_.call(this, 0, {}, cache, cb) | ||
}.bind(this)) | ||
} | ||
var t = +data._updated || 0 | ||
requestAll_.call(this, t, data, cb) | ||
requestAll_.call(this, t, data, cache, cb) | ||
}.bind(this)) | ||
@@ -77,3 +71,3 @@ }.bind(this)) | ||
function requestAll_ (c, data, cb) { | ||
function requestAll_ (c, data, cache, cb) { | ||
// use the cache and update in the background if it's not too old | ||
@@ -92,3 +86,2 @@ if (Date.now() - c < 60000) { | ||
var cache = path.join(this.conf.get('cache'), "-/all", ".cache.json") | ||
this.request('GET', uri, function (er, updates, _, res) { | ||
@@ -95,0 +88,0 @@ if (er) return cb(er, data) |
@@ -284,22 +284,3 @@ module.exports = regRequest | ||
// only result will be a stale cache for some helper commands. | ||
var path = require("path") | ||
, p = url.parse(where).pathname.split("/") | ||
, _ = "/" | ||
, caches = p.map(function (part) { | ||
part = part.replace(/:/g, "_") | ||
return _ = path.join(_, part) | ||
}).map(function (cache) { | ||
return path.join(this.conf.get('cache'), cache, ".cache.json") | ||
}, this) | ||
// if the method is DELETE, then also remove the thing itself. | ||
// Note that the search index is probably invalid. Whatever. | ||
// That's what you get for deleting stuff. Don't do that. | ||
if (method === "DELETE") { | ||
p = p.slice(0, p.indexOf("-rev")) | ||
p = p.join("/").replace(/:/g, "_") | ||
caches.push(path.join(this.conf.get('cache'), p)) | ||
} | ||
asyncMap(caches, rm, function () {}) | ||
rm(this.cacheFile(where), function() {}) | ||
} | ||
@@ -306,0 +287,0 @@ return cb(er, parsed, data, response) |
@@ -5,3 +5,3 @@ { | ||
"description": "Client for the npm registry", | ||
"version": "0.4.12", | ||
"version": "1.0.0", | ||
"repository": { | ||
@@ -15,10 +15,11 @@ "url": "git://github.com/isaacs/npm-registry-client" | ||
"dependencies": { | ||
"request": "2 >=2.25.0", | ||
"chownr": "0", | ||
"graceful-fs": "~2.0.0", | ||
"semver": "2 >=2.2.1", | ||
"slide": "~1.1.3", | ||
"chownr": "0", | ||
"mkdirp": "~0.3.3", | ||
"npm-cache-filename": "^1.0.0", | ||
"request": "2 >=2.25.0", | ||
"retry": "0.6.0", | ||
"rimraf": "~2", | ||
"retry": "0.6.0" | ||
"semver": "2 >=2.2.1", | ||
"slide": "~1.1.3" | ||
}, | ||
@@ -25,0 +26,0 @@ "devDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
74296
10
1242
+ Addednpm-cache-filename@^1.0.0
+ Addednpm-cache-filename@1.0.2(transitive)