From 41dbc20be9340d95f8912e5e147b992989205c8d Mon Sep 17 00:00:00 2001 From: badrAZ Date: Fri, 8 Nov 2019 15:27:22 +0100 Subject: [PATCH] fix(xo-server/plugins): try empty config if none provided (#4647) Required by #4581 Plugins with optional configuration should be loadable without explicit user configuration. --- packages/xo-server/src/xo-mixins/plugins.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/xo-server/src/xo-mixins/plugins.js b/packages/xo-server/src/xo-mixins/plugins.js index 466a71080..c2237c978 100644 --- a/packages/xo-server/src/xo-mixins/plugins.js +++ b/packages/xo-server/src/xo-mixins/plugins.js @@ -60,7 +60,7 @@ export default class { const plugin = (this._plugins[id] = { configurationPresets, configurationSchema, - configured: !configurationSchema, + configured: configurationSchema === undefined, description, id, instance, @@ -84,12 +84,17 @@ export default class { }) } - if (configurationSchema !== undefined) { - if (configuration === undefined) { - return + if (!plugin.configured) { + const tryEmptyConfig = configuration === undefined + try { + await this._configurePlugin(plugin, tryEmptyConfig ? {} : configuration) + } catch (error) { + // dont throw any error in case the empty config did not work + if (tryEmptyConfig) { + return + } + throw error } - - await this._configurePlugin(plugin, configuration) } if (autoload) {