diff --git a/docs/docs/snippets/middlewares/global-middleware-configuration.ts b/docs/docs/snippets/middlewares/global-middleware-configuration.ts index f5136ead3c9..a5ece319d99 100644 --- a/docs/docs/snippets/middlewares/global-middleware-configuration.ts +++ b/docs/docs/snippets/middlewares/global-middleware-configuration.ts @@ -9,7 +9,7 @@ export class Server { @Inject() app: PlatformApplication; - $beforeRoutesInits() { + $beforeRoutesInit() { this.app.use(GlobalAcceptMimeMiddleware); } diff --git a/lerna.json b/lerna.json index f20f219c831..67b3e1ab8c2 100644 --- a/lerna.json +++ b/lerna.json @@ -14,9 +14,7 @@ "version": "7.30.3", "command": { "bootstrap": { - "npmClientArgs": [ - "--no-package-lock" - ] + "npmClientArgs": ["--no-package-lock"] } } } diff --git a/packages/core/package.json b/packages/core/package.json index 300af7f1c3b..d23ce305e74 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -34,4 +34,4 @@ "eslint": "^8.12.0" }, "peerDependencies": {} -} \ No newline at end of file +} diff --git a/packages/core/src/utils/proxyDelegation.ts b/packages/core/src/utils/proxyDelegation.ts index 21ce5bbafc6..b81db233453 100644 --- a/packages/core/src/utils/proxyDelegation.ts +++ b/packages/core/src/utils/proxyDelegation.ts @@ -1,4 +1,5 @@ import {uniq} from "./uniq"; + /** * @ignore */ @@ -15,6 +16,7 @@ export type ProxyDelegationSetter = (target: T, property: PropertyKey, * @ignore */ export type ProxyDelegationOwnKeys = (target: T) => (string | symbol)[]; + /** * @ignore */ diff --git a/packages/di/.barrelsby.json b/packages/di/.barrelsby.json new file mode 100644 index 00000000000..022ce249c14 --- /dev/null +++ b/packages/di/.barrelsby.json @@ -0,0 +1,5 @@ +{ + "directory": ["./src/common", "./src/node"], + "exclude": ["__mock__", "__mocks__", ".spec.ts"], + "delete": true +} diff --git a/packages/di/jest.config.js b/packages/di/jest.config.js index 1a8032cc794..9f4237c4d92 100644 --- a/packages/di/jest.config.js +++ b/packages/di/jest.config.js @@ -5,10 +5,10 @@ module.exports = { ...require("@tsed/jest-config"), coverageThreshold: { global: { - statements: 98.62, - branches: 96.51, - lines: 98.62, - functions: 98.72 + statements: 98.81, + branches: 96.71, + lines: 98.81, + functions: 98.32 } } }; diff --git a/packages/di/package.json b/packages/di/package.json index 2b416be6981..507b2ea0fa6 100644 --- a/packages/di/package.json +++ b/packages/di/package.json @@ -4,22 +4,25 @@ "description": "DI module for Ts.ED Framework", "private": false, "source": "./src/index.ts", - "main": "./lib/cjs/index.js", - "module": "./lib/esm/index.js", + "main": "lib/cjs/index.js", + "module": "lib/esm/index.js", "typings": "./lib/types/index.d.ts", + "browser": "./lib/browser/di.umd.min.js", "exports": { "types": "./lib/types/index.d.ts", + "browser": "./lib/browser/di.umd.min.js", "import": "./lib/esm/index.js", "require": "./lib/cjs/index.js", "default": "./lib/esm/index.js" }, "scripts": { - "build": "yarn barrels && yarn build:ts", - "barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\"", + "build": "yarn barrels && yarn build:ts && yarn run build:browser", + "build:browser": "webpack", + "barrels": "yarn barrelsby --config .barrelsby.json", "test": "cross-env NODE_ENV=test yarn jest --max-workers=2 && jest-coverage-thresholds-bumper", "build:ts": "tsc --build tsconfig.json && tsc --build tsconfig.esm.json", - "lint": "eslint '**/*.{ts,js}'", - "lint:fix": "eslint '**/*.{ts,js}' --fix" + "lint": "node_modules/.bin/eslint '**/*.{ts,js}'", + "lint:fix": "node_modules/.bin/eslint '**/*.{ts,js}' --fix" }, "dependencies": { "tslib": "2.5.0" @@ -48,4 +51,4 @@ "optional": false } } -} \ No newline at end of file +} diff --git a/packages/di/src/constants/constants.ts b/packages/di/src/common/constants/constants.ts similarity index 100% rename from packages/di/src/constants/constants.ts rename to packages/di/src/common/constants/constants.ts diff --git a/packages/di/src/decorators/__mock__/lazy.import.module.ts b/packages/di/src/common/decorators/__mock__/lazy.import.module.ts similarity index 100% rename from packages/di/src/decorators/__mock__/lazy.import.module.ts rename to packages/di/src/common/decorators/__mock__/lazy.import.module.ts diff --git a/packages/di/src/decorators/__mock__/lazy.module.ts b/packages/di/src/common/decorators/__mock__/lazy.module.ts similarity index 100% rename from packages/di/src/decorators/__mock__/lazy.module.ts rename to packages/di/src/common/decorators/__mock__/lazy.module.ts diff --git a/packages/di/src/decorators/__mock__/lazy.nodefault.module.ts b/packages/di/src/common/decorators/__mock__/lazy.nodefault.module.ts similarity index 100% rename from packages/di/src/decorators/__mock__/lazy.nodefault.module.ts rename to packages/di/src/common/decorators/__mock__/lazy.nodefault.module.ts diff --git a/packages/di/src/decorators/configuration.spec.ts b/packages/di/src/common/decorators/configuration.spec.ts similarity index 100% rename from packages/di/src/decorators/configuration.spec.ts rename to packages/di/src/common/decorators/configuration.spec.ts diff --git a/packages/di/src/decorators/configuration.ts b/packages/di/src/common/decorators/configuration.ts similarity index 94% rename from packages/di/src/decorators/configuration.ts rename to packages/di/src/common/decorators/configuration.ts index 1933732652c..2fea2c185bc 100644 --- a/packages/di/src/decorators/configuration.ts +++ b/packages/di/src/common/decorators/configuration.ts @@ -1,5 +1,5 @@ import {DecoratorParameters, decoratorTypeOf, DecoratorTypes, StoreSet} from "@tsed/core"; -import {Inject} from "../decorators/inject"; +import {Inject} from "./inject"; import {DIConfiguration} from "../services/DIConfiguration"; /** diff --git a/packages/di/src/decorators/constant.spec.ts b/packages/di/src/common/decorators/constant.spec.ts similarity index 100% rename from packages/di/src/decorators/constant.spec.ts rename to packages/di/src/common/decorators/constant.spec.ts diff --git a/packages/di/src/decorators/constant.ts b/packages/di/src/common/decorators/constant.ts similarity index 100% rename from packages/di/src/decorators/constant.ts rename to packages/di/src/common/decorators/constant.ts diff --git a/packages/di/src/decorators/controller.spec.ts b/packages/di/src/common/decorators/controller.spec.ts similarity index 100% rename from packages/di/src/decorators/controller.spec.ts rename to packages/di/src/common/decorators/controller.spec.ts diff --git a/packages/di/src/decorators/controller.ts b/packages/di/src/common/decorators/controller.ts similarity index 100% rename from packages/di/src/decorators/controller.ts rename to packages/di/src/common/decorators/controller.ts diff --git a/packages/di/src/decorators/inject.spec.ts b/packages/di/src/common/decorators/inject.spec.ts similarity index 100% rename from packages/di/src/decorators/inject.spec.ts rename to packages/di/src/common/decorators/inject.spec.ts diff --git a/packages/di/src/decorators/inject.ts b/packages/di/src/common/decorators/inject.ts similarity index 86% rename from packages/di/src/decorators/inject.ts rename to packages/di/src/common/decorators/inject.ts index ab93d35e854..54fc9f09f68 100644 --- a/packages/di/src/decorators/inject.ts +++ b/packages/di/src/common/decorators/inject.ts @@ -3,7 +3,6 @@ import {DI_PARAM_OPTIONS, INJECTABLE_PROP} from "../constants/constants"; import {InvalidPropertyTokenError} from "../errors/InvalidPropertyTokenError"; import type {InjectablePropertyOptions} from "../interfaces/InjectableProperties"; import {TokenProvider} from "../interfaces/TokenProvider"; -import {getContext} from "../utils/asyncHookContext"; export function injectProperty(target: any, propertyKey: string, options: Partial) { Store.from(target).merge(INJECTABLE_PROP, { @@ -104,27 +103,3 @@ export function Inject(token?: TokenProvider | (() => TokenProvider), onGet = (b } }; } - -/** - * Inject a context like PlatformContext or any BaseContext. - * - * ```typescript - * @Injectable() - * export class MyService { - * @InjectContext() - * ctx?: Context; - * } - * ``` - * - * @returns {Function} - * @decorator - */ -export function InjectContext(): PropertyDecorator { - return (target: any, propertyKey: string): any | void => { - injectProperty(target, propertyKey, { - resolver() { - return () => getContext(); - } - }); - }; -} diff --git a/packages/di/src/decorators/injectable.spec.ts b/packages/di/src/common/decorators/injectable.spec.ts similarity index 95% rename from packages/di/src/decorators/injectable.spec.ts rename to packages/di/src/common/decorators/injectable.spec.ts index af260e32492..f3654d0cb04 100644 --- a/packages/di/src/decorators/injectable.spec.ts +++ b/packages/di/src/common/decorators/injectable.spec.ts @@ -1,4 +1,4 @@ -import {Injectable} from "../decorators/injectable"; +import {Injectable} from "./injectable"; import {GlobalProviders} from "../registries/GlobalProviders"; import * as ProviderRegistry from "../registries/ProviderRegistry"; diff --git a/packages/di/src/decorators/injectable.ts b/packages/di/src/common/decorators/injectable.ts similarity index 100% rename from packages/di/src/decorators/injectable.ts rename to packages/di/src/common/decorators/injectable.ts diff --git a/packages/di/src/decorators/intercept.spec.ts b/packages/di/src/common/decorators/intercept.spec.ts similarity index 100% rename from packages/di/src/decorators/intercept.spec.ts rename to packages/di/src/common/decorators/intercept.spec.ts diff --git a/packages/di/src/decorators/intercept.ts b/packages/di/src/common/decorators/intercept.ts similarity index 100% rename from packages/di/src/decorators/intercept.ts rename to packages/di/src/common/decorators/intercept.ts diff --git a/packages/di/src/decorators/interceptor.ts b/packages/di/src/common/decorators/interceptor.ts similarity index 100% rename from packages/di/src/decorators/interceptor.ts rename to packages/di/src/common/decorators/interceptor.ts diff --git a/packages/di/src/decorators/lazyInject.spec.ts b/packages/di/src/common/decorators/lazyInject.spec.ts similarity index 100% rename from packages/di/src/decorators/lazyInject.spec.ts rename to packages/di/src/common/decorators/lazyInject.spec.ts diff --git a/packages/di/src/decorators/lazyInject.ts b/packages/di/src/common/decorators/lazyInject.ts similarity index 100% rename from packages/di/src/decorators/lazyInject.ts rename to packages/di/src/common/decorators/lazyInject.ts diff --git a/packages/di/src/decorators/module.ts b/packages/di/src/common/decorators/module.ts similarity index 100% rename from packages/di/src/decorators/module.ts rename to packages/di/src/common/decorators/module.ts diff --git a/packages/di/src/decorators/opts.ts b/packages/di/src/common/decorators/opts.ts similarity index 100% rename from packages/di/src/decorators/opts.ts rename to packages/di/src/common/decorators/opts.ts diff --git a/packages/di/src/decorators/overrideProvider.spec.ts b/packages/di/src/common/decorators/overrideProvider.spec.ts similarity index 100% rename from packages/di/src/decorators/overrideProvider.spec.ts rename to packages/di/src/common/decorators/overrideProvider.spec.ts diff --git a/packages/di/src/decorators/overrideProvider.ts b/packages/di/src/common/decorators/overrideProvider.ts similarity index 100% rename from packages/di/src/decorators/overrideProvider.ts rename to packages/di/src/common/decorators/overrideProvider.ts diff --git a/packages/di/src/decorators/scope.spec.ts b/packages/di/src/common/decorators/scope.spec.ts similarity index 100% rename from packages/di/src/decorators/scope.spec.ts rename to packages/di/src/common/decorators/scope.spec.ts diff --git a/packages/di/src/decorators/scope.ts b/packages/di/src/common/decorators/scope.ts similarity index 100% rename from packages/di/src/decorators/scope.ts rename to packages/di/src/common/decorators/scope.ts diff --git a/packages/di/src/decorators/service.ts b/packages/di/src/common/decorators/service.ts similarity index 100% rename from packages/di/src/decorators/service.ts rename to packages/di/src/common/decorators/service.ts diff --git a/packages/di/src/decorators/useOpts.spec.ts b/packages/di/src/common/decorators/useOpts.spec.ts similarity index 98% rename from packages/di/src/decorators/useOpts.spec.ts rename to packages/di/src/common/decorators/useOpts.spec.ts index 7056121f355..d6a491315be 100644 --- a/packages/di/src/decorators/useOpts.spec.ts +++ b/packages/di/src/common/decorators/useOpts.spec.ts @@ -1,6 +1,6 @@ import {descriptorOf} from "@tsed/core"; +import {DITest} from "../../node/index"; import {ProviderScope} from "../domain/ProviderScope"; -import {DITest} from "../services/DITest"; import {Inject} from "./inject"; import {Injectable} from "./injectable"; import {Opts} from "./opts"; diff --git a/packages/di/src/decorators/useOpts.ts b/packages/di/src/common/decorators/useOpts.ts similarity index 100% rename from packages/di/src/decorators/useOpts.ts rename to packages/di/src/common/decorators/useOpts.ts diff --git a/packages/di/src/decorators/value.spec.ts b/packages/di/src/common/decorators/value.spec.ts similarity index 100% rename from packages/di/src/decorators/value.spec.ts rename to packages/di/src/common/decorators/value.spec.ts diff --git a/packages/di/src/decorators/value.ts b/packages/di/src/common/decorators/value.ts similarity index 100% rename from packages/di/src/decorators/value.ts rename to packages/di/src/common/decorators/value.ts diff --git a/packages/di/src/domain/Container.spec.ts b/packages/di/src/common/domain/Container.spec.ts similarity index 100% rename from packages/di/src/domain/Container.spec.ts rename to packages/di/src/common/domain/Container.spec.ts diff --git a/packages/di/src/domain/Container.ts b/packages/di/src/common/domain/Container.ts similarity index 100% rename from packages/di/src/domain/Container.ts rename to packages/di/src/common/domain/Container.ts diff --git a/packages/di/src/domain/ControllerProvider.spec.ts b/packages/di/src/common/domain/ControllerProvider.spec.ts similarity index 100% rename from packages/di/src/domain/ControllerProvider.spec.ts rename to packages/di/src/common/domain/ControllerProvider.spec.ts diff --git a/packages/di/src/domain/ControllerProvider.ts b/packages/di/src/common/domain/ControllerProvider.ts similarity index 100% rename from packages/di/src/domain/ControllerProvider.ts rename to packages/di/src/common/domain/ControllerProvider.ts diff --git a/packages/di/src/domain/InjectablePropertyType.ts b/packages/di/src/common/domain/InjectablePropertyType.ts similarity index 100% rename from packages/di/src/domain/InjectablePropertyType.ts rename to packages/di/src/common/domain/InjectablePropertyType.ts diff --git a/packages/di/src/domain/LocalsContainer.spec.ts b/packages/di/src/common/domain/LocalsContainer.spec.ts similarity index 100% rename from packages/di/src/domain/LocalsContainer.spec.ts rename to packages/di/src/common/domain/LocalsContainer.spec.ts diff --git a/packages/di/src/domain/LocalsContainer.ts b/packages/di/src/common/domain/LocalsContainer.ts similarity index 100% rename from packages/di/src/domain/LocalsContainer.ts rename to packages/di/src/common/domain/LocalsContainer.ts diff --git a/packages/di/src/domain/Provider.spec.ts b/packages/di/src/common/domain/Provider.spec.ts similarity index 100% rename from packages/di/src/domain/Provider.spec.ts rename to packages/di/src/common/domain/Provider.spec.ts diff --git a/packages/di/src/domain/Provider.ts b/packages/di/src/common/domain/Provider.ts similarity index 100% rename from packages/di/src/domain/Provider.ts rename to packages/di/src/common/domain/Provider.ts diff --git a/packages/di/src/domain/ProviderScope.ts b/packages/di/src/common/domain/ProviderScope.ts similarity index 100% rename from packages/di/src/domain/ProviderScope.ts rename to packages/di/src/common/domain/ProviderScope.ts diff --git a/packages/di/src/domain/ProviderType.ts b/packages/di/src/common/domain/ProviderType.ts similarity index 100% rename from packages/di/src/domain/ProviderType.ts rename to packages/di/src/common/domain/ProviderType.ts diff --git a/packages/di/src/errors/InjectionError.spec.ts b/packages/di/src/common/errors/InjectionError.spec.ts similarity index 100% rename from packages/di/src/errors/InjectionError.spec.ts rename to packages/di/src/common/errors/InjectionError.spec.ts diff --git a/packages/di/src/errors/InjectionError.ts b/packages/di/src/common/errors/InjectionError.ts similarity index 100% rename from packages/di/src/errors/InjectionError.ts rename to packages/di/src/common/errors/InjectionError.ts diff --git a/packages/di/src/errors/InvalidPropertyTokenError.ts b/packages/di/src/common/errors/InvalidPropertyTokenError.ts similarity index 100% rename from packages/di/src/errors/InvalidPropertyTokenError.ts rename to packages/di/src/common/errors/InvalidPropertyTokenError.ts diff --git a/packages/di/src/errors/UndefinedTokenError.ts b/packages/di/src/common/errors/UndefinedTokenError.ts similarity index 100% rename from packages/di/src/errors/UndefinedTokenError.ts rename to packages/di/src/common/errors/UndefinedTokenError.ts diff --git a/packages/di/src/common/index.ts b/packages/di/src/common/index.ts new file mode 100644 index 00000000000..d692b68f060 --- /dev/null +++ b/packages/di/src/common/index.ts @@ -0,0 +1,54 @@ +/** + * @file Automatically generated by barrelsby. + */ + +export * from "./constants/constants"; +export * from "./decorators/configuration"; +export * from "./decorators/constant"; +export * from "./decorators/controller"; +export * from "./decorators/inject"; +export * from "./decorators/injectable"; +export * from "./decorators/intercept"; +export * from "./decorators/interceptor"; +export * from "./decorators/lazyInject"; +export * from "./decorators/module"; +export * from "./decorators/opts"; +export * from "./decorators/overrideProvider"; +export * from "./decorators/scope"; +export * from "./decorators/service"; +export * from "./decorators/useOpts"; +export * from "./decorators/value"; +export * from "./domain/Container"; +export * from "./domain/ControllerProvider"; +export * from "./domain/InjectablePropertyType"; +export * from "./domain/LocalsContainer"; +export * from "./domain/Provider"; +export * from "./domain/ProviderScope"; +export * from "./domain/ProviderType"; +export * from "./errors/InjectionError"; +export * from "./errors/InvalidPropertyTokenError"; +export * from "./errors/UndefinedTokenError"; +export * from "./interfaces/DIConfigurationOptions"; +export * from "./interfaces/DILogger"; +export * from "./interfaces/DILoggerOptions"; +export * from "./interfaces/DIResolver"; +export * from "./interfaces/InjectableProperties"; +export * from "./interfaces/InterceptorContext"; +export * from "./interfaces/InterceptorMethods"; +export * from "./interfaces/InvokeOptions"; +export * from "./interfaces/OnDestroy"; +export * from "./interfaces/OnInit"; +export * from "./interfaces/ProviderOpts"; +export * from "./interfaces/RegistrySettings"; +export * from "./interfaces/ResolvedInvokeOptions"; +export * from "./interfaces/TokenProvider"; +export * from "./interfaces/TokenRoute"; +export * from "./registries/GlobalProviders"; +export * from "./registries/ProviderRegistry"; +export * from "./services/DIConfiguration"; +export * from "./services/DILogger"; +export * from "./services/InjectorService"; +export * from "./utils/colors"; +export * from "./utils/createContainer"; +export * from "./utils/getConfiguration"; +export * from "./utils/resolveControllers"; diff --git a/packages/di/src/integration/async-factory.spec.ts b/packages/di/src/common/integration/async-factory.spec.ts similarity index 100% rename from packages/di/src/integration/async-factory.spec.ts rename to packages/di/src/common/integration/async-factory.spec.ts diff --git a/packages/di/src/integration/di.spec.ts b/packages/di/src/common/integration/di.spec.ts similarity index 100% rename from packages/di/src/integration/di.spec.ts rename to packages/di/src/common/integration/di.spec.ts diff --git a/packages/di/src/integration/imports.spec.ts b/packages/di/src/common/integration/imports.spec.ts similarity index 94% rename from packages/di/src/integration/imports.spec.ts rename to packages/di/src/common/integration/imports.spec.ts index 204e4b4eb01..53b206298e6 100644 --- a/packages/di/src/integration/imports.spec.ts +++ b/packages/di/src/common/integration/imports.spec.ts @@ -1,7 +1,7 @@ +import {DITest} from "../../node/index"; import {Inject} from "../decorators/inject"; import {Injectable} from "../decorators/injectable"; import {Module} from "../decorators/module"; -import {DITest} from "../services/DITest"; @Injectable() class MyService { diff --git a/packages/di/src/integration/interceptor.spec.ts b/packages/di/src/common/integration/interceptor.spec.ts similarity index 100% rename from packages/di/src/integration/interceptor.spec.ts rename to packages/di/src/common/integration/interceptor.spec.ts diff --git a/packages/di/src/integration/request.spec.ts b/packages/di/src/common/integration/request.spec.ts similarity index 100% rename from packages/di/src/integration/request.spec.ts rename to packages/di/src/common/integration/request.spec.ts diff --git a/packages/di/src/integration/resolvers.spec.ts b/packages/di/src/common/integration/resolvers.spec.ts similarity index 100% rename from packages/di/src/integration/resolvers.spec.ts rename to packages/di/src/common/integration/resolvers.spec.ts diff --git a/packages/di/src/integration/singleton.spec.ts b/packages/di/src/common/integration/singleton.spec.ts similarity index 100% rename from packages/di/src/integration/singleton.spec.ts rename to packages/di/src/common/integration/singleton.spec.ts diff --git a/packages/di/src/interfaces/DIConfigurationOptions.ts b/packages/di/src/common/interfaces/DIConfigurationOptions.ts similarity index 100% rename from packages/di/src/interfaces/DIConfigurationOptions.ts rename to packages/di/src/common/interfaces/DIConfigurationOptions.ts diff --git a/packages/di/src/interfaces/DILogger.ts b/packages/di/src/common/interfaces/DILogger.ts similarity index 100% rename from packages/di/src/interfaces/DILogger.ts rename to packages/di/src/common/interfaces/DILogger.ts diff --git a/packages/di/src/interfaces/DILoggerOptions.ts b/packages/di/src/common/interfaces/DILoggerOptions.ts similarity index 100% rename from packages/di/src/interfaces/DILoggerOptions.ts rename to packages/di/src/common/interfaces/DILoggerOptions.ts diff --git a/packages/di/src/interfaces/DIResolver.ts b/packages/di/src/common/interfaces/DIResolver.ts similarity index 100% rename from packages/di/src/interfaces/DIResolver.ts rename to packages/di/src/common/interfaces/DIResolver.ts diff --git a/packages/di/src/interfaces/InjectableProperties.ts b/packages/di/src/common/interfaces/InjectableProperties.ts similarity index 100% rename from packages/di/src/interfaces/InjectableProperties.ts rename to packages/di/src/common/interfaces/InjectableProperties.ts diff --git a/packages/di/src/interfaces/InterceptorContext.ts b/packages/di/src/common/interfaces/InterceptorContext.ts similarity index 100% rename from packages/di/src/interfaces/InterceptorContext.ts rename to packages/di/src/common/interfaces/InterceptorContext.ts diff --git a/packages/di/src/interfaces/InterceptorMethods.ts b/packages/di/src/common/interfaces/InterceptorMethods.ts similarity index 100% rename from packages/di/src/interfaces/InterceptorMethods.ts rename to packages/di/src/common/interfaces/InterceptorMethods.ts diff --git a/packages/di/src/interfaces/InvokeOptions.ts b/packages/di/src/common/interfaces/InvokeOptions.ts similarity index 100% rename from packages/di/src/interfaces/InvokeOptions.ts rename to packages/di/src/common/interfaces/InvokeOptions.ts diff --git a/packages/di/src/interfaces/OnDestroy.ts b/packages/di/src/common/interfaces/OnDestroy.ts similarity index 100% rename from packages/di/src/interfaces/OnDestroy.ts rename to packages/di/src/common/interfaces/OnDestroy.ts diff --git a/packages/di/src/interfaces/OnInit.ts b/packages/di/src/common/interfaces/OnInit.ts similarity index 100% rename from packages/di/src/interfaces/OnInit.ts rename to packages/di/src/common/interfaces/OnInit.ts diff --git a/packages/di/src/interfaces/ProviderOpts.ts b/packages/di/src/common/interfaces/ProviderOpts.ts similarity index 100% rename from packages/di/src/interfaces/ProviderOpts.ts rename to packages/di/src/common/interfaces/ProviderOpts.ts diff --git a/packages/di/src/interfaces/RegistrySettings.ts b/packages/di/src/common/interfaces/RegistrySettings.ts similarity index 100% rename from packages/di/src/interfaces/RegistrySettings.ts rename to packages/di/src/common/interfaces/RegistrySettings.ts diff --git a/packages/di/src/interfaces/ResolvedInvokeOptions.ts b/packages/di/src/common/interfaces/ResolvedInvokeOptions.ts similarity index 100% rename from packages/di/src/interfaces/ResolvedInvokeOptions.ts rename to packages/di/src/common/interfaces/ResolvedInvokeOptions.ts diff --git a/packages/di/src/interfaces/TokenProvider.ts b/packages/di/src/common/interfaces/TokenProvider.ts similarity index 100% rename from packages/di/src/interfaces/TokenProvider.ts rename to packages/di/src/common/interfaces/TokenProvider.ts diff --git a/packages/di/src/interfaces/TokenRoute.ts b/packages/di/src/common/interfaces/TokenRoute.ts similarity index 100% rename from packages/di/src/interfaces/TokenRoute.ts rename to packages/di/src/common/interfaces/TokenRoute.ts diff --git a/packages/di/src/registries/GlobalProviders.spec.ts b/packages/di/src/common/registries/GlobalProviders.spec.ts similarity index 100% rename from packages/di/src/registries/GlobalProviders.spec.ts rename to packages/di/src/common/registries/GlobalProviders.spec.ts diff --git a/packages/di/src/registries/GlobalProviders.ts b/packages/di/src/common/registries/GlobalProviders.ts similarity index 96% rename from packages/di/src/registries/GlobalProviders.ts rename to packages/di/src/common/registries/GlobalProviders.ts index b2a6a6aef63..32f19a111e6 100644 --- a/packages/di/src/registries/GlobalProviders.ts +++ b/packages/di/src/common/registries/GlobalProviders.ts @@ -108,13 +108,6 @@ export class GlobalProviderRegistry extends Map { createRegisterFn(type: string) { return (provider: any | ProviderOpts, instance?: any): void => { - // istanbul ignore next - if (!provider.provide) { - provider = { - provide: provider - }; - } - provider = Object.assign({instance}, provider, {type}); this.merge(provider.provide, provider); }; diff --git a/packages/di/src/registries/ProviderRegistry.spec.ts b/packages/di/src/common/registries/ProviderRegistry.spec.ts similarity index 100% rename from packages/di/src/registries/ProviderRegistry.spec.ts rename to packages/di/src/common/registries/ProviderRegistry.spec.ts diff --git a/packages/di/src/registries/ProviderRegistry.ts b/packages/di/src/common/registries/ProviderRegistry.ts similarity index 100% rename from packages/di/src/registries/ProviderRegistry.ts rename to packages/di/src/common/registries/ProviderRegistry.ts diff --git a/packages/di/src/services/DIConfiguration.spec.ts b/packages/di/src/common/services/DIConfiguration.spec.ts similarity index 66% rename from packages/di/src/services/DIConfiguration.spec.ts rename to packages/di/src/common/services/DIConfiguration.spec.ts index 7175d92cfa6..96c27ef3626 100644 --- a/packages/di/src/services/DIConfiguration.spec.ts +++ b/packages/di/src/common/services/DIConfiguration.spec.ts @@ -79,35 +79,11 @@ describe("DIConfiguration", () => { }); }); - describe("proxy", () => { - it("should set and get data", () => { + describe("rootDir()", () => { + it("should replace rootDir", () => { const configuration = new DIConfiguration(); - - configuration.set("test", "test"); - expect(configuration.get("test")).toEqual("test"); - expect("test" in configuration).toEqual(true); - expect(configuration.get("test")).toEqual("test"); - }); - - it("ownKeys", () => { - const configuration = new DIConfiguration(); - configuration.set("test", "test"); - expect(Reflect.ownKeys(configuration)).toEqual(["default", "map", "scopes", "resolvers", "imports", "routes", "logger", "test"]); - }); - - it("defineProperty", () => { - const configuration = new (class extends DIConfiguration {})(); - - expect(Reflect.defineProperty(configuration, "test", {})).toEqual(true); - expect(Reflect.deleteProperty(configuration, "test")).toEqual(false); - }); - - describe("resolve()", () => { - it("should replace rootDir", () => { - const configuration = new DIConfiguration(); - configuration.set("rootDir", "/root"); - expect(configuration.resolve("${rootDir}")).toEqual("/root"); - }); + configuration.set("rootDir", "/root"); + expect(configuration.resolve("${rootDir}")).toEqual("/root"); }); }); }); diff --git a/packages/di/src/services/DIConfiguration.ts b/packages/di/src/common/services/DIConfiguration.ts similarity index 93% rename from packages/di/src/services/DIConfiguration.ts rename to packages/di/src/common/services/DIConfiguration.ts index 2c6f1fb451d..01db425a969 100644 --- a/packages/di/src/services/DIConfiguration.ts +++ b/packages/di/src/common/services/DIConfiguration.ts @@ -1,9 +1,8 @@ -import {classOf, Env, getValue, proxyDelegation, setValue} from "@tsed/core"; +import {Env, getValue, proxyDelegation, setValue} from "@tsed/core"; import type {ProviderScope} from "../domain/ProviderScope"; import type {DILoggerOptions} from "../interfaces/DILoggerOptions"; import type {DIResolver} from "../interfaces/DIResolver"; -import {TokenProviderOpts} from "../interfaces/TokenProvider"; -import type {TokenProvider} from "../interfaces/TokenProvider"; +import type {TokenProvider, TokenProviderOpts} from "../interfaces/TokenProvider"; import type {TokenRoute} from "../interfaces/TokenRoute"; export class DIConfiguration { @@ -120,7 +119,7 @@ export class DIConfiguration { */ set(propertyKey: string | Partial, value?: any): this { if (typeof propertyKey === "string") { - if (propertyKey in this) { + if (Reflect.has(this, propertyKey)) { // @ts-ignore this[propertyKey] = value; } else { @@ -151,6 +150,15 @@ export class DIConfiguration { return this.getRaw(propertyKey, defaultValue); } + /** + * + * @param value + * @returns {any} + */ + resolve(value: any) { + return value.replace("${rootDir}", this.rootDir); + } + protected getRaw(propertyKey: string, defaultValue?: any): any { const value = getValue(this.map, propertyKey); @@ -160,13 +168,4 @@ export class DIConfiguration { return getValue(this.default, propertyKey, defaultValue); } - - /** - * - * @param value - * @returns {any} - */ - resolve(value: any) { - return value.replace("${rootDir}", this.rootDir); - } } diff --git a/packages/di/src/common/services/DILogger.spec.ts b/packages/di/src/common/services/DILogger.spec.ts new file mode 100644 index 00000000000..5cb53a6bfeb --- /dev/null +++ b/packages/di/src/common/services/DILogger.spec.ts @@ -0,0 +1,22 @@ +import {Container, Inject, Injectable, InjectorService, LOGGER} from "../../common/index"; + +describe("DILogger", () => { + it("should inject logger in another service", async () => { + @Injectable() + class MyService { + @Inject(LOGGER) + logger: LOGGER; + } + + const injector = new InjectorService(); + injector.logger = console; + + const container = new Container(); + container.add(MyService); + + await injector.load(container); + const logger = injector.get(MyService).logger; + + expect(logger).toEqual(injector.logger); + }); +}); diff --git a/packages/di/src/services/DILogger.ts b/packages/di/src/common/services/DILogger.ts similarity index 62% rename from packages/di/src/services/DILogger.ts rename to packages/di/src/common/services/DILogger.ts index 1980aa93b05..2331b747e5e 100644 --- a/packages/di/src/services/DILogger.ts +++ b/packages/di/src/common/services/DILogger.ts @@ -1,9 +1,12 @@ -import {Logger} from "@tsed/logger"; +import {DILogger} from "../interfaces/DILogger"; import {registerProvider} from "../registries/ProviderRegistry"; import {InjectorService} from "./InjectorService"; +export const LOGGER = Symbol.for("LOGGER"); +export type LOGGER = DILogger; + registerProvider({ - provide: Logger, + provide: LOGGER, deps: [InjectorService], useFactory(injector: InjectorService) { return injector.logger; diff --git a/packages/di/src/services/InjectorService.spec.ts b/packages/di/src/common/services/InjectorService.spec.ts similarity index 99% rename from packages/di/src/services/InjectorService.spec.ts rename to packages/di/src/common/services/InjectorService.spec.ts index 897d4f12b77..4707d384241 100644 --- a/packages/di/src/services/InjectorService.spec.ts +++ b/packages/di/src/common/services/InjectorService.spec.ts @@ -10,7 +10,7 @@ import {ProviderScope} from "../domain/ProviderScope"; import {ProviderType} from "../domain/ProviderType"; import {GlobalProviders} from "../registries/GlobalProviders"; import {registerProvider} from "../registries/ProviderRegistry"; -import {InjectorService} from "../services/InjectorService"; +import {InjectorService} from "./InjectorService"; class Test { @Inject() diff --git a/packages/di/src/services/InjectorService.ts b/packages/di/src/common/services/InjectorService.ts similarity index 100% rename from packages/di/src/services/InjectorService.ts rename to packages/di/src/common/services/InjectorService.ts diff --git a/packages/di/src/utils/__mock__/Test1.ts b/packages/di/src/common/utils/__mock__/Test1.ts similarity index 100% rename from packages/di/src/utils/__mock__/Test1.ts rename to packages/di/src/common/utils/__mock__/Test1.ts diff --git a/packages/di/src/utils/__mock__/Test2.ts b/packages/di/src/common/utils/__mock__/Test2.ts similarity index 100% rename from packages/di/src/utils/__mock__/Test2.ts rename to packages/di/src/common/utils/__mock__/Test2.ts diff --git a/packages/di/src/utils/__mock__/module1/Module1.ts b/packages/di/src/common/utils/__mock__/module1/Module1.ts similarity index 100% rename from packages/di/src/utils/__mock__/module1/Module1.ts rename to packages/di/src/common/utils/__mock__/module1/Module1.ts diff --git a/packages/di/src/utils/__mock__/module1/controllers/M1Ctrl1.ts b/packages/di/src/common/utils/__mock__/module1/controllers/M1Ctrl1.ts similarity index 100% rename from packages/di/src/utils/__mock__/module1/controllers/M1Ctrl1.ts rename to packages/di/src/common/utils/__mock__/module1/controllers/M1Ctrl1.ts diff --git a/packages/di/src/utils/__mock__/module1/services/M1Service.ts b/packages/di/src/common/utils/__mock__/module1/services/M1Service.ts similarity index 100% rename from packages/di/src/utils/__mock__/module1/services/M1Service.ts rename to packages/di/src/common/utils/__mock__/module1/services/M1Service.ts diff --git a/packages/di/src/utils/__mock__/module1/submodule/SubModule.ts b/packages/di/src/common/utils/__mock__/module1/submodule/SubModule.ts similarity index 100% rename from packages/di/src/utils/__mock__/module1/submodule/SubModule.ts rename to packages/di/src/common/utils/__mock__/module1/submodule/SubModule.ts diff --git a/packages/di/src/utils/__mock__/module1/submodule/SubService.ts b/packages/di/src/common/utils/__mock__/module1/submodule/SubService.ts similarity index 100% rename from packages/di/src/utils/__mock__/module1/submodule/SubService.ts rename to packages/di/src/common/utils/__mock__/module1/submodule/SubService.ts diff --git a/packages/di/src/utils/__mock__/module2/Module2.ts b/packages/di/src/common/utils/__mock__/module2/Module2.ts similarity index 100% rename from packages/di/src/utils/__mock__/module2/Module2.ts rename to packages/di/src/common/utils/__mock__/module2/Module2.ts diff --git a/packages/di/src/utils/__mock__/module2/controllers/M2Ctrl.ts b/packages/di/src/common/utils/__mock__/module2/controllers/M2Ctrl.ts similarity index 100% rename from packages/di/src/utils/__mock__/module2/controllers/M2Ctrl.ts rename to packages/di/src/common/utils/__mock__/module2/controllers/M2Ctrl.ts diff --git a/packages/di/src/utils/colors.spec.ts b/packages/di/src/common/utils/colors.spec.ts similarity index 100% rename from packages/di/src/utils/colors.spec.ts rename to packages/di/src/common/utils/colors.spec.ts diff --git a/packages/di/src/utils/colors.ts b/packages/di/src/common/utils/colors.ts similarity index 100% rename from packages/di/src/utils/colors.ts rename to packages/di/src/common/utils/colors.ts diff --git a/packages/di/src/utils/createContainer.spec.ts b/packages/di/src/common/utils/createContainer.spec.ts similarity index 100% rename from packages/di/src/utils/createContainer.spec.ts rename to packages/di/src/common/utils/createContainer.spec.ts diff --git a/packages/di/src/utils/createContainer.ts b/packages/di/src/common/utils/createContainer.ts similarity index 100% rename from packages/di/src/utils/createContainer.ts rename to packages/di/src/common/utils/createContainer.ts diff --git a/packages/di/src/utils/getConfiguration.spec.ts b/packages/di/src/common/utils/getConfiguration.spec.ts similarity index 100% rename from packages/di/src/utils/getConfiguration.spec.ts rename to packages/di/src/common/utils/getConfiguration.spec.ts diff --git a/packages/di/src/utils/getConfiguration.ts b/packages/di/src/common/utils/getConfiguration.ts similarity index 100% rename from packages/di/src/utils/getConfiguration.ts rename to packages/di/src/common/utils/getConfiguration.ts diff --git a/packages/di/src/utils/resolveControllers.spec.ts b/packages/di/src/common/utils/resolveControllers.spec.ts similarity index 100% rename from packages/di/src/utils/resolveControllers.spec.ts rename to packages/di/src/common/utils/resolveControllers.spec.ts diff --git a/packages/di/src/utils/resolveControllers.ts b/packages/di/src/common/utils/resolveControllers.ts similarity index 100% rename from packages/di/src/utils/resolveControllers.ts rename to packages/di/src/common/utils/resolveControllers.ts diff --git a/packages/di/src/index.ts b/packages/di/src/index.ts index df482d2ee68..4e2b5f5549b 100644 --- a/packages/di/src/index.ts +++ b/packages/di/src/index.ts @@ -1,63 +1,2 @@ -/** - * @file Automatically generated by barrelsby. - */ - -export * from "./constants/constants"; -export * from "./decorators/configuration"; -export * from "./decorators/constant"; -export * from "./decorators/controller"; -export * from "./decorators/inject"; -export * from "./decorators/injectable"; -export * from "./decorators/intercept"; -export * from "./decorators/interceptor"; -export * from "./decorators/lazyInject"; -export * from "./decorators/module"; -export * from "./decorators/opts"; -export * from "./decorators/overrideProvider"; -export * from "./decorators/scope"; -export * from "./decorators/service"; -export * from "./decorators/useOpts"; -export * from "./decorators/value"; -export * from "./domain/Container"; -export * from "./domain/ContextLogger"; -export * from "./domain/ControllerProvider"; -export * from "./domain/DIContext"; -export * from "./domain/InjectablePropertyType"; -export * from "./domain/LocalsContainer"; -export * from "./domain/Provider"; -export * from "./domain/ProviderScope"; -export * from "./domain/ProviderType"; -export * from "./errors/InjectionError"; -export * from "./errors/InvalidPropertyTokenError"; -export * from "./errors/UndefinedTokenError"; -export * from "./interfaces/AlterRunInContext"; -export * from "./interfaces/DIConfigurationOptions"; -export * from "./interfaces/DILogger"; -export * from "./interfaces/DILoggerOptions"; -export * from "./interfaces/DIResolver"; -export * from "./interfaces/InjectableProperties"; -export * from "./interfaces/InterceptorContext"; -export * from "./interfaces/InterceptorMethods"; -export * from "./interfaces/InvokeOptions"; -export * from "./interfaces/OnDestroy"; -export * from "./interfaces/OnInit"; -export * from "./interfaces/ProviderOpts"; -export * from "./interfaces/RegistrySettings"; -export * from "./interfaces/ResolvedInvokeOptions"; -export * from "./interfaces/TokenProvider"; -export * from "./interfaces/TokenRoute"; -export * from "./registries/GlobalProviders"; -export * from "./registries/ProviderRegistry"; -export * from "./services/DIConfiguration"; -export * from "./services/DILogger"; -export * from "./services/DITest"; -export * from "./services/InjectorService"; -export * from "./utils/asyncHookContext"; -export * from "./utils/attachLogger"; -export * from "./utils/colors"; -export * from "./utils/createContainer"; -export * from "./utils/getConfiguration"; -export * from "./utils/resolveControllers"; -export * from "./utils/setLoggerConfiguration"; -export * from "./utils/setLoggerFormat"; -export * from "./utils/setLoggerLevel"; +export * from "./common/index"; +export * from "./node/index"; diff --git a/packages/di/src/node/decorators/injectContext.ts b/packages/di/src/node/decorators/injectContext.ts new file mode 100644 index 00000000000..5118ceed067 --- /dev/null +++ b/packages/di/src/node/decorators/injectContext.ts @@ -0,0 +1,26 @@ +import {injectProperty} from "../../common/index"; +import {getContext} from "../utils/asyncHookContext"; + +/** + * Inject a context like PlatformContext or any BaseContext. + * + * ```typescript + * @Injectable() + * export class MyService { + * @InjectContext() + * ctx?: Context; + * } + * ``` + * + * @returns {Function} + * @decorator + */ +export function InjectContext(): PropertyDecorator { + return (target: any, propertyKey: string): any | void => { + injectProperty(target, propertyKey, { + resolver() { + return () => getContext(); + } + }); + }; +} diff --git a/packages/di/src/domain/ContextLogger.spec.ts b/packages/di/src/node/domain/ContextLogger.spec.ts similarity index 99% rename from packages/di/src/domain/ContextLogger.spec.ts rename to packages/di/src/node/domain/ContextLogger.spec.ts index 5aededd2461..e3a764f55e1 100644 --- a/packages/di/src/domain/ContextLogger.spec.ts +++ b/packages/di/src/node/domain/ContextLogger.spec.ts @@ -1,4 +1,4 @@ -import {InjectorService} from "../services/InjectorService"; +import {InjectorService} from "../../common/index"; import {ContextLogger} from "./ContextLogger"; function getIgnoreLogFixture(ignore: string[], url: string) { diff --git a/packages/di/src/domain/ContextLogger.ts b/packages/di/src/node/domain/ContextLogger.ts similarity index 98% rename from packages/di/src/domain/ContextLogger.ts rename to packages/di/src/node/domain/ContextLogger.ts index 706b722f3f1..b728d3fdba4 100644 --- a/packages/di/src/domain/ContextLogger.ts +++ b/packages/di/src/node/domain/ContextLogger.ts @@ -1,6 +1,6 @@ +import {DILogger} from "../../common/index"; import {Hooks} from "@tsed/core"; import {levels, LogLevel} from "@tsed/logger"; -import {DILogger} from "../interfaces/DILogger"; export interface ContextLoggerOptions extends Record { id: string; diff --git a/packages/di/src/domain/DIContext.spec.ts b/packages/di/src/node/domain/DIContext.spec.ts similarity index 100% rename from packages/di/src/domain/DIContext.spec.ts rename to packages/di/src/node/domain/DIContext.spec.ts diff --git a/packages/di/src/domain/DIContext.ts b/packages/di/src/node/domain/DIContext.ts similarity index 95% rename from packages/di/src/domain/DIContext.ts rename to packages/di/src/node/domain/DIContext.ts index 156e82eec57..749dcbe31da 100644 --- a/packages/di/src/domain/DIContext.ts +++ b/packages/di/src/node/domain/DIContext.ts @@ -1,7 +1,6 @@ -import {InjectorService} from "../services/InjectorService"; +import {InjectorService, LocalsContainer} from "../../common/index"; import {runInContext} from "../utils/asyncHookContext"; import {ContextLogger, ContextLoggerOptions} from "./ContextLogger"; -import {LocalsContainer} from "./LocalsContainer"; export interface DIContextOptions extends Omit { id: string; diff --git a/packages/di/src/node/index.ts b/packages/di/src/node/index.ts new file mode 100644 index 00000000000..4f7d753589c --- /dev/null +++ b/packages/di/src/node/index.ts @@ -0,0 +1,15 @@ +/** + * @file Automatically generated by barrelsby. + */ + +export * from "./decorators/injectContext"; +export * from "./domain/ContextLogger"; +export * from "./domain/DIContext"; +export * from "./interfaces/AlterRunInContext"; +export * from "./services/DILogger"; +export * from "./services/DITest"; +export * from "./utils/asyncHookContext"; +export * from "./utils/attachLogger"; +export * from "./utils/setLoggerConfiguration"; +export * from "./utils/setLoggerFormat"; +export * from "./utils/setLoggerLevel"; diff --git a/packages/di/src/integration/inject-context.spec.ts b/packages/di/src/node/integration/inject-context.spec.ts similarity index 85% rename from packages/di/src/integration/inject-context.spec.ts rename to packages/di/src/node/integration/inject-context.spec.ts index f768de71514..3b20e306d35 100644 --- a/packages/di/src/integration/inject-context.spec.ts +++ b/packages/di/src/node/integration/inject-context.spec.ts @@ -1,5 +1,5 @@ -import {InjectContext} from "../decorators/inject"; -import {Injectable} from "../decorators/injectable"; +import {Injectable} from "../../common/index"; +import {InjectContext} from "../decorators/injectContext"; import {DIContext} from "../domain/DIContext"; import {DITest} from "../services/DITest"; import {runInContext} from "../utils/asyncHookContext"; diff --git a/packages/di/src/interfaces/AlterRunInContext.ts b/packages/di/src/node/interfaces/AlterRunInContext.ts similarity index 100% rename from packages/di/src/interfaces/AlterRunInContext.ts rename to packages/di/src/node/interfaces/AlterRunInContext.ts diff --git a/packages/di/src/services/DILogger.spec.ts b/packages/di/src/node/services/DILogger.spec.ts similarity index 72% rename from packages/di/src/services/DILogger.spec.ts rename to packages/di/src/node/services/DILogger.spec.ts index 5bcba96bd04..67f91447717 100644 --- a/packages/di/src/services/DILogger.spec.ts +++ b/packages/di/src/node/services/DILogger.spec.ts @@ -1,8 +1,5 @@ import {Logger} from "@tsed/logger"; -import {Inject} from "../decorators/inject"; -import {Injectable} from "../decorators/injectable"; -import {Container} from "../domain/Container"; -import {InjectorService} from "./InjectorService"; +import {Container, Inject, Injectable, InjectorService} from "../../common/index"; describe("DILogger", () => { it("should inject logger in another service", async () => { diff --git a/packages/di/src/node/services/DILogger.ts b/packages/di/src/node/services/DILogger.ts new file mode 100644 index 00000000000..91140bd7f0b --- /dev/null +++ b/packages/di/src/node/services/DILogger.ts @@ -0,0 +1,10 @@ +import {Logger} from "@tsed/logger"; +import {InjectorService, registerProvider} from "../../common/index"; + +registerProvider({ + provide: Logger, + deps: [InjectorService], + useFactory(injector: InjectorService) { + return injector.logger; + } +}); diff --git a/packages/di/src/services/DITest.ts b/packages/di/src/node/services/DITest.ts similarity index 92% rename from packages/di/src/services/DITest.ts rename to packages/di/src/node/services/DITest.ts index 12d39626dc6..bfab5462cd3 100644 --- a/packages/di/src/services/DITest.ts +++ b/packages/di/src/node/services/DITest.ts @@ -1,12 +1,8 @@ import {Env, getValue, setValue} from "@tsed/core"; import {$log} from "@tsed/logger"; +import {createContainer, InjectorService, LocalsContainer, OnInit, TokenProvider, TokenProviderOpts} from "../../common/index"; import {DIContext} from "../domain/DIContext"; -import {LocalsContainer} from "../domain/LocalsContainer"; -import {OnInit} from "../interfaces/OnInit"; -import {TokenProviderOpts, TokenProvider} from "../interfaces/TokenProvider"; -import {createContainer} from "../utils/createContainer"; import {setLoggerConfiguration} from "../utils/setLoggerConfiguration"; -import {InjectorService} from "./InjectorService"; /** * Tool to run test with lightweight DI sandbox. diff --git a/packages/di/src/node/utils/__mock__/Test1.ts b/packages/di/src/node/utils/__mock__/Test1.ts new file mode 100644 index 00000000000..dd5c3e5fe98 --- /dev/null +++ b/packages/di/src/node/utils/__mock__/Test1.ts @@ -0,0 +1,3 @@ +export const value1 = "value"; + +export class Test1 {} diff --git a/packages/di/src/node/utils/__mock__/Test2.ts b/packages/di/src/node/utils/__mock__/Test2.ts new file mode 100644 index 00000000000..84466960d59 --- /dev/null +++ b/packages/di/src/node/utils/__mock__/Test2.ts @@ -0,0 +1,3 @@ +export const value2 = "value"; + +export class Test2 {} diff --git a/packages/di/src/node/utils/__mock__/module1/Module1.ts b/packages/di/src/node/utils/__mock__/module1/Module1.ts new file mode 100644 index 00000000000..013500e3a91 --- /dev/null +++ b/packages/di/src/node/utils/__mock__/module1/Module1.ts @@ -0,0 +1,11 @@ +import {SubModule} from "./submodule/SubModule"; +import {Module} from "../../../decorators/module"; +import {M1Ctrl1} from "./controllers/M1Ctrl1"; + +@Module({ + mount: { + "/m1": [M1Ctrl1] + }, + imports: [SubModule] +}) +export class Module1 {} diff --git a/packages/di/src/node/utils/__mock__/module1/controllers/M1Ctrl1.ts b/packages/di/src/node/utils/__mock__/module1/controllers/M1Ctrl1.ts new file mode 100644 index 00000000000..6f9e798a143 --- /dev/null +++ b/packages/di/src/node/utils/__mock__/module1/controllers/M1Ctrl1.ts @@ -0,0 +1,7 @@ +import {Controller} from "../../../../decorators/controller"; +import {M1Service} from "../services/M1Service"; + +@Controller("/m1") +export class M1Ctrl1 { + constructor(public service: M1Service) {} +} diff --git a/packages/di/src/node/utils/__mock__/module1/services/M1Service.ts b/packages/di/src/node/utils/__mock__/module1/services/M1Service.ts new file mode 100644 index 00000000000..8f6e37ed3fb --- /dev/null +++ b/packages/di/src/node/utils/__mock__/module1/services/M1Service.ts @@ -0,0 +1,7 @@ +import {Injectable} from "../../../../decorators/injectable"; +import {SubService} from "../submodule/SubService"; + +@Injectable() +export class M1Service { + constructor(public subService: SubService) {} +} diff --git a/packages/di/src/node/utils/__mock__/module1/submodule/SubModule.ts b/packages/di/src/node/utils/__mock__/module1/submodule/SubModule.ts new file mode 100644 index 00000000000..ec0d9f93831 --- /dev/null +++ b/packages/di/src/node/utils/__mock__/module1/submodule/SubModule.ts @@ -0,0 +1,7 @@ +import {Module} from "../../../../decorators/module"; +import {SubService} from "./SubService"; + +@Module({ + imports: [SubService] +}) +export class SubModule {} diff --git a/packages/di/src/node/utils/__mock__/module1/submodule/SubService.ts b/packages/di/src/node/utils/__mock__/module1/submodule/SubService.ts new file mode 100644 index 00000000000..8425dc9e7f0 --- /dev/null +++ b/packages/di/src/node/utils/__mock__/module1/submodule/SubService.ts @@ -0,0 +1,4 @@ +import {Injectable} from "../../../../decorators/injectable"; + +@Injectable() +export class SubService {} diff --git a/packages/di/src/node/utils/__mock__/module2/Module2.ts b/packages/di/src/node/utils/__mock__/module2/Module2.ts new file mode 100644 index 00000000000..6b215dace44 --- /dev/null +++ b/packages/di/src/node/utils/__mock__/module2/Module2.ts @@ -0,0 +1,10 @@ +import {Module} from "../../../decorators/module"; +import {M2Ctrl} from "./controllers/M2Ctrl"; + +@Module({ + mount: { + "/mod2": [M2Ctrl] + }, + imports: [] +}) +export class Module2 {} diff --git a/packages/di/src/node/utils/__mock__/module2/controllers/M2Ctrl.ts b/packages/di/src/node/utils/__mock__/module2/controllers/M2Ctrl.ts new file mode 100644 index 00000000000..5b685d77ec5 --- /dev/null +++ b/packages/di/src/node/utils/__mock__/module2/controllers/M2Ctrl.ts @@ -0,0 +1,4 @@ +import {Controller} from "../../../../decorators/controller"; + +@Controller("/m2") +export class M2Ctrl {} diff --git a/packages/di/src/utils/asyncHookContext.spec.ts b/packages/di/src/node/utils/asyncHookContext.spec.ts similarity index 100% rename from packages/di/src/utils/asyncHookContext.spec.ts rename to packages/di/src/node/utils/asyncHookContext.spec.ts diff --git a/packages/di/src/utils/asyncHookContext.ts b/packages/di/src/node/utils/asyncHookContext.ts similarity index 94% rename from packages/di/src/utils/asyncHookContext.ts rename to packages/di/src/node/utils/asyncHookContext.ts index 9fa5c99e2cd..b67c37d8c55 100644 --- a/packages/di/src/utils/asyncHookContext.ts +++ b/packages/di/src/node/utils/asyncHookContext.ts @@ -1,6 +1,6 @@ import {AsyncLocalStorage, AsyncResource} from "async_hooks"; +import {InjectorService} from "../../common/index"; import type {DIContext} from "../domain/DIContext"; -import type {InjectorService} from "../services/InjectorService"; const storage: AsyncLocalStorage<{current: DIContext | undefined}> = new AsyncLocalStorage(); diff --git a/packages/di/src/utils/attachLogger.spec.ts b/packages/di/src/node/utils/attachLogger.spec.ts similarity index 84% rename from packages/di/src/utils/attachLogger.spec.ts rename to packages/di/src/node/utils/attachLogger.spec.ts index bb389c1daf1..f1c0b50917b 100644 --- a/packages/di/src/utils/attachLogger.spec.ts +++ b/packages/di/src/node/utils/attachLogger.spec.ts @@ -1,5 +1,5 @@ import {Logger} from "@tsed/logger"; -import {InjectorService} from "../services/InjectorService"; +import {InjectorService} from "../../common/index"; import {attachLogger} from "./attachLogger"; describe("attachLogger", () => { diff --git a/packages/di/src/node/utils/attachLogger.ts b/packages/di/src/node/utils/attachLogger.ts new file mode 100644 index 00000000000..f374b49d982 --- /dev/null +++ b/packages/di/src/node/utils/attachLogger.ts @@ -0,0 +1,7 @@ +import {DILogger, InjectorService} from "../../common/index"; +import {setLoggerConfiguration} from "./setLoggerConfiguration"; + +export function attachLogger(injector: InjectorService, $log: DILogger) { + injector.logger = $log; + setLoggerConfiguration(injector); +} diff --git a/packages/di/src/utils/setLoggerConfiguration.spec.ts b/packages/di/src/node/utils/setLoggerConfiguration.spec.ts similarity index 95% rename from packages/di/src/utils/setLoggerConfiguration.spec.ts rename to packages/di/src/node/utils/setLoggerConfiguration.spec.ts index 8d18ae09c71..2ca047fd64e 100644 --- a/packages/di/src/utils/setLoggerConfiguration.spec.ts +++ b/packages/di/src/node/utils/setLoggerConfiguration.spec.ts @@ -1,5 +1,5 @@ import {Logger} from "@tsed/logger"; -import {InjectorService} from "../services/InjectorService"; +import {InjectorService} from "../../common/index"; import {setLoggerConfiguration} from "./setLoggerConfiguration"; describe("setLoggerConfiguration", () => { diff --git a/packages/di/src/utils/setLoggerConfiguration.ts b/packages/di/src/node/utils/setLoggerConfiguration.ts similarity index 77% rename from packages/di/src/utils/setLoggerConfiguration.ts rename to packages/di/src/node/utils/setLoggerConfiguration.ts index 555b8d45d0c..08733d4db76 100644 --- a/packages/di/src/utils/setLoggerConfiguration.ts +++ b/packages/di/src/node/utils/setLoggerConfiguration.ts @@ -1,4 +1,4 @@ -import type {InjectorService} from "../services/InjectorService"; +import type {InjectorService} from "../../common/index"; import {setLoggerFormat} from "./setLoggerFormat"; import {setLoggerLevel} from "./setLoggerLevel"; diff --git a/packages/di/src/utils/setLoggerFormat.ts b/packages/di/src/node/utils/setLoggerFormat.ts similarity index 90% rename from packages/di/src/utils/setLoggerFormat.ts rename to packages/di/src/node/utils/setLoggerFormat.ts index 604bd0c13e2..be434ecfdd2 100644 --- a/packages/di/src/utils/setLoggerFormat.ts +++ b/packages/di/src/node/utils/setLoggerFormat.ts @@ -1,4 +1,4 @@ -import type {InjectorService} from "../services/InjectorService"; +import type {InjectorService} from "../../common/index"; /** * @ignore diff --git a/packages/di/src/utils/setLoggerLevel.ts b/packages/di/src/node/utils/setLoggerLevel.ts similarity index 75% rename from packages/di/src/utils/setLoggerLevel.ts rename to packages/di/src/node/utils/setLoggerLevel.ts index b9d7ebde3f3..e197c62b019 100644 --- a/packages/di/src/utils/setLoggerLevel.ts +++ b/packages/di/src/node/utils/setLoggerLevel.ts @@ -1,4 +1,4 @@ -import type {InjectorService} from "../services/InjectorService"; +import type {InjectorService} from "../../common/index"; /** * @ignore diff --git a/packages/di/src/utils/attachLogger.ts b/packages/di/src/utils/attachLogger.ts deleted file mode 100644 index e8da87551b9..00000000000 --- a/packages/di/src/utils/attachLogger.ts +++ /dev/null @@ -1,8 +0,0 @@ -import type {Logger} from "@tsed/logger"; -import {InjectorService} from "../services/InjectorService"; -import {setLoggerConfiguration} from "./setLoggerConfiguration"; - -export function attachLogger(injector: InjectorService, $log: Logger) { - injector.logger = $log; - setLoggerConfiguration(injector); -} diff --git a/packages/di/tsconfig.esm.json b/packages/di/tsconfig.esm.json index d3ff57636c5..bfd3400c530 100644 --- a/packages/di/tsconfig.esm.json +++ b/packages/di/tsconfig.esm.json @@ -1,7 +1,7 @@ { "extends": "@tsed/typescript/tsconfig.node.json", "compilerOptions": { - "baseUrl": ".", + "baseUrl": "./", "module": "ES2020", "rootDir": "src", "outDir": "./lib/esm", @@ -26,6 +26,9 @@ "webpack.config.js" ], "references": [ + { + "path": "../core" + }, { "path": "../core" }, diff --git a/packages/di/tsconfig.json b/packages/di/tsconfig.json index ca187cdb4d5..cc188e5d1ed 100644 --- a/packages/di/tsconfig.json +++ b/packages/di/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "@tsed/typescript/tsconfig.node.json", "compilerOptions": { - "baseUrl": ".", + "baseUrl": "./", "module": "commonjs", "rootDir": "src", "outDir": "./lib/cjs", @@ -26,6 +26,9 @@ "webpack.config.js" ], "references": [ + { + "path": "../core" + }, { "path": "../core" }, diff --git a/packages/di/webpack.config.js b/packages/di/webpack.config.js new file mode 100644 index 00000000000..d08a3b15cbd --- /dev/null +++ b/packages/di/webpack.config.js @@ -0,0 +1,7 @@ +module.exports = require("@tsed/webpack-config").create({ + root: __dirname, + name: "di", + entry: { + main: "./src/common/index.ts" + } +}); diff --git a/packages/engines/package.json b/packages/engines/package.json index a1c3b1dd08e..8d2442ad0ac 100644 --- a/packages/engines/package.json +++ b/packages/engines/package.json @@ -95,4 +95,4 @@ "view" ], "peerDependencies": {} -} \ No newline at end of file +} diff --git a/packages/graphql/apollo/package.json b/packages/graphql/apollo/package.json index 1aebea80447..e36bbd8fca4 100644 --- a/packages/graphql/apollo/package.json +++ b/packages/graphql/apollo/package.json @@ -51,4 +51,4 @@ "apollo-server-core": ">=3.0.0", "graphql": ">15.0.0" } -} \ No newline at end of file +} diff --git a/packages/graphql/typegraphql/package.json b/packages/graphql/typegraphql/package.json index f3bbbfff737..d6f80075740 100644 --- a/packages/graphql/typegraphql/package.json +++ b/packages/graphql/typegraphql/package.json @@ -45,4 +45,4 @@ "graphql": ">=15.0.0", "type-graphql": ">=1.0.0" } -} \ No newline at end of file +} diff --git a/packages/orm/adapters-redis/package.json b/packages/orm/adapters-redis/package.json index 45c42aa738f..625973f3f75 100644 --- a/packages/orm/adapters-redis/package.json +++ b/packages/orm/adapters-redis/package.json @@ -41,4 +41,4 @@ "ioredis-mock": ">=8.2.2", "uuid": "8.3.2" } -} \ No newline at end of file +} diff --git a/packages/orm/adapters/package.json b/packages/orm/adapters/package.json index 027ea143312..d628d67c273 100644 --- a/packages/orm/adapters/package.json +++ b/packages/orm/adapters/package.json @@ -71,4 +71,4 @@ "optional": false } } -} \ No newline at end of file +} diff --git a/packages/orm/ioredis/package.json b/packages/orm/ioredis/package.json index 39c34cd9395..c6a05a9ae60 100644 --- a/packages/orm/ioredis/package.json +++ b/packages/orm/ioredis/package.json @@ -40,4 +40,4 @@ "ioredis": ">=5.2.3", "ioredis-mock": ">=8.2.2" } -} \ No newline at end of file +} diff --git a/packages/orm/mikro-orm/package.json b/packages/orm/mikro-orm/package.json index bda472fc74b..e03e7291672 100644 --- a/packages/orm/mikro-orm/package.json +++ b/packages/orm/mikro-orm/package.json @@ -46,4 +46,4 @@ "@tsed/di": "^7.30.3", "@tsed/logger": ">=6.2.2" } -} \ No newline at end of file +} diff --git a/packages/orm/mongoose/package.json b/packages/orm/mongoose/package.json index 52c9de67cb3..6a860cd633c 100644 --- a/packages/orm/mongoose/package.json +++ b/packages/orm/mongoose/package.json @@ -53,4 +53,4 @@ "@tsed/schema": "^7.30.3", "mongoose": ">=6.0.0" } -} \ No newline at end of file +} diff --git a/packages/orm/objection/package.json b/packages/orm/objection/package.json index 761d270cf37..aec9103dee8 100644 --- a/packages/orm/objection/package.json +++ b/packages/orm/objection/package.json @@ -69,4 +69,4 @@ "optional": false } } -} \ No newline at end of file +} diff --git a/packages/orm/prisma/package.json b/packages/orm/prisma/package.json index dffff33b8e3..9c2e817fca8 100644 --- a/packages/orm/prisma/package.json +++ b/packages/orm/prisma/package.json @@ -65,4 +65,4 @@ "tsed", "prisma" ] -} \ No newline at end of file +} diff --git a/packages/orm/testing-mongoose/package.json b/packages/orm/testing-mongoose/package.json index ecdb294c353..dc0fbd8f5c4 100644 --- a/packages/orm/testing-mongoose/package.json +++ b/packages/orm/testing-mongoose/package.json @@ -38,4 +38,4 @@ "@tsed/mongoose": "^7.30.3", "mongoose": "^6.1.7" } -} \ No newline at end of file +} diff --git a/packages/orm/typeorm/package.json b/packages/orm/typeorm/package.json index 7ac82635374..487a3437ce5 100644 --- a/packages/orm/typeorm/package.json +++ b/packages/orm/typeorm/package.json @@ -41,4 +41,4 @@ "@tsed/schema": "^7.30.3", "typeorm": "^0.2.26" } -} \ No newline at end of file +} diff --git a/packages/perf/package.json b/packages/perf/package.json index 646dd8a5eca..8b521cde753 100644 --- a/packages/perf/package.json +++ b/packages/perf/package.json @@ -30,4 +30,4 @@ "eslint": "^8.12.0" }, "peerDependencies": {} -} \ No newline at end of file +} diff --git a/packages/platform/common/package.json b/packages/platform/common/package.json index 904e362a38a..3e816a8b0a5 100644 --- a/packages/platform/common/package.json +++ b/packages/platform/common/package.json @@ -105,4 +105,4 @@ "optional": false } } -} \ No newline at end of file +} diff --git a/packages/platform/platform-cache/package.json b/packages/platform/platform-cache/package.json index 0ed231877f9..8245f9b51c2 100644 --- a/packages/platform/platform-cache/package.json +++ b/packages/platform/platform-cache/package.json @@ -56,4 +56,4 @@ "optional": false } } -} \ No newline at end of file +} diff --git a/packages/platform/platform-exceptions/package.json b/packages/platform/platform-exceptions/package.json index d81abdc4423..42b867f5f6b 100644 --- a/packages/platform/platform-exceptions/package.json +++ b/packages/platform/platform-exceptions/package.json @@ -53,4 +53,4 @@ "optional": false } } -} \ No newline at end of file +} diff --git a/packages/platform/platform-express/package.json b/packages/platform/platform-express/package.json index 3704de8d46c..450e276acdf 100644 --- a/packages/platform/platform-express/package.json +++ b/packages/platform/platform-express/package.json @@ -124,4 +124,4 @@ "optional": false } } -} \ No newline at end of file +} diff --git a/packages/platform/platform-koa/package.json b/packages/platform/platform-koa/package.json index 44b8ac51cda..43e45ce9d4b 100644 --- a/packages/platform/platform-koa/package.json +++ b/packages/platform/platform-koa/package.json @@ -130,4 +130,4 @@ "optional": false } } -} \ No newline at end of file +} diff --git a/packages/platform/platform-log-middleware/package.json b/packages/platform/platform-log-middleware/package.json index 604df6af1e7..ebd766c07ca 100644 --- a/packages/platform/platform-log-middleware/package.json +++ b/packages/platform/platform-log-middleware/package.json @@ -48,4 +48,4 @@ "optional": false } } -} \ No newline at end of file +} diff --git a/packages/platform/platform-middlewares/package.json b/packages/platform/platform-middlewares/package.json index f6204d5052f..8c3404d0f86 100644 --- a/packages/platform/platform-middlewares/package.json +++ b/packages/platform/platform-middlewares/package.json @@ -48,4 +48,4 @@ "optional": true } } -} \ No newline at end of file +} diff --git a/packages/platform/platform-params/package.json b/packages/platform/platform-params/package.json index 81846f98fed..61e9e8cb9c6 100644 --- a/packages/platform/platform-params/package.json +++ b/packages/platform/platform-params/package.json @@ -58,4 +58,4 @@ "optional": false } } -} \ No newline at end of file +} diff --git a/packages/platform/platform-response-filter/package.json b/packages/platform/platform-response-filter/package.json index 2cb30d19a9d..b6f440bae26 100644 --- a/packages/platform/platform-response-filter/package.json +++ b/packages/platform/platform-response-filter/package.json @@ -58,4 +58,4 @@ "optional": false } } -} \ No newline at end of file +} diff --git a/packages/platform/platform-router/package.json b/packages/platform/platform-router/package.json index a4c7f0bc3fd..db18c761899 100644 --- a/packages/platform/platform-router/package.json +++ b/packages/platform/platform-router/package.json @@ -63,4 +63,4 @@ "optional": false } } -} \ No newline at end of file +} diff --git a/packages/platform/platform-serverless-http/package.json b/packages/platform/platform-serverless-http/package.json index 5590657886e..5d05932ca42 100644 --- a/packages/platform/platform-serverless-http/package.json +++ b/packages/platform/platform-serverless-http/package.json @@ -106,4 +106,4 @@ "optional": false } } -} \ No newline at end of file +} diff --git a/packages/platform/platform-serverless-testing/package.json b/packages/platform/platform-serverless-testing/package.json index cc23fe7e579..214bb27d3f2 100644 --- a/packages/platform/platform-serverless-testing/package.json +++ b/packages/platform/platform-serverless-testing/package.json @@ -78,4 +78,4 @@ "@tsed/openspec": "^7.30.3", "@tsed/schema": "^7.30.3" } -} \ No newline at end of file +} diff --git a/packages/platform/platform-serverless/package.json b/packages/platform/platform-serverless/package.json index 9930b7035dc..7bfeed99fde 100644 --- a/packages/platform/platform-serverless/package.json +++ b/packages/platform/platform-serverless/package.json @@ -58,4 +58,4 @@ "optional": true } } -} \ No newline at end of file +} diff --git a/packages/platform/platform-test-sdk/package.json b/packages/platform/platform-test-sdk/package.json index 1b180c32bf9..b4048582482 100644 --- a/packages/platform/platform-test-sdk/package.json +++ b/packages/platform/platform-test-sdk/package.json @@ -50,4 +50,4 @@ "eslint": "^8.12.0" }, "peerDependencies": {} -} \ No newline at end of file +} diff --git a/packages/platform/platform-views/package.json b/packages/platform/platform-views/package.json index ea9d4ace2d4..eda28e0691e 100644 --- a/packages/platform/platform-views/package.json +++ b/packages/platform/platform-views/package.json @@ -58,4 +58,4 @@ "optional": false } } -} \ No newline at end of file +} diff --git a/packages/security/jwks/package.json b/packages/security/jwks/package.json index a10d47294b4..e1f35561575 100644 --- a/packages/security/jwks/package.json +++ b/packages/security/jwks/package.json @@ -31,4 +31,4 @@ "eslint": "^8.12.0" }, "peerDependencies": {} -} \ No newline at end of file +} diff --git a/packages/security/oidc-provider-plugin-wildcard-redirect-uri/package.json b/packages/security/oidc-provider-plugin-wildcard-redirect-uri/package.json index 993236e44e4..72376bbab1c 100644 --- a/packages/security/oidc-provider-plugin-wildcard-redirect-uri/package.json +++ b/packages/security/oidc-provider-plugin-wildcard-redirect-uri/package.json @@ -57,4 +57,4 @@ "optional": false } } -} \ No newline at end of file +} diff --git a/packages/security/oidc-provider/package.json b/packages/security/oidc-provider/package.json index 702c1d8707b..83e8a81ad39 100644 --- a/packages/security/oidc-provider/package.json +++ b/packages/security/oidc-provider/package.json @@ -86,4 +86,4 @@ "optional": false } } -} \ No newline at end of file +} diff --git a/packages/security/passport/package.json b/packages/security/passport/package.json index 1c936075937..9789798ff1f 100644 --- a/packages/security/passport/package.json +++ b/packages/security/passport/package.json @@ -51,4 +51,4 @@ "optional": false } } -} \ No newline at end of file +} diff --git a/packages/specs/ajv/package.json b/packages/specs/ajv/package.json index c07f38d0e3c..d5c268d09df 100644 --- a/packages/specs/ajv/package.json +++ b/packages/specs/ajv/package.json @@ -57,4 +57,4 @@ "optional": false } } -} \ No newline at end of file +} diff --git a/packages/specs/exceptions/package.json b/packages/specs/exceptions/package.json index 7f6150f694c..0eb5ec119ef 100644 --- a/packages/specs/exceptions/package.json +++ b/packages/specs/exceptions/package.json @@ -35,4 +35,4 @@ "peerDependencies": { "@tsed/core": "^7.30.3" } -} \ No newline at end of file +} diff --git a/packages/specs/json-mapper/package.json b/packages/specs/json-mapper/package.json index deda06c5515..7fb4a36a766 100644 --- a/packages/specs/json-mapper/package.json +++ b/packages/specs/json-mapper/package.json @@ -59,4 +59,4 @@ "optional": false } } -} \ No newline at end of file +} diff --git a/packages/specs/openspec/package.json b/packages/specs/openspec/package.json index d86c4f084ee..7c2168509d8 100644 --- a/packages/specs/openspec/package.json +++ b/packages/specs/openspec/package.json @@ -37,4 +37,4 @@ }, "dependencies": {}, "peerDependencies": {} -} \ No newline at end of file +} diff --git a/packages/specs/schema/package.json b/packages/specs/schema/package.json index 9451ac25656..13b201b38c4 100644 --- a/packages/specs/schema/package.json +++ b/packages/specs/schema/package.json @@ -69,4 +69,4 @@ "optional": false } } -} \ No newline at end of file +} diff --git a/packages/specs/swagger/package.json b/packages/specs/swagger/package.json index c02857d8a38..4a83f8eac15 100644 --- a/packages/specs/swagger/package.json +++ b/packages/specs/swagger/package.json @@ -52,4 +52,4 @@ "optional": false } } -} \ No newline at end of file +} diff --git a/packages/third-parties/agenda/package.json b/packages/third-parties/agenda/package.json index 9302dfc5079..20ec89cca05 100644 --- a/packages/third-parties/agenda/package.json +++ b/packages/third-parties/agenda/package.json @@ -41,4 +41,4 @@ "peerDependencies": { "agenda": "^4.1.3" } -} \ No newline at end of file +} diff --git a/packages/third-parties/components-scan/package.json b/packages/third-parties/components-scan/package.json index a98ed2ee37e..2528aa5d6a4 100644 --- a/packages/third-parties/components-scan/package.json +++ b/packages/third-parties/components-scan/package.json @@ -41,4 +41,4 @@ "optional": false } } -} \ No newline at end of file +} diff --git a/packages/third-parties/event-emitter/package.json b/packages/third-parties/event-emitter/package.json index 0c3cc09fba9..f7ffdaf7066 100644 --- a/packages/third-parties/event-emitter/package.json +++ b/packages/third-parties/event-emitter/package.json @@ -11,14 +11,17 @@ "main": "./lib/cjs/index.js", "module": "./lib/esm/index.js", "typings": "./lib/types/index.d.ts", + "browser": "./lib/browser/event-emitter.umd.min.js", "exports": { "types": "./lib/types/index.d.ts", + "browser": "./lib/browser/event-emitter.umd.min.js", "import": "./lib/esm/index.js", "require": "./lib/cjs/index.js", "default": "./lib/esm/index.js" }, "scripts": { - "build": "yarn barrels && yarn build:ts", + "build": "yarn barrels && yarn build:ts && yarn run build:browser", + "build:browser": "webpack", "barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\" -e \".benchmark.ts\"", "test": "cross-env NODE_ENV=test yarn jest --max-workers=2 && jest-coverage-thresholds-bumper", "build:ts": "tsc --build tsconfig.json && tsc --build tsconfig.esm.json", @@ -41,4 +44,4 @@ "peerDependencies": { "eventemitter2": "^6.4.4" } -} \ No newline at end of file +} diff --git a/packages/third-parties/event-emitter/src/EventEmitterModule.ts b/packages/third-parties/event-emitter/src/EventEmitterModule.ts index 70de2120bd4..9c2e63315b5 100644 --- a/packages/third-parties/event-emitter/src/EventEmitterModule.ts +++ b/packages/third-parties/event-emitter/src/EventEmitterModule.ts @@ -1,16 +1,12 @@ -import {Constant, Inject, InjectorService, Module, Provider} from "@tsed/di"; -import {Logger} from "@tsed/logger"; +import {Constant, Inject, InjectorService, LOGGER, Module, Provider} from "@tsed/di"; import {ListenerFn} from "eventemitter2"; import {EventEmitterStore} from "./interfaces/EventEmitterStore"; import {EventEmitterService} from "./services/EventEmitterFactory"; @Module() export class EventEmitterModule { - @Constant("eventEmitter.disableSummary", false) - private disableSummary: boolean; - - @Inject() - protected logger: Logger; + @Inject(LOGGER) + protected logger: LOGGER; @Inject() protected injector: InjectorService; @@ -18,6 +14,9 @@ export class EventEmitterModule { @Inject() protected eventEmitter: EventEmitterService; + @Constant("eventEmitter.disableSummary", false) + private disableSummary: boolean; + @Constant("eventEmitter.enabled", false) private loadEventEmitter: boolean; diff --git a/packages/third-parties/event-emitter/webpack.config.js b/packages/third-parties/event-emitter/webpack.config.js new file mode 100644 index 00000000000..f9021022a7a --- /dev/null +++ b/packages/third-parties/event-emitter/webpack.config.js @@ -0,0 +1,7 @@ +module.exports = require("@tsed/webpack-config").create({ + root: __dirname, + name: "event-emitter", + entry: { + main: "./src/index.ts" + } +}); diff --git a/packages/third-parties/formio-types/package.json b/packages/third-parties/formio-types/package.json index 9bf628eaa9b..13dbf4392f7 100644 --- a/packages/third-parties/formio-types/package.json +++ b/packages/third-parties/formio-types/package.json @@ -40,4 +40,4 @@ "@tsed/typescript": "7.30.3", "eslint": "^8.12.0" } -} \ No newline at end of file +} diff --git a/packages/third-parties/formio/package.json b/packages/third-parties/formio/package.json index c61b38df2c8..bd24dcbc271 100644 --- a/packages/third-parties/formio/package.json +++ b/packages/third-parties/formio/package.json @@ -62,4 +62,4 @@ "optional": false } } -} \ No newline at end of file +} diff --git a/packages/third-parties/schema-formio/package.json b/packages/third-parties/schema-formio/package.json index 3cd78bfa731..ad42cad8110 100644 --- a/packages/third-parties/schema-formio/package.json +++ b/packages/third-parties/schema-formio/package.json @@ -78,4 +78,4 @@ "optional": false } } -} \ No newline at end of file +} diff --git a/packages/third-parties/socketio-testing/package.json b/packages/third-parties/socketio-testing/package.json index b89492c5152..5d444035e0d 100644 --- a/packages/third-parties/socketio-testing/package.json +++ b/packages/third-parties/socketio-testing/package.json @@ -37,4 +37,4 @@ "@tsed/di": "^7.30.3", "socket.io-client": "^4.0.1" } -} \ No newline at end of file +} diff --git a/packages/third-parties/socketio/package.json b/packages/third-parties/socketio/package.json index 621f6ab1a38..b8abeaa8b12 100644 --- a/packages/third-parties/socketio/package.json +++ b/packages/third-parties/socketio/package.json @@ -70,4 +70,4 @@ "optional": false } } -} \ No newline at end of file +} diff --git a/packages/third-parties/stripe/package.json b/packages/third-parties/stripe/package.json index 11365fe710b..16bb6b30192 100644 --- a/packages/third-parties/stripe/package.json +++ b/packages/third-parties/stripe/package.json @@ -71,4 +71,4 @@ "optional": false } } -} \ No newline at end of file +} diff --git a/packages/third-parties/terminus/package.json b/packages/third-parties/terminus/package.json index 57f90760a64..c514a18c72b 100644 --- a/packages/third-parties/terminus/package.json +++ b/packages/third-parties/terminus/package.json @@ -57,4 +57,4 @@ "optional": false } } -} \ No newline at end of file +} diff --git a/packages/third-parties/vite-ssr-plugin/package.json b/packages/third-parties/vite-ssr-plugin/package.json index 95d1b94bdc7..fe7cf160019 100644 --- a/packages/third-parties/vite-ssr-plugin/package.json +++ b/packages/third-parties/vite-ssr-plugin/package.json @@ -50,4 +50,4 @@ "optional": false } } -} \ No newline at end of file +} diff --git a/packages/utils/normalize-path/package.json b/packages/utils/normalize-path/package.json index f2648253cc1..316eb84a99a 100644 --- a/packages/utils/normalize-path/package.json +++ b/packages/utils/normalize-path/package.json @@ -32,4 +32,4 @@ "eslint": "^8.12.0" }, "peerDependencies": {} -} \ No newline at end of file +} diff --git a/tools/eslint/package.json b/tools/eslint/package.json index f36e9945d1b..96987677db8 100644 --- a/tools/eslint/package.json +++ b/tools/eslint/package.json @@ -12,4 +12,4 @@ "dependencies": {}, "devDependencies": {}, "peerDependencies": {} -} \ No newline at end of file +} diff --git a/tools/github-sponsors/package.json b/tools/github-sponsors/package.json index a0fae633a8f..77fbc22d5f2 100644 --- a/tools/github-sponsors/package.json +++ b/tools/github-sponsors/package.json @@ -14,4 +14,4 @@ }, "dependencies": {}, "peerDependencies": {} -} \ No newline at end of file +} diff --git a/tools/integration/package.json b/tools/integration/package.json index de65f317b44..113d6cdcda6 100644 --- a/tools/integration/package.json +++ b/tools/integration/package.json @@ -22,4 +22,4 @@ }, "dependencies": {}, "peerDependencies": {} -} \ No newline at end of file +} diff --git a/tools/jest/package.json b/tools/jest/package.json index 0484131a3d3..93385eb5262 100644 --- a/tools/jest/package.json +++ b/tools/jest/package.json @@ -7,4 +7,4 @@ "dependencies": {}, "devDependencies": {}, "peerDependencies": {} -} \ No newline at end of file +} diff --git a/tools/mocha/package.json b/tools/mocha/package.json index 0b1b692b487..af0f20056f7 100644 --- a/tools/mocha/package.json +++ b/tools/mocha/package.json @@ -7,4 +7,4 @@ "dependencies": {}, "devDependencies": {}, "peerDependencies": {} -} \ No newline at end of file +} diff --git a/tools/typescript/package.json b/tools/typescript/package.json index 6118f8c57a4..4ad3c2bbd2f 100644 --- a/tools/typescript/package.json +++ b/tools/typescript/package.json @@ -14,4 +14,4 @@ "dependencies": {}, "devDependencies": {}, "peerDependencies": {} -} \ No newline at end of file +} diff --git a/tools/webpack/package.json b/tools/webpack/package.json index 73e21d7f88c..d3beed633de 100644 --- a/tools/webpack/package.json +++ b/tools/webpack/package.json @@ -7,4 +7,4 @@ "dependencies": {}, "devDependencies": {}, "peerDependencies": {} -} \ No newline at end of file +} diff --git a/tools/webpack/webpack.config.js b/tools/webpack/webpack.config.js index 27d1bbf3d73..214f26c5dcf 100644 --- a/tools/webpack/webpack.config.js +++ b/tools/webpack/webpack.config.js @@ -1,11 +1,12 @@ -exports.create = ({root, name, externals = {}, resolve = {}}) => { +exports.create = ({root, name, entry, externals = {}, resolve = {}}) => { return { mode: "production", devtool: "source-map", stats: {warnings: false}, target: "web", entry: { - main: "./src/index.ts" + main: "./src/index.ts", + ...entry }, output: { path: `${root}/lib/browser/`,