Prettier everything up

This commit is contained in:
MICHAEL JACKSON
2017-11-08 08:57:15 -08:00
parent f3e041ace6
commit 2d57d96e62
36 changed files with 785 additions and 577 deletions

View File

@ -20,9 +20,9 @@ function fetchPackageInfo(packageName) {
return fetch(url, {
headers: {
'Accept': 'application/json'
Accept: 'application/json'
}
}).then(function (res) {
}).then(function(res) {
return res.status === 404 ? null : res.json()
})
}
@ -31,32 +31,35 @@ const PackageNotFound = 'PackageNotFound'
// This mutex prevents multiple concurrent requests to
// the registry for the same package info.
const fetchMutex = createMutex(function (packageName, callback) {
fetchPackageInfo(packageName).then(function (value) {
if (value == null) {
// Cache 404s for 5 minutes. This prevents us from making
// unnecessary requests to the registry for bad package names.
// In the worst case, a brand new package's info will be
// available within 5 minutes.
PackageInfoCache.set(packageName, PackageNotFound, 300, function () {
callback(null, value)
})
} else {
// Cache valid package info for 1 minute.
PackageInfoCache.set(packageName, value, 60, function () {
callback(null, value)
const fetchMutex = createMutex(function(packageName, callback) {
fetchPackageInfo(packageName).then(
function(value) {
if (value == null) {
// Cache 404s for 5 minutes. This prevents us from making
// unnecessary requests to the registry for bad package names.
// In the worst case, a brand new package's info will be
// available within 5 minutes.
PackageInfoCache.set(packageName, PackageNotFound, 300, function() {
callback(null, value)
})
} else {
// Cache valid package info for 1 minute.
PackageInfoCache.set(packageName, value, 60, function() {
callback(null, value)
})
}
},
function(error) {
// Do not cache errors.
PackageInfoCache.del(packageName, function() {
callback(error)
})
}
}, function (error) {
// Do not cache errors.
PackageInfoCache.del(packageName, function () {
callback(error)
})
})
)
})
function getPackageInfo(packageName, callback) {
PackageInfoCache.get(packageName, function (error, value) {
PackageInfoCache.get(packageName, function(error, value) {
if (error || value != null) {
callback(error, value === PackageNotFound ? null : value)
} else {