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.
This commit is contained in:
badrAZ
2019-11-08 15:27:22 +01:00
committed by Julien Fontanet
parent 10a631ec96
commit 41dbc20be9

View File

@@ -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) {