Use arrow functions for callbacks
This commit is contained in:
@ -13,7 +13,7 @@ function createMutex(doWork) {
|
||||
]
|
||||
|
||||
doWork(payload, function(error, value) {
|
||||
mutex[key].forEach(function(callback) {
|
||||
mutex[key].forEach(callback => {
|
||||
callback(error, value)
|
||||
})
|
||||
})
|
||||
|
@ -1,7 +1,7 @@
|
||||
function createSearch(query) {
|
||||
const params = []
|
||||
|
||||
Object.keys(query).forEach(function(param) {
|
||||
Object.keys(query).forEach(param => {
|
||||
if (query[param] === '') {
|
||||
params.push(param) // Omit the trailing "=" from param=
|
||||
} else {
|
||||
|
@ -8,7 +8,7 @@ const IndexPage = require('../components/IndexPage')
|
||||
const e = React.createElement
|
||||
|
||||
function getEntries(dir) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.readdir(dir, function(error, files) {
|
||||
if (error) {
|
||||
reject(error)
|
||||
@ -16,8 +16,8 @@ function getEntries(dir) {
|
||||
resolve(
|
||||
Promise.all(
|
||||
files.map(file => getFileStats(path.join(dir, file)))
|
||||
).then(function(statsArray) {
|
||||
return statsArray.map(function(stats, index) {
|
||||
).then(statsArray => {
|
||||
return statsArray.map((stats, index) => {
|
||||
return { file: files[index], stats }
|
||||
})
|
||||
})
|
||||
|
@ -6,26 +6,24 @@ const getFileStats = require('./getFileStats')
|
||||
const getFileType = require('./getFileType')
|
||||
|
||||
function getEntries(dir, file, maximumDepth) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.readdir(path.join(dir, file), function(error, files) {
|
||||
if (error) {
|
||||
reject(error)
|
||||
} else {
|
||||
resolve(
|
||||
Promise.all(
|
||||
files.map(function(f) {
|
||||
return getFileStats(path.join(dir, file, f))
|
||||
})
|
||||
).then(function(statsArray) {
|
||||
files.map(f => getFileStats(path.join(dir, file, f)))
|
||||
).then(statsArray => {
|
||||
return Promise.all(
|
||||
statsArray.map(function(stats, index) {
|
||||
return getMetadataRecursive(
|
||||
statsArray.map((stats, index) =>
|
||||
getMetadataRecursive(
|
||||
dir,
|
||||
path.join(file, files[index]),
|
||||
stats,
|
||||
maximumDepth - 1
|
||||
)
|
||||
})
|
||||
)
|
||||
)
|
||||
})
|
||||
)
|
||||
@ -39,7 +37,7 @@ function formatTime(time) {
|
||||
}
|
||||
|
||||
function getIntegrity(file) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.readFile(file, function(error, data) {
|
||||
if (error) {
|
||||
reject(error)
|
||||
@ -60,7 +58,7 @@ function getMetadataRecursive(dir, file, stats, maximumDepth) {
|
||||
}
|
||||
|
||||
if (stats.isFile()) {
|
||||
return getIntegrity(path.join(dir, file)).then(function(integrity) {
|
||||
return getIntegrity(path.join(dir, file)).then(integrity => {
|
||||
metadata.integrity = integrity
|
||||
return metadata
|
||||
})
|
||||
@ -69,7 +67,7 @@ function getMetadataRecursive(dir, file, stats, maximumDepth) {
|
||||
if (!stats.isDirectory() || maximumDepth === 0)
|
||||
return Promise.resolve(metadata)
|
||||
|
||||
return getEntries(dir, file, maximumDepth).then(function(files) {
|
||||
return getEntries(dir, file, maximumDepth).then(files => {
|
||||
metadata.files = files
|
||||
return metadata
|
||||
})
|
||||
|
@ -26,7 +26,7 @@ function ignoreSymlinks(file, headers) {
|
||||
}
|
||||
|
||||
function extractResponse(response, outputDir) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const extract = tar.extract(outputDir, {
|
||||
readable: true, // All dirs/files should be readable.
|
||||
map: stripNamePrefix,
|
||||
@ -44,12 +44,12 @@ function extractResponse(response, outputDir) {
|
||||
function fetchAndExtract(tarballURL, outputDir) {
|
||||
console.log(`info: Fetching ${tarballURL} and extracting to ${outputDir}`)
|
||||
|
||||
return fetch(tarballURL).then(function(response) {
|
||||
return fetch(tarballURL).then(response => {
|
||||
return extractResponse(response, outputDir)
|
||||
})
|
||||
}
|
||||
|
||||
const fetchMutex = createMutex(function(payload, callback) {
|
||||
const fetchMutex = createMutex((payload, callback) => {
|
||||
const { tarballURL, outputDir } = payload
|
||||
|
||||
fs.access(outputDir, function(error) {
|
||||
@ -61,7 +61,7 @@ const fetchMutex = createMutex(function(payload, callback) {
|
||||
if (error) {
|
||||
callback(error)
|
||||
} else {
|
||||
fetchAndExtract(tarballURL, outputDir).then(function() {
|
||||
fetchAndExtract(tarballURL, outputDir).then(() => {
|
||||
callback()
|
||||
}, callback)
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ function fetchPackageInfo(packageName) {
|
||||
headers: {
|
||||
Accept: 'application/json'
|
||||
}
|
||||
}).then(function(res) {
|
||||
}).then(res => {
|
||||
return res.status === 404 ? null : res.json()
|
||||
})
|
||||
}
|
||||
@ -31,7 +31,7 @@ const PackageNotFound = 'PackageNotFound'
|
||||
|
||||
// This mutex prevents multiple concurrent requests to
|
||||
// the registry for the same package info.
|
||||
const fetchMutex = createMutex(function(packageName, callback) {
|
||||
const fetchMutex = createMutex((packageName, callback) => {
|
||||
fetchPackageInfo(packageName).then(
|
||||
function(value) {
|
||||
if (value == null) {
|
||||
|
Reference in New Issue
Block a user