Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(plugins): clean the legacy tree when uninstalling a failed plugin
Yudhi Armyndharis179fed648354
diff --git a/src/core/plugins/plugin-legacy-dir.spec.ts b/src/core/plugins/plugin-legacy-dir.spec.tsindex 85cda76a5..dc3cc0cf7 100644--- a/src/core/plugins/plugin-legacy-dir.spec.ts+++ b/src/core/plugins/plugin-legacy-dir.spec.ts@@ -105,6 +105,21 @@ describe('PluginLoaderService — a plugin loaded from the legacy plugins directexpect(next.getPlugin(manifest.id)).toBeUndefined();});+ it('uninstalls a legacy package that failed to load, so it does not load once the fault is fixed', async () => {+ // A package the boot scan could not load has no runtime record, so no recorded directory; the+ // loader must hand the uninstaller the legacy root or only the configured tree is cleaned.+ const broken = path.join(legacyDir, 'broken-plg');+ fs.mkdirSync(broken, { recursive: true });+ fs.writeFileSync(path.join(broken, 'manifest.json'), '{ not json');+ const fresh = makeLoader();+ fresh.onModuleInit();+ expect(fresh.getPlugin('broken-plg')).toBeUndefined();++ await fresh.uninstallPlugin('broken-plg');++ expect(fs.existsSync(broken)).toBe(false);+ });+it('resolves its package directory to the legacy tree', () => {expect(loader.getPluginPackageDir(manifest.id)).toBe(path.resolve(legacyDir, manifest.id));});diff --git a/src/core/plugins/plugin-loader.service.ts b/src/core/plugins/plugin-loader.service.tsindex 3e47f67a0..aed549ba2 100644--- a/src/core/plugins/plugin-loader.service.ts+++ b/src/core/plugins/plugin-loader.service.ts@@ -221,8 +221,13 @@ export class PluginLoaderService implements OnModuleInit, OnApplicationBootstrapthis.lastSandboxHookError,this.pluginsDir,);- this.uninstaller = new PluginUninstaller(this.logger, this.plugins, this.pluginStorage, this.pluginsDir, pluginId =>- this.lifecycle.unloadPlugin(pluginId),+ this.uninstaller = new PluginUninstaller(+ this.logger,+ this.plugins,+ this.pluginStorage,+ this.pluginsDir,+ pluginId => this.lifecycle.unloadPlugin(pluginId),+ this.legacyPluginsDir,);}