Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade TypeScript, Jest, Prettier, etc. to modern versions #176

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ plugins:
- "prettier"
extends:
- "plugin:@typescript-eslint/recommended"
- "prettier/@typescript-eslint"
- "plugin:prettier/recommended"
globals:
Atomics: readonly
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

strategy:
matrix:
node-version: [8.x, 10.x, 12.x]
node-version: [10.x, 12.x, 14.x]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're dropping support for older node versions, this new requirement should also be updated on the "engines" section of the package.json file.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we should probably also bump the major package version.


steps:
- uses: actions/checkout@v1
Expand Down
3 changes: 2 additions & 1 deletion .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
trailingComma: none
tabWidth: 2
bracketSpacing: false
bracketSpacing: false
endOfLine: auto
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@
"devDependencies": {
"@types/jest": "^24.0.21",
"@types/node": "^8.10.16",
"@typescript-eslint/eslint-plugin": "^2.6.0",
"@typescript-eslint/parser": "^2.6.0",
"eslint": "^6.6.0",
"eslint-config-prettier": "^6.5.0",
"@typescript-eslint/eslint-plugin": "^4.29.1",
"@typescript-eslint/parser": "^4.29.1",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.1.1",
"husky": "^3.0.0",
"jest": "^24.7.1",
"prettier": "1.18.2",
"jest": "^27.0.6",
"prettier": "2.3.2",
"reflect-metadata": "^0.1.12",
"rimraf": "^3.0.0",
"ts-jest": "^24.0.2",
"typescript": "^3.1.6"
"ts-jest": "^27.0.4",
"typescript": "^4.3.0"
}
}
2 changes: 1 addition & 1 deletion src/__tests__/child-container.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/interface-name-prefix, @typescript-eslint/no-empty-interface */
/* eslint-disable @typescript-eslint/no-empty-interface */

import {instance as globalContainer} from "../dependency-container";

Expand Down
2 changes: 0 additions & 2 deletions src/__tests__/global-container.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable @typescript-eslint/interface-name-prefix */

