Skip to content

Commit

Permalink
feat(contributing): adds Prettier formatting to the project
Browse files Browse the repository at this point in the history
  • Loading branch information
wessberg committed Jan 20, 2019
1 parent 0dfb26e commit edc62e6
Show file tree
Hide file tree
Showing 83 changed files with 476 additions and 565 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"bs:watch": "npm run watch & npm run serve",
"watch": "npm run rollup:watch",
"validate": "npm run lint && npm run test",
"prettier": "prettier --write 'src/**/*.*'",
"publish:pre": "NODE_ENV=production npm run validate && NODE_ENV=production npm run build",
"publish:meta": "npm run generate:all && git add . && (git commit -am \"Bumped version\" || true) && git push",
"publish:patch": "npm run publish:pre && npm version patch && npm run publish:meta && npm publish",
Expand Down
2 changes: 1 addition & 1 deletion src/bl/polyfill/i-get-polyfills-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import {IPolyfillFeature} from "../../polyfill/i-polyfill-feature";
export interface IGetPolyfillsResult {
result: IRegistryGetResult;
featureSet: Set<IPolyfillFeature>;
}
}
4 changes: 2 additions & 2 deletions src/bl/polyfill/i-polyfill-bl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import {IPolyfillRequest} from "../../polyfill/i-polyfill-request";
import {IGetPolyfillsResult} from "./i-get-polyfills-result";

export interface IPolyfillBl {
getPolyfills (request: IPolyfillRequest): Promise<IGetPolyfillsResult>;
}
getPolyfills(request: IPolyfillRequest): Promise<IGetPolyfillsResult>;
}
19 changes: 8 additions & 11 deletions src/bl/polyfill/polyfill-bl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,25 @@ import {IGetPolyfillsResult} from "./i-get-polyfills-result";
* Business logic for polyfills
*/
export class PolyfillBl implements IPolyfillBl {

constructor (private readonly cacheRegistry: ICacheRegistryService,
private readonly logger: ILoggerService,
private readonly builder: IPolyfillBuilderService) {
}
constructor(private readonly cacheRegistry: ICacheRegistryService, private readonly logger: ILoggerService, private readonly builder: IPolyfillBuilderService) {}

/**
* Generates a chunk of polyfills that matches the given request
* @param {IPolyfillRequest} request
* @returns {Promise<IGetPolyfillsResult>}
*/
public async getPolyfills (request: IPolyfillRequest): Promise<IGetPolyfillsResult> {
public async getPolyfills(request: IPolyfillRequest): Promise<IGetPolyfillsResult> {
// Check if a polyfill set exists within the cache for the request features and the user agent of the request
let featureSet = await this.cacheRegistry.getPolyfillFeatureSet(request.features, request.userAgent);

// If not, resolve and order the required polyfills
if (featureSet == null) {
featureSet = await getOrderedPolyfillsWithDependencies(
new Set([...request.features]
// Take only valid names
.filter(feature => feature.name in constant.polyfill)),
new Set(
[...request.features]
// Take only valid names
.filter(feature => feature.name in constant.polyfill)
),
request.userAgent
);

Expand Down Expand Up @@ -72,5 +70,4 @@ export class PolyfillBl implements IPolyfillBl {
return {result: minifiedResult, featureSet};
}
}

}
}
4 changes: 2 additions & 2 deletions src/bl/static/i-static-bl.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export interface IStaticBl {
getWelcomeMessage (): Promise<string>;
}
getWelcomeMessage(): Promise<string>;
}
5 changes: 2 additions & 3 deletions src/bl/static/static-bl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class StaticBl implements IStaticBl {
* Generates a HTML-formatted welcome message
* @returns {Promise<string>}
*/
public async getWelcomeMessage (): Promise<string> {
public async getWelcomeMessage(): Promise<string> {
return generateHtml(`
<div style="display: flex; flex-direction: row;">
<img style="margin-right: 30px" alt="logo" height="100" src="https://raw.githubusercontent.com/wessberg/Polyfiller/master/documentation/asset/logo-color.png" />
Expand All @@ -20,5 +20,4 @@ export class StaticBl implements IStaticBl {
<h3>For API reference, please see <a href="${constant.meta.github}">Github</a></h3>
`);
}

}
}
16 changes: 13 additions & 3 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ export const config: IConfig = {
host: environment.HOST,
port: parseInt(environment.PORT),
email: environment.EMAIL != null && environment.EMAIL !== "" ? environment.EMAIL : undefined,
key: environment.KEY == null || environment.KEY === "" ? undefined : environment.KEY.trim().startsWith("-----BEGIN RSA PRIVATE KEY-----") ? Buffer.from(environment.KEY.replace(/\\n/g, "\n")) : readFileSync(environment.KEY),
cert: environment.CERT == null || environment.CERT === "" ? undefined : environment.CERT.trim().startsWith("-----BEGIN CERTIFICATE-----") ? Buffer.from(environment.CERT.replace(/\\n/g, "\n")) : readFileSync(environment.CERT)
};
key:
environment.KEY == null || environment.KEY === ""
? undefined
: environment.KEY.trim().startsWith("-----BEGIN RSA PRIVATE KEY-----")
? Buffer.from(environment.KEY.replace(/\\n/g, "\n"))
: readFileSync(environment.KEY),
cert:
environment.CERT == null || environment.CERT === ""
? undefined
: environment.CERT.trim().startsWith("-----BEGIN CERTIFICATE-----")
? Buffer.from(environment.CERT.replace(/\\n/g, "\n"))
: readFileSync(environment.CERT)
};
8 changes: 4 additions & 4 deletions src/config/i-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export declare type IConfig = typeof environment & {
http2: boolean;
port: number;
host: string;
email: string|undefined;
key: Buffer|undefined;
cert: Buffer|undefined;
};
email: string | undefined;
key: Buffer | undefined;
cert: Buffer | undefined;
};
4 changes: 2 additions & 2 deletions src/constant/i-constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Path} from "../server/path";
import {PolyfillDict} from "../polyfill/polyfill-dict";

