Enforce single quotes
This commit is contained in:
45
.eslintrc.js
45
.eslintrc.js
@@ -9,32 +9,33 @@ module.exports = {
|
||||
],
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
"plugin:@typescript-eslint/eslint-recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:promise/recommended",
|
||||
'plugin:@typescript-eslint/eslint-recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:promise/recommended',
|
||||
],
|
||||
rules: {
|
||||
"no-console": "error",
|
||||
"max-len": ["error", {"code": 128}],
|
||||
"no-process-env": "error",
|
||||
"no-process-exit": "error",
|
||||
"no-null/no-null": "error",
|
||||
"no-useless-return": "error",
|
||||
"prefer-arrow-callback": "warn",
|
||||
"object-curly-spacing": "error",
|
||||
"consistent-return": "error",
|
||||
"@typescript-eslint/explicit-function-return-type": [
|
||||
"error", {
|
||||
"allowExpressions": true,
|
||||
'no-console': 'error',
|
||||
'max-len': ['error', {'code': 128}],
|
||||
'no-process-env': 'error',
|
||||
'no-process-exit': 'error',
|
||||
'no-null/no-null': 'error',
|
||||
'no-useless-return': 'error',
|
||||
'prefer-arrow-callback': 'warn',
|
||||
'object-curly-spacing': 'error',
|
||||
'consistent-return': 'error',
|
||||
'@typescript-eslint/explicit-function-return-type': [
|
||||
'error', {
|
||||
'allowExpressions': true,
|
||||
},
|
||||
],
|
||||
"no-void": "error",
|
||||
"comma-spacing": "error",
|
||||
"comma-dangle": ["error", "always-multiline"],
|
||||
"comma-style": "error",
|
||||
"semi": "error",
|
||||
"no-implicit-coercion": "error",
|
||||
'no-void': 'error',
|
||||
'comma-spacing': 'error',
|
||||
'comma-dangle': ['error', 'always-multiline'],
|
||||
'comma-style': 'error',
|
||||
'semi': 'error',
|
||||
'no-implicit-coercion': 'error',
|
||||
'quotes': ['error', 'single', 'avoid-escape'],
|
||||
|
||||
"promise/always-return": "off",
|
||||
'promise/always-return': 'off',
|
||||
},
|
||||
};
|
||||
|
||||
@@ -14,7 +14,7 @@ function getRouter(opts) {
|
||||
if (!_1.DefaultConfig.isProduction) {
|
||||
let uuid = uuid_1.v4();
|
||||
let updateTimeout = undefined;
|
||||
Promise.resolve().then(() => require("node-watch")).then((watch) => {
|
||||
Promise.resolve().then(() => require('node-watch')).then((watch) => {
|
||||
for (const frontendDir of config.frontendDirs) {
|
||||
watch.default(frontendDir, { recursive: true }, () => {
|
||||
if (updateTimeout !== undefined)
|
||||
@@ -28,7 +28,7 @@ function getRouter(opts) {
|
||||
// /auto-reload/client.js
|
||||
router.get(_1.urlJoin(config.subPath, config.jsName), (req, res) => {
|
||||
_1.Logger.debug(req.url, req.originalUrl, req.baseUrl);
|
||||
res.setHeader('Content-Type', "application/javascript");
|
||||
res.setHeader('Content-Type', 'application/javascript');
|
||||
// language=JavaScript
|
||||
res.send(`
|
||||
const loc = window.location;
|
||||
@@ -58,7 +58,7 @@ function getRouter(opts) {
|
||||
}
|
||||
}
|
||||
}, 3000);
|
||||
`.replace(/\t/g, ""));
|
||||
`.replace(/\t/g, ''));
|
||||
});
|
||||
// /auto-reload
|
||||
router.get(_1.urlJoin(config.subPath), (req, res) => {
|
||||
|
||||
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DefaultConfig = void 0;
|
||||
const env = require("env-var");
|
||||
const _1 = require(".");
|
||||
const NODE_ENV = env.get('NODE_ENV').default("development").asString();
|
||||
const NODE_ENV = env.get('NODE_ENV').default('development').asString();
|
||||
const isProduction = NODE_ENV === 'production';
|
||||
const envs = {
|
||||
NODE_ENV,
|
||||
@@ -20,9 +20,9 @@ const envs = {
|
||||
// cookie secret for the session id (required in production using Session)
|
||||
SESSION_SECRET: env.get('SESSION_SECRET').asString() || undefined,
|
||||
// header where user info token is stored to request auth proxy
|
||||
USERINFO_HEADER: env.get('USERINFO_HEADER').default("X-Userinfo-Token").asString(),
|
||||
USERINFO_HEADER: env.get('USERINFO_HEADER').default('X-Userinfo-Token').asString(),
|
||||
// header when user info token expires (seconds after 01/01/1970)
|
||||
EXPIRE_HEADER: env.get('EXPIRE_HEADER').default("X-Userinfo-Expire").asString(),
|
||||
EXPIRE_HEADER: env.get('EXPIRE_HEADER').default('X-Userinfo-Expire').asString(),
|
||||
// base url to init a logout or request user info
|
||||
AUTH_PROXY_URL: env.get('AUTH_PROXY_URL').asString() || undefined,
|
||||
// override AUTH_PROXY_URL to request user info
|
||||
@@ -34,7 +34,7 @@ function requireEnv(name, onlyInProduction = false) {
|
||||
env.get(name).required(!onlyInProduction || isProduction).asString();
|
||||
}
|
||||
exports.DefaultConfig = Object.assign(Object.assign({}, envs), { EXTERNAL_BASE_URL: envs.EXTERNAL_BASE_URL ||
|
||||
_1.urlJoin(`http://${envs.HOSTNAME}${envs.PORT !== 80 ? `:${envs.PORT}` : ""}`, envs.BASE_PATH), isProduction,
|
||||
_1.urlJoin(`http://${envs.HOSTNAME}${envs.PORT !== 80 ? `:${envs.PORT}` : ''}`, envs.BASE_PATH), isProduction,
|
||||
requireEnv, AUTH_PROXY_USERINFO_URL: envs.AUTH_PROXY_USERINFO_URL ||
|
||||
envs.AUTH_PROXY_URL && _1.urlJoin(envs.AUTH_PROXY_URL, "userinfo"), AUTH_PROXY_INIT_LOGOUT_URL: envs.AUTH_PROXY_INIT_LOGOUT_URL ||
|
||||
envs.AUTH_PROXY_URL && _1.urlJoin(envs.AUTH_PROXY_URL, "init-logout") });
|
||||
envs.AUTH_PROXY_URL && _1.urlJoin(envs.AUTH_PROXY_URL, 'userinfo'), AUTH_PROXY_INIT_LOGOUT_URL: envs.AUTH_PROXY_INIT_LOGOUT_URL ||
|
||||
envs.AUTH_PROXY_URL && _1.urlJoin(envs.AUTH_PROXY_URL, 'init-logout') });
|
||||
|
||||
2
out/logging.d.ts
vendored
2
out/logging.d.ts
vendored
@@ -1,7 +1,7 @@
|
||||
import * as winston from 'winston';
|
||||
import { RequestHandler } from 'express';
|
||||
export declare const levels: readonly ["error", "warn", "info", "http", "verbose", "debug", "silly"];
|
||||
export declare type LogLevels = typeof levels[number] | "log";
|
||||
export declare type LogLevels = typeof levels[number] | 'log';
|
||||
export declare const Logger: {
|
||||
error: (...args: unknown[]) => winston.Logger;
|
||||
http: (...args: unknown[]) => winston.Logger;
|
||||
|
||||
@@ -6,7 +6,7 @@ const colors = require("colors");
|
||||
const _1 = require(".");
|
||||
const prune = require("json-prune");
|
||||
const logger = winston.createLogger({
|
||||
level: _1.DefaultConfig.isProduction ? "info" : "silly",
|
||||
level: _1.DefaultConfig.isProduction ? 'info' : 'silly',
|
||||
format: winston.format.json(),
|
||||
transports: [
|
||||
new winston.transports.Console({
|
||||
@@ -14,17 +14,17 @@ const logger = winston.createLogger({
|
||||
}),
|
||||
],
|
||||
});
|
||||
exports.levels = ["error", "warn", "info", "http", "verbose", "debug", "silly"];
|
||||
exports.levels = ['error', 'warn', 'info', 'http', 'verbose', 'debug', 'silly'];
|
||||
const wrapper = (original) => {
|
||||
return (...args) => {
|
||||
return original(args.map((obj) => typeof obj === "string" ? obj : prune(obj)).join(" "));
|
||||
return original(args.map((obj) => typeof obj === 'string' ? obj : prune(obj)).join(' '));
|
||||
};
|
||||
};
|
||||
exports.Logger = {};
|
||||
for (const level of exports.levels) {
|
||||
exports.Logger[level] = wrapper(logger[level]);
|
||||
}
|
||||
exports.Logger.log = wrapper(logger["silly"]);
|
||||
exports.Logger.log = wrapper(logger['silly']);
|
||||
exports.HttpLogger = (req, res, next) => {
|
||||
const start = Date.now();
|
||||
const path = req.path;
|
||||
@@ -37,8 +37,8 @@ exports.HttpLogger = (req, res, next) => {
|
||||
: statusCode >= 200 ? colors.green
|
||||
: colors.gray;
|
||||
const status = colorFunction(res.statusCode.toString(10));
|
||||
const method = req.method.toUpperCase().padEnd(6, " ");
|
||||
const responseTime = (Date.now() - start).toString(10).padStart(3, " ");
|
||||
const method = req.method.toUpperCase().padEnd(6, ' ');
|
||||
const responseTime = (Date.now() - start).toString(10).padStart(3, ' ');
|
||||
if (!req.noHttpLogging)
|
||||
exports.Logger.http(`${status} ${method} ${responseTime}ms ${path}`);
|
||||
end.apply(res, args);
|
||||
|
||||
@@ -88,7 +88,7 @@ class PermQuery extends Query_1.Query {
|
||||
return this;
|
||||
}
|
||||
sync() {
|
||||
throw new role_acl_1.AccessControlError("Sync method is not allowed on PermissionManager!");
|
||||
throw new role_acl_1.AccessControlError('Sync method is not allowed on PermissionManager!');
|
||||
}
|
||||
}
|
||||
exports.PermQuery = PermQuery;
|
||||
|
||||
@@ -7,9 +7,9 @@ const polyfill_analyzer_1 = require("@10xjs/polyfill-analyzer");
|
||||
const polyfills_1 = require("@10xjs/polyfill-analyzer/dist/polyfills");
|
||||
worker_1.expose((fileToWatch) => {
|
||||
const exclude = [
|
||||
"console.markTimeline",
|
||||
"console.timeline",
|
||||
"console.timelineEnd",
|
||||
'console.markTimeline',
|
||||
'console.timeline',
|
||||
'console.timelineEnd',
|
||||
];
|
||||
const featureList = polyfill_analyzer_1.analyze({
|
||||
source: fs.readFileSync(fileToWatch, 'utf-8'),
|
||||
|
||||
@@ -16,20 +16,20 @@ const threads_1 = require("threads");
|
||||
function getRouter(fileToWatch, opts) {
|
||||
const features = new _1.WaitForSync();
|
||||
(() => __awaiter(this, void 0, void 0, function* () {
|
||||
const worker = yield threads_1.spawn(new threads_1.Worker("./polyfill-worker"));
|
||||
const worker = yield threads_1.spawn(new threads_1.Worker('./polyfill-worker'));
|
||||
const feats = yield worker(fileToWatch);
|
||||
yield threads_1.Thread.terminate(worker);
|
||||
return feats;
|
||||
}))()
|
||||
.then(feats => {
|
||||
feats["fetch"] = {};
|
||||
_1.Logger.debug("Polyfill analysed:", Object.keys(feats));
|
||||
feats['fetch'] = {};
|
||||
_1.Logger.debug('Polyfill analysed:', Object.keys(feats));
|
||||
features.setData(feats);
|
||||
})
|
||||
.catch(err => features.setError(err));
|
||||
const options = Object.assign({ minify: _1.DefaultConfig.isProduction, unknown: "polyfill" }, opts);
|
||||
const options = Object.assign({ minify: _1.DefaultConfig.isProduction, unknown: 'polyfill' }, opts);
|
||||
return (req, res) => __awaiter(this, void 0, void 0, function* () {
|
||||
const polyfillBundle = yield polyfillLibrary.getPolyfillString(Object.assign(Object.assign({}, options), { uaString: req.header("user-agent"), features: yield features.resolve(), stream: false }));
|
||||
const polyfillBundle = yield polyfillLibrary.getPolyfillString(Object.assign(Object.assign({}, options), { uaString: req.header('user-agent'), features: yield features.resolve(), stream: false }));
|
||||
res.setHeader('Content-Type', 'text/javascript');
|
||||
res.send(polyfillBundle);
|
||||
});
|
||||
|
||||
@@ -32,7 +32,7 @@ function getRouter(opts: ReloaderConfig): Router {
|
||||
if (!DefaultConfig.isProduction) {
|
||||
let uuid = v4();
|
||||
let updateTimeout: Timeout|undefined = undefined;
|
||||
import("node-watch").then((watch) => {
|
||||
import('node-watch').then((watch) => {
|
||||
for (const frontendDir of config.frontendDirs) {
|
||||
watch.default(frontendDir, {recursive: true}, () => {
|
||||
if (updateTimeout !== undefined) clearTimeout(updateTimeout);
|
||||
@@ -46,7 +46,7 @@ function getRouter(opts: ReloaderConfig): Router {
|
||||
// /auto-reload/client.js
|
||||
router.get(urlJoin(config.subPath, config.jsName), (req, res) => {
|
||||
Logger.debug(req.url, req.originalUrl, req.baseUrl);
|
||||
res.setHeader('Content-Type', "application/javascript");
|
||||
res.setHeader('Content-Type', 'application/javascript');
|
||||
// language=JavaScript
|
||||
res.send(`
|
||||
const loc = window.location;
|
||||
@@ -76,7 +76,7 @@ function getRouter(opts: ReloaderConfig): Router {
|
||||
}
|
||||
}
|
||||
}, 3000);
|
||||
`.replace(/\t/g, ""));
|
||||
`.replace(/\t/g, ''));
|
||||
});
|
||||
|
||||
// /auto-reload
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as env from 'env-var';
|
||||
import {urlJoin} from '.';
|
||||
|
||||
const NODE_ENV = env.get('NODE_ENV').default("development").asString();
|
||||
const NODE_ENV = env.get('NODE_ENV').default('development').asString();
|
||||
const isProduction = NODE_ENV === 'production';
|
||||
|
||||
const envs = {
|
||||
@@ -21,9 +21,9 @@ const envs = {
|
||||
SESSION_SECRET: env.get('SESSION_SECRET').asString() || undefined,
|
||||
|
||||
// header where user info token is stored to request auth proxy
|
||||
USERINFO_HEADER: env.get('USERINFO_HEADER').default("X-Userinfo-Token").asString(),
|
||||
USERINFO_HEADER: env.get('USERINFO_HEADER').default('X-Userinfo-Token').asString(),
|
||||
// header when user info token expires (seconds after 01/01/1970)
|
||||
EXPIRE_HEADER: env.get('EXPIRE_HEADER').default("X-Userinfo-Expire").asString(),
|
||||
EXPIRE_HEADER: env.get('EXPIRE_HEADER').default('X-Userinfo-Expire').asString(),
|
||||
// base url to init a logout or request user info
|
||||
AUTH_PROXY_URL: env.get('AUTH_PROXY_URL').asString() || undefined,
|
||||
// override AUTH_PROXY_URL to request user info
|
||||
@@ -40,11 +40,11 @@ export const DefaultConfig = {
|
||||
...envs,
|
||||
EXTERNAL_BASE_URL:
|
||||
envs.EXTERNAL_BASE_URL ||
|
||||
urlJoin(`http://${envs.HOSTNAME}${envs.PORT !== 80 ? `:${envs.PORT}` : ""}`, envs.BASE_PATH),
|
||||
urlJoin(`http://${envs.HOSTNAME}${envs.PORT !== 80 ? `:${envs.PORT}` : ''}`, envs.BASE_PATH),
|
||||
isProduction,
|
||||
requireEnv,
|
||||
AUTH_PROXY_USERINFO_URL: envs.AUTH_PROXY_USERINFO_URL ||
|
||||
envs.AUTH_PROXY_URL && urlJoin(envs.AUTH_PROXY_URL, "userinfo"),
|
||||
envs.AUTH_PROXY_URL && urlJoin(envs.AUTH_PROXY_URL, 'userinfo'),
|
||||
AUTH_PROXY_INIT_LOGOUT_URL: envs.AUTH_PROXY_INIT_LOGOUT_URL ||
|
||||
envs.AUTH_PROXY_URL && urlJoin(envs.AUTH_PROXY_URL, "init-logout"),
|
||||
envs.AUTH_PROXY_URL && urlJoin(envs.AUTH_PROXY_URL, 'init-logout'),
|
||||
};
|
||||
|
||||
@@ -7,7 +7,7 @@ import prune = require('json-prune');
|
||||
|
||||
|
||||
const logger = winston.createLogger({
|
||||
level: DefaultConfig.isProduction ? "info" : "silly",
|
||||
level: DefaultConfig.isProduction ? 'info' : 'silly',
|
||||
format: winston.format.json(),
|
||||
transports: [
|
||||
new winston.transports.Console({
|
||||
@@ -16,11 +16,11 @@ const logger = winston.createLogger({
|
||||
],
|
||||
});
|
||||
|
||||
export const levels = ["error", "warn", "info", "http", "verbose", "debug", "silly"] as const;
|
||||
export type LogLevels = typeof levels[number]|"log";
|
||||
export const levels = ['error', 'warn', 'info', 'http', 'verbose', 'debug', 'silly'] as const;
|
||||
export type LogLevels = typeof levels[number]|'log';
|
||||
const wrapper = (original: LeveledLogMethod) => {
|
||||
return (...args: unknown[]) => {
|
||||
return original(args.map((obj) => typeof obj === "string" ? obj : prune(obj)).join(" "));
|
||||
return original(args.map((obj) => typeof obj === 'string' ? obj : prune(obj)).join(' '));
|
||||
};
|
||||
};
|
||||
|
||||
@@ -30,7 +30,7 @@ export const Logger = {
|
||||
for (const level of levels) {
|
||||
Logger[level] = wrapper(logger[level]);
|
||||
}
|
||||
Logger.log = wrapper(logger["silly"]);
|
||||
Logger.log = wrapper(logger['silly']);
|
||||
|
||||
export const HttpLogger: RequestHandler = (req, res, next) => {
|
||||
const start = Date.now();
|
||||
@@ -45,8 +45,8 @@ export const HttpLogger: RequestHandler = (req, res, next) => {
|
||||
: statusCode >= 200 ? colors.green
|
||||
: colors.gray;
|
||||
const status = colorFunction(res.statusCode.toString(10));
|
||||
const method = req.method.toUpperCase().padEnd(6, " ");
|
||||
const responseTime = (Date.now()-start).toString(10).padStart(3, " ");
|
||||
const method = req.method.toUpperCase().padEnd(6, ' ');
|
||||
const responseTime = (Date.now()-start).toString(10).padStart(3, ' ');
|
||||
if (!req.noHttpLogging)
|
||||
Logger.http(`${status} ${method} ${responseTime}ms ${path}`);
|
||||
end.apply(res, args);
|
||||
|
||||
@@ -87,7 +87,7 @@ export class PermQuery extends Query {
|
||||
}
|
||||
|
||||
public sync(): PermQuery {
|
||||
throw new AccessControlError("Sync method is not allowed on PermissionManager!");
|
||||
throw new AccessControlError('Sync method is not allowed on PermissionManager!');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
// workers/add.js
|
||||
import {expose} from "threads/worker";
|
||||
import * as fs from "fs";
|
||||
import {expose} from 'threads/worker';
|
||||
import * as fs from 'fs';
|
||||
import {analyze} from '@10xjs/polyfill-analyzer';
|
||||
import allPolyfills from '@10xjs/polyfill-analyzer/dist/polyfills';
|
||||
import {PolyfillFeatureList} from 'polyfill-library';
|
||||
|
||||
expose((fileToWatch) => {
|
||||
const exclude = [
|
||||
"console.markTimeline",
|
||||
"console.timeline",
|
||||
"console.timelineEnd",
|
||||
'console.markTimeline',
|
||||
'console.timeline',
|
||||
'console.timelineEnd',
|
||||
];
|
||||
const featureList = analyze({
|
||||
source: fs.readFileSync(fileToWatch, 'utf-8'),
|
||||
|
||||
@@ -22,27 +22,27 @@ export type PolyfillOptions = {
|
||||
function getRouter(fileToWatch: string, opts?: Partial<PolyfillOptions>): RequestHandler {
|
||||
const features = new WaitForSync<PolyfillFeatureList>();
|
||||
(async () => {
|
||||
const worker = await spawn<WorkerFunction>(new Worker("./polyfill-worker"));
|
||||
const worker = await spawn<WorkerFunction>(new Worker('./polyfill-worker'));
|
||||
const feats = await worker(fileToWatch) as PolyfillFeatureList;
|
||||
await Thread.terminate(worker);
|
||||
return feats;
|
||||
})()
|
||||
.then(feats => {
|
||||
feats["fetch"] = {};
|
||||
Logger.debug("Polyfill analysed:", Object.keys(feats));
|
||||
feats['fetch'] = {};
|
||||
Logger.debug('Polyfill analysed:', Object.keys(feats));
|
||||
features.setData(feats);
|
||||
})
|
||||
.catch(err => features.setError(err));
|
||||
|
||||
const options: Partial<PolyfillOptions> = {
|
||||
minify: DefaultConfig.isProduction,
|
||||
unknown: "polyfill",
|
||||
unknown: 'polyfill',
|
||||
...opts,
|
||||
};
|
||||
return async (req, res) => {
|
||||
const polyfillBundle = await polyfillLibrary.getPolyfillString({
|
||||
...options,
|
||||
uaString: req.header("user-agent"),
|
||||
uaString: req.header('user-agent'),
|
||||
features: await features.resolve(),
|
||||
stream: false,
|
||||
});
|
||||
|
||||
@@ -12,8 +12,8 @@ interface RedisType {
|
||||
class RealRedis implements RedisType {
|
||||
private _client: redis.RedisClient|undefined;
|
||||
private _promGet: ((key: string) => Promise<string|null>)|undefined;
|
||||
private _promSet: RedisType["set"]|undefined;
|
||||
private _promDel: RedisType["del"]|undefined;
|
||||
private _promSet: RedisType['set']|undefined;
|
||||
private _promDel: RedisType['del']|undefined;
|
||||
|
||||
get client(): redis.RedisClient {
|
||||
if (this._client !== undefined) return this._client;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import * as session from 'express-session';
|
||||
import {Store} from 'express-session';
|
||||
import {DefaultConfig, Redis} from '.';
|
||||
import * as redisStore from "connect-redis";
|
||||
import * as redisStore from 'connect-redis';
|
||||
import {RequestHandler, Router} from 'express';
|
||||
import {promisify} from "util";
|
||||
import {promisify} from 'util';
|
||||
|
||||
|
||||
let sessionStore: Store|undefined = undefined;
|
||||
|
||||
2
src/types/json-prune.d.ts
vendored
2
src/types/json-prune.d.ts
vendored
@@ -1,4 +1,4 @@
|
||||
declare module "json-prune" {
|
||||
declare module 'json-prune' {
|
||||
function prune(object: unknown): string;
|
||||
|
||||
export = prune;
|
||||
|
||||
2
src/types/polyfill.d.ts
vendored
2
src/types/polyfill.d.ts
vendored
@@ -1,4 +1,4 @@
|
||||
declare module "polyfill-library" {
|
||||
declare module 'polyfill-library' {
|
||||
import {Readable} from 'stream';
|
||||
|
||||
function listAllPolyfills(): string[];
|
||||
|
||||
Reference in New Issue
Block a user