From cccda85fc7688c9cfe3b9bdd45681579f23460f4 Mon Sep 17 00:00:00 2001 From: Chris Barber Date: Fri, 26 Jan 2024 01:16:03 -0600 Subject: [PATCH] Maybe fixed hook system --- src/cli.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/cli.js b/src/cli.js index e4f339bf..cce6d0a8 100644 --- a/src/cli.js +++ b/src/cli.js @@ -264,7 +264,7 @@ export class CLI { * @access public */ createHook(name, ctx, fn) { - let dataPayload = {}; + let dataPayload; if (typeof ctx === 'function') { fn = ctx; @@ -274,8 +274,11 @@ export class CLI { ctx = null; } + const hookType = typeof fn === 'function' ? 'function' : 'event'; + this.debugLogger.trace(`Creating ${hookType} hook "${name}"`); + return (...args) => { - let data = Object.assign(dataPayload, { + let data = Object.assign(dataPayload || {}, { type: name, args, fn, @@ -285,6 +288,8 @@ export class CLI { const pres = this.hooks.pre[name] || []; const posts = this.hooks.post[name] || []; + this.debugLogger.trace(`Firing ${hookType} hook "${name}" pres=${pres.length}, posts=${posts.length}`); + (async () => { // call all pre filters await pres