Small tweaks + whitespace

This commit is contained in:
Michael Jackson 2018-05-25 20:25:04 -04:00
parent a8471ed950
commit c0e0f899d2
5 changed files with 12 additions and 8 deletions

View File

@ -4,10 +4,11 @@ const validateNpmPackageName = require("validate-npm-package-name");
* Reject requests for invalid npm package names.
*/
function validatePackageName(req, res, next) {
const nameErrors = validateNpmPackageName(req.packageName).errors;
const errors = validateNpmPackageName(req.packageName).errors;
if (errors) {
const reason = errors.join(", ");
if (nameErrors) {
const reason = nameErrors.join(", ");
return res
.status(403)
.type("text")

View File

@ -1,8 +1,10 @@
function createPackageURL(packageName, version, pathname, search) {
let url = `/${packageName}`;
if (version != null) url += `@${version}`;
if (pathname) url += pathname;
if (search) url += search;
return url;
}

View File

@ -32,15 +32,15 @@ const fetchMutex = createMutex((packageConfig, callback) => {
callback(error);
}
} else {
lockfile.check(outputDir).then(isLocked => {
if (isLocked) {
lockfile.check(outputDir).then(locked => {
if (locked) {
// Another process on this same machine has locked the
// directory. We need to wait for it to be unlocked
// before we callback.
const timer = setInterval(() => {
lockfile.check(outputDir).then(
isLocked => {
if (!isLocked) {
locked => {
if (!locked) {
clearInterval(timer);
callback(null, outputDir);
}

View File

@ -1,6 +1,6 @@
const db = require("./redis");
function incrementCounter(counter, key, by) {
function incrementCounter(counter, key, by = 1) {
return new Promise((resolve, reject) => {
db.hincrby(counter, key, by, (error, value) => {
if (error) {

View File

@ -7,6 +7,7 @@ function renderPage(page, props) {
const html = ReactDOMServer.renderToStaticMarkup(
React.createElement(page, props)
);
return doctype + html;
}