export interface IEndpointConstant {
index: Path[]|Path;
index: Path[] | Path;
polyfill: Path;
}

Expand All @@ -28,4 +28,4 @@ export interface IConstant {
polyfill: PolyfillDict;
path: IPathConstant;
header: IHeaderConstant;
}
}
2 changes: 1 addition & 1 deletion src/controller/controller/controller-method.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Request} from "../../server/i-request";
import {Response} from "../../server/i-response";

export declare type ControllerMethod = (request: Request) => Promise<Response>;
export declare type ControllerMethod = (request: Request) => Promise<Response>;
8 changes: 3 additions & 5 deletions src/controller/controller/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@ import {Path} from "../../server/path";
* A controller can handle a request and return a response for it
*/
export abstract class Controller implements IController {

// noinspection JSPotentiallyInvalidConstructorUsage
/**
* The controller method listeners of this concrete Controller instance
* @type {Map<RegExp, ControllerMethod>}
*/
public readonly controllerMethods: Map<Method, Map<Path[]|Path, ControllerMethod>> = (<any>this).constructor.prototype.controllerMethods;
public readonly controllerMethods: Map<Method, Map<Path[] | Path, ControllerMethod>> = (<any>this).constructor.prototype.controllerMethods;

/**
* Returns a ControllerMatch for the given request, if any exists
* @param {Request} request
* @returns {ControllerMethod | undefined}
*/
public match (request: Request): ControllerMethod|undefined {
public match(request: Request): ControllerMethod | undefined {
const controllerMethodListener = this.controllerMethods.get(request.method);
if (controllerMethodListener == null) {
return undefined;
Expand All @@ -41,5 +40,4 @@ export abstract class Controller implements IController {

return undefined;
}

}
}
6 changes: 3 additions & 3 deletions src/controller/controller/i-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import {Method} from "../../server/method";
import {Path} from "../../server/path";

export interface IController {
readonly controllerMethods: Map<Method, Map<Path[]|Path, ControllerMethod>>;
match (request: Request): ControllerMethod|undefined;
}
readonly controllerMethods: Map<Method, Map<Path[] | Path, ControllerMethod>>;
match(request: Request): ControllerMethod | undefined;
}
2 changes: 1 addition & 1 deletion src/controller/controller/registered-controllers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import {IController} from "./i-controller";

export declare type RegisteredControllers = IController[];
export declare type RegisteredControllers = IController[];
2 changes: 1 addition & 1 deletion src/controller/polyfill/i-polyfill-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import {ControllerMethod} from "../controller/controller-method";

export interface IPolyfillController extends IController {
onPolyfillRequested: ControllerMethod;
}
}
25 changes: 10 additions & 15 deletions src/controller/polyfill/polyfill-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import {generateErrorHtml} from "../../util/html/generate-html";
* A controller that can respond to requests for polyfills
*/
export class PolyfillController extends Controller implements IPolyfillController {

constructor (private readonly polyfillBl: IPolyfillBl) {
constructor(private readonly polyfillBl: IPolyfillBl) {
super();
}

Expand All @@ -26,20 +25,21 @@ export class PolyfillController extends Controller implements IPolyfillControlle
* @returns {Promise<Response>}
*/
@GET({path: constant.endpoint.polyfill})
public async onPolyfillRequested (request: Request): Promise<Response> {
public async onPolyfillRequested(request: Request): Promise<Response> {
// Normalize the polyfill request
const polyfillRequest = getPolyfillRequestFromUrl(request.url, request.userAgent, pickEncoding(request.acceptEncoding));

// Generate polyfill bundle
try {
const {result: {buffer, checksum}, featureSet} = await this.polyfillBl.getPolyfills(polyfillRequest);
const {
result: {buffer, checksum},
featureSet
} = await this.polyfillBl.getPolyfills(polyfillRequest);

// If the cached checksum (ETag) is identical, respond with NOT_MODIFIED
if (request.cachedChecksum != null && request.cachedChecksum === checksum) {
return {
statusCode: request.http2
? constants.HTTP_STATUS_NOT_MODIFIED
: NOT_MODIFIED,
statusCode: request.http2 ? constants.HTTP_STATUS_NOT_MODIFIED : NOT_MODIFIED,
cacheControl: "public,max-age=31536000,immutable",
polyfillsHeader: encodeFeatureSetForHttpHeader(featureSet)
};
Expand All @@ -48,9 +48,7 @@ export class PolyfillController extends Controller implements IPolyfillControlle
// Return an OK
return {
contentType: "application/javascript",
statusCode: request.http2
? constants.HTTP_STATUS_OK
: OK,
statusCode: request.http2 ? constants.HTTP_STATUS_OK : OK,
body: buffer,
cacheControl: "public,max-age=31536000,immutable",
contentEncoding: polyfillRequest.encoding,
Expand All @@ -59,9 +57,7 @@ export class PolyfillController extends Controller implements IPolyfillControlle
};
} catch (ex) {
// Respond with error code 500
const statusCode = request.http2
? constants.HTTP_STATUS_INTERNAL_SERVER_ERROR
: INTERNAL_SERVER_ERROR;
const statusCode = request.http2 ? constants.HTTP_STATUS_INTERNAL_SERVER_ERROR : INTERNAL_SERVER_ERROR;

return {
contentType: "text/html",
Expand All @@ -70,5 +66,4 @@ export class PolyfillController extends Controller implements IPolyfillControlle
};
}
}

}
}
2 changes: 1 addition & 1 deletion src/controller/static/i-static-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import {ControllerMethod} from "../controller/controller-method";

export interface IStaticController extends IController {
onIndexRequested: ControllerMethod;
}
}
13 changes: 4 additions & 9 deletions src/controller/static/static-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import {IStaticBl} from "../../bl/static/i-static-bl";
* A controller that can respond to requests for static resources
*/
export class StaticController extends Controller implements IStaticController {

constructor (private readonly staticBl: IStaticBl) {
constructor(private readonly staticBl: IStaticBl) {
super();
}

Expand All @@ -23,16 +22,12 @@ export class StaticController extends Controller implements IStaticController {
* @returns {Promise<Response>}
*/
@GET({path: constant.endpoint.index})
public async onIndexRequested (request: Request): Promise<Response> {

public async onIndexRequested(request: Request): Promise<Response> {
// Return an OK
return {
contentType: "text/html",
statusCode: request.http2
? constants.HTTP_STATUS_OK
: OK,
statusCode: request.http2 ? constants.HTTP_STATUS_OK : OK,
body: await this.staticBl.getWelcomeMessage()
};
}

}
}
2 changes: 1 addition & 1 deletion src/encoding/content-encoding-kind.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export enum ContentEncodingKind {
GZIP = "gzip",
BROTLI = "br"
}
}
2 changes: 1 addition & 1 deletion src/encoding/encoding-extension-kind.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export enum EncodingExtensionKind {
GZIP = ".gz",
BROTLI = ".br"
}
}
2 changes: 1 addition & 1 deletion src/environment/environment-defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ export const environmentDefaults = {
EMAIL: "",
KEY: "",
CERT: ""
};
};
2 changes: 1 addition & 1 deletion src/environment/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import {uppercaseKeys} from "../util/uppercase-keys/uppercase-keys";
export const environment = uppercaseKeys({
...environmentDefaults,
...process.env
});
});
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import {IApiService} from "./service/api/i-api-service";
import {ICacheRegistryService} from "./service/registry/cache-registry/i-cache-registry-service";

