You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
664 B
JavaScript

'use strict';
const Promise = require("bluebird");
const bhttp = require("bhttp");
const rfr = require("rfr");
const cacheize = rfr("lib/db/cacheize");
module.exports = function(cache) {
return cacheize(cache, function(packageName) {
return Promise.try(() => {
let encodedPackageName = encodeURIComponent(packageName).replace(/%40/g, "@");
return bhttp.get(`https://registry.npmjs.org/${encodedPackageName}`);
}).then((response) => {
if (response.statusCode !== 200) {
// FIXME: Proper error types
throw new Error(`Got non-200 status code from NPM registry: ${response.statusCode}`);
} else {
return response.body;
}
});
});
}