From 137a6c1b616dcbb1eca90c5cfab171f68573c719 Mon Sep 17 00:00:00 2001 From: Brad Cornes Date: Wed, 5 May 2021 16:25:36 +0100 Subject: [PATCH] bust user plugin cache? fixes classes not updating when plugin is changed --- src/server.ts | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/server.ts b/src/server.ts index 5f14ebd..1651cbe 100644 --- a/src/server.ts +++ b/src/server.ts @@ -536,6 +536,7 @@ async function createProjectService( let userPurge let userVariants: any let userMode: any + let userPlugins: any let hook = new Hook(fs.realpathSync(state.configPath), (exports) => { userSeperator = dlv(exports, sepLocation) if (typeof userSeperator !== 'string') { @@ -560,25 +561,33 @@ async function createProjectService( // inject JIT `matchUtilities` function if (Array.isArray(exports.plugins)) { - for (let index in exports.plugins) { - let plugin = exports.plugins[index] + userPlugins = exports.plugins + exports.plugins = exports.plugins.map((plugin) => { if (typeof plugin === 'function') { - exports.plugins[index] = (...args) => { + let newPlugin = (...args) => { if (!args[0].matchUtilities) { args[0].matchUtilities = () => {} } return plugin(...args) } - } else if (plugin.handler) { - let oldHandler = plugin.handler - plugin.handler = (...args) => { - if (!args[0].matchUtilities) { - args[0].matchUtilities = () => {} - } - return oldHandler(...args) + // @ts-ignore + newPlugin.__intellisense_cache_bust = Math.random() + return newPlugin + } + if (plugin.handler) { + return { + ...plugin, + handler: (...args) => { + if (!args[0].matchUtilities) { + args[0].matchUtilities = () => {} + } + return plugin.handler(...args) + }, + __intellisense_cache_bust: Math.random(), } } - } + return plugin + }) } return exports @@ -640,6 +649,9 @@ async function createProjectService( if (typeof userMode !== 'undefined') { config.mode = userMode } + if (typeof userPlugins !== 'undefined') { + config.plugins = userPlugins + } if (state.dependencies) { watcher.unwatch(state.dependencies)