From 0eafa251ae8c53ac0fd5b30cd313a43fddd1ab6d Mon Sep 17 00:00:00 2001 From: David Park Date: Fri, 2 Apr 2021 15:08:32 +0700 Subject: [PATCH] wrap hooks so that plugins can add custom hooks, this fixes some incremental builds --- WrappedPlugin/index.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/WrappedPlugin/index.js b/WrappedPlugin/index.js index 64875f1..738907c 100644 --- a/WrappedPlugin/index.js +++ b/WrappedPlugin/index.js @@ -152,10 +152,24 @@ const wrapHooks = (orig, pluginName, smp, type) => { acc[method] = genProxy(method); return acc; }, {}); - - wrappedHooks.push({ orig: hooks, wrapped, pluginName }); - - return wrapped; + const wrappedProxy = new Proxy(wrapped, { + get: (target, property) => { + return Reflect.get(target, property); + }, + set: (target, property, value) => { + Reflect.set(hooks, property, value); + const wrappedHook = value; // genProxy(property); // unsure why, but genProxy on custom hooks hang the build + Reflect.set(target, property, wrappedHook); + return wrappedHook; + }, + deleteProperty: (target, property) => { + return Reflect.deleteProperty(target, property); + }, + }) + + wrappedHooks.push({ orig: hooks, wrapped: wrappedProxy, pluginName }); + + return wrappedProxy; }; const construcNamesToWrap = [