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. * Reject requests for invalid npm package names.
*/ */
function validatePackageName(req, res, next) { 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 return res
.status(403) .status(403)
.type("text") .type("text")

View File

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

View File

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

View File

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

View File

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