Skip to content

Commit

Permalink
refactor(core): Replace typedi with our custom DI package (no-changelog)
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy committed Dec 28, 2024
1 parent 870f864 commit 7680449
Show file tree
Hide file tree
Showing 412 changed files with 927 additions and 449 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
"ws": ">=8.17.1"
},
"patchedDependencies": {
"[email protected]": "patches/[email protected]",
"[email protected]": "patches/[email protected]",
"[email protected]": "patches/[email protected]",
"@types/[email protected]": "patches/@[email protected]",
Expand Down
4 changes: 2 additions & 2 deletions packages/@n8n/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"dist/**/*"
],
"dependencies": {
"reflect-metadata": "0.2.2",
"typedi": "catalog:"
"@n8n/di": "workspace:*",
"reflect-metadata": "0.2.2"
}
}
7 changes: 4 additions & 3 deletions packages/@n8n/config/src/decorators.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'reflect-metadata';
import { Container, Service } from '@n8n/di';
import { readFileSync } from 'fs';
import { Container, Service } from 'typedi';

// eslint-disable-next-line @typescript-eslint/ban-types
type Class = Function;
Expand All @@ -24,6 +24,7 @@ const readEnv = (envName: string) => {
return undefined;
};

// @ts-expect-error xyzy
export const Config: ClassDecorator = (ConfigClass: Class) => {
const factory = function () {
const config = new (ConfigClass as new () => Record<PropertyKey, unknown>)();
Expand All @@ -35,7 +36,7 @@ export const Config: ClassDecorator = (ConfigClass: Class) => {

for (const [key, { type, envName }] of classMetadata) {
if (typeof type === 'function' && globalMetadata.has(type)) {
config[key] = Container.get(type);
config[key] = Container.get(type as Constructable);
} else if (envName) {
const value = readEnv(envName);
if (value === undefined) continue;
Expand Down Expand Up @@ -64,7 +65,7 @@ export const Config: ClassDecorator = (ConfigClass: Class) => {
}
return config;
};
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
return Service({ factory })(ConfigClass);
};

Expand Down
2 changes: 1 addition & 1 deletion packages/@n8n/config/test/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Container } from '@n8n/di';
import fs from 'fs';
import { mock } from 'jest-mock-extended';
import { Container } from 'typedi';

import { GlobalConfig } from '../src/index';

Expand Down
2 changes: 1 addition & 1 deletion packages/@n8n/config/test/decorators.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Container } from 'typedi';
import { Container } from '@n8n/di';

import { Config, Env } from '../src/decorators';

Expand Down
3 changes: 2 additions & 1 deletion packages/@n8n/config/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"baseUrl": "src",
"tsBuildInfoFile": "dist/typecheck.tsbuildinfo"
},
"include": ["src/**/*.ts", "test/**/*.ts"]
"include": ["src/**/*.ts", "test/**/*.ts"],
"references": [{ "path": "../di/tsconfig.build.json" }]
}
7 changes: 7 additions & 0 deletions packages/@n8n/di/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const sharedOptions = require('@n8n_io/eslint-config/shared');

/** @type {import('@types/eslint').ESLint.ConfigData} */
module.exports = {
extends: ['@n8n_io/eslint-config/base'],
...sharedOptions(__dirname),
};
1 change: 1 addition & 0 deletions packages/@n8n/di/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## @n8n/di
2 changes: 2 additions & 0 deletions packages/@n8n/di/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/** @type {import('jest').Config} */
module.exports = require('../../../jest.config');
26 changes: 26 additions & 0 deletions packages/@n8n/di/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@n8n/di",
"version": "0.1.0",
"scripts": {
"clean": "rimraf dist .turbo",
"dev": "pnpm watch",
"typecheck": "tsc --noEmit",
"build": "tsc -p tsconfig.build.json",
"format": "biome format --write .",
"format:check": "biome ci .",
"lint": "eslint .",
"lintfix": "eslint . --fix",
"watch": "tsc -p tsconfig.build.json --watch",
"test": "jest",
"test:dev": "jest --watch"
},
"main": "dist/di.js",
"module": "src/di.ts",
"types": "dist/di.d.ts",
"files": [
"dist/**/*"
],
"peerDependencies": {
"reflect-metadata": "*"
}
}
Loading

0 comments on commit 7680449

Please sign in to comment.