Plugin reload now properly invalidates cached files

This commit is contained in:
Gregory Schier committed 2018-04-05 16:54:11 -04:00
1 parent 1fca65005e
commit d7db623c66
1 file changed
+7 -2
+7 -2
View File
@@ -100,8 +100,14 @@ export async function getPlugins (force: boolean = false): Promise<Array<Plugin>
continue;
}
// Delete `require` cache if plugin has been required before
for (const p of Object.keys(global.require.cache)) {
if (p.indexOf(modulePath) === 0) {
delete global.require.cache[p];
}
}
// Use global.require() instead of require() because Webpack wraps require()
delete global.require.cache[global.require.resolve(packageJSONPath)];
const pluginJson = global.require(packageJSONPath);
// Not an Insomnia plugin because it doesn't have the package.json['insomnia']
@@ -110,7 +116,6 @@ export async function getPlugins (force: boolean = false): Promise<Array<Plugin>
}
// Delete require cache entry and re-require
delete global.require.cache[global.require.resolve(modulePath)];
const module = global.require(modulePath);
pluginMap[pluginJson.name] = _initPlugin(pluginJson || {}, module, modulePath);