Skip to content

Commit 137a6c1

Browse files
committed
bust user plugin cache?
fixes classes not updating when plugin is changed
1 parent fb2e9d9 commit 137a6c1

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

src/server.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ async function createProjectService(
536536
let userPurge
537537
let userVariants: any
538538
let userMode: any
539+
let userPlugins: any
539540
let hook = new Hook(fs.realpathSync(state.configPath), (exports) => {
540541
userSeperator = dlv(exports, sepLocation)
541542
if (typeof userSeperator !== 'string') {
@@ -560,25 +561,33 @@ async function createProjectService(
560561

561562
// inject JIT `matchUtilities` function
562563
if (Array.isArray(exports.plugins)) {
563-
for (let index in exports.plugins) {
564-
let plugin = exports.plugins[index]
564+
userPlugins = exports.plugins
565+
exports.plugins = exports.plugins.map((plugin) => {
565566
if (typeof plugin === 'function') {
566-
exports.plugins[index] = (...args) => {
567+
let newPlugin = (...args) => {
567568
if (!args[0].matchUtilities) {
568569
args[0].matchUtilities = () => {}
569570
}
570571
return plugin(...args)
571572
}
572-
} else if (plugin.handler) {
573-
let oldHandler = plugin.handler
574-
plugin.handler = (...args) => {
575-
if (!args[0].matchUtilities) {
576-
args[0].matchUtilities = () => {}
577-
}
578-
return oldHandler(...args)
573+
// @ts-ignore
574+
newPlugin.__intellisense_cache_bust = Math.random()
575+
return newPlugin
576+
}
577+
if (plugin.handler) {
578+
return {
579+
...plugin,
580+
handler: (...args) => {
581+
if (!args[0].matchUtilities) {
582+
args[0].matchUtilities = () => {}
583+
}
584+
return plugin.handler(...args)
585+
},
586+
__intellisense_cache_bust: Math.random(),
579587
}
580588
}
581-
}
589+
return plugin
590+
})
582591
}
583592

584593
return exports
@@ -640,6 +649,9 @@ async function createProjectService(
640649
if (typeof userMode !== 'undefined') {
641650
config.mode = userMode
642651
}
652+
if (typeof userPlugins !== 'undefined') {
653+
config.plugins = userPlugins
654+
}
643655

644656
if (state.dependencies) {
645657
watcher.unwatch(state.dependencies)

0 commit comments

Comments
 (0)