From faffd3492f9edd411213034651d6863fb3f1a24d Mon Sep 17 00:00:00 2001 From: Gxkl Date: Tue, 5 Nov 2024 18:53:36 +0800 Subject: [PATCH] fix: remove inner class hook (#257) --- .../standalone/src/LoadUnitInnerClassHook.ts | 26 ------------------- standalone/standalone/src/Runner.ts | 9 ------- standalone/standalone/test/index.test.ts | 6 ++++- 3 files changed, 5 insertions(+), 36 deletions(-) delete mode 100644 standalone/standalone/src/LoadUnitInnerClassHook.ts diff --git a/standalone/standalone/src/LoadUnitInnerClassHook.ts b/standalone/standalone/src/LoadUnitInnerClassHook.ts deleted file mode 100644 index 6fddd4a5..00000000 --- a/standalone/standalone/src/LoadUnitInnerClassHook.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { LifecycleHook } from '@eggjs/tegg-lifecycle'; -import { - EggPrototypeFactory, - LoadUnit, - LoadUnitLifecycleContext, - EggPrototypeCreatorFactory, -} from '@eggjs/tegg-metadata'; -import { EggProtoImplClass } from '@eggjs/tegg'; -import { EggObjectFactory } from '@eggjs/tegg-dynamic-inject-runtime'; - -const INNER_CLASS_LIST = [ - EggObjectFactory, -]; - -export class LoadUnitInnerClassHook implements LifecycleHook { - async postCreate(_: LoadUnitLifecycleContext, loadUnit: LoadUnit): Promise { - if (loadUnit.type === 'StandaloneLoadUnitType') { - for (const clazz of INNER_CLASS_LIST) { - const protos = await EggPrototypeCreatorFactory.createProto(clazz as EggProtoImplClass, loadUnit); - for (const proto of protos) { - EggPrototypeFactory.instance.registerPrototype(proto, loadUnit); - } - } - } - } -} diff --git a/standalone/standalone/src/Runner.ts b/standalone/standalone/src/Runner.ts index c845a237..ca6c677b 100644 --- a/standalone/standalone/src/Runner.ts +++ b/standalone/standalone/src/Runner.ts @@ -38,7 +38,6 @@ import { InnerObject, StandaloneLoadUnit, StandaloneLoadUnitType } from './Stand import { StandaloneContext } from './StandaloneContext'; import { StandaloneContextHandler } from './StandaloneContextHandler'; import { ConfigSourceLoadUnitHook } from './ConfigSourceLoadUnitHook'; -import { LoadUnitInnerClassHook } from './LoadUnitInnerClassHook'; import { DalTableEggPrototypeHook } from '@eggjs/tegg-dal-plugin/lib/DalTableEggPrototypeHook'; import { DalModuleLoadUnitHook } from '@eggjs/tegg-dal-plugin/lib/DalModuleLoadUnitHook'; import { MysqlDataSourceManager } from '@eggjs/tegg-dal-plugin/lib/MysqlDataSourceManager'; @@ -77,7 +76,6 @@ export class Runner { private dalModuleLoadUnitHook: DalModuleLoadUnitHook; private transactionPrototypeHook: TransactionPrototypeHook; - private readonly loadUnitInnerClassHook: LoadUnitInnerClassHook; private readonly crosscutAdviceFactory: CrosscutAdviceFactory; private readonly loadUnitAopHook: LoadUnitAopHook; private readonly eggPrototypeCrossCutHook: EggPrototypeCrossCutHook; @@ -155,9 +153,6 @@ export class Runner { const configSourceEggPrototypeHook = new ConfigSourceLoadUnitHook(); LoadUnitLifecycleUtil.registerLifecycle(configSourceEggPrototypeHook); - this.loadUnitInnerClassHook = new LoadUnitInnerClassHook(); - LoadUnitLifecycleUtil.registerLifecycle(this.loadUnitInnerClassHook); - // TODO refactor with egg module // aop runtime this.crosscutAdviceFactory = new CrosscutAdviceFactory(); @@ -270,10 +265,6 @@ export class Runner { LoadUnitLifecycleUtil.deleteLifecycle(this.configSourceEggPrototypeHook); } - if (this.loadUnitInnerClassHook) { - LoadUnitLifecycleUtil.deleteLifecycle(this.loadUnitInnerClassHook); - } - if (this.eggPrototypeCrossCutHook) { EggPrototypeLifecycleUtil.deleteLifecycle(this.eggPrototypeCrossCutHook); } diff --git a/standalone/standalone/test/index.test.ts b/standalone/standalone/test/index.test.ts index beefca8f..00e73494 100644 --- a/standalone/standalone/test/index.test.ts +++ b/standalone/standalone/test/index.test.ts @@ -175,7 +175,11 @@ describe('standalone/standalone/test/index.test.ts', () => { const fixturePath = path.join(__dirname, './fixtures/dynamic-inject-module'); it('should work', async () => { - const msgs = await main(fixturePath); + const msgs = await main(fixturePath, { + dependencies: [ + { baseDir: path.join(__dirname, '..'), extraFilePattern: [ '!**/test' ] }, + ], + }); assert.deepEqual(msgs, [ 'hello, foo(context:0)', 'hello, bar(context:0)',