From 279d29ea798b9e6df537a97d5644901befa68a0b Mon Sep 17 00:00:00 2001 From: Kristiyan Tachev Date: Thu, 7 Mar 2024 16:38:57 +0200 Subject: [PATCH] fix(di): removed initialization of dependencies of type providers aka classes before initialization all services are lazy loaded --- packages/component/package.json | 3 ++- packages/components/package.json | 3 ++- packages/custom-attributes/package.json | 3 ++- packages/decorators/package.json | 3 ++- packages/di/src/module/module.spec.ts | 4 ++-- packages/di/src/module/module.ts | 7 +------ packages/experiments/package.json | 3 ++- packages/graphql/package.json | 3 ++- packages/hooks/package.json | 3 ++- packages/modifiers/package.json | 3 ++- packages/operators/package.json | 3 ++- packages/renderer/package.json | 3 ++- packages/schematics/package.json | 3 ++- 13 files changed, 25 insertions(+), 19 deletions(-) diff --git a/packages/component/package.json b/packages/component/package.json index 9c5c132..1d020e3 100644 --- a/packages/component/package.json +++ b/packages/component/package.json @@ -7,6 +7,7 @@ "patch": "npm run build && npm version patch && npm publish --update-readme --access public && npm run delete-dist", "delete-dist": "rm -rf dist", "clean": "git clean -dxf", + "test": "echo 'missing tests'", "lint": "npx eslint . --ext .ts", "lint-fix": "npx eslint . --fix --ext .ts", "build": "rm -rf dist && tsc" @@ -32,4 +33,4 @@ "types": "./dist/index.d.ts", "module": "./dist/index.js", "typings": "./dist/index.d.ts" -} +} \ No newline at end of file diff --git a/packages/components/package.json b/packages/components/package.json index 409ab73..c0e4f80 100644 --- a/packages/components/package.json +++ b/packages/components/package.json @@ -6,6 +6,7 @@ "start": "npx parcel ./examples/index.html --out-dir build/examples", "patch": "npm run build && npm version patch && npm publish --update-readme --access public && npm run delete-dist", "delete-dist": "rm -rf dist", + "test": "echo 'missing tests'", "clean": "git clean -dxf", "lint": "npx eslint . --ext .ts", "lint-fix": "npx eslint . --fix --ext .ts", @@ -30,4 +31,4 @@ "types": "./dist/index.d.ts", "module": "./dist/index.js", "typings": "./dist/index.d.ts" -} +} \ No newline at end of file diff --git a/packages/custom-attributes/package.json b/packages/custom-attributes/package.json index a66e2af..36f8001 100644 --- a/packages/custom-attributes/package.json +++ b/packages/custom-attributes/package.json @@ -6,6 +6,7 @@ "start": "npx parcel ./examples/index.html --out-dir build/examples", "patch": "npm run build && npm version patch && npm publish --update-readme --access public && npm run delete-dist", "delete-dist": "rm -rf dist", + "test": "echo 'missing tests'", "clean": "git clean -dxf", "lint": "npx eslint . --ext .ts", "lint-fix": "npx eslint . --fix --ext .ts", @@ -26,4 +27,4 @@ "types": "./dist/index.d.ts", "module": "./dist/index.js", "typings": "./dist/index.d.ts" -} +} \ No newline at end of file diff --git a/packages/decorators/package.json b/packages/decorators/package.json index 346f644..da120f4 100644 --- a/packages/decorators/package.json +++ b/packages/decorators/package.json @@ -7,6 +7,7 @@ "patch": "npm run build && npm version patch && npm publish --update-readme --access public && npm run delete-dist", "delete-dist": "rm -rf dist", "clean": "git clean -dxf", + "test": "echo 'missing tests'", "lint": "npx eslint . --ext .ts", "lint-fix": "npx eslint . --fix --ext .ts", "build": "rm -rf dist && npx npx tsc" @@ -26,4 +27,4 @@ "types": "./dist/index.d.ts", "module": "./dist/index.js", "typings": "./dist/index.d.ts" -} +} \ No newline at end of file diff --git a/packages/di/src/module/module.spec.ts b/packages/di/src/module/module.spec.ts index d2733d0..7b07d56 100644 --- a/packages/di/src/module/module.spec.ts +++ b/packages/di/src/module/module.spec.ts @@ -65,7 +65,7 @@ describe('[Module]: tests', () => { expect(test1.one).toBe(1); }); - it('Should automatically create new instance', async () => { + it('Should not inject provider when defined in module (lazy loading of providers feature)', async () => { @Injectable() class Test1 {} @@ -75,7 +75,7 @@ describe('[Module]: tests', () => { class MyModule {} await Bootstrap(MyModule); - expect(has(Test1)).toBeTruthy(); + expect(has(Test1)).toBeFalsy(); }); it('Should pass custom providers', async () => { diff --git a/packages/di/src/module/module.ts b/packages/di/src/module/module.ts index c8c8794..cd930ec 100644 --- a/packages/di/src/module/module.ts +++ b/packages/di/src/module/module.ts @@ -42,15 +42,10 @@ export const Module = ( const providers = (entries.providers || []) as WithProviders[]; const factories = filterNonNull(providers).filter(v => !!v.useFactory); - const services = filterNonNull(providers).filter(v => !v.useFactory); - + for (const entry of factories) { ProvidersMetadata.set(entry, entry); } - - for (const entry of services) { - set(entry); - } for (const entry of filterNonNull( (entries.bootstrap || []) as ObjectUnion[] diff --git a/packages/experiments/package.json b/packages/experiments/package.json index 4802cf7..5eea239 100644 --- a/packages/experiments/package.json +++ b/packages/experiments/package.json @@ -7,6 +7,7 @@ "patch": "npm run build && npm version patch && npm publish --update-readme --access public && npm run delete-dist", "delete-dist": "rm -rf dist", "clean": "git clean -dxf", + "test": "echo 'missing tests'", "lint": "npx eslint . --ext .ts", "lint-fix": "npx eslint . --fix --ext .ts", "build": "rm -rf dist && tsc" @@ -29,4 +30,4 @@ "types": "./dist/index.d.ts", "module": "./dist/index.js", "typings": "./dist/index.d.ts" -} +} \ No newline at end of file diff --git a/packages/graphql/package.json b/packages/graphql/package.json index 9016405..b62cb98 100644 --- a/packages/graphql/package.json +++ b/packages/graphql/package.json @@ -8,6 +8,7 @@ "delete-dist": "rm -rf dist", "clean": "git clean -dxf", "lint": "npx eslint . --ext .ts", + "test": "echo 'missing tests'", "lint-fix": "npx eslint . --fix --ext .ts", "build": "cp ./libs/types ../../node_modules/@apollo/client/link/core/types.d.ts && rm -rf dist && tsc" }, @@ -34,4 +35,4 @@ "types": "./dist/index.d.ts", "module": "./dist/index.js", "typings": "./dist/index.d.ts" -} +} \ No newline at end of file diff --git a/packages/hooks/package.json b/packages/hooks/package.json index ccaab39..2572ddb 100644 --- a/packages/hooks/package.json +++ b/packages/hooks/package.json @@ -7,6 +7,7 @@ "patch": "npm run build && npm version patch && npm publish --update-readme --access public && npm run delete-dist", "delete-dist": "rm -rf dist", "clean": "git clean -dxf", + "test": "echo 'missing tests'", "lint": "npx eslint . --ext .ts", "lint-fix": "npx eslint . --fix --ext .ts", "build": "rm -rf dist && tsc" @@ -28,4 +29,4 @@ "types": "./dist/index.d.ts", "module": "./dist/index.js", "typings": "./dist/index.d.ts" -} +} \ No newline at end of file diff --git a/packages/modifiers/package.json b/packages/modifiers/package.json index b7ed7a9..8c601ba 100644 --- a/packages/modifiers/package.json +++ b/packages/modifiers/package.json @@ -7,6 +7,7 @@ "patch": "npm run build && npm version patch && npm publish --update-readme --access public && npm run delete-dist", "delete-dist": "rm -rf dist", "clean": "git clean -dxf", + "test": "echo 'missing tests'", "lint": "npx eslint . --ext .ts", "lint-fix": "npx eslint . --fix --ext .ts", "build": "rm -rf dist && npx tsc" @@ -28,4 +29,4 @@ "types": "./dist/index.d.ts", "module": "./dist/index.js", "typings": "./dist/index.d.ts" -} +} \ No newline at end of file diff --git a/packages/operators/package.json b/packages/operators/package.json index 9c7b4b2..93e1732 100644 --- a/packages/operators/package.json +++ b/packages/operators/package.json @@ -9,6 +9,7 @@ "clean": "git clean -dxf", "lint": "npx eslint . --ext .ts", "lint-fix": "npx eslint . --fix --ext .ts", + "test": "echo 'missing tests'", "build": "rm -rf dist && tsc" }, "repository": { @@ -29,4 +30,4 @@ "types": "./dist/index.d.ts", "module": "./dist/index.js", "typings": "./dist/index.d.ts" -} +} \ No newline at end of file diff --git a/packages/renderer/package.json b/packages/renderer/package.json index baa4a7a..a869d65 100644 --- a/packages/renderer/package.json +++ b/packages/renderer/package.json @@ -6,6 +6,7 @@ "patch": "npm run build && npm version patch && npm publish --update-readme --access public && npm run delete-dist", "delete-dist": "rm -rf dist", "clean": "git clean -dxf", + "test": "echo 'missing tests'", "lint": "npx eslint . --ext .ts", "lint-fix": "npx eslint . --fix --ext .ts", "build": "rm -rf dist && tsc" @@ -30,4 +31,4 @@ "types": "./dist/index.d.ts", "module": "./dist/index.js", "typings": "./dist/index.d.ts" -} +} \ No newline at end of file diff --git a/packages/schematics/package.json b/packages/schematics/package.json index 83d8d61..c19f829 100644 --- a/packages/schematics/package.json +++ b/packages/schematics/package.json @@ -8,6 +8,7 @@ "delete-dist": "rm -rf dist", "clean": "git clean -dxf", "lint": "echo LINT", + "test": "echo 'missing tests'", "lint-fix": "echo LINT-FIX", "lint-old": "npx eslint . --ext .ts || true", "lint-fix-old": "npx eslint . --fix --ext .ts", @@ -34,4 +35,4 @@ "module": "./dist/index.js", "typings": "./dist/index.d.ts", "schematics": "./collection.json" -} +} \ No newline at end of file