Skip to content

Commit

Permalink
fix initPlugins not reassigning
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoobes committed May 21, 2024
1 parent e700297 commit 88598b0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
1 change: 0 additions & 1 deletion src/core/ioc/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]())
}
Expand Down
10 changes: 6 additions & 4 deletions src/handlers/event-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,14 @@ export function createResultResolver<Output>(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 = { ...module, ...partial };
return module;
_module = { ..._module, ...partial };
return _module;
},
deps
});
Expand All @@ -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 = {};
Expand Down
7 changes: 4 additions & 3 deletions src/handlers/ready.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
1 change: 0 additions & 1 deletion test/handlers/dispatchers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ function mockDeps() {
}
}



describe('eventDispatcher standard', () => {
let m: Processed<Module>;
Expand Down

0 comments on commit 88598b0

Please sign in to comment.