diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..1261f4a --- /dev/null +++ b/.eslintignore @@ -0,0 +1,3 @@ +node_modules +lib +coverage diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..333a758 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,25 @@ +{ + "extends": [ + "@artus/eslint-config-artus/typescript", + "plugin:import/recommended", + "plugin:import/typescript" + ], + "parserOptions": { + "project": "./tsconfig.json" + }, + "rules": { + "@typescript-eslint/ban-types": "off", + "no-unused-vars": "off", + "@typescript-eslint/no-unused-vars": ["error", { "varsIgnorePattern": "^_", "argsIgnorePattern": "^_" }] + }, + "overrides": [ + { + "files": [ + "test/**/*" + ], + "rules": { + "@typescript-eslint/no-var-requires": "off" + } + } + ] +} \ No newline at end of file diff --git a/package.json b/package.json index 657baf2..a9eb320 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,9 @@ "scripts": { "build": "tsc -p ./tsconfig.build.json", "test": "jest --detectOpenHandles", - "ci": "npm run test" + "ci": "npm run lint && npm run test", + "lint:fix": "eslint . --ext .ts --fix", + "lint": "eslint . --ext .ts" }, "repository": { "type": "git", @@ -42,6 +44,7 @@ }, "homepage": "https://github.com/artusjs/core#readme", "devDependencies": { + "@artus/eslint-config-artus": "0.0.1", "@artus/tsconfig": "0.0.1", "@types/jest": "^27.4.1", "@types/js-yaml": "^4.0.5", @@ -50,6 +53,8 @@ "axios": "^0.26.1", "babel-jest": "^27.5.1", "egg-ci": "^1.19.0", + "eslint": "^8.19.0", + "eslint-plugin-import": "^2.26.0", "jest": "^27.5.1", "koa": "^2.13.4", "reflect-metadata": "^0.1.13", diff --git a/src/application.ts b/src/application.ts index 7df5f30..de6013e 100644 --- a/src/application.ts +++ b/src/application.ts @@ -15,7 +15,7 @@ export class ArtusApplication implements Application { protected container: Container; protected lifecycleManager: LifecycleManager; protected loaderFactory: LoaderFactory; - protected defaultClazzLoaded: boolean = false; + protected defaultClazzLoaded = false; constructor(opts?: ApplicationInitOptions) { this.container = new Container(opts?.containerName ?? ArtusInjectEnum.DefaultContainerName); @@ -97,7 +97,7 @@ export class ArtusApplication implements Application { this.lifecycleManager.registerHook(hookName, hookFn); } - async close(exit: boolean = false) { + async close(exit = false) { try { await this.lifecycleManager.emitHook('beforeClose'); } catch (e) { @@ -116,5 +116,3 @@ export class ArtusApplication implements Application { return this.exceptionHandler.create(code); } } - -export { Application }; diff --git a/src/configuration/decorator.ts b/src/configuration/decorator.ts index 6f51576..f717236 100644 --- a/src/configuration/decorator.ts +++ b/src/configuration/decorator.ts @@ -7,4 +7,4 @@ export function DefineConfigHandle(handleName?: string): PropertyDecorator { } Reflect.defineMetadata(`${HOOK_CONFIG_HANDLE}${handleName}`, propertyKey, target.constructor); }; -}; \ No newline at end of file +} \ No newline at end of file diff --git a/src/configuration/index.ts b/src/configuration/index.ts index b4a6727..5c8eeea 100644 --- a/src/configuration/index.ts +++ b/src/configuration/index.ts @@ -15,7 +15,7 @@ export default class ConfigurationHandler { static getEnvFromFilename(filename: string): string { let [_, env, extname] = filename.split('.'); if (!extname) { - env = ARTUS_DEFAULT_CONFIG_ENV.DEFAULT; + env = ARTUS_DEFAULT_CONFIG_ENV.DEFAULT; } return env; } diff --git a/src/constant.ts b/src/constant.ts index 59a92bd..6e31ca8 100644 --- a/src/constant.ts +++ b/src/constant.ts @@ -22,7 +22,7 @@ export enum ARTUS_DEFAULT_CONFIG_ENV { DEV = 'development', PROD = 'production', DEFAULT = 'default', -}; +} export const HOOK_NAME_META_PREFIX = 'hookName:'; export const CONSTRUCTOR_PARAMS = 'constructor:params'; @@ -40,7 +40,7 @@ export const DEFAULT_EXCLUDES = [ '*.d.ts', 'jest.config.*', 'meta.*', - 'LICENSE' + 'LICENSE', ]; export const FRAMEWORK_PATTERN = 'framework.*'; diff --git a/src/decorator.ts b/src/decorator.ts index 77cf655..33bed41 100644 --- a/src/decorator.ts +++ b/src/decorator.ts @@ -12,7 +12,7 @@ export function LifecycleHookUnit(): ClassDecorator { // Ready to remove? Reflect.defineMetadata(HOOK_FILE_LOADER, { loader: 'lifecycle-hook-unit' }, target); }; -}; +} export function LifecycleHook(hookName?: string): PropertyDecorator { return (target: any, propertyKey: string | symbol) => { @@ -21,7 +21,7 @@ export function LifecycleHook(hookName?: string): PropertyDecorator { } Reflect.defineMetadata(`${HOOK_NAME_META_PREFIX}${propertyKey}`, hookName ?? propertyKey, target.constructor); }; -}; +} const WithConstructorParams = (tag: string): ParameterDecorator => { return (target: any, _propertyKey: string | symbol, parameterIndex: number) => { @@ -33,7 +33,7 @@ const WithConstructorParams = (tag: string): ParameterDecorator => { Reflect.defineMetadata(CONSTRUCTOR_PARAMS, paramsMd, target); // for constructor } }; -} +}; export function WithApplication(): ParameterDecorator { return WithConstructorParams(CONSTRUCTOR_PARAMS_APP); diff --git a/src/exception/error.ts b/src/exception/error.ts index 7bffa9b..f58dc3e 100644 --- a/src/exception/error.ts +++ b/src/exception/error.ts @@ -12,22 +12,22 @@ export const ErrorCodeUtils = { return exceptionItem.desc; } return exceptionItem.desc[currentLocale]; - } + }, }; export class ArtusStdError extends Error { - name: string = 'ArtusStdError'; + name = 'ArtusStdError'; private _code: string; private _codeMap: Map; constructor (code: string, codeMap: Map) { - super(`[${code}] This is Artus standard error, Please check on https://github.com/artusjs/error-code`); - this._code = code; - this._codeMap = codeMap + super(`[${code}] This is Artus standard error, Please check on https://github.com/artusjs/error-code`); + this._code = code; + this._codeMap = codeMap; } get code(): string { - return this._code; + return this._code; } get desc(): string { diff --git a/src/exception/index.ts b/src/exception/index.ts index cbe398c..aad7804 100644 --- a/src/exception/index.ts +++ b/src/exception/index.ts @@ -3,5 +3,5 @@ import ExceptionHandler from './handler'; export * from './error'; export { - ExceptionHandler + ExceptionHandler, }; diff --git a/src/framework/handler.ts b/src/framework/handler.ts index 7c3237e..59537e3 100644 --- a/src/framework/handler.ts +++ b/src/framework/handler.ts @@ -1,6 +1,6 @@ import path from 'path'; import ConfigurationHandler, { ConfigObject } from '../configuration'; -import { ManifestItem } from '../types'; +import { ManifestItem } from '../loader/types'; export interface FrameworkConfig { path?: string, @@ -27,7 +27,7 @@ export class FrameworkHandler { } try { - let baseFrameworkPath = config.path ?? path.dirname(require.resolve(config.package ?? '', { paths: [root] })); + const baseFrameworkPath = config.path ?? path.dirname(require.resolve(config.package ?? '', { paths: [root] })); return baseFrameworkPath; } catch (err) { throw new Error(`load framework faild: ${err}, framework config: ${JSON.stringify(config)}`); diff --git a/src/index.ts b/src/index.ts index 39856b6..f79718f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,12 +2,9 @@ export { Inject, - Injectable + Injectable, } from '@artus/injection'; -export { - ArtusInjectEnum -} from './constant'; export * from './loader'; export * from './logger'; export * from './lifecycle'; @@ -24,7 +21,3 @@ export { ConfigurationHandler }; import Trigger from './trigger'; export { Trigger }; - -export type { - Manifest -} from './loader/types'; diff --git a/src/lifecycle/index.ts b/src/lifecycle/index.ts index f149f9c..c3b7e48 100644 --- a/src/lifecycle/index.ts +++ b/src/lifecycle/index.ts @@ -4,7 +4,7 @@ import { CONSTRUCTOR_PARAMS, CONSTRUCTOR_PARAMS_APP, CONSTRUCTOR_PARAMS_CONTAINER, - HOOK_NAME_META_PREFIX + HOOK_NAME_META_PREFIX, } from '../constant'; export type HookFunction = (hookProps : { @@ -20,7 +20,7 @@ export class LifecycleManager { 'didLoad', // 文件加载完成 'willReady', // 插件启动完毕 'didReady', // 应用启动完成 - 'beforeClose' // 应用即将关闭 + 'beforeClose', // 应用即将关闭 ]; hookFnMap: Map = new Map(); private app: Application; @@ -32,7 +32,7 @@ export class LifecycleManager { } insertHook(existHookName: string, newHookName: string) { - const startIndex = this.hookList.findIndex((val) => val === existHookName); + const startIndex = this.hookList.findIndex(val => val === existHookName); this.hookList.splice(startIndex, 0, newHookName); } @@ -45,7 +45,7 @@ export class LifecycleManager { this.hookFnMap.get(hookName)?.push(hookFn); } else { this.hookFnMap.set(hookName, [ - hookFn + hookFn, ]); } } @@ -55,9 +55,9 @@ export class LifecycleManager { const constructorParams = Reflect.getMetadata(CONSTRUCTOR_PARAMS, extClazz) ?? []; const paramsMap = { [CONSTRUCTOR_PARAMS_APP]: this.app, - [CONSTRUCTOR_PARAMS_CONTAINER]: this.container + [CONSTRUCTOR_PARAMS_CONTAINER]: this.container, }; - const extClazzInstance = new extClazz(...constructorParams.map((param) => paramsMap[param])); + const extClazzInstance = new extClazz(...constructorParams.map(param => paramsMap[param])); for (const fnMetaKey of fnMetaKeys) { if (typeof fnMetaKey !== 'string' || !fnMetaKey.startsWith(HOOK_NAME_META_PREFIX)) { continue; @@ -80,8 +80,8 @@ export class LifecycleManager { await hookFn({ app: this.app, lifecycleManager: this, - payload + payload, }); } } -}; +} diff --git a/src/loader/factory.ts b/src/loader/factory.ts index f7bb047..ab99c6d 100644 --- a/src/loader/factory.ts +++ b/src/loader/factory.ts @@ -46,28 +46,28 @@ export class LoaderFactory { after: () => { this.container.set({ id: ArtusInjectEnum.Config, - value: this.configurationHandler.getMergedConfig() + value: this.configurationHandler.getMergedConfig(), }); this.lifecycleManager.emitHook('configDidLoad'); - } + }, }, 'framework-config': { after: () => this.container.set({ id: ArtusInjectEnum.Frameworks, - value: this.configurationHandler.getFrameworkConfig() - }) + value: this.configurationHandler.getFrameworkConfig(), + }), }, 'package-json': { after: () => this.container.set({ id: ArtusInjectEnum.Packages, - value: this.configurationHandler.getPackages() - }) - } + value: this.configurationHandler.getPackages(), + }), + }, }, root); } async loadItemList(itemList: ManifestItem[] = [], hookMap?: Record, root?: string): Promise { - let prevLoader: string = ''; + let prevLoader = ''; for (const item of itemList) { item.path = root ? path.join(root, item.path) : item.path; const curLoader = item.loader ?? DEFAULT_LOADER; diff --git a/src/loader/impl/config.ts b/src/loader/impl/config.ts index 9532d61..2f18f0c 100644 --- a/src/loader/impl/config.ts +++ b/src/loader/impl/config.ts @@ -37,8 +37,8 @@ class ConfigLoader implements Loader { } protected static isConfigDir(opts: LoaderFindOptions): boolean { - const { configDir, baseDir, root } = opts; - return path.join(baseDir, configDir) === root; + const { configDir, baseDir, root } = opts; + return path.join(baseDir, configDir) === root; } async load(item: ManifestItem) { @@ -46,7 +46,7 @@ class ConfigLoader implements Loader { let configObj = await this.loadConfigFile(item); if (namespace) { configObj = { - [namespace]: configObj + [namespace]: configObj, }; } this.configurationHandler.setConfig(env, configObj); @@ -59,12 +59,12 @@ class ConfigLoader implements Loader { env = ARTUS_DEFAULT_CONFIG_ENV.DEFAULT; } const meta: ConfigFileMeta = { - env + env, }; if (namespace !== 'config') { meta.namespace = namespace; } - return meta + return meta; } protected async loadConfigFile(item: ManifestItem): Promise> { diff --git a/src/loader/impl/framework_config.ts b/src/loader/impl/framework_config.ts index 9c84706..8d6bf30 100644 --- a/src/loader/impl/framework_config.ts +++ b/src/loader/impl/framework_config.ts @@ -7,10 +7,6 @@ import { isMatch } from '../../utils'; @DefineLoader('framework-config') class FrameworkConfigLoader extends ConfigLoader implements Loader { - constructor(container) { - super(container); - } - static async is(opts: LoaderFindOptions): Promise { if (this.isConfigDir(opts)) { return isMatch(opts.filename, FRAMEWORK_PATTERN); diff --git a/src/loader/impl/module.ts b/src/loader/impl/module.ts index 6cefa38..b9d1a12 100644 --- a/src/loader/impl/module.ts +++ b/src/loader/impl/module.ts @@ -15,7 +15,7 @@ class ModuleLoader implements Loader { const moduleClazz = await compatibleRequire(item.path); const opts: Partial = { path: item.path, - type: moduleClazz + type: moduleClazz, }; if (item.id) { opts.id = item.id; diff --git a/src/loader/impl/plugin_config.ts b/src/loader/impl/plugin_config.ts index 9afceeb..63464ef 100644 --- a/src/loader/impl/plugin_config.ts +++ b/src/loader/impl/plugin_config.ts @@ -18,7 +18,7 @@ class PluginConfigLoader extends ConfigLoader implements Loader { async load(item: ManifestItem) { const { env } = await this.getConfigFileMeta(item); - let configObj = await this.loadConfigFile(item); + const configObj = await this.loadConfigFile(item); for (const pluginName of Object.keys(configObj)) { const pluginConfigItem: PluginConfigItem = configObj[pluginName]; if (pluginConfigItem.package) { @@ -34,7 +34,7 @@ class PluginConfigLoader extends ConfigLoader implements Loader { } } this.configurationHandler.setConfig(env, { - plugin: configObj + plugin: configObj, }); } } diff --git a/src/loader/impl/plugin_meta.ts b/src/loader/impl/plugin_meta.ts index f1aaa77..9002281 100644 --- a/src/loader/impl/plugin_meta.ts +++ b/src/loader/impl/plugin_meta.ts @@ -21,7 +21,7 @@ class PluginMetaLoader implements Loader { const pluginMeta: PluginMetadata = await loadMetaFile(item); this.container.set({ id: `pluginMeta_${pluginMeta.name}`, - value: pluginMeta + value: pluginMeta, }); } } diff --git a/src/loader/index.ts b/src/loader/index.ts index 2b4820f..c1bbf80 100644 --- a/src/loader/index.ts +++ b/src/loader/index.ts @@ -1,6 +1,4 @@ import { LoaderFactory } from './factory'; -import { Manifest, ManifestItem, Loader, LoaderConstructor } from './types'; -import { DefineLoader } from './decorator'; import BaseLoader from './base'; // Import inner impls @@ -11,17 +9,10 @@ for (const [_, impl] of Object.entries(LoaderImpls)) { LoaderFactory.register(impl); } -export { - // Decorator - DefineLoader, +export * from './types'; +export { // Class LoaderFactory, BaseLoader, - - // Typings - Loader, - LoaderConstructor, - Manifest, - ManifestItem, }; diff --git a/src/loader/types.ts b/src/loader/types.ts index 2f8531f..0c0f5e2 100644 --- a/src/loader/types.ts +++ b/src/loader/types.ts @@ -30,17 +30,17 @@ interface LoaderFindResult { interface LoaderHookUnit { before?: Function, after?: Function, -}; +} interface LoaderConstructor { new(container: Container): Loader; is?(opts: LoaderFindOptions): Promise; onFind?(opts: LoaderFindOptions): Promise; -}; +} interface Loader { state?: any; load(item: ManifestItem): Promise; -}; +} export { Manifest, diff --git a/src/logger/base.ts b/src/logger/base.ts index 78bc7cf..e8b29f8 100644 --- a/src/logger/base.ts +++ b/src/logger/base.ts @@ -11,7 +11,7 @@ export class BaseLogger implements Logger { protected get loggerOpts(): LoggerOptions { return this.appConfig?.logger ?? {}; } - + protected checkLoggerLevel(level: LoggerLevel) { const targetLevel = this.loggerOpts.level ?? LoggerLevel.INFO; if (LOGGER_LEVEL_MAP[level] < LOGGER_LEVEL_MAP[targetLevel]) { diff --git a/src/logger/decorator.ts b/src/logger/decorator.ts index 890a28d..fe86dac 100644 --- a/src/logger/decorator.ts +++ b/src/logger/decorator.ts @@ -5,6 +5,6 @@ export const DefineLogger = (injectableOpts: InjectableOption = {}): ClassDecora return Injectable({ id: ArtusInjectEnum.Logger, scope: ScopeEnum.SINGLETON, - ...injectableOpts + ...injectableOpts, }); }; diff --git a/src/logger/impl.ts b/src/logger/impl.ts index 73e46cb..c10b939 100644 --- a/src/logger/impl.ts +++ b/src/logger/impl.ts @@ -5,10 +5,6 @@ import { LogOptions } from './types'; @DefineLogger() export default class ArtusLogger extends BaseLogger { - constructor() { - super(); - } - public trace(message: string, ...args: any[]) { if (!this.checkLoggerLevel(LoggerLevel.TRACE)) { return; @@ -22,7 +18,7 @@ export default class ArtusLogger extends BaseLogger { } console.debug(message, ...args); } - + public info(message: string, ...args: any[]) { if (!this.checkLoggerLevel(LoggerLevel.INFO)) { return; @@ -54,7 +50,7 @@ export default class ArtusLogger extends BaseLogger { public log({ level, message, - splat = [] + splat = [], }: LogOptions) { if (message instanceof Error) { if (level === LoggerLevel.ERROR) { diff --git a/src/logger/level.ts b/src/logger/level.ts index b6e769b..b714978 100644 --- a/src/logger/level.ts +++ b/src/logger/level.ts @@ -5,7 +5,7 @@ export enum LoggerLevel { WARN = 'warn', ERROR = 'error', FATAL = 'fatal', -}; +} export const LOGGER_LEVEL_MAP = { [LoggerLevel.TRACE]: 0, diff --git a/src/plugin/base.ts b/src/plugin/base.ts index 132df0f..be5469c 100644 --- a/src/plugin/base.ts +++ b/src/plugin/base.ts @@ -9,9 +9,9 @@ export class BasePlugin implements Plugin { public name: string; public enable: boolean; - public importPath: string = ''; + public importPath = ''; public metadata: Partial = {}; - public metaFilePath: string = ''; + public metaFilePath = ''; constructor(name: string, configItem: PluginConfigItem) { this.name = name; @@ -31,6 +31,7 @@ export class BasePlugin implements Plugin { } } + // eslint-disable-next-line @typescript-eslint/no-empty-function async init() { } checkDepExisted(pluginMap: PluginMap) { @@ -39,7 +40,7 @@ export class BasePlugin implements Plugin { if (!instance || !instance.enable) { if (optional) { // TODO: use artus logger instead - console.warn(`Plugin ${this.name} need have optional dependence: ${pluginName}.`) + console.warn(`Plugin ${this.name} need have optional dependence: ${pluginName}.`); } else { throw new Error(`Plugin ${this.name} need have dependence: ${pluginName}.`); } diff --git a/src/plugin/factory.ts b/src/plugin/factory.ts index 82c8d3f..7a49c45 100644 --- a/src/plugin/factory.ts +++ b/src/plugin/factory.ts @@ -26,10 +26,10 @@ export class PluginFactory { } const pluginSortResult: string[] = topologicalSort(pluginInstanceMap, pluginDepEdgeList); if (pluginSortResult.length !== pluginInstanceMap.size) { - const diffPlugin = [...pluginInstanceMap.keys()].filter((name) => !pluginSortResult.includes(name)); + const diffPlugin = [...pluginInstanceMap.keys()].filter(name => !pluginSortResult.includes(name)); throw new Error(`There is a cycle in the dependencies, wrong plugin is ${diffPlugin.join(',')}.`); } - return pluginSortResult.map((name) => pluginInstanceMap.get(name)!); + return pluginSortResult.map(name => pluginInstanceMap.get(name)!); } static filterDuplicatePlugins(plugins: BasePlugin[]): BasePlugin[] { diff --git a/src/scanner/scan.ts b/src/scanner/scan.ts index 762c5df..97f6e7d 100644 --- a/src/scanner/scan.ts +++ b/src/scanner/scan.ts @@ -49,7 +49,7 @@ export class Scanner { throw new Error(`Loader ${loaderClazz.name} must have a @DefineLoader() decorator.`); } return [loaderName, []]; - }) + }), ); } @@ -88,7 +88,7 @@ export class Scanner { private async scanManifestByEnv(root: string, env: string): Promise { // 0. init clean itemMap await this.initItemMap(); - + const config = await this.getAllConfig(root, env); // 1. scan all file in framework @@ -110,7 +110,7 @@ export class Scanner { this.setPluginMeta(plugin); await this.walk( plugin.importPath, - this.formatWalkOptions('plugin', plugin.importPath, plugin.name, plugin.metadata.configDir) + this.formatWalkOptions('plugin', plugin.importPath, plugin.name, plugin.metadata.configDir), ); } @@ -159,7 +159,7 @@ export class Scanner { filename, baseDir, root, - configDir + configDir, }); if (loader === 'framework-config') { // SEEME: framework-config is a special loader, cannot be used when scan, need refactor later @@ -201,7 +201,7 @@ export class Scanner { config: FrameworkConfig, root: string, env: string, - dirs: string[] = [] + dirs: string[] = [], ): Promise { if (!config || (!config.path && !config.package)) { return dirs; @@ -212,7 +212,8 @@ export class Scanner { // scan recurse const configInFramework = await this.getAllConfig(frameworkBaseDir, env); - return await this.getFrameworkDirs(configInFramework.framework, frameworkBaseDir, env, dirs); + const frameworkDirs = await this.getFrameworkDirs(configInFramework.framework, frameworkBaseDir, env, dirs); + return frameworkDirs; } private formatWalkOptions(source: string, baseDir: string, unitName?: string, configDir?: string): WalkOptions { @@ -245,7 +246,7 @@ export class Scanner { )); } - private async writeFile(filename: string = 'manifest.json', data: string) { + private async writeFile(filename = 'manifest.json', data: string) { await fs.writeFile(filename, data); } } diff --git a/src/scanner/utils.ts b/src/scanner/utils.ts index 20fa7df..5cdbc66 100644 --- a/src/scanner/utils.ts +++ b/src/scanner/utils.ts @@ -6,7 +6,7 @@ import { Container } from '@artus/injection'; import { ArtusInjectEnum, DEFAULT_LOADER, - PLUGIN_META + PLUGIN_META, } from '../constant'; import { LoaderFactory, ManifestItem } from '../loader'; import { WalkOptions } from './types'; @@ -56,14 +56,14 @@ export class ScanUtils { filename, root, baseDir, - configDir + configDir, }); const item: ManifestItem = { path: options.extensions.includes(extname) ? path.resolve(root, filenameWithoutExt) : realPath, extname, filename, loader: loaderName, - source + source, }; if (loaderState) { item._loaderState = loaderState; diff --git a/src/trigger/decorator.ts b/src/trigger/decorator.ts index b9bfd5b..7a15018 100644 --- a/src/trigger/decorator.ts +++ b/src/trigger/decorator.ts @@ -4,6 +4,6 @@ import { ArtusInjectEnum } from '../constant'; export function DefineTrigger(): ClassDecorator { return (target:any) => Injectable({ id: ArtusInjectEnum.Trigger, - scope: ScopeEnum.SINGLETON + scope: ScopeEnum.SINGLETON, })(target); -}; +} diff --git a/src/trigger/index.ts b/src/trigger/index.ts index 75ccadb..9ce7499 100644 --- a/src/trigger/index.ts +++ b/src/trigger/index.ts @@ -9,7 +9,6 @@ export default class Trigger implements TriggerType { private pipeline: Pipeline; @Inject(ArtusInjectEnum.Application) - // @ts-ignore private app: Application; constructor() { diff --git a/src/types.ts b/src/types.ts index 7e4760e..e612d72 100644 --- a/src/types.ts +++ b/src/types.ts @@ -36,4 +36,3 @@ export interface TriggerType { startPipeline(...args): Promise; } -export * from './loader/types'; diff --git a/src/utils/compatible_require.ts b/src/utils/compatible_require.ts index c86f7c2..ec72f2e 100644 --- a/src/utils/compatible_require.ts +++ b/src/utils/compatible_require.ts @@ -5,7 +5,7 @@ import assert from 'assert'; * @param path */ export default async function compatibleRequire(path: string): Promise { - let requiredModule = await import(path); + const requiredModule = await import(path); assert(requiredModule, `module '${path}' exports is undefined`); diff --git a/src/utils/fs.ts b/src/utils/fs.ts index ba94c36..6b6f687 100644 --- a/src/utils/fs.ts +++ b/src/utils/fs.ts @@ -7,4 +7,4 @@ export async function exisis(path: string): Promise { return false; } return true; -}; \ No newline at end of file +} \ No newline at end of file diff --git a/src/utils/index.ts b/src/utils/index.ts index f280edc..aca9416 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,7 +1,7 @@ import minimatch from 'minimatch'; export function getDefaultExtensions() { - return Object.keys(require.extensions) + return Object.keys(require.extensions); } export function isMatch(filename: string, patterns: string | string[]) { diff --git a/src/utils/is.ts b/src/utils/is.ts index 5854af4..b44ab4b 100644 --- a/src/utils/is.ts +++ b/src/utils/is.ts @@ -21,7 +21,7 @@ export function isClass(arg: any): boolean { fnStr.substring(0, 5) === 'class' || Boolean(~fnStr.indexOf('classCallCheck(')) || Boolean( - ~fnStr.indexOf('TypeError("Cannot call a class as a function")') + ~fnStr.indexOf('TypeError("Cannot call a class as a function")'), ) ); } diff --git a/src/utils/load_meta_file.ts b/src/utils/load_meta_file.ts index d96a89b..f77f411 100644 --- a/src/utils/load_meta_file.ts +++ b/src/utils/load_meta_file.ts @@ -6,7 +6,7 @@ type ParserFunction = >(content: string) => T; const YamlParser: ParserFunction = >(content: string) => { return yaml.load(content, { - json: true + json: true, }) as T; }; const JsonParser: ParserFunction = >(content: string) => { @@ -23,7 +23,7 @@ export const loadMetaFile = async >(item: ManifestItem): throw new Error(`[Artus-Loader] Unsupported file extension: ${item.extname} in ${item.path}`); } const content = await readFile(item.path, { - encoding: 'utf-8' + encoding: 'utf-8', }); if (!content) { throw new Error(`[Artus-Loader] File content is empty in ${item.path}.`); diff --git a/test/app.test.ts b/test/app.test.ts index ebf3724..8bbdf43 100644 --- a/test/app.test.ts +++ b/test/app.test.ts @@ -11,19 +11,19 @@ describe('test/app.test.ts', () => { expect(await new HelloController.default().index()).toStrictEqual({ content: 'Hello Artus', status: 200, - headers: {} + headers: {}, }); try { const { main, - isListening + isListening, } = await import('./fixtures/app_koa_with_ts/src/bootstrap'); const app = await main(); const testResponse = await axios.get('http://127.0.0.1:3000', { headers: { - 'x-hello-artus': 'true' - } + 'x-hello-artus': 'true', + }, }); expect(testResponse.status).toBe(200); expect(testResponse.data).toBe('Hello Artus'); diff --git a/test/config.test.ts b/test/config.test.ts index 00830fa..7644e7a 100644 --- a/test/config.test.ts +++ b/test/config.test.ts @@ -7,7 +7,7 @@ describe('test/app.test.ts', () => { process.env[ARTUS_SERVER_ENV] = 'production'; const { main } = await import('./fixtures/app_with_config/bootstrap'); const app = await main(); - expect(app.config).toEqual({ name: 'test-for-config', test: 1, arr: [ 4, 5, 6 ] }) + expect(app.config).toEqual({ name: 'test-for-config', test: 1, arr: [ 4, 5, 6 ] }); process.env[ARTUS_SERVER_ENV] = undefined; }); }); diff --git a/test/exception.test.ts b/test/exception.test.ts index 58e6120..84eb7a3 100644 --- a/test/exception.test.ts +++ b/test/exception.test.ts @@ -6,10 +6,10 @@ import { ExceptionItem } from '../src/exception/types'; describe('test/app.test.ts', () => { describe('register error code and throw', () => { const exceptionHandler = new ExceptionHandler(); - const errorCode: string = 'ARTUS:TEMP_TEST'; + const errorCode = 'ARTUS:TEMP_TEST'; const exceptionItem: ExceptionItem = { desc: 'TEST-DESC', - detailUrl: 'http://test.artusjs.org' + detailUrl: 'http://test.artusjs.org', }; exceptionHandler.registerCode(errorCode, exceptionItem); try { @@ -29,26 +29,26 @@ describe('test/app.test.ts', () => { describe('register error code and throw, with i18n', () => { const exceptionHandler = new ExceptionHandler(); - const errorCode: string = 'ARTUS:TEMP_TEST_I18N'; + const errorCode = 'ARTUS:TEMP_TEST_I18N'; const exceptionItem: ExceptionItem = { desc: { zh: 'TEST-DESC-ZH', - en: 'TEST-DESC-EN' + en: 'TEST-DESC-EN', }, - detailUrl: 'http://test.artusjs.org' + detailUrl: 'http://test.artusjs.org', }; exceptionHandler.registerCode(errorCode, exceptionItem); [ undefined, 'zh', - 'en' - ].forEach((locale) => { + 'en', + ].forEach(locale => { if (locale) { process.env.ARTUS_ERROR_LOCALE = locale; } const tDesc = exceptionItem.desc[locale || 'en']; const tmpCodeMap: Map = new Map([ - [errorCode, exceptionItem] + [errorCode, exceptionItem], ]); assert(ErrorCodeUtils.getI18NDesc(tmpCodeMap, errorCode, locale) === tDesc); try { @@ -64,14 +64,14 @@ describe('test/app.test.ts', () => { assert(error.code === errorCode); assert(error.desc === tDesc); assert(error.detailUrl === exceptionItem.detailUrl); - }) + }); }); describe('app test for ts and yaml', () => { it('should run app', async () => { try { const { - main + main, } = await import('./fixtures/exception_with_ts_yaml/bootstrap'); const app = await main(); diff --git a/test/fixtures/app_koa_with_ts/src/bootstrap.ts b/test/fixtures/app_koa_with_ts/src/bootstrap.ts index db13dcf..d1bc696 100644 --- a/test/fixtures/app_koa_with_ts/src/bootstrap.ts +++ b/test/fixtures/app_koa_with_ts/src/bootstrap.ts @@ -12,46 +12,46 @@ async function main() { extname: '.ts', filename: 'app.ts', loader: 'lifecycle-hook-unit', - source: 'app' + source: 'app', }, { path: path.resolve(__dirname, './koa_app'), extname: '.ts', filename: 'koaApp.ts', loader: 'module', - source: 'app' + source: 'app', }, { path: path.resolve(__dirname, './http_trigger'), extname: '.ts', filename: 'httpTrigger.ts', loader: 'module', - source: 'app' + source: 'app', }, { path: path.resolve(__dirname, './controllers/hello'), extname: '.ts', filename: 'hello.ts', loader: 'module', - source: 'app' + source: 'app', }, { path: path.resolve(__dirname, './services/hello'), extname: '.ts', filename: 'hello.ts', loader: 'module', - source: 'app' - } - ] + source: 'app', + }, + ], }); await app.run(); return app; -}; +} const isListening = () => server.listening; export { main, - isListening + isListening, }; diff --git a/test/fixtures/app_koa_with_ts/src/config/config.default.ts b/test/fixtures/app_koa_with_ts/src/config/config.default.ts index f4b1c92..55dddb7 100644 --- a/test/fixtures/app_koa_with_ts/src/config/config.default.ts +++ b/test/fixtures/app_koa_with_ts/src/config/config.default.ts @@ -1,3 +1,3 @@ export default { - name: 'artus' + name: 'artus', }; diff --git a/test/fixtures/app_koa_with_ts/src/config/plugin.d.ts b/test/fixtures/app_koa_with_ts/src/config/plugin.d.ts index c085239..880b78b 100644 --- a/test/fixtures/app_koa_with_ts/src/config/plugin.d.ts +++ b/test/fixtures/app_koa_with_ts/src/config/plugin.d.ts @@ -1,7 +1,7 @@ declare const _default: { redis: { - enable: boolean; - package: string; + enable: boolean; + package: string; }; }; export default _default; diff --git a/test/fixtures/app_koa_with_ts/src/config/plugin.default.ts b/test/fixtures/app_koa_with_ts/src/config/plugin.default.ts index 29c6920..c6e9eb3 100644 --- a/test/fixtures/app_koa_with_ts/src/config/plugin.default.ts +++ b/test/fixtures/app_koa_with_ts/src/config/plugin.default.ts @@ -3,14 +3,14 @@ import path from 'path'; export default { redis: { enable: true, - path: path.resolve(__dirname, '../redis_plugin') + path: path.resolve(__dirname, '../redis_plugin'), }, mysql: { enable: false, - path: path.resolve(__dirname, '../mysql_plugin') + path: path.resolve(__dirname, '../mysql_plugin'), }, testDuplicate: { enable: false, - package: 'unimportant-package' + package: 'unimportant-package', }, }; diff --git a/test/fixtures/app_koa_with_ts/src/config/plugin.dev.ts b/test/fixtures/app_koa_with_ts/src/config/plugin.dev.ts index 62e5cea..c9cd376 100644 --- a/test/fixtures/app_koa_with_ts/src/config/plugin.dev.ts +++ b/test/fixtures/app_koa_with_ts/src/config/plugin.dev.ts @@ -3,6 +3,6 @@ import path from 'path'; export default { testDuplicate: { enable: true, - path: path.resolve(__dirname, '../test_duplicate_plugin') + path: path.resolve(__dirname, '../test_duplicate_plugin'), }, }; diff --git a/test/fixtures/app_koa_with_ts/src/controllers/hello.ts b/test/fixtures/app_koa_with_ts/src/controllers/hello.ts index 91b7a3a..e9c19a8 100644 --- a/test/fixtures/app_koa_with_ts/src/controllers/hello.ts +++ b/test/fixtures/app_koa_with_ts/src/controllers/hello.ts @@ -4,11 +4,10 @@ import HelloService from '../services/hello'; // TODO: 待实现 Controller/Route 装饰器 @Injectable({ - scope: ScopeEnum.EXECUTION + scope: ScopeEnum.EXECUTION, }) export default class HelloController { @Inject(HelloService) - // @ts-ignore helloService: HelloService; async index () { @@ -16,8 +15,8 @@ export default class HelloController { status: 200, content: 'Hello Artus', headers: { - ...this.helloService?.getTestHeaders() - } + ...this.helloService?.getTestHeaders(), + }, }; } } \ No newline at end of file diff --git a/test/fixtures/app_koa_with_ts/src/koa_app.ts b/test/fixtures/app_koa_with_ts/src/koa_app.ts index 462b5e4..1640fdc 100644 --- a/test/fixtures/app_koa_with_ts/src/koa_app.ts +++ b/test/fixtures/app_koa_with_ts/src/koa_app.ts @@ -2,4 +2,4 @@ import { Injectable } from '@artus/injection'; import Koa from 'koa'; @Injectable() -export default class KoaApplication extends Koa {}; +export default class KoaApplication extends Koa {} diff --git a/test/fixtures/app_koa_with_ts/src/services/hello.ts b/test/fixtures/app_koa_with_ts/src/services/hello.ts index b79acc9..b8ed870 100644 --- a/test/fixtures/app_koa_with_ts/src/services/hello.ts +++ b/test/fixtures/app_koa_with_ts/src/services/hello.ts @@ -2,16 +2,15 @@ import 'reflect-metadata'; import { Inject, Injectable, ScopeEnum } from '@artus/injection'; @Injectable({ - scope: ScopeEnum.EXECUTION + scope: ScopeEnum.EXECUTION, }) export default class HelloService { @Inject('headers') - // @ts-ignore headers: Record; public getTestHeaders() { return { - ['x-hello-artus']: this.headers['x-hello-artus'] + 'x-hello-artus': this.headers['x-hello-artus'], }; } } \ No newline at end of file diff --git a/test/fixtures/app_with_config/app.ts b/test/fixtures/app_with_config/app.ts index e80c641..af1f365 100644 --- a/test/fixtures/app_with_config/app.ts +++ b/test/fixtures/app_with_config/app.ts @@ -8,11 +8,11 @@ const koaApp = new Koa(); @LifecycleHookUnit() export default class MyLifecycle implements ApplicationLifecycle { - testStr: string = 'Hello Artus'; + testStr = 'Hello Artus'; @LifecycleHook() willReady() { - koaApp.use((ctx) => { + koaApp.use(ctx => { ctx.status = 200; ctx.body = this.testStr; }); diff --git a/test/fixtures/app_with_config/bootstrap.ts b/test/fixtures/app_with_config/bootstrap.ts index 573ee1e..2219500 100644 --- a/test/fixtures/app_with_config/bootstrap.ts +++ b/test/fixtures/app_with_config/bootstrap.ts @@ -12,26 +12,26 @@ async function main() { extname: '.ts', filename: 'app.ts', loader: 'lifecycle-hook-unit', - source: 'app' + source: 'app', }, { path: path.resolve(rootDir, './config/config.default'), extname: '.ts', filename: 'config.default.ts', loader: 'config', - source: 'app' + source: 'app', }, { path: path.resolve(rootDir, './config/config.production'), extname: '.ts', filename: 'config.production.ts', loader: 'config', - source: 'app' + source: 'app', }, - ] + ], }); return app; -}; +} export { diff --git a/test/fixtures/app_with_config/config/config.default.ts b/test/fixtures/app_with_config/config/config.default.ts index dc3de6b..75c7dbf 100644 --- a/test/fixtures/app_with_config/config/config.default.ts +++ b/test/fixtures/app_with_config/config/config.default.ts @@ -1,5 +1,5 @@ export default { name: "test-for-config", test: 1, - arr: [1,2,3] -} \ No newline at end of file + arr: [1,2,3], +}; \ No newline at end of file diff --git a/test/fixtures/app_with_config/config/config.production.ts b/test/fixtures/app_with_config/config/config.production.ts index 4b79044..f51eacd 100644 --- a/test/fixtures/app_with_config/config/config.production.ts +++ b/test/fixtures/app_with_config/config/config.production.ts @@ -1,5 +1,5 @@ export default { name: "test-for-config", test: 1, - arr: [4,5,6] -} \ No newline at end of file + arr: [4,5,6], +}; \ No newline at end of file diff --git a/test/fixtures/artus_application/src/config/framework.ts b/test/fixtures/artus_application/src/config/framework.ts index 7b001fb..671bb6d 100644 --- a/test/fixtures/artus_application/src/config/framework.ts +++ b/test/fixtures/artus_application/src/config/framework.ts @@ -1,5 +1,5 @@ import path from 'path'; export default { - path: path.resolve(__dirname, '../../../frameworks/bar') + path: path.resolve(__dirname, '../../../frameworks/bar'), }; diff --git a/test/fixtures/artus_application/src/config/plugin.default.ts b/test/fixtures/artus_application/src/config/plugin.default.ts index dc22d22..0324b1f 100644 --- a/test/fixtures/artus_application/src/config/plugin.default.ts +++ b/test/fixtures/artus_application/src/config/plugin.default.ts @@ -3,14 +3,14 @@ import path from 'path'; export default { mysql: { enable: true, - path: path.resolve(__dirname, '../plugins/artus_plugin_mysql_rds') + path: path.resolve(__dirname, '../plugins/artus_plugin_mysql_rds'), }, redis: { enable: true, - path: path.resolve(__dirname, '../plugins/artus_plugin_redis') + path: path.resolve(__dirname, '../plugins/artus_plugin_redis'), }, base: { enable: true, - path: path.resolve(__dirname, '../plugins/artus_plugin_base') - } -} \ No newline at end of file + path: path.resolve(__dirname, '../plugins/artus_plugin_base'), + }, +}; \ No newline at end of file diff --git a/test/fixtures/artus_application/src/config/plugin.private.ts b/test/fixtures/artus_application/src/config/plugin.private.ts index dbe0d85..b7014e1 100644 --- a/test/fixtures/artus_application/src/config/plugin.private.ts +++ b/test/fixtures/artus_application/src/config/plugin.private.ts @@ -3,9 +3,9 @@ import path from 'path'; export default { mysql: { enable: true, - path: path.resolve(__dirname, '../plugins/artus_plugin_mysql_ob') + path: path.resolve(__dirname, '../plugins/artus_plugin_mysql_ob'), }, redis: { - enable: false + enable: false, }, -} \ No newline at end of file +}; \ No newline at end of file diff --git a/test/fixtures/artus_application/src/controller/conifg.ts b/test/fixtures/artus_application/src/controller/conifg.ts index dd2bb96..fe51331 100644 --- a/test/fixtures/artus_application/src/controller/conifg.ts +++ b/test/fixtures/artus_application/src/controller/conifg.ts @@ -6,13 +6,13 @@ import { WithContext } from '../../../../../src/decorator'; export default class Hello { @HttpMethod({ method: HTTPMethodEnum.GET, - path: '/config' + path: '/config', }) async index(@WithContext() ctx: Context) { const { params: { config } } = ctx.input; return { message: `get conifg succeed`, - config + config, }; } -}; +} diff --git a/test/fixtures/artus_application/src/controller/hello.ts b/test/fixtures/artus_application/src/controller/hello.ts index 685067f..71393e8 100644 --- a/test/fixtures/artus_application/src/controller/hello.ts +++ b/test/fixtures/artus_application/src/controller/hello.ts @@ -6,7 +6,7 @@ import { WithContext } from '../../../../../src/decorator'; export default class Hello { @HttpMethod({ method: HTTPMethodEnum.GET, - path: '/home' + path: '/home', }) async index(@WithContext() ctx: Context) { const { params: { config } } = ctx.input; @@ -15,7 +15,7 @@ export default class Hello { @HttpMethod({ method: HTTPMethodEnum.GET, - path: '/get_name2' + path: '/get_name2', }) async name2(@WithContext() ctx: Context) { const { params: { config } } = ctx.input; @@ -24,10 +24,10 @@ export default class Hello { @HttpMethod({ method: HTTPMethodEnum.GET, - path: '/get_name3' + path: '/get_name3', }) async name3(@WithContext() ctx: Context) { const { params: { config } } = ctx.input; return { title: `Hello Artus ${config.name3}` }; } -}; +} diff --git a/test/fixtures/artus_application/src/controller/plugin.ts b/test/fixtures/artus_application/src/controller/plugin.ts index b91faad..39e2c51 100644 --- a/test/fixtures/artus_application/src/controller/plugin.ts +++ b/test/fixtures/artus_application/src/controller/plugin.ts @@ -7,22 +7,21 @@ import { Context } from '@artus/pipeline'; @HttpController() export default class Hello { @Inject('ARTUS_MYSQL') - // @ts-ignore private client: any; @HttpMethod({ method: HTTPMethodEnum.GET, - path: '/plugin-mysql' + path: '/plugin-mysql', }) async getMysqlClient() { return { - client: await this.client.getClient() + client: await this.client.getClient(), }; } @HttpMethod({ method: HTTPMethodEnum.GET, - path: '/plugin-redis' + path: '/plugin-redis', }) async getRedisClient(@WithContext() ctx: Context) { const app: ArtusApplication = ctx.input.params.app; @@ -34,8 +33,8 @@ export default class Hello { } const result = client ? { - client: await client.getClient() + client: await client.getClient(), } : { message: 'plugin redis not enabled' }; return result; } -}; +} diff --git a/test/fixtures/artus_application/src/index.ts b/test/fixtures/artus_application/src/index.ts index a71d9ae..20a25eb 100644 --- a/test/fixtures/artus_application/src/index.ts +++ b/test/fixtures/artus_application/src/index.ts @@ -1,15 +1,13 @@ import path from 'path'; import { Manifest, ArtusApplication, ArtusInjectEnum } from "../../../../src"; import { AbstractBar } from '../../frameworks/bar/src'; -import { Inject, Injectable } from "@artus/injection" +import { Inject, Injectable } from "@artus/injection"; @Injectable() export default class MyArtusApplication { @Inject('ABSTRACT_BAR') - // @ts-ignore private bar: AbstractBar; @Inject(ArtusInjectEnum.Application) - // @ts-ignore public artus: ArtusApplication; static async instance(manifest: Manifest): Promise { diff --git a/test/fixtures/artus_application/src/plugins/artus_plugin_base/src/config.default.ts b/test/fixtures/artus_application/src/plugins/artus_plugin_base/src/config.default.ts index 52bd877..643f4cd 100644 --- a/test/fixtures/artus_application/src/plugins/artus_plugin_base/src/config.default.ts +++ b/test/fixtures/artus_application/src/plugins/artus_plugin_base/src/config.default.ts @@ -1,5 +1,5 @@ export default { mysql: { - clientName: 'mysql-ob-base' - } -} \ No newline at end of file + clientName: 'mysql-ob-base', + }, +}; \ No newline at end of file diff --git a/test/fixtures/artus_application/src/plugins/artus_plugin_mysql_ob/src/client.ts b/test/fixtures/artus_application/src/plugins/artus_plugin_mysql_ob/src/client.ts index 38fe0a5..bddcea5 100644 --- a/test/fixtures/artus_application/src/plugins/artus_plugin_mysql_ob/src/client.ts +++ b/test/fixtures/artus_application/src/plugins/artus_plugin_mysql_ob/src/client.ts @@ -5,10 +5,10 @@ export interface MysqlConfig { } @Injectable({ - id: 'ARTUS_MYSQL' + id: 'ARTUS_MYSQL', }) export default class Client { - private clientName: string = ''; + private clientName = ''; async init(config: MysqlConfig) { this.clientName = config.clientName; @@ -17,4 +17,4 @@ export default class Client { async getClient(): Promise { return this.clientName; } -}; \ No newline at end of file +} \ No newline at end of file diff --git a/test/fixtures/artus_application/src/plugins/artus_plugin_mysql_ob/src/custom_config/config.default.ts b/test/fixtures/artus_application/src/plugins/artus_plugin_mysql_ob/src/custom_config/config.default.ts index 3dbe803..13aa1b5 100644 --- a/test/fixtures/artus_application/src/plugins/artus_plugin_mysql_ob/src/custom_config/config.default.ts +++ b/test/fixtures/artus_application/src/plugins/artus_plugin_mysql_ob/src/custom_config/config.default.ts @@ -1,5 +1,5 @@ export default { mysql: { - clientName: 'mysql-ob' - } -} \ No newline at end of file + clientName: 'mysql-ob', + }, +}; \ No newline at end of file diff --git a/test/fixtures/artus_application/src/plugins/artus_plugin_mysql_rds/src/client.ts b/test/fixtures/artus_application/src/plugins/artus_plugin_mysql_rds/src/client.ts index 38fe0a5..bddcea5 100644 --- a/test/fixtures/artus_application/src/plugins/artus_plugin_mysql_rds/src/client.ts +++ b/test/fixtures/artus_application/src/plugins/artus_plugin_mysql_rds/src/client.ts @@ -5,10 +5,10 @@ export interface MysqlConfig { } @Injectable({ - id: 'ARTUS_MYSQL' + id: 'ARTUS_MYSQL', }) export default class Client { - private clientName: string = ''; + private clientName = ''; async init(config: MysqlConfig) { this.clientName = config.clientName; @@ -17,4 +17,4 @@ export default class Client { async getClient(): Promise { return this.clientName; } -}; \ No newline at end of file +} \ No newline at end of file diff --git a/test/fixtures/artus_application/src/plugins/artus_plugin_mysql_rds/src/config/config.default.ts b/test/fixtures/artus_application/src/plugins/artus_plugin_mysql_rds/src/config/config.default.ts index 9a5af95..9b5306e 100644 --- a/test/fixtures/artus_application/src/plugins/artus_plugin_mysql_rds/src/config/config.default.ts +++ b/test/fixtures/artus_application/src/plugins/artus_plugin_mysql_rds/src/config/config.default.ts @@ -1,5 +1,5 @@ export default { mysql: { - clientName: 'mysql-rds' - } -} \ No newline at end of file + clientName: 'mysql-rds', + }, +}; \ No newline at end of file diff --git a/test/fixtures/artus_application/src/plugins/artus_plugin_redis/src/client.ts b/test/fixtures/artus_application/src/plugins/artus_plugin_redis/src/client.ts index 6ce87f8..9d73ff5 100644 --- a/test/fixtures/artus_application/src/plugins/artus_plugin_redis/src/client.ts +++ b/test/fixtures/artus_application/src/plugins/artus_plugin_redis/src/client.ts @@ -5,10 +5,10 @@ export interface RedisConfig { } @Injectable({ - id: 'ARTUS_REDIS' + id: 'ARTUS_REDIS', }) export default class Client { - private clientName: string = ''; + private clientName = ''; async init(config: RedisConfig) { this.clientName = config.clientName; @@ -17,4 +17,4 @@ export default class Client { async getClient(): Promise { return this.clientName; } -}; \ No newline at end of file +} \ No newline at end of file diff --git a/test/fixtures/artus_application/src/plugins/artus_plugin_redis/src/config/config.default.ts b/test/fixtures/artus_application/src/plugins/artus_plugin_redis/src/config/config.default.ts index fc76d5e..70e47a0 100644 --- a/test/fixtures/artus_application/src/plugins/artus_plugin_redis/src/config/config.default.ts +++ b/test/fixtures/artus_application/src/plugins/artus_plugin_redis/src/config/config.default.ts @@ -1,5 +1,5 @@ export default { redis: { - clientName: 'redis' - } -} \ No newline at end of file + clientName: 'redis', + }, +}; \ No newline at end of file diff --git a/test/fixtures/custom_instance/bootstrap.ts b/test/fixtures/custom_instance/bootstrap.ts index 0593f91..c766784 100644 --- a/test/fixtures/custom_instance/bootstrap.ts +++ b/test/fixtures/custom_instance/bootstrap.ts @@ -1,7 +1,7 @@ import { ArtusApplication, ApplicationLifecycle, LifecycleHookUnit, LifecycleHook, - WithApplication, WithContainer + WithApplication, WithContainer, } from '../../../src/index'; import { Container } from '@artus/injection'; @@ -24,6 +24,6 @@ export default class MyLifecycle implements ApplicationLifecycle { @LifecycleHook() async beforeClose() { - console.log(this.container.get(Custom)) + console.log(this.container.get(Custom)); } } \ No newline at end of file diff --git a/test/fixtures/exception_with_ts_yaml/app.ts b/test/fixtures/exception_with_ts_yaml/app.ts index 7111502..d7d23dc 100644 --- a/test/fixtures/exception_with_ts_yaml/app.ts +++ b/test/fixtures/exception_with_ts_yaml/app.ts @@ -8,11 +8,11 @@ const koaApp = new Koa(); @LifecycleHookUnit() export default class MyLifecycle implements ApplicationLifecycle { - testStr: string = 'Hello Artus'; + testStr = 'Hello Artus'; @LifecycleHook() willReady() { - koaApp.use((ctx) => { + koaApp.use(ctx => { ctx.status = 200; ctx.body = this.testStr; }); diff --git a/test/fixtures/exception_with_ts_yaml/bootstrap.ts b/test/fixtures/exception_with_ts_yaml/bootstrap.ts index 3c07d50..57c9c98 100644 --- a/test/fixtures/exception_with_ts_yaml/bootstrap.ts +++ b/test/fixtures/exception_with_ts_yaml/bootstrap.ts @@ -11,31 +11,31 @@ async function main() { extname: '.ts', filename: 'app.ts', loader: 'lifecycle-hook-unit', - source: 'app' + source: 'app', }, { path: path.resolve(__dirname, '../../../exception.yaml'), extname: '.yaml', filename: 'exception.yaml', loader: 'exception', - source: 'app' + source: 'app', }, { path: path.resolve(__dirname, './exception.yaml'), extname: '.yaml', filename: 'exception.yaml', loader: 'exception', - source: 'app' - } - ] + source: 'app', + }, + ], }); await app.run(); return app; -}; +} const isListening = () => server.listening; export { main, - isListening + isListening, }; diff --git a/test/fixtures/frameworks/bar/src/config/framework.default.ts b/test/fixtures/frameworks/bar/src/config/framework.default.ts index f30b90c..3236076 100644 --- a/test/fixtures/frameworks/bar/src/config/framework.default.ts +++ b/test/fixtures/frameworks/bar/src/config/framework.default.ts @@ -1,5 +1,5 @@ import path from 'path'; export default { - path: path.join(__dirname, '../../../layer/foo/foo1') -} + path: path.join(__dirname, '../../../layer/foo/foo1'), +}; diff --git a/test/fixtures/frameworks/bar/src/config/framework.private.ts b/test/fixtures/frameworks/bar/src/config/framework.private.ts index 68cbcba..7cc07a6 100644 --- a/test/fixtures/frameworks/bar/src/config/framework.private.ts +++ b/test/fixtures/frameworks/bar/src/config/framework.private.ts @@ -1,5 +1,5 @@ import path from 'path'; export default { - path: path.join(__dirname, '../../../layer/foo/foo2') -} + path: path.join(__dirname, '../../../layer/foo/foo2'), +}; diff --git a/test/fixtures/frameworks/bar/src/http.ts b/test/fixtures/frameworks/bar/src/http.ts index 36375a1..9fcd2f0 100644 --- a/test/fixtures/frameworks/bar/src/http.ts +++ b/test/fixtures/frameworks/bar/src/http.ts @@ -1,16 +1,15 @@ import 'reflect-metadata'; import { Context, Next } from '@artus/pipeline'; -import { Constructable } from '@artus/injection'; +import { Constructable , Injectable, ScopeEnum } from '@artus/injection'; import { CONSTRUCTOR_PARAMS, CONSTRUCTOR_PARAMS_CONTEXT } from '../../../../../src/constant'; import { HttpTrigger } from '../../abstract/foo'; -import { Injectable, ScopeEnum } from '@artus/injection'; export const enum HTTPMethodEnum { GET = 'GET', POST = 'POST', DELETE = ' DELETE', PUT = 'PUT', -}; +} export type ControllerParams = { path?: string @@ -24,7 +23,7 @@ export type HttpParams = { export type ControllerMeta = { prefix: string, clazz: Constructable -} +}; export const controllerMap = new Set(); @@ -72,9 +71,9 @@ export function registerController(trigger: HttpTrigger) { const target = instance[key]; const params: any = Reflect.getMetadata(CONSTRUCTOR_PARAMS, target) ?? []; const paramsMap = { - [CONSTRUCTOR_PARAMS_CONTEXT]: ctx + [CONSTRUCTOR_PARAMS_CONTEXT]: ctx, }; - ctx.output.data.content = await target.call(instance, ...params.map((param) => paramsMap[param])); + ctx.output.data.content = await target.call(instance, ...params.map(param => paramsMap[param])); } await next(); }); diff --git a/test/fixtures/frameworks/bar/src/index.ts b/test/fixtures/frameworks/bar/src/index.ts index 2eec702..04d6024 100644 --- a/test/fixtures/frameworks/bar/src/index.ts +++ b/test/fixtures/frameworks/bar/src/index.ts @@ -1,12 +1,11 @@ -import { Inject, Injectable } from "@artus/injection" +import { Inject, Injectable } from "@artus/injection"; import { AbstractFoo } from "../../abstract/foo"; -export interface AbstractBar extends AbstractFoo { }; +export interface AbstractBar extends AbstractFoo { } @Injectable({ id: 'ABSTRACT_BAR' }) export default class FrameworkBar implements AbstractBar { @Inject('ABSTRACT_FOO') - // @ts-ignore private foo: AbstractFoo; isListening() { diff --git a/test/fixtures/frameworks/layer/foo/foo1/src/index.ts b/test/fixtures/frameworks/layer/foo/foo1/src/index.ts index 2bde11b..827abb3 100644 --- a/test/fixtures/frameworks/layer/foo/foo1/src/index.ts +++ b/test/fixtures/frameworks/layer/foo/foo1/src/index.ts @@ -1,4 +1,4 @@ -import { Injectable } from "@artus/injection" +import { Injectable } from "@artus/injection"; import { ArtusApplication } from '../../../../../../../src'; import { server } from './lifecycle'; diff --git a/test/fixtures/frameworks/layer/foo/foo1/src/lifecycle.ts b/test/fixtures/frameworks/layer/foo/foo1/src/lifecycle.ts index c910d37..4a2bc17 100644 --- a/test/fixtures/frameworks/layer/foo/foo1/src/lifecycle.ts +++ b/test/fixtures/frameworks/layer/foo/foo1/src/lifecycle.ts @@ -1,5 +1,4 @@ -import { Server } from 'http'; -import http from 'http'; +import http, { Server } from 'http'; import { LifecycleHookUnit, LifecycleHook, WithApplication } from '../../../../../../../src/decorator'; import { ApplicationLifecycle } from '../../../../../../../src/types'; import { Input } from '@artus/pipeline'; diff --git a/test/fixtures/frameworks/layer/foo/foo2/src/index.ts b/test/fixtures/frameworks/layer/foo/foo2/src/index.ts index 2bde11b..827abb3 100644 --- a/test/fixtures/frameworks/layer/foo/foo2/src/index.ts +++ b/test/fixtures/frameworks/layer/foo/foo2/src/index.ts @@ -1,4 +1,4 @@ -import { Injectable } from "@artus/injection" +import { Injectable } from "@artus/injection"; import { ArtusApplication } from '../../../../../../../src'; import { server } from './lifecycle'; diff --git a/test/fixtures/frameworks/layer/foo/foo2/src/lifecycle.ts b/test/fixtures/frameworks/layer/foo/foo2/src/lifecycle.ts index c910d37..4a2bc17 100644 --- a/test/fixtures/frameworks/layer/foo/foo2/src/lifecycle.ts +++ b/test/fixtures/frameworks/layer/foo/foo2/src/lifecycle.ts @@ -1,5 +1,4 @@ -import { Server } from 'http'; -import http from 'http'; +import http, { Server } from 'http'; import { LifecycleHookUnit, LifecycleHook, WithApplication } from '../../../../../../../src/decorator'; import { ApplicationLifecycle } from '../../../../../../../src/types'; import { Input } from '@artus/pipeline'; diff --git a/test/fixtures/logger/src/custom_logger.ts b/test/fixtures/logger/src/custom_logger.ts index 609ca32..8117fe7 100644 --- a/test/fixtures/logger/src/custom_logger.ts +++ b/test/fixtures/logger/src/custom_logger.ts @@ -3,10 +3,6 @@ import { BaseLogger } from '../../../../src/logger/base'; @DefineLogger() export default class CustomLogger extends BaseLogger { - constructor() { - super(); - } - public info(message: string, ...args: any[]): void { console.info('[Custom]', message, ...args); } diff --git a/test/fixtures/logger/src/index.ts b/test/fixtures/logger/src/index.ts index f225c77..46d0344 100644 --- a/test/fixtures/logger/src/index.ts +++ b/test/fixtures/logger/src/index.ts @@ -9,9 +9,9 @@ const defaultManifest: Manifest = { { path: path.resolve(rootDir, './test_clazz.ts'), extname: '.ts', - filename: 'test_clazz.ts' - } - ] + filename: 'test_clazz.ts', + }, + ], }; export const manifestWithCustomLogger: Manifest = { @@ -20,14 +20,14 @@ export const manifestWithCustomLogger: Manifest = { { path: path.resolve(rootDir, './test_custom_clazz.ts'), extname: '.ts', - filename: 'test_custom_clazz.ts' + filename: 'test_custom_clazz.ts', }, { path: path.resolve(rootDir, './custom_logger.ts'), extname: '.ts', - filename: 'custom_logger.ts' - } - ] + filename: 'custom_logger.ts', + }, + ], }; export default defaultManifest; diff --git a/test/fixtures/module_with_custom_loader/src/index.ts b/test/fixtures/module_with_custom_loader/src/index.ts index 6406d61..af0d2c7 100644 --- a/test/fixtures/module_with_custom_loader/src/index.ts +++ b/test/fixtures/module_with_custom_loader/src/index.ts @@ -12,8 +12,8 @@ export default ({ filename: 'test_clazz.ts', loader: 'test-custom-loader', _loaderState: { - hello: 'loaderState' - } - } - ] + hello: 'loaderState', + }, + }, + ], }) as Manifest; diff --git a/test/fixtures/module_with_custom_loader/src/loader/test_custom_loader.ts b/test/fixtures/module_with_custom_loader/src/loader/test_custom_loader.ts index 2b9df1b..f2fee4b 100644 --- a/test/fixtures/module_with_custom_loader/src/loader/test_custom_loader.ts +++ b/test/fixtures/module_with_custom_loader/src/loader/test_custom_loader.ts @@ -9,12 +9,12 @@ interface TestLoaderState { @DefineLoader('test-custom-loader') export default class TestCustomLoader implements Loader { static async is(opts: LoaderFindOptions) { - return opts.filename === 'test_clazz.ts' + return opts.filename === 'test_clazz.ts'; } static async onFind(_opts: LoaderFindOptions): Promise { return { - hello: 'loaderState' + hello: 'loaderState', }; } diff --git a/test/fixtures/module_with_ts/src/index.ts b/test/fixtures/module_with_ts/src/index.ts index 1820021..16789cd 100644 --- a/test/fixtures/module_with_ts/src/index.ts +++ b/test/fixtures/module_with_ts/src/index.ts @@ -14,6 +14,6 @@ export default ({ path: path.resolve(rootDir, './test_service_b.ts'), extname: '.ts', filename: 'test_service_b.ts', - } - ] + }, + ], }) as Manifest; diff --git a/test/fixtures/module_with_ts/src/test_service_a.ts b/test/fixtures/module_with_ts/src/test_service_a.ts index 6467d25..fd6d50b 100644 --- a/test/fixtures/module_with_ts/src/test_service_a.ts +++ b/test/fixtures/module_with_ts/src/test_service_a.ts @@ -3,11 +3,10 @@ import TestServiceB from './test_service_b'; @Injectable({ id: 'testServiceA', - scope: ScopeEnum.SINGLETON + scope: ScopeEnum.SINGLETON, }) export default class TestServiceA { @Inject('testServiceB') - // @ts-ignore testServiceB: TestServiceB; testMethod() { diff --git a/test/fixtures/module_with_ts/src/test_service_b.ts b/test/fixtures/module_with_ts/src/test_service_b.ts index 5754d15..e5e6511 100644 --- a/test/fixtures/module_with_ts/src/test_service_b.ts +++ b/test/fixtures/module_with_ts/src/test_service_b.ts @@ -2,7 +2,7 @@ import { ScopeEnum, Injectable } from '@artus/injection'; @Injectable({ id: 'testServiceB', - scope: ScopeEnum.SINGLETON + scope: ScopeEnum.SINGLETON, }) export default class TestServiceB { sayHello() { diff --git a/test/fixtures/trigger/event/app.ts b/test/fixtures/trigger/event/app.ts index 7485773..a1f599c 100644 --- a/test/fixtures/trigger/event/app.ts +++ b/test/fixtures/trigger/event/app.ts @@ -4,7 +4,7 @@ import { LifecycleHookUnit, LifecycleHook, WithApplication } from '../../../../s import { Context, Input, Next } from '@artus/pipeline'; import { ApplicationLifecycle } from '../../../../src/types'; -export let event = new EventEmitter(); +export const event = new EventEmitter(); @LifecycleHookUnit() export default class MyLifecycle implements ApplicationLifecycle { @@ -19,7 +19,8 @@ export default class MyLifecycle implements ApplicationLifecycle { this.app.trigger.use(async (ctx: Context, next: Next) => { const { input: { params: { type, payload } } } = ctx; if (type !== 'e1') { - return await next(); + await next(); + return; } const { output: { data } } = ctx; data.type = Array.from(type).reverse().join(''); @@ -29,7 +30,8 @@ export default class MyLifecycle implements ApplicationLifecycle { this.app.trigger.use(async (ctx: Context, next: Next) => { const { input: { params: { type, payload } } } = ctx; if (type !== 'e2') { - return await next(); + await next(); + return; } const { output: { data } } = ctx; data.type = Array.from(type).reverse().join(''); diff --git a/test/fixtures/trigger/event/bootstrap.ts b/test/fixtures/trigger/event/bootstrap.ts index de82e03..a1e0a64 100644 --- a/test/fixtures/trigger/event/bootstrap.ts +++ b/test/fixtures/trigger/event/bootstrap.ts @@ -11,21 +11,21 @@ async function main() { extname: '.ts', filename: 'app.ts', loader: 'lifecycle-hook-unit', - source: 'app' + source: 'app', }, { path: path.resolve(__dirname, './event_trigger'), extname: '.ts', filename: 'event_trigger.ts', loader: 'module', - source: 'app' - } - ] + source: 'app', + }, + ], }); await app.run(); return app; -}; +} function pub(e: 'e1' | 'e2', p: any) { event.emit(e, p); @@ -33,5 +33,5 @@ function pub(e: 'e1' | 'e2', p: any) { export { main, - pub + pub, }; diff --git a/test/fixtures/trigger/event/event_trigger.ts b/test/fixtures/trigger/event/event_trigger.ts index beba8f9..0d9cb2a 100644 --- a/test/fixtures/trigger/event/event_trigger.ts +++ b/test/fixtures/trigger/event/event_trigger.ts @@ -9,7 +9,7 @@ export default class EventTrigger extends Trigger { // first of all this.use(async (ctx: Context, next: Next) => { await next(); - await this.respond(ctx) + await this.respond(ctx); }); } diff --git a/test/fixtures/trigger/http/app.ts b/test/fixtures/trigger/http/app.ts index 65d3696..a8fd02b 100644 --- a/test/fixtures/trigger/http/app.ts +++ b/test/fixtures/trigger/http/app.ts @@ -31,7 +31,7 @@ export default class MyLifecycle implements ApplicationLifecycle { const ctx = await this.app.trigger.initContext(input); await this.app.trigger.startPipeline(ctx); }) - .listen(3001) + .listen(3001); } @LifecycleHook() diff --git a/test/fixtures/trigger/http/bootstrap.ts b/test/fixtures/trigger/http/bootstrap.ts index a6aed9e..d0b4159 100644 --- a/test/fixtures/trigger/http/bootstrap.ts +++ b/test/fixtures/trigger/http/bootstrap.ts @@ -11,25 +11,25 @@ async function main() { extname: '.ts', filename: 'app.ts', loader: 'lifecycle-hook-unit', - source: 'app' + source: 'app', }, { path: path.resolve(__dirname, './http_trigger'), extname: '.ts', filename: 'http_trigger.ts', loader: 'module', - source: 'app' - } - ] + source: 'app', + }, + ], }); await app.run(); return app; -}; +} const isListening = () => server.listening; export { main, - isListening + isListening, }; diff --git a/test/fixtures/trigger/timer/app.ts b/test/fixtures/trigger/timer/app.ts index f21a937..33482dc 100644 --- a/test/fixtures/trigger/timer/app.ts +++ b/test/fixtures/trigger/timer/app.ts @@ -3,16 +3,16 @@ import { LifecycleHookUnit, LifecycleHook, WithApplication } from '../../../../s import { Context, Input } from '@artus/pipeline'; import { ApplicationLifecycle } from '../../../../src/types'; -let timers: any[] = []; -export let execution = { +const timers: any[] = []; +export const execution = { task1: { count: 0, cost: 0, }, task2: { count: 0, - cost: 0 - } + cost: 0, + }, }; @LifecycleHookUnit() diff --git a/test/fixtures/trigger/timer/bootstrap.ts b/test/fixtures/trigger/timer/bootstrap.ts index 8cdc039..7cf8223 100644 --- a/test/fixtures/trigger/timer/bootstrap.ts +++ b/test/fixtures/trigger/timer/bootstrap.ts @@ -11,21 +11,21 @@ async function main() { extname: '.ts', filename: 'app.ts', loader: 'lifecycle-hook-unit', - source: 'app' + source: 'app', }, { path: path.resolve(__dirname, './timer_trigger'), extname: '.ts', filename: 'timer_trigger.ts', loader: 'module', - source: 'app' - } - ] + source: 'app', + }, + ], }); await app.run(); return app; -}; +} function getTaskExecution() { return execution; @@ -33,5 +33,5 @@ function getTaskExecution() { export { main, - getTaskExecution + getTaskExecution, }; diff --git a/test/framework.test.ts b/test/framework.test.ts index cc80f6a..26531a9 100644 --- a/test/framework.test.ts +++ b/test/framework.test.ts @@ -18,7 +18,7 @@ describe('test/framework.test.ts', () => { const scanner = new Scanner({ needWriteFile: false, extensions: ['.ts', '.js', '.json'], configDir: 'src/config', - envs: ['private'] + envs: ['private'], }); const { private: manifest } = await scanner.scan(path.resolve(__dirname, './fixtures/artus_application')); // console.log('manifest', manifest); diff --git a/test/loader.test.ts b/test/loader.test.ts index 4669b78..defd345 100644 --- a/test/loader.test.ts +++ b/test/loader.test.ts @@ -29,7 +29,7 @@ describe('test/loader.test.ts', () => { const appProxy = new Proxy({}, { get(_target, properName: string) { return container.get(properName); - } + }, }); assert((container.get('testServiceA') as any).testMethod(appProxy) === 'Hello Artus'); }); @@ -50,7 +50,7 @@ describe('test/loader.test.ts', () => { filename: 'test_clazz.ts', root: path.resolve(__dirname, './fixtures/module_with_custom_loader/src'), baseDir: path.resolve(__dirname, './fixtures/module_with_custom_loader/src'), - configDir: '' + configDir: '', }); expect(loaderName).toBe('test-custom-loader'); jest.spyOn(console, 'log'); @@ -64,6 +64,6 @@ describe('test/loader.test.ts', () => { it('should not overide custom instance', async () => { const app = await createApp(); expect(app.getContainer().get(Custom).getName()).toBe('foo'); - }) + }); }); }); diff --git a/test/logger.test.ts b/test/logger.test.ts index 432ed8c..525cb42 100644 --- a/test/logger.test.ts +++ b/test/logger.test.ts @@ -61,21 +61,21 @@ describe('test/logger.test.ts', () => { app.logger.log({ level: LoggerLevel.TRACE, message: 'trace', - splat: [ 0, {} ] + splat: [ 0, {} ], }); expect(console.trace).toBeCalledTimes(0); app.logger.log({ level: LoggerLevel.DEBUG, message: 'debug', - splat: [ 1, {} ] + splat: [ 1, {} ], }); expect(console.debug).toBeCalledTimes(0); app.logger.log({ level: LoggerLevel.INFO, message: 'info', - splat: [ 2, {} ] + splat: [ 2, {} ], }); expect(console.info).toBeCalledTimes(1); expect(console.info).toBeCalledWith('info', 2, {}); @@ -83,7 +83,7 @@ describe('test/logger.test.ts', () => { app.logger.log({ level: LoggerLevel.WARN, message: 'warn', - splat: [ 3, {} ] + splat: [ 3, {} ], }); expect(console.warn).toBeCalledTimes(1); expect(console.warn).toBeCalledWith('warn', 3, {}); @@ -91,12 +91,12 @@ describe('test/logger.test.ts', () => { app.logger.log({ level: LoggerLevel.ERROR, message: 'error', - splat: [ 4, {} ] + splat: [ 4, {} ], }); app.logger.log({ level: LoggerLevel.ERROR, message: err, - splat: [ 5, {} ] + splat: [ 5, {} ], }); expect(console.error).toBeCalledTimes(2); expect(console.error).toBeCalledWith('error', 4, {}); @@ -163,7 +163,7 @@ describe('test/logger.test.ts', () => { const app = await _getAppWithConfig({ logger: { level: LoggerLevel.TRACE, - } + }, }); app.logger.trace('trace', 0, {}); @@ -192,13 +192,13 @@ describe('test/logger.test.ts', () => { const app = await _getAppWithConfig({ logger: { level: LoggerLevel.TRACE, - } + }, }); app.logger.log({ level: LoggerLevel.TRACE, message: 'trace', - splat: [ 0, {} ] + splat: [ 0, {} ], }); expect(console.trace).toBeCalledTimes(1); expect(console.trace).toBeCalledWith('trace', 0, {}); @@ -206,7 +206,7 @@ describe('test/logger.test.ts', () => { app.logger.log({ level: LoggerLevel.DEBUG, message: 'debug', - splat: [ 1, {} ] + splat: [ 1, {} ], }); expect(console.debug).toBeCalledTimes(1); expect(console.debug).toBeCalledWith('debug', 1, {}); @@ -214,7 +214,7 @@ describe('test/logger.test.ts', () => { app.logger.log({ level: LoggerLevel.INFO, message: 'info', - splat: [ 2, {} ] + splat: [ 2, {} ], }); expect(console.info).toBeCalledTimes(1); expect(console.info).toBeCalledWith('info', 2, {}); @@ -222,7 +222,7 @@ describe('test/logger.test.ts', () => { app.logger.log({ level: LoggerLevel.WARN, message: 'warn', - splat: [ 3, {} ] + splat: [ 3, {} ], }); expect(console.warn).toBeCalledTimes(1); expect(console.warn).toBeCalledWith('warn', 3, {}); @@ -230,12 +230,12 @@ describe('test/logger.test.ts', () => { app.logger.log({ level: LoggerLevel.ERROR, message: 'error', - splat: [ 4, {} ] + splat: [ 4, {} ], }); app.logger.log({ level: LoggerLevel.ERROR, message: err, - splat: [ 5, {} ] + splat: [ 5, {} ], }); expect(console.error).toBeCalledTimes(2); expect(console.error).toBeCalledWith('error', 4, {}); @@ -247,7 +247,7 @@ describe('test/logger.test.ts', () => { const app = await _getAppWithConfig({ logger: { level: LoggerLevel.TRACE, - } + }, }, manifest); const testClazz = app.getContainer().get(TestLoggerClazz); @@ -280,7 +280,7 @@ describe('test/logger.test.ts', () => { const app = await _getAppWithConfig({ logger: { level: LoggerLevel.TRACE, - } + }, }, manifest); const testClazz = app.getContainer().get(TestLoggerClazz); @@ -315,7 +315,7 @@ describe('test/logger.test.ts', () => { app.logger.log({ level: LoggerLevel.INFO, - message: err + message: err, }); expect(console.info).toBeCalledTimes(1); diff --git a/test/plugin.test.ts b/test/plugin.test.ts index 16628d1..57a0761 100644 --- a/test/plugin.test.ts +++ b/test/plugin.test.ts @@ -16,8 +16,8 @@ describe('test/app.test.ts', () => { path: path.resolve(__dirname, `${pluginPrefix}/plugin_a/meta.js`), extname: '.js', filename: 'meta.js', - } - } + }, + }, }, 'plugin-b': { enable: true, @@ -27,8 +27,8 @@ describe('test/app.test.ts', () => { path: path.resolve(__dirname, `${pluginPrefix}/plugin_b/meta.js`), extname: '.js', filename: 'meta.js', - } - } + }, + }, }, 'plugin-c': { enable: true, @@ -38,17 +38,17 @@ describe('test/app.test.ts', () => { path: path.resolve(__dirname, `${pluginPrefix}/plugin_c/meta.js`), extname: '.js', filename: 'meta.js', - } - } - } - } + }, + }, + }, + }; const pluginList = await PluginFactory.createFromConfig(mockPluginConfig); expect(pluginList.length).toEqual(3); pluginList.forEach(plugin => { expect(plugin).toBeInstanceOf(ArtusPlugin); expect(plugin.enable).toBeTruthy(); }); - expect(pluginList.map((plugin) => plugin.name)).toStrictEqual(['plugin-c', 'plugin-b', 'plugin-a']); + expect(pluginList.map(plugin => plugin.name)).toStrictEqual(['plugin-c', 'plugin-b', 'plugin-a']); }); it('should not load plugin with wrong order', async () => { @@ -61,8 +61,8 @@ describe('test/app.test.ts', () => { path: path.resolve(__dirname, `${pluginPrefix}/plugin_a/meta.js`), extname: '.js', filename: 'meta.js', - } - } + }, + }, }, 'plugin-b': { enable: true, @@ -72,8 +72,8 @@ describe('test/app.test.ts', () => { path: path.resolve(__dirname, `${pluginPrefix}/plugin_b/meta.js`), extname: '.js', filename: 'meta.js', - } - } + }, + }, }, 'plugin-c': { enable: true, @@ -83,8 +83,8 @@ describe('test/app.test.ts', () => { path: path.resolve(__dirname, `${pluginPrefix}/plugin_c/meta.js`), extname: '.js', filename: 'meta.js', - } - } + }, + }, }, 'plugin-wrong-a': { enable: true, @@ -94,8 +94,8 @@ describe('test/app.test.ts', () => { path: path.resolve(__dirname, `${pluginPrefix}/plugin_wrong_a/meta.js`), extname: '.js', filename: 'meta.js', - } - } + }, + }, }, 'plugin-wrong-b': { enable: true, @@ -105,12 +105,12 @@ describe('test/app.test.ts', () => { path: path.resolve(__dirname, `${pluginPrefix}/plugin_wrong_b/meta.js`), extname: '.js', filename: 'meta.js', - } - } - } - } + }, + }, + }, + }; expect(async () => { - await PluginFactory.createFromConfig(mockPluginConfig) + await PluginFactory.createFromConfig(mockPluginConfig); }).rejects.toThrowError(new Error(`There is a cycle in the dependencies, wrong plugin is plugin-wrong-a,plugin-wrong-b.`)); }); @@ -124,12 +124,12 @@ describe('test/app.test.ts', () => { path: path.resolve(__dirname, `${pluginPrefix}/plugin_a/meta.js`), extname: '.js', filename: 'meta.js', - } - } - } - } + }, + }, + }, + }; expect(async () => { - await PluginFactory.createFromConfig(mockPluginConfig) + await PluginFactory.createFromConfig(mockPluginConfig); }).rejects.toThrowError(new Error(`Plugin plugin-a need have dependence: plugin-b.`)); }); @@ -143,8 +143,8 @@ describe('test/app.test.ts', () => { path: path.resolve(__dirname, `${pluginPrefix}/plugin_a/meta.js`), extname: '.js', filename: 'meta.js', - } - } + }, + }, }, 'plugin-b': { enable: false, @@ -154,8 +154,8 @@ describe('test/app.test.ts', () => { path: path.resolve(__dirname, `${pluginPrefix}/plugin_b/meta.js`), extname: '.js', filename: 'meta.js', - } - } + }, + }, }, 'plugin-c': { enable: true, @@ -165,12 +165,12 @@ describe('test/app.test.ts', () => { path: path.resolve(__dirname, `${pluginPrefix}/plugin_c/meta.js`), extname: '.js', filename: 'meta.js', - } - } - } - } + }, + }, + }, + }; expect(async () => { - await PluginFactory.createFromConfig(mockPluginConfig) + await PluginFactory.createFromConfig(mockPluginConfig); }).rejects.toThrowError(new Error(`Plugin plugin-a need have dependence: plugin-b.`)); }); @@ -184,10 +184,10 @@ describe('test/app.test.ts', () => { path: path.resolve(__dirname, `${pluginPrefix}/plugin_d/meta.js`), extname: '.js', filename: 'meta.js', - } - } - } - } + }, + }, + }, + }; // mock warn const originWarn = console.warn; diff --git a/test/scanner.test.ts b/test/scanner.test.ts index f56a78c..679756a 100644 --- a/test/scanner.test.ts +++ b/test/scanner.test.ts @@ -4,55 +4,55 @@ import { LoaderFactory } from '../src'; describe('test/scanner.test.ts', () => { - it('should scan application', async () => { - const scanner = new Scanner({ needWriteFile: false, extensions: ['.ts', '.js', '.json'] }); - const scanResults = await scanner.scan(path.resolve(__dirname, './fixtures/app_koa_with_ts')); - const { default: manifest } = scanResults; - expect(Object.entries(scanResults).length).toBe(2); - expect(manifest).toBeDefined(); - expect(manifest.items).toBeDefined(); - // console.log('manifest', manifest); - expect(manifest.items.length).toBe(11); + it('should scan application', async () => { + const scanner = new Scanner({ needWriteFile: false, extensions: ['.ts', '.js', '.json'] }); + const scanResults = await scanner.scan(path.resolve(__dirname, './fixtures/app_koa_with_ts')); + const { default: manifest } = scanResults; + expect(Object.entries(scanResults).length).toBe(2); + expect(manifest).toBeDefined(); + expect(manifest.items).toBeDefined(); + // console.log('manifest', manifest); + expect(manifest.items.length).toBe(11); - expect(manifest.items.filter(item => item.loader === 'plugin-config').length).toBe(0); - expect(manifest.items.filter(item => item.loader === 'plugin-meta').length).toBe(1); - expect(manifest.items.filter(item => item.loader === 'exception').length).toBe(1); - expect(manifest.items.filter(item => item.loader === 'lifecycle-hook-unit').length).toBe(2); - expect(manifest.items.filter(item => item.loader === 'config').length).toBe(1); - expect(manifest.items.filter(item => item.loader === 'module').length).toBe(5); + expect(manifest.items.filter(item => item.loader === 'plugin-config').length).toBe(0); + expect(manifest.items.filter(item => item.loader === 'plugin-meta').length).toBe(1); + expect(manifest.items.filter(item => item.loader === 'exception').length).toBe(1); + expect(manifest.items.filter(item => item.loader === 'lifecycle-hook-unit').length).toBe(2); + expect(manifest.items.filter(item => item.loader === 'config').length).toBe(1); + expect(manifest.items.filter(item => item.loader === 'module').length).toBe(5); - expect(manifest.items.filter(item => item.unitName === 'redis').length).toBe(2); - expect(manifest.items.filter(item => item.unitName === 'mysql').length).toBe(0); - expect(manifest.items.filter(item => item.source === 'app').length).toBe(9); + expect(manifest.items.filter(item => item.unitName === 'redis').length).toBe(2); + expect(manifest.items.filter(item => item.unitName === 'mysql').length).toBe(0); + expect(manifest.items.filter(item => item.source === 'app').length).toBe(9); - const { dev: devManifest } = scanResults; - // console.log('devManifest', devManifest); - expect(devManifest).toBeDefined(); - expect(devManifest.items).toBeDefined(); - expect(devManifest.items.length).toBe(12); - expect(devManifest.items.filter(item => item.loader === 'plugin-meta').length).toBe(2); - expect(devManifest.items.find(item => item.unitName === 'testDuplicate')).toBeDefined(); - }); + const { dev: devManifest } = scanResults; + // console.log('devManifest', devManifest); + expect(devManifest).toBeDefined(); + expect(devManifest.items).toBeDefined(); + expect(devManifest.items.length).toBe(12); + expect(devManifest.items.filter(item => item.loader === 'plugin-meta').length).toBe(2); + expect(devManifest.items.find(item => item.unitName === 'testDuplicate')).toBeDefined(); + }); - it('should scan module with custom loader', async () => { - // TODO: allow scan custom loader - const { default: TestCustomLoader } = await import('./fixtures/module_with_custom_loader/src/loader/test_custom_loader'); - LoaderFactory.register(TestCustomLoader); + it('should scan module with custom loader', async () => { + // TODO: allow scan custom loader + const { default: TestCustomLoader } = await import('./fixtures/module_with_custom_loader/src/loader/test_custom_loader'); + LoaderFactory.register(TestCustomLoader); - const scanner = new Scanner({ - needWriteFile: false, - extensions: ['.ts', '.js', '.json'], - configDir: '.', - loaderListGenerator: () => [TestCustomLoader] - }); - const scanResults = await scanner.scan(path.resolve(__dirname, './fixtures/module_with_custom_loader')); - const { default: manifest } = scanResults; - // console.log('manifest', manifest); - expect(Object.entries(scanResults).length).toBe(1); - expect(manifest).toBeDefined(); - expect(manifest.items).toBeDefined(); - expect(Array.isArray(manifest.items)).toBe(true); - expect(manifest.items.length).toBe(1); - expect(manifest.items[0]?.loader).toBe('test-custom-loader'); + const scanner = new Scanner({ + needWriteFile: false, + extensions: ['.ts', '.js', '.json'], + configDir: '.', + loaderListGenerator: () => [TestCustomLoader], }); + const scanResults = await scanner.scan(path.resolve(__dirname, './fixtures/module_with_custom_loader')); + const { default: manifest } = scanResults; + // console.log('manifest', manifest); + expect(Object.entries(scanResults).length).toBe(1); + expect(manifest).toBeDefined(); + expect(manifest.items).toBeDefined(); + expect(Array.isArray(manifest.items)).toBe(true); + expect(manifest.items.length).toBe(1); + expect(manifest.items[0]?.loader).toBe('test-custom-loader'); + }); }); diff --git a/test/trigger/event.test.ts b/test/trigger/event.test.ts index ba0a89f..c8328d1 100644 --- a/test/trigger/event.test.ts +++ b/test/trigger/event.test.ts @@ -5,19 +5,19 @@ describe('test/trigger/event.test.ts', () => { it('[trigger with event] should run succeed', async () => { const { main, - pub + pub, } = await import('../fixtures/trigger/event/bootstrap'); const app = await main(); let e1Result, e2Result; pub('e1', { cb(res) { e1Result = res; - } + }, }); pub('e2', { cb(res) { e2Result = res; - } + }, }); // wait for event handle await new Promise(resolve => setTimeout(resolve, 1000)); diff --git a/test/trigger/http.test.ts b/test/trigger/http.test.ts index d11d8ae..8d0f44b 100644 --- a/test/trigger/http.test.ts +++ b/test/trigger/http.test.ts @@ -6,7 +6,7 @@ describe('test/trigger/http.test.ts', () => { it('should run succeed', async () => { const { main, - isListening + isListening, } = await import('../fixtures/trigger/http/bootstrap'); const app = await main(); const testResponse = await axios.get('http://127.0.0.1:3001');