fix: 🥅 fix a plugin loading error

While reloading, plugin cache may not be deleted.
This happens when a loaded plugin encounters an error during reload.
This causes a deadlock in the unloading code.

So make sure cache is always deleted:
- ignore when an `unload()` function doesn't exist
- delete cache even if there are no `exports`
This commit is contained in:
jay 2021-04-19 13:15:25 +05:00
parent f50e388c39
commit d001280383

View File

@ -47,7 +47,9 @@ function unloadplugin(pluginname, pluginpath) {
const plugin = require.resolve(pluginpath)
try {
if (plugin && require.cache[plugin]) {
require.cache[plugin].exports.unload()
// `unload()` isn't exported sometimes,
// when plugin isn't properly loaded
require.cache[plugin].exports?.unload?.()
delete plugins[pluginname]
delete require.cache[plugin]
}