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`
master
jay 3 years ago
parent f50e388c39
commit d001280383
  1. 4
      lib/index.js

@ -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]
}

Loading…
Cancel
Save