Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
36 changes: 0 additions & 36 deletions .eslintrc.yml

This file was deleted.

6 changes: 4 additions & 2 deletions .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, 14.x, 16.x, 18.x, 20.x, 22.x]
node-version: [18.x, 20.x, 22.x]

steps:
- uses: actions/checkout@v4
Expand All @@ -28,10 +28,12 @@ jobs:
run: |
npm -g i yarn

- name: npm install, build, and test
- name: yarn install, yarn build, and yarn test
run: |
yarn
yarn build
yarn test
env:
CI: true


65 changes: 65 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { defineConfig } from "eslint/config";
import typescriptEslint from "@typescript-eslint/eslint-plugin";
import prettier from "eslint-plugin-prettier";
import globals from "globals";
import tsParser from "@typescript-eslint/parser";
import path from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});

export default defineConfig([{
files: ["./src/**/*.js", "./src/**/*.jsx", "./src/**/*.ts", "./src/**/*.tsx"],
extends: compat.extends(
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
),

plugins: {
"@typescript-eslint": typescriptEslint,
prettier,
},

languageOptions: {
globals: {
...globals.browser,
...globals.commonjs,
Atomics: "readonly",
SharedArrayBuffer: "readonly",
},

parser: tsParser,
ecmaVersion: 2018,
sourceType: "script",
},

rules: {
"@typescript-eslint/explicit-function-return-type": ["warn", {
allowExpressions: true,
}],

"@typescript-eslint/explicit-member-accessibility": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-angle-bracket-type-assertion": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-parameter-properties": "off",
"@typescript-eslint/prefer-interface": "off",
"@typescript-eslint/indent": "off",
},
}, {
files: ["**/*.test.ts", "**/*.spec.ts"],

rules: {
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/interface-name-prefix": "off",
},
}]);
43 changes: 23 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
{
"name": "tsyringe",
"version": "4.9.1",
"version": "5.0.0-alpha.1",
"description": "Lightweight dependency injection container for JavaScript/TypeScript",
"main": "dist/cjs/index.js",
"module": "./dist/esm5/index.js",
"es2015": "./dist/esm2015/index.js",
"typings": "./dist/typings/index.d.ts",
"scripts": {
"build": "yarn clean && yarn build:cjs && yarn build:es5 && yarn build:es2015 && yarn build:types",
"build": "yarn clean && yarn build:cjs && yarn build:es5 && yarn build:es2015 && yarn build:es2020 && yarn build:esnext && yarn build:types",
"build:cjs": "tsc",
"build:es5": "tsc -p ./typescript/tsconfig.esm5.json",
"build:es2015": "tsc -p ./typescript/tsconfig.esm2015.json",
"build:es2020": "tsc -p ./typescript/tsconfig.esm2020.json",
"build:esnext": "tsc -p ./typescript/tsconfig.esmnext.json",
"build:types": "tsc -p ./typescript/tsconfig.types.json",
"clean": "rimraf ./dist",
"test": "yarn lint && jest --config test/jest.config.js",
"test:inspect": "yarn lint && node --inspect-brk ./node_modules/jest/bin/jest.js --runInBand --config test/jest.config.js",
"test:coverage": "jest --config test/jest.config.js --coverage",
"lint": "eslint --ext \".js,.jsx,.ts,.tsx\" \"./src\"",
"lint:fix": "eslint --fix --ext \".js,.jsx,.ts,.tsx\" \"./src\""
"lint": "eslint",
"lint:fix": "eslint --fix"
},
"repository": {
"type": "git",
Expand All @@ -33,7 +35,7 @@
"typescript"
],
"engines": {
"node": ">= 6.0.0"
"node": ">= 18.0.0"
},
"author": "Steven Hobson-Campbell",
"license": "MIT",
Expand All @@ -42,22 +44,23 @@
},
"homepage": "https://github.com/Microsoft/tsyringe#readme",
"dependencies": {
"tslib": "^1.9.3"
"tslib": "^2.8.1"
},
"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",
"eslint-plugin-prettier": "^3.1.1",
"husky": "^3.0.0",
"jest": "^24.7.1",
"prettier": "1.18.2",
"reflect-metadata": "^0.1.12",
"rimraf": "^3.0.0",
"ts-jest": "^24.0.2",
"typescript": "^3.1.6"
"@types/istanbul-lib-report": "^3.0.3",
"@types/jest": "^29.5.14",
"@types/node": "^22.14.0",
"@typescript-eslint/eslint-plugin": "^8.29.0",
"@typescript-eslint/parser": "^8.29.0",
"eslint": "^9.24.0",
"eslint-config-prettier": "^10.1.1",
"eslint-plugin-prettier": "^5.2.6",
"husky": "^9.1.7",
"jest": "^29.7.0",
"prettier": "^3.5.3",
"reflect-metadata": "^0.2.2",
"rimraf": "^5.0.10",
"ts-jest": "^29.3.1",
"typescript": "^5.8.3"
}
}
5 changes: 4 additions & 1 deletion src/__tests__/auto-injectable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ test("@autoInjectable injects parameters beyond those specified manually", () =>
class FooBar {}
@autoInjectable()
class Foo {
constructor(public myFooBar: FooBar, public myBar?: Bar) {}
constructor(
public myFooBar: FooBar,
public myBar?: Bar
) {}
}

const myFooBar = new FooBar();
Expand Down
6 changes: 4 additions & 2 deletions src/__tests__/child-container.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/* eslint-disable @typescript-eslint/interface-name-prefix, @typescript-eslint/no-empty-interface */

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

afterEach(() => {
globalContainer.reset();
});

test("child container resolves even when parent doesn't have registration", () => {
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface IFoo {}
class Foo implements IFoo {}

Expand All @@ -19,6 +18,7 @@ test("child container resolves even when parent doesn't have registration", () =
});

test("child container resolves using parent's registration when child container doesn't have registration", () => {
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface IFoo {}
class Foo implements IFoo {}

Expand All @@ -31,6 +31,7 @@ test("child container resolves using parent's registration when child container
});

test("child container resolves all even when parent doesn't have registration", () => {
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface IFoo {}
class Foo implements IFoo {}

Expand All @@ -45,6 +46,7 @@ test("child container resolves all even when parent doesn't have registration",
});

test("child container resolves all using parent's registration when child container doesn't have registration", () => {
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface IFoo {}
class Foo implements IFoo {}

Expand Down
1 change: 1 addition & 0 deletions src/__tests__/disposable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe("Disposable", () => {

it("returns false when dispose method takes too many args", () => {
const specialDisposable = {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
dispose(_: any) {}
};

Expand Down
5 changes: 4 additions & 1 deletion src/__tests__/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ test("Error message composition", () => {

@injectable()
class A {
constructor(public d: Ok, public b: B) {}
constructor(
public d: Ok,
public b: B
) {}
}

expect(() => {
Expand Down
10 changes: 6 additions & 4 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 Expand Up @@ -558,7 +556,11 @@ test("dependencies of an @singleton can be resolved", () => {
test("passes through the given params", () => {
@injectable()
class MyViewModel {
constructor(public a: any, public b: any, public c: any) {}
constructor(
public a: any,
public b: any,
public c: any
) {}
}

const a = {};
Expand Down Expand Up @@ -936,7 +938,7 @@ describe("dispose", () => {
class Baz implements Disposable {
disposed = false;
async dispose(): Promise<void> {
return new Promise(resolve => {
return new Promise((resolve) => {
process.nextTick(() => {
this.disposed = true;
resolve();
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
5 changes: 4 additions & 1 deletion src/__tests__/scoped.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ describe("Scoped registrations", () => {

@injectable()
class A {
constructor(public b: B, public c: C) {}
constructor(
public b: B,
public c: C
) {}
}

globalContainer.register(
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
4 changes: 2 additions & 2 deletions src/decorators/injectable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import {instance as globalContainer} from "../dependency-container";
function injectable<T>(options?: {
token?: InjectionToken<T> | InjectionToken<T>[];
}): (target: constructor<T>) => void {
return function(target: constructor<T>): void {
return function (target: constructor<T>): void {
typeInfo.set(target, getParamInfo(target));

if (options && options.token) {
if (!Array.isArray(options.token)) {
globalContainer.register(options.token, target);
} else {
options.token.forEach(token => {
options.token.forEach((token) => {
globalContainer.register(token, 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
Loading