Use single quotes :P
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
const BlacklistAPI = require("../BlacklistAPI");
|
||||
const BlacklistAPI = require('../BlacklistAPI');
|
||||
|
||||
function checkBlacklist(req, res, next) {
|
||||
BlacklistAPI.includesPackage(req.packageName).then(
|
||||
@ -7,14 +7,14 @@ function checkBlacklist(req, res, next) {
|
||||
if (blacklisted) {
|
||||
res
|
||||
.status(403)
|
||||
.type("text")
|
||||
.type('text')
|
||||
.send(`Package "${req.packageName}" is blacklisted`);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
},
|
||||
error => {
|
||||
console.error("Unable to fetch the blacklist: %s", error);
|
||||
console.error('Unable to fetch the blacklist: %s', error);
|
||||
|
||||
// Continue anyway.
|
||||
next();
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
const invariant = require("invariant");
|
||||
const invariant = require('invariant');
|
||||
|
||||
const createAssets = require("./utils/createAssets");
|
||||
const createAssets = require('./utils/createAssets');
|
||||
|
||||
/**
|
||||
* An express middleware that sets req.assets from the
|
||||
@ -9,15 +9,15 @@ const createAssets = require("./utils/createAssets");
|
||||
*/
|
||||
function devAssets(webpackCompiler) {
|
||||
let assets;
|
||||
webpackCompiler.plugin("done", stats => {
|
||||
webpackCompiler.plugin('done', stats => {
|
||||
assets = createAssets(stats.toJson());
|
||||
});
|
||||
|
||||
return (req, res, next) => {
|
||||
invariant(
|
||||
assets != null,
|
||||
"devAssets middleware needs a running compiler; " +
|
||||
"use webpack-dev-middleware in front of devAssets"
|
||||
'devAssets middleware needs a running compiler; ' +
|
||||
'use webpack-dev-middleware in front of devAssets'
|
||||
);
|
||||
|
||||
req.assets = assets;
|
||||
|
||||
@ -1,19 +1,19 @@
|
||||
const semver = require("semver");
|
||||
const semver = require('semver');
|
||||
|
||||
const addLeadingSlash = require("../utils/addLeadingSlash");
|
||||
const createPackageURL = require("../utils/createPackageURL");
|
||||
const createSearch = require("../utils/createSearch");
|
||||
const getNpmPackageInfo = require("../utils/getNpmPackageInfo");
|
||||
const incrementCounter = require("../utils/incrementCounter");
|
||||
const addLeadingSlash = require('../utils/addLeadingSlash');
|
||||
const createPackageURL = require('../utils/createPackageURL');
|
||||
const createSearch = require('../utils/createSearch');
|
||||
const getNpmPackageInfo = require('../utils/getNpmPackageInfo');
|
||||
const incrementCounter = require('../utils/incrementCounter');
|
||||
|
||||
function tagRedirect(req, res) {
|
||||
const version = req.packageInfo["dist-tags"][req.packageVersion];
|
||||
const version = req.packageInfo['dist-tags'][req.packageVersion];
|
||||
|
||||
// Cache tag redirects for 1 minute.
|
||||
res
|
||||
.set({
|
||||
"Cache-Control": "public, max-age=60",
|
||||
"Cache-Tag": "redirect,tag-redirect"
|
||||
'Cache-Control': 'public, max-age=60',
|
||||
'Cache-Tag': 'redirect,tag-redirect'
|
||||
})
|
||||
.redirect(
|
||||
302,
|
||||
@ -31,8 +31,8 @@ function semverRedirect(req, res) {
|
||||
// Cache semver redirects for 1 minute.
|
||||
res
|
||||
.set({
|
||||
"Cache-Control": "public, max-age=60",
|
||||
"Cache-Tag": "redirect,semver-redirect"
|
||||
'Cache-Control': 'public, max-age=60',
|
||||
'Cache-Tag': 'redirect,semver-redirect'
|
||||
})
|
||||
.redirect(
|
||||
302,
|
||||
@ -41,7 +41,7 @@ function semverRedirect(req, res) {
|
||||
} else {
|
||||
res
|
||||
.status(404)
|
||||
.type("text")
|
||||
.type('text')
|
||||
.send(`Cannot find package ${req.packageSpec}`);
|
||||
}
|
||||
}
|
||||
@ -52,12 +52,12 @@ function filenameRedirect(req, res) {
|
||||
// See https://github.com/rollup/rollup/wiki/pkg.module
|
||||
filename =
|
||||
req.packageConfig.module ||
|
||||
req.packageConfig["jsnext:main"] ||
|
||||
"/index.js";
|
||||
req.packageConfig['jsnext:main'] ||
|
||||
'/index.js';
|
||||
} else if (
|
||||
req.query.main &&
|
||||
req.packageConfig[req.query.main] &&
|
||||
typeof req.packageConfig[req.query.main] === "string"
|
||||
typeof req.packageConfig[req.query.main] === 'string'
|
||||
) {
|
||||
// Deprecated, see #63
|
||||
filename = req.packageConfig[req.query.main];
|
||||
@ -65,35 +65,35 @@ function filenameRedirect(req, res) {
|
||||
// Count which packages are using this so we can warn them when we
|
||||
// remove this functionality.
|
||||
incrementCounter(
|
||||
"package-json-custom-main",
|
||||
req.packageSpec + "?main=" + req.query.main,
|
||||
'package-json-custom-main',
|
||||
req.packageSpec + '?main=' + req.query.main,
|
||||
1
|
||||
);
|
||||
} else if (
|
||||
req.packageConfig.unpkg &&
|
||||
typeof req.packageConfig.unpkg === "string"
|
||||
typeof req.packageConfig.unpkg === 'string'
|
||||
) {
|
||||
filename = req.packageConfig.unpkg;
|
||||
} else if (
|
||||
req.packageConfig.browser &&
|
||||
typeof req.packageConfig.browser === "string"
|
||||
typeof req.packageConfig.browser === 'string'
|
||||
) {
|
||||
// Deprecated, see #63
|
||||
filename = req.packageConfig.browser;
|
||||
|
||||
// Count which packages are using this so we can warn them when we
|
||||
// remove this functionality.
|
||||
incrementCounter("package-json-browser-fallback", req.packageSpec, 1);
|
||||
incrementCounter('package-json-browser-fallback', req.packageSpec, 1);
|
||||
} else {
|
||||
filename = req.packageConfig.main || "/index.js";
|
||||
filename = req.packageConfig.main || '/index.js';
|
||||
}
|
||||
|
||||
// Redirect to the exact filename so relative imports
|
||||
// and URLs resolve correctly.
|
||||
res
|
||||
.set({
|
||||
"Cache-Control": "public, max-age=31536000, immutable", // 1 year
|
||||
"Cache-Tag": "redirect, filename-redirect"
|
||||
'Cache-Control': 'public, max-age=31536000, immutable', // 1 year
|
||||
'Cache-Tag': 'redirect, filename-redirect'
|
||||
})
|
||||
.redirect(
|
||||
302,
|
||||
@ -117,7 +117,7 @@ function fetchPackage(req, res, next) {
|
||||
if (packageInfo == null || packageInfo.versions == null) {
|
||||
return res
|
||||
.status(404)
|
||||
.type("text")
|
||||
.type('text')
|
||||
.send(`Cannot find package "${req.packageName}"`);
|
||||
}
|
||||
|
||||
@ -126,7 +126,7 @@ function fetchPackage(req, res, next) {
|
||||
|
||||
if (!req.packageConfig) {
|
||||
// Redirect to a fully-resolved version.
|
||||
if (req.packageVersion in req.packageInfo["dist-tags"]) {
|
||||
if (req.packageVersion in req.packageInfo['dist-tags']) {
|
||||
return tagRedirect(req, res);
|
||||
} else {
|
||||
return semverRedirect(req, res);
|
||||
@ -144,7 +144,7 @@ function fetchPackage(req, res, next) {
|
||||
|
||||
return res
|
||||
.status(500)
|
||||
.type("text")
|
||||
.type('text')
|
||||
.send(`Cannot get info for package "${req.packageName}"`);
|
||||
}
|
||||
);
|
||||
|
||||
@ -1,19 +1,19 @@
|
||||
const path = require("path");
|
||||
const path = require('path');
|
||||
|
||||
const addLeadingSlash = require("../utils/addLeadingSlash");
|
||||
const createPackageURL = require("../utils/createPackageURL");
|
||||
const createSearch = require("../utils/createSearch");
|
||||
const fetchNpmPackage = require("../utils/fetchNpmPackage");
|
||||
const getIntegrity = require("../utils/getIntegrity");
|
||||
const getContentType = require("../utils/getContentType");
|
||||
const addLeadingSlash = require('../utils/addLeadingSlash');
|
||||
const createPackageURL = require('../utils/createPackageURL');
|
||||
const createSearch = require('../utils/createSearch');
|
||||
const fetchNpmPackage = require('../utils/fetchNpmPackage');
|
||||
const getIntegrity = require('../utils/getIntegrity');
|
||||
const getContentType = require('../utils/getContentType');
|
||||
|
||||
function indexRedirect(req, res, entry) {
|
||||
// Redirect to the index file so relative imports
|
||||
// resolve correctly.
|
||||
res
|
||||
.set({
|
||||
"Cache-Control": "public, max-age=31536000, immutable", // 1 year
|
||||
"Cache-Tag": "redirect, index-redirect"
|
||||
'Cache-Control': 'public, max-age=31536000, immutable', // 1 year
|
||||
'Cache-Tag': 'redirect, index-redirect'
|
||||
})
|
||||
.redirect(
|
||||
302,
|
||||
@ -27,7 +27,7 @@ function indexRedirect(req, res, entry) {
|
||||
}
|
||||
|
||||
function stripLeadingSegment(name) {
|
||||
return name.replace(/^[^/]+\/?/, "");
|
||||
return name.replace(/^[^/]+\/?/, '');
|
||||
}
|
||||
|
||||
function searchEntries(tarballStream, entryName, wantsIndex) {
|
||||
@ -35,14 +35,14 @@ function searchEntries(tarballStream, entryName, wantsIndex) {
|
||||
const entries = {};
|
||||
let foundEntry = null;
|
||||
|
||||
if (entryName === "") {
|
||||
foundEntry = entries[""] = { name: "", type: "directory" };
|
||||
if (entryName === '') {
|
||||
foundEntry = entries[''] = { name: '', type: 'directory' };
|
||||
}
|
||||
|
||||
tarballStream
|
||||
.on("error", reject)
|
||||
.on("finish", () => resolve({ entries, foundEntry }))
|
||||
.on("entry", (header, stream, next) => {
|
||||
.on('error', reject)
|
||||
.on('finish', () => resolve({ entries, foundEntry }))
|
||||
.on('entry', (header, stream, next) => {
|
||||
const entry = {
|
||||
// Most packages have header names that look like `package/index.js`
|
||||
// so we shorten that to just `index.js` here. A few packages use a
|
||||
@ -53,9 +53,9 @@ function searchEntries(tarballStream, entryName, wantsIndex) {
|
||||
};
|
||||
|
||||
// We are only interested in files that match the entryName.
|
||||
if (entry.type !== "file" || entry.name.indexOf(entryName) !== 0) {
|
||||
if (entry.type !== 'file' || entry.name.indexOf(entryName) !== 0) {
|
||||
stream.resume();
|
||||
stream.on("end", next);
|
||||
stream.on('end', next);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -65,8 +65,8 @@ function searchEntries(tarballStream, entryName, wantsIndex) {
|
||||
// that are in this file's path. Some tarballs omit these entries
|
||||
// for some reason, so this is the brute force method.
|
||||
let dirname = path.dirname(entry.name);
|
||||
while (dirname !== ".") {
|
||||
const directoryEntry = { name: dirname, type: "directory" };
|
||||
while (dirname !== '.') {
|
||||
const directoryEntry = { name: dirname, type: 'directory' };
|
||||
|
||||
if (!entries[dirname]) {
|
||||
entries[dirname] = directoryEntry;
|
||||
@ -94,7 +94,7 @@ function searchEntries(tarballStream, entryName, wantsIndex) {
|
||||
|
||||
const chunks = [];
|
||||
|
||||
stream.on("data", chunk => chunks.push(chunk)).on("end", () => {
|
||||
stream.on('data', chunk => chunks.push(chunk)).on('end', () => {
|
||||
const content = Buffer.concat(chunks);
|
||||
|
||||
// Set some extra properties for files that we will
|
||||
@ -126,8 +126,8 @@ const trailingSlash = /\/$/;
|
||||
function findFile(req, res, next) {
|
||||
fetchNpmPackage(req.packageConfig).then(tarballStream => {
|
||||
const entryName = req.filename
|
||||
.replace(trailingSlash, "")
|
||||
.replace(leadingSlash, "");
|
||||
.replace(trailingSlash, '')
|
||||
.replace(leadingSlash, '');
|
||||
const wantsIndex = trailingSlash.test(req.filename);
|
||||
|
||||
searchEntries(tarballStream, entryName, wantsIndex).then(
|
||||
@ -135,7 +135,7 @@ function findFile(req, res, next) {
|
||||
if (!foundEntry) {
|
||||
return res
|
||||
.status(404)
|
||||
.type("text")
|
||||
.type('text')
|
||||
.send(`Cannot find "${req.filename}" in ${req.packageSpec}`);
|
||||
}
|
||||
|
||||
@ -144,17 +144,17 @@ function findFile(req, res, next) {
|
||||
// inside that directory. This is so our URLs work in a similar way
|
||||
// to require("lib") in node where it searches for `lib/index.js`
|
||||
// and `lib/index.json` when `lib` is a directory.
|
||||
if (foundEntry.type === "directory" && !wantsIndex) {
|
||||
if (foundEntry.type === 'directory' && !wantsIndex) {
|
||||
const indexEntry =
|
||||
entries[path.join(entryName, "index.js")] ||
|
||||
entries[path.join(entryName, "index.json")];
|
||||
entries[path.join(entryName, 'index.js')] ||
|
||||
entries[path.join(entryName, 'index.json')];
|
||||
|
||||
if (indexEntry && indexEntry.type === "file") {
|
||||
if (indexEntry && indexEntry.type === 'file') {
|
||||
return indexRedirect(req, res, indexEntry);
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.type("text")
|
||||
.type('text')
|
||||
.send(
|
||||
`Cannot find an index in "${req.filename}" in ${
|
||||
req.packageSpec
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
const createSearch = require("../utils/createSearch");
|
||||
const createSearch = require('../utils/createSearch');
|
||||
|
||||
/**
|
||||
* Redirect old URLs that we no longer support.
|
||||
@ -6,14 +6,14 @@ const createSearch = require("../utils/createSearch");
|
||||
function redirectLegacyURLs(req, res, next) {
|
||||
// Permanently redirect /_meta/path to /path?meta.
|
||||
if (req.path.match(/^\/_meta\//)) {
|
||||
req.query.meta = "";
|
||||
req.query.meta = '';
|
||||
return res.redirect(301, req.path.substr(6) + createSearch(req.query));
|
||||
}
|
||||
|
||||
// Permanently redirect /path?json => /path?meta
|
||||
if (req.query.json != null) {
|
||||
delete req.query.json;
|
||||
req.query.meta = "";
|
||||
req.query.meta = '';
|
||||
return res.redirect(301, req.path + createSearch(req.query));
|
||||
}
|
||||
|
||||
|
||||
@ -4,8 +4,8 @@
|
||||
*/
|
||||
function requireAuth(scope) {
|
||||
let checkScopes;
|
||||
if (scope.includes(".")) {
|
||||
const parts = scope.split(".");
|
||||
if (scope.includes('.')) {
|
||||
const parts = scope.split('.');
|
||||
checkScopes = scopes =>
|
||||
parts.reduce((memo, part) => memo && memo[part], scopes) != null;
|
||||
} else {
|
||||
@ -20,11 +20,11 @@ function requireAuth(scope) {
|
||||
const user = req.user;
|
||||
|
||||
if (!user) {
|
||||
return res.status(403).send({ error: "Missing auth token" });
|
||||
return res.status(403).send({ error: 'Missing auth token' });
|
||||
}
|
||||
|
||||
if (!user.scopes || !checkScopes(user.scopes)) {
|
||||
return res.status(403).send({ error: "Insufficient scopes" });
|
||||
return res.status(403).send({ error: 'Insufficient scopes' });
|
||||
}
|
||||
|
||||
if (req.auth) {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
const fs = require("fs");
|
||||
const invariant = require("invariant");
|
||||
const fs = require('fs');
|
||||
const invariant = require('invariant');
|
||||
|
||||
const createAssets = require("./utils/createAssets");
|
||||
const createAssets = require('./utils/createAssets');
|
||||
|
||||
/**
|
||||
* An express middleware that sets req.assets from the build
|
||||
@ -10,12 +10,12 @@ const createAssets = require("./utils/createAssets");
|
||||
function staticAssets(webpackStatsFile) {
|
||||
let stats;
|
||||
try {
|
||||
stats = JSON.parse(fs.readFileSync(webpackStatsFile, "utf8"));
|
||||
stats = JSON.parse(fs.readFileSync(webpackStatsFile, 'utf8'));
|
||||
} catch (error) {
|
||||
invariant(
|
||||
false,
|
||||
"staticAssets middleware cannot read the build stats in %s; " +
|
||||
"run the `build` script before starting the server",
|
||||
'staticAssets middleware cannot read the build stats in %s; ' +
|
||||
'run the `build` script before starting the server',
|
||||
webpackStatsFile
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
const AuthAPI = require("../AuthAPI");
|
||||
const AuthAPI = require('../AuthAPI');
|
||||
|
||||
const ReadMethods = { GET: true, HEAD: true };
|
||||
|
||||
function decodeBase64(string) {
|
||||
return Buffer.from(string, "base64").toString();
|
||||
return Buffer.from(string, 'base64').toString();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -14,7 +14,7 @@ function userToken(req, res, next) {
|
||||
return next();
|
||||
}
|
||||
|
||||
const auth = req.get("Authorization");
|
||||
const auth = req.get('Authorization');
|
||||
const token = auth
|
||||
? decodeBase64(auth)
|
||||
: (ReadMethods[req.method] ? req.query : req.body).token;
|
||||
@ -30,7 +30,7 @@ function userToken(req, res, next) {
|
||||
next();
|
||||
},
|
||||
error => {
|
||||
if (error.name === "JsonWebTokenError") {
|
||||
if (error.name === 'JsonWebTokenError') {
|
||||
res.status(403).send({
|
||||
error: `Bad auth token: ${error.message}`
|
||||
});
|
||||
@ -38,7 +38,7 @@ function userToken(req, res, next) {
|
||||
console.error(error);
|
||||
|
||||
res.status(500).send({
|
||||
error: "Unable to verify auth"
|
||||
error: 'Unable to verify auth'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,7 +12,7 @@ function createAssets(webpackStats) {
|
||||
/**
|
||||
* Returns an array of URLs to all assets in the given chunks.
|
||||
*/
|
||||
const getAll = (chunks = ["main"]) =>
|
||||
const getAll = (chunks = ['main']) =>
|
||||
(Array.isArray(chunks) ? chunks : [chunks])
|
||||
.reduce((memo, chunk) => memo.concat(assetsByChunkName[chunk] || []), [])
|
||||
.map(createURL);
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
const validateNpmPackageName = require("validate-npm-package-name");
|
||||
const validateNpmPackageName = require('validate-npm-package-name');
|
||||
|
||||
const hexValue = /^[a-f0-9]+$/i;
|
||||
|
||||
@ -13,18 +13,18 @@ function validatePackageName(req, res, next) {
|
||||
if (isHash(req.packageName)) {
|
||||
return res
|
||||
.status(403)
|
||||
.type("text")
|
||||
.type('text')
|
||||
.send(`Invalid package name "${req.packageName}" (cannot be a hash)`);
|
||||
}
|
||||
|
||||
const errors = validateNpmPackageName(req.packageName).errors;
|
||||
|
||||
if (errors) {
|
||||
const reason = errors.join(", ");
|
||||
const reason = errors.join(', ');
|
||||
|
||||
return res
|
||||
.status(403)
|
||||
.type("text")
|
||||
.type('text')
|
||||
.send(`Invalid package name "${req.packageName}" (${reason})`);
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
const parsePackageURL = require("../utils/parsePackageURL");
|
||||
const parsePackageURL = require('../utils/parsePackageURL');
|
||||
|
||||
/**
|
||||
* Parse the URL and add various properties to the request object to
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
const createSearch = require("../utils/createSearch");
|
||||
const createSearch = require('../utils/createSearch');
|
||||
|
||||
const knownQueryParams = {
|
||||
main: true, // Deprecated, see #63
|
||||
|
||||
Reference in New Issue
Block a user