From d001280383f5d7c3dda06826ad256e28b20e293f Mon Sep 17 00:00:00 2001 From: jay Date: Mon, 19 Apr 2021 13:15:25 +0500 Subject: [PATCH] fix: :goal_net: 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` --- lib/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 6942b7b..72d5454 100644 --- a/lib/index.js +++ b/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] }