import {inject, injectable, registry, singleton} from "../decorators";
import {
instanceCachingFactory,
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/inject-lazy.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test("DelayedConstructor delays creation until first usage", () => {
}
const delayedConstructor = delay(() => Foo);
expect(delayedConstructor).toBeInstanceOf(DelayedConstructor);
const foo: Foo = delayedConstructor.createProxy(Target => new Target());
const foo: Foo = delayedConstructor.createProxy((Target) => new Target());
expect(created).toBe(false);
expect(foo).toBeInstanceOf(Foo);
expect(created).toBe(true);
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ test("Injecting all with transform should allow the transformer to act over an a

class FooTransform implements Transform<FooInterface[], string> {
public transform(foos: FooInterface[]): string {
return foos.map(f => f.bar).reduce((acc, f) => acc + f);
return foos.map((f) => f.bar).reduce((acc, f) => acc + f);
}
}

Expand Down Expand Up @@ -172,7 +172,7 @@ test("Injecting all with transform should work with a decorator parameter", () =

class FooTransform implements Transform<FooInterface[], string> {
public transform(foos: FooInterface[], suffix: string): string {
return foos.map(f => f.bar + suffix).reduce((acc, f) => acc + f);
return foos.map((f) => f.bar + suffix).reduce((acc, f) => acc + f);
}
}

Expand Down Expand Up @@ -212,7 +212,7 @@ test("Injecting all with transform should allow multiple decorator params", () =
suffix: string
): string {
return (
foos.map(f => f.bar + delimiter).reduce((acc, f) => acc + f) + suffix
foos.map((f) => f.bar + delimiter).reduce((acc, f) => acc + f) + suffix
);
}
}
Expand Down Expand Up @@ -253,7 +253,7 @@ test("@autoInjectable should work with transforms", () => {
suffix: string
): string {
return (
foos.map(f => f.bar + delimiter).reduce((acc, f) => acc + f) + suffix
foos.map((f) => f.bar + delimiter).reduce((acc, f) => acc + f) + suffix
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/utils/error-match.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default function errorMatch(lines: RegExp[]): RegExp {
return new RegExp(lines.map(x => x.source).join("\\s+"));
return new RegExp(lines.map((x) => x.source).join("\\s+"));
}
2 changes: 1 addition & 1 deletion src/decorators/auto-injectable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {formatErrorCtor} from "../error-helpers";
* @return {Function} The class decorator
*/
function autoInjectable(): (target: constructor<any>) => any {
return function(target: constructor<any>): constructor<any> {
return function (target: constructor<any>): constructor<any> {
const paramInfo = getParamInfo(target);

return class extends target {
Expand Down
2 changes: 1 addition & 1 deletion src/decorators/injectable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {typeInfo} from "../dependency-container";
* @return {Function} The class decorator
*/
function injectable<T>(): (target: constructor<T>) => void {
return function(target: constructor<T>): void {
return function (target: constructor<T>): void {
typeInfo.set(target, getParamInfo(target));
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/decorators/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function registry(
options?: RegistrationOptions;
} & Provider<any>)[] = []
): (target: any) => any {
return function(target: any): any {
return function (target: any): any {
registrations.forEach(({token, options, ...provider}) =>
globalContainer.register(token, provider as any, options)
);
Expand Down
2 changes: 1 addition & 1 deletion src/decorators/scoped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function scoped<T>(
lifecycle: Lifecycle.ContainerScoped | Lifecycle.ResolutionScoped,
token?: InjectionToken<T>
): (target: constructor<T>) => void {
return function(target: constructor<T>): void {
return function (target: constructor<T>): void {
injectable()(target);
globalContainer.register(token || target, target, {
lifecycle
Expand Down
2 changes: 1 addition & 1 deletion src/decorators/singleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {instance as globalContainer} from "../dependency-container";
* @return {Function} The class decorator
*/
function singleton<T>(): (target: constructor<T>) => void {
return function(target: constructor<T>): void {
return function (target: constructor<T>): void {
injectable()(target);
globalContainer.registerSingleton(target);
};
Expand Down
8 changes: 4 additions & 4 deletions src/dependency-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ class InternalDependencyContainer implements DependencyContainer {
this.executePreResolutionInterceptor(token, "All");

if (registrations) {
const result = registrations.map(item =>
const result = registrations.map((item) =>
this.resolveRegistration<T>(item, context)
);

Expand Down Expand Up @@ -380,9 +380,9 @@ class InternalDependencyContainer implements DependencyContainer {
token,
registrations
// Clear ValueProvider registrations
.filter(registration => !isValueProvider(registration.provider))
.filter((registration) => !isValueProvider(registration.provider))
// Clear instances
.map(registration => {
.map((registration) => {
registration.instance = undefined;
return registration;
})
Expand All @@ -404,7 +404,7 @@ class InternalDependencyContainer implements DependencyContainer {
) {
childContainer._registry.setAll(
token,
registrations.map<Registration>(registration => {
registrations.map<Registration>((registration) => {
if (registration.options.lifecycle === Lifecycle.ContainerScoped) {
return {
provider: registration.provider,
Expand Down
2 changes: 1 addition & 1 deletion src/error-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function formatDependency(params: string | null, idx: number): string {
}

function composeErrorMessage(msg: string, e: Error, indent = " "): string {
return [msg, ...e.message.split("\n").map(l => indent + l)].join("\n");
return [msg, ...e.message.split("\n").map((l) => indent + l)].join("\n");
}

export function formatErrorCtor(
Expand Down
8 changes: 2 additions & 6 deletions src/factories/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
export {default as FactoryFunction} from "./factory-function";
export {default as instanceCachingFactory} from "./instance-caching-factory";
export {
default as instancePerContainerCachingFactory
} from "./instance-per-container-caching-factory";
export {
default as predicateAwareClassFactory
} from "./predicate-aware-class-factory";
export {default as instancePerContainerCachingFactory} from "./instance-per-container-caching-factory";
export {default as predicateAwareClassFactory} from "./predicate-aware-class-factory";
14 changes: 6 additions & 8 deletions src/interceptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ export type PostResolutionInterceptor = {
options: InterceptionOptions;
};

export class PreResolutionInterceptors extends RegistryBase<
PreResolutionInterceptor
> {}
export class PreResolutionInterceptors extends RegistryBase<PreResolutionInterceptor> {}

export class PostResolutionInterceptors extends RegistryBase<
PostResolutionInterceptor
> {}
export class PostResolutionInterceptors extends RegistryBase<PostResolutionInterceptor> {}

export default class Interceptors {
public preResolution: PreResolutionInterceptors = new PreResolutionInterceptors();
public postResolution: PostResolutionInterceptors = new PostResolutionInterceptors();
public preResolution: PreResolutionInterceptors =
new PreResolutionInterceptors();
public postResolution: PostResolutionInterceptors =
new PostResolutionInterceptors();
}
1 change: 1 addition & 0 deletions src/providers/injection-token.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import constructor from "../types/constructor";
import {DelayedConstructor} from "../lazy-helpers";
import Transform from "../types/transform";
Expand Down
1 change: 1 addition & 0 deletions src/providers/provider.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import ClassProvider, {isClassProvider} from "./class-provider";
import ValueProvider, {isValueProvider} from "./value-provider";
import TokenProvider, {isTokenProvider} from "./token-provider";
Expand Down
5 changes: 3 additions & 2 deletions src/reflection-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import Dictionary from "./types/dictionary";
import constructor from "./types/constructor";
import InjectionToken, {TokenDescriptor} from "./providers/injection-token";
Expand All @@ -10,7 +11,7 @@ export function getParamInfo(target: constructor<any>): ParamInfo[] {
const params: any[] = Reflect.getMetadata("design:paramtypes", target) || [];
const injectionTokens: Dictionary<InjectionToken<any>> =
Reflect.getOwnMetadata(INJECTION_TOKEN_METADATA_KEY, target) || {};
Object.keys(injectionTokens).forEach(key => {
Object.keys(injectionTokens).forEach((key) => {
params[+key] = injectionTokens[key];
});

Expand All @@ -21,7 +22,7 @@ export function defineInjectionTokenMetadata(
data: any,
transform?: {transformToken: InjectionToken<Transform<any, any>>; args: any[]}
): (target: any, propertyKey: string | symbol, parameterIndex: number) => any {
return function(
return function (
target: any,
_propertyKey: string | symbol,
parameterIndex: number
Expand Down
Loading