From 88598b0948943770620cdff32c44e55ba5c93829 Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Tue, 21 May 2024 00:35:19 -0500 Subject: [PATCH] fix initPlugins not reassigning --- src/core/ioc/container.ts | 1 - src/handlers/event-utils.ts | 10 ++++++---- src/handlers/ready.ts | 7 ++++--- test/handlers/dispatchers.test.ts | 1 - 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/core/ioc/container.ts b/src/core/ioc/container.ts index 8a41e70..2a959fe 100644 --- a/src/core/ioc/container.ts +++ b/src/core/ioc/container.ts @@ -26,7 +26,6 @@ export class Container { } private registerHooks(hookname: string, insert: object) { if(hasCallableMethod(insert, hookname)) { - console.log(hookname) //@ts-ignore this.addHook(hookname, () => insert[hookname]()) } diff --git a/src/handlers/event-utils.ts b/src/handlers/event-utils.ts index 66b47ae..26cc93a 100644 --- a/src/handlers/event-utils.ts +++ b/src/handlers/event-utils.ts @@ -199,13 +199,14 @@ export function createResultResolver(config: { }; }; export async function callInitPlugins(module: Module, deps: Dependencies, sEmitter?: Emitter) { - for(const plugin of module.plugins) { + let _module = module; + for(const plugin of _module.plugins ?? []) { const res = await plugin.execute({ module, - absPath: module.meta.absPath , + absPath: _module.meta.absPath , updateModule: (partial: Partial) => { - module = { ...module, ...partial }; - return module; + _module = { ..._module, ...partial }; + return _module; }, deps }); @@ -214,6 +215,7 @@ export async function callInitPlugins(module: Module, deps: Dependencies, sEmitt throw Error("Plugin failed with controller.stop()"); } } + return _module } async function callPlugins({ args, module, deps }: ExecutePayload) { let state = {}; diff --git a/src/handlers/ready.ts b/src/handlers/ready.ts index 41c7af3..c8fa11b 100644 --- a/src/handlers/ready.ts +++ b/src/handlers/ready.ts @@ -24,10 +24,11 @@ export default async function(dir: string, deps : UnpackedDependencies) { if(!validType) { throw Error(`Found ${module.name} at ${module.meta.absPath}, which has incorrect \`type\``); } - await callInitPlugins(module, deps, sEmitter); + const resultModule = await callInitPlugins(module, deps, sEmitter); + console.log(resultModule) // FREEZE! no more writing!! - commands.set(module.meta.id, Object.freeze(module)); - sEmitter.emit('module.register', resultPayload(PayloadType.Success, module)); + commands.set(resultModule.meta.id, Object.freeze(resultModule)); + sEmitter.emit('module.register', resultPayload(PayloadType.Success, resultModule)); } sEmitter.emit('modulesLoaded'); } diff --git a/test/handlers/dispatchers.test.ts b/test/handlers/dispatchers.test.ts index 325eff3..9337d7e 100644 --- a/test/handlers/dispatchers.test.ts +++ b/test/handlers/dispatchers.test.ts @@ -24,7 +24,6 @@ function mockDeps() { } } - describe('eventDispatcher standard', () => { let m: Processed;