Use single quotes :P

This commit is contained in:
Michael Jackson
2018-12-17 09:38:05 -08:00
parent ada37035cd
commit 19b2e5574b
93 changed files with 792 additions and 791 deletions

View File

@ -1,15 +1,15 @@
const createSearch = require("../createSearch");
const createSearch = require('../createSearch');
describe("createSearch", () => {
it("omits the trailing = for empty string values", () => {
expect(createSearch({ a: "a", b: "" })).toEqual("?a=a&b");
describe('createSearch', () => {
it('omits the trailing = for empty string values', () => {
expect(createSearch({ a: 'a', b: '' })).toEqual('?a=a&b');
});
it("sorts keys", () => {
expect(createSearch({ b: "b", a: "a", c: "c" })).toEqual("?a=a&b=b&c=c");
it('sorts keys', () => {
expect(createSearch({ b: 'b', a: 'a', c: 'c' })).toEqual('?a=a&b=b&c=c');
});
it("returns an empty string when there are no params", () => {
expect(createSearch({})).toEqual("");
it('returns an empty string when there are no params', () => {
expect(createSearch({})).toEqual('');
});
});

View File

@ -1,39 +1,39 @@
const getContentType = require("../getContentType");
const getContentType = require('../getContentType');
it("gets a content type of text/plain for LICENSE|README|CHANGES|AUTHORS|Makefile", () => {
expect(getContentType("AUTHORS")).toBe("text/plain");
expect(getContentType("CHANGES")).toBe("text/plain");
expect(getContentType("LICENSE")).toBe("text/plain");
expect(getContentType("Makefile")).toBe("text/plain");
expect(getContentType("PATENTS")).toBe("text/plain");
expect(getContentType("README")).toBe("text/plain");
it('gets a content type of text/plain for LICENSE|README|CHANGES|AUTHORS|Makefile', () => {
expect(getContentType('AUTHORS')).toBe('text/plain');
expect(getContentType('CHANGES')).toBe('text/plain');
expect(getContentType('LICENSE')).toBe('text/plain');
expect(getContentType('Makefile')).toBe('text/plain');
expect(getContentType('PATENTS')).toBe('text/plain');
expect(getContentType('README')).toBe('text/plain');
});
it("gets a content type of text/plain for .*rc files", () => {
expect(getContentType(".eslintrc")).toBe("text/plain");
expect(getContentType(".babelrc")).toBe("text/plain");
expect(getContentType(".anythingrc")).toBe("text/plain");
it('gets a content type of text/plain for .*rc files', () => {
expect(getContentType('.eslintrc')).toBe('text/plain');
expect(getContentType('.babelrc')).toBe('text/plain');
expect(getContentType('.anythingrc')).toBe('text/plain');
});
it("gets a content type of text/plain for .git* files", () => {
expect(getContentType(".gitignore")).toBe("text/plain");
expect(getContentType(".gitanything")).toBe("text/plain");
it('gets a content type of text/plain for .git* files', () => {
expect(getContentType('.gitignore')).toBe('text/plain');
expect(getContentType('.gitanything')).toBe('text/plain');
});
it("gets a content type of text/plain for .*ignore files", () => {
expect(getContentType(".eslintignore")).toBe("text/plain");
expect(getContentType(".anythingignore")).toBe("text/plain");
it('gets a content type of text/plain for .*ignore files', () => {
expect(getContentType('.eslintignore')).toBe('text/plain');
expect(getContentType('.anythingignore')).toBe('text/plain');
});
it("gets a content type of text/plain for .ts files", () => {
expect(getContentType("app.ts")).toBe("text/plain");
expect(getContentType("app.d.ts")).toBe("text/plain");
it('gets a content type of text/plain for .ts files', () => {
expect(getContentType('app.ts')).toBe('text/plain');
expect(getContentType('app.d.ts')).toBe('text/plain');
});
it("gets a content type of text/plain for .flow files", () => {
expect(getContentType("app.js.flow")).toBe("text/plain");
it('gets a content type of text/plain for .flow files', () => {
expect(getContentType('app.js.flow')).toBe('text/plain');
});
it("gets a content type of text/plain for .lock files", () => {
expect(getContentType("yarn.lock")).toBe("text/plain");
it('gets a content type of text/plain for .lock files', () => {
expect(getContentType('yarn.lock')).toBe('text/plain');
});

View File

@ -1,80 +1,80 @@
const parsePackageURL = require("../parsePackageURL");
const parsePackageURL = require('../parsePackageURL');
describe("parsePackageURL", () => {
it("parses plain packages", () => {
expect(parsePackageURL("/history@1.0.0/umd/history.min.js")).toEqual({
pathname: "/history@1.0.0/umd/history.min.js",
search: "",
describe('parsePackageURL', () => {
it('parses plain packages', () => {
expect(parsePackageURL('/history@1.0.0/umd/history.min.js')).toEqual({
pathname: '/history@1.0.0/umd/history.min.js',
search: '',
query: {},
packageName: "history",
packageVersion: "1.0.0",
filename: "/umd/history.min.js"
packageName: 'history',
packageVersion: '1.0.0',
filename: '/umd/history.min.js'
});
});
it("parses plain packages with a hyphen in the name", () => {
expect(parsePackageURL("/query-string@5.0.0/index.js")).toEqual({
pathname: "/query-string@5.0.0/index.js",
search: "",
it('parses plain packages with a hyphen in the name', () => {
expect(parsePackageURL('/query-string@5.0.0/index.js')).toEqual({
pathname: '/query-string@5.0.0/index.js',
search: '',
query: {},
packageName: "query-string",
packageVersion: "5.0.0",
filename: "/index.js"
packageName: 'query-string',
packageVersion: '5.0.0',
filename: '/index.js'
});
});
it("parses plain packages with no version specified", () => {
expect(parsePackageURL("/query-string/index.js")).toEqual({
pathname: "/query-string/index.js",
search: "",
it('parses plain packages with no version specified', () => {
expect(parsePackageURL('/query-string/index.js')).toEqual({
pathname: '/query-string/index.js',
search: '',
query: {},
packageName: "query-string",
packageVersion: "latest",
filename: "/index.js"
packageName: 'query-string',
packageVersion: 'latest',
filename: '/index.js'
});
});
it("parses plain packages with version spec", () => {
expect(parsePackageURL("/query-string@>=4.0.0/index.js")).toEqual({
pathname: "/query-string@>=4.0.0/index.js",
search: "",
it('parses plain packages with version spec', () => {
expect(parsePackageURL('/query-string@>=4.0.0/index.js')).toEqual({
pathname: '/query-string@>=4.0.0/index.js',
search: '',
query: {},
packageName: "query-string",
packageVersion: ">=4.0.0",
filename: "/index.js"
packageName: 'query-string',
packageVersion: '>=4.0.0',
filename: '/index.js'
});
});
it("parses scoped packages", () => {
expect(parsePackageURL("/@angular/router@4.3.3/src/index.d.ts")).toEqual({
pathname: "/@angular/router@4.3.3/src/index.d.ts",
search: "",
it('parses scoped packages', () => {
expect(parsePackageURL('/@angular/router@4.3.3/src/index.d.ts')).toEqual({
pathname: '/@angular/router@4.3.3/src/index.d.ts',
search: '',
query: {},
packageName: "@angular/router",
packageVersion: "4.3.3",
filename: "/src/index.d.ts"
packageName: '@angular/router',
packageVersion: '4.3.3',
filename: '/src/index.d.ts'
});
});
it("parses package names with a period in them", () => {
expect(parsePackageURL("/index.js")).toEqual({
pathname: "/index.js",
search: "",
it('parses package names with a period in them', () => {
expect(parsePackageURL('/index.js')).toEqual({
pathname: '/index.js',
search: '',
query: {},
packageName: "index.js",
packageVersion: "latest",
filename: ""
packageName: 'index.js',
packageVersion: 'latest',
filename: ''
});
});
it("parses valid query parameters", () => {
expect(parsePackageURL("/history?main=browser")).toEqual({
pathname: "/history",
search: "?main=browser",
query: { main: "browser" },
packageName: "history",
packageVersion: "latest",
filename: ""
it('parses valid query parameters', () => {
expect(parsePackageURL('/history?main=browser')).toEqual({
pathname: '/history',
search: '?main=browser',
query: { main: 'browser' },
packageName: 'history',
packageVersion: 'latest',
filename: ''
});
});
});

View File

@ -1,5 +1,5 @@
function addLeadingSlash(name) {
return name.charAt(0) === "/" ? name : "/" + name;
return name.charAt(0) === '/' ? name : '/' + name;
}
module.exports = addLeadingSlash;

View File

@ -3,9 +3,9 @@ function bufferStream(stream) {
const chunks = [];
stream
.on("error", reject)
.on("data", chunk => chunks.push(chunk))
.on("end", () => resolve(Buffer.concat(chunks)));
.on('error', reject)
.on('data', chunk => chunks.push(chunk))
.on('end', () => resolve(Buffer.concat(chunks)));
});
}

View File

@ -1,9 +1,9 @@
const redis = require("redis");
const redis = require('redis');
redis.debug_mode = process.env.DEBUG_REDIS != null;
const client = redis.createClient(
process.env.CACHE_URL || process.env.OPENREDIS_URL || "redis://localhost:6379"
process.env.CACHE_URL || process.env.OPENREDIS_URL || 'redis://localhost:6379'
);
module.exports = client;

View File

@ -3,14 +3,14 @@ function createSearch(query) {
const params = keys.reduce(
(memo, key) =>
memo.concat(
query[key] === ""
query[key] === ''
? key // Omit the trailing "=" from key=
: `${key}=${encodeURIComponent(query[key])}`
),
[]
);
return params.length ? `?${params.join("&")}` : "";
return params.length ? `?${params.join('&')}` : '';
}
module.exports = createSearch;

View File

@ -1,9 +1,9 @@
const redis = require("redis");
const redis = require('redis');
redis.debug_mode = process.env.DEBUG_REDIS != null;
const client = redis.createClient(
process.env.DATA_URL || process.env.OPENREDIS_URL || "redis://localhost:6379"
process.env.DATA_URL || process.env.OPENREDIS_URL || 'redis://localhost:6379'
);
module.exports = client;

View File

@ -1,18 +1,18 @@
const url = require("url");
const https = require("https");
const gunzip = require("gunzip-maybe");
const tar = require("tar-stream");
const url = require('url');
const https = require('https');
const gunzip = require('gunzip-maybe');
const tar = require('tar-stream');
const bufferStream = require("./bufferStream");
const agent = require("./registryAgent");
const logging = require("./logging");
const bufferStream = require('./bufferStream');
const agent = require('./registryAgent');
const logging = require('./logging');
function fetchNpmPackage(packageConfig) {
return new Promise((resolve, reject) => {
const tarballURL = packageConfig.dist.tarball;
logging.debug(
"Fetching package for %s from %s",
'Fetching package for %s from %s',
packageConfig.name,
tarballURL
);
@ -31,7 +31,7 @@ function fetchNpmPackage(packageConfig) {
} else {
bufferStream(res).then(data => {
const spec = `${packageConfig.name}@${packageConfig.version}`;
const content = data.toString("utf-8");
const content = data.toString('utf-8');
const error = new Error(
`Failed to fetch tarball for ${spec}\nstatus: ${
res.statusCode
@ -42,7 +42,7 @@ function fetchNpmPackage(packageConfig) {
});
}
})
.on("error", reject);
.on('error', reject);
});
}

View File

@ -1,10 +1,10 @@
const url = require("url");
const https = require("https");
const url = require('url');
const https = require('https');
const serverConfig = require("../serverConfig");
const bufferStream = require("./bufferStream");
const agent = require("./registryAgent");
const logging = require("./logging");
const serverConfig = require('../serverConfig');
const bufferStream = require('./bufferStream');
const agent = require('./registryAgent');
const logging = require('./logging');
function parseJSON(res) {
return bufferStream(res).then(JSON.parse);
@ -13,13 +13,13 @@ function parseJSON(res) {
function fetchNpmPackageInfo(packageName) {
return new Promise((resolve, reject) => {
const encodedPackageName =
packageName.charAt(0) === "@"
packageName.charAt(0) === '@'
? `@${encodeURIComponent(packageName.substring(1))}`
: encodeURIComponent(packageName);
const infoURL = `${serverConfig.registryURL}/${encodedPackageName}`;
logging.debug("Fetching package info for %s from %s", packageName, infoURL);
logging.debug('Fetching package info for %s from %s', packageName, infoURL);
const { hostname, pathname } = url.parse(infoURL);
const options = {
@ -27,7 +27,7 @@ function fetchNpmPackageInfo(packageName) {
hostname: hostname,
path: pathname,
headers: {
Accept: "application/json"
Accept: 'application/json'
}
};
@ -39,7 +39,7 @@ function fetchNpmPackageInfo(packageName) {
resolve(null);
} else {
bufferStream(res).then(data => {
const content = data.toString("utf-8");
const content = data.toString('utf-8');
const error = new Error(
`Failed to fetch info for ${packageName}\nstatus: ${
res.statusCode
@ -50,7 +50,7 @@ function fetchNpmPackageInfo(packageName) {
});
}
})
.on("error", reject);
.on('error', reject);
});
}

View File

@ -1,22 +1,22 @@
const mime = require("mime");
const mime = require('mime');
mime.define({
"text/plain": [
"authors",
"changes",
"license",
"makefile",
"patents",
"readme",
"ts",
"flow"
'text/plain': [
'authors',
'changes',
'license',
'makefile',
'patents',
'readme',
'ts',
'flow'
]
});
const textFiles = /\/?(\.[a-z]*rc|\.git[a-z]*|\.[a-z]*ignore|\.lock)$/i;
function getContentType(file) {
return textFiles.test(file) ? "text/plain" : mime.lookup(file);
return textFiles.test(file) ? 'text/plain' : mime.lookup(file);
}
module.exports = getContentType;

View File

@ -1,5 +1,5 @@
function getContentTypeHeader(type) {
return type === "application/javascript" ? type + "; charset=utf-8" : type;
return type === 'application/javascript' ? type + '; charset=utf-8' : type;
}
module.exports = getContentTypeHeader;

View File

@ -1,7 +1,7 @@
const SRIToolbox = require("sri-toolbox");
const SRIToolbox = require('sri-toolbox');
function getIntegrity(data) {
return SRIToolbox.generate({ algorithms: ["sha384"] }, data);
return SRIToolbox.generate({ algorithms: ['sha384'] }, data);
}
module.exports = getIntegrity;

View File

@ -1,5 +1,5 @@
const cache = require("./cache");
const fetchNpmPackageInfo = require("./fetchNpmPackageInfo");
const cache = require('./cache');
const fetchNpmPackageInfo = require('./fetchNpmPackageInfo');
const notFound = 0;

View File

@ -1,4 +1,4 @@
const db = require("./data");
const db = require('./data');
function incrementCounter(counter, key, by = 1) {
return new Promise((resolve, reject) => {

View File

@ -1,4 +1,4 @@
const validateNpmPackageName = require("validate-npm-package-name");
const validateNpmPackageName = require('validate-npm-package-name');
function isValidPackageName(packageName) {
return validateNpmPackageName(packageName).errors == null;

View File

@ -4,11 +4,11 @@ function noop() {}
let debug, info, warn;
if (process.env.LOG_LEVEL === "none") {
if (process.env.LOG_LEVEL === 'none') {
debug = info = warn = noop;
} else if (process.env.LOG_LEVEL === "debug") {
} else if (process.env.LOG_LEVEL === 'debug') {
debug = info = warn = log;
} else if (process.env.LOG_LEVEL === "warn") {
} else if (process.env.LOG_LEVEL === 'warn') {
debug = info = noop;
warn = log;
} else {

View File

@ -1,4 +1,4 @@
const url = require("url");
const url = require('url');
const packageURLFormat = /^\/((?:@[^/@]+\/)?[^/@]+)(?:@([^/]+))?(\/.*)?$/;
@ -11,7 +11,7 @@ function decodeParam(param) {
}
}
return "";
return '';
}
function parsePackageURL(originalURL) {
@ -24,13 +24,13 @@ function parsePackageURL(originalURL) {
}
const packageName = match[1];
const packageVersion = decodeParam(match[2]) || "latest";
const packageVersion = decodeParam(match[2]) || 'latest';
const filename = decodeParam(match[3]);
return {
// If the URL is /@scope/name@version/file.js?main=browser:
pathname, // /@scope/name@version/path.js
search: search || "", // ?main=browser
search: search || '', // ?main=browser
query, // { main: 'browser' }
packageName, // @scope/name
packageVersion, // version

View File

@ -1,4 +1,4 @@
const https = require("https");
const https = require('https');
const agent = new https.Agent({
keepAlive: true

View File

@ -1,7 +1,7 @@
const React = require("react");
const ReactDOMServer = require("react-dom/server");
const React = require('react');
const ReactDOMServer = require('react-dom/server');
const doctype = "<!DOCTYPE html>";
const doctype = '<!DOCTYPE html>';
function renderPage(page, props) {
const element = React.createElement(page, props);

View File

@ -1,6 +1,6 @@
const babel = require("babel-core");
const babel = require('babel-core');
const unpkgRewrite = require("../plugins/unpkgRewrite");
const unpkgRewrite = require('../plugins/unpkgRewrite');
function rewriteBareModuleIdentifiers(code, packageConfig) {
const dependencies = Object.assign(