// Initializes the Cache Registry and then launches the server
container.get<ICacheRegistryService>().initialize()
container
.get<ICacheRegistryService>()
.initialize()
.then(async () => container.get<IApiService>().launch());

// Exports
export {PolyfillName} from "./polyfill/polyfill-name";
export {polyfillRawForceName} from "./polyfill/polyfill-raw-force-name";
export {polyfillOptionValueSeparator} from "./polyfill/polyfill-option-value-separator";
export {polyfillRawDivider} from "./polyfill/polyfill-raw-divider";
export {polyfillRawSeparator} from "./polyfill/polyfill-raw-separator";
export {polyfillRawSeparator} from "./polyfill/polyfill-raw-separator";
12 changes: 6 additions & 6 deletions src/package-json/i-package-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ export interface IPackageJson {
name: string;
version: string;
description: string;
scripts?: { [key: string]: string };
scripts?: {[key: string]: string};
keywords?: string[];
devDependencies?: { [key: string]: string };
peerDependencies?: { [key: string]: string };
dependencies?: { [key: string]: string };
devDependencies?: {[key: string]: string};
peerDependencies?: {[key: string]: string};
dependencies?: {[key: string]: string};
module?: string;
main?: string;
"jsnext:main"?: string;
Expand All @@ -33,7 +33,7 @@ export interface IPackageJson {
bugs?: IBugs;
author?: IAuthor;
authors?: IAuthor[];
engines?: { [key: string]: string };
engines?: {[key: string]: string};
license?: string;
private?: boolean;
}
}
2 changes: 1 addition & 1 deletion src/polyfill/i-polyfill-feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export interface IPolyfillFeature {

export interface IPolyfillFeatureInput extends IPolyfillFeature {
force: boolean;
}
}
2 changes: 1 addition & 1 deletion src/polyfill/i-polyfill-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ export interface IPolyfillRequest {
userAgent: string;
encoding?: ContentEncodingKind;
features: Set<IPolyfillFeatureInput>;
}
}
Loading

0 comments on commit edc62e6

Please sign in to comment.