Skip to content

Commit

Permalink
feat: forwards compatibility for config reload (#773)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley authored Aug 29, 2023
1 parent bb971e4 commit b751bbe
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,21 @@ export class Config implements IConfig {
private _commandIDs!: string[]

constructor(public options: Options) {
if (options.config) Object.assign(this, options.config)
if (options.config) {
if (Array.isArray(options.config.plugins) && Array.isArray(this.plugins)) {
// incoming config is v2 with plugins array and this config is v2 with plugins array
Object.assign(this, options.config)
} else if (Array.isArray(options.config.plugins) && !Array.isArray(this.plugins)) {
// incoming config is v2 with plugins array and this config is v3 with plugin Map
Object.assign(this, options.config, {plugins: new Map(options.config.plugins.map(p => [p.name, p]))})
} else if (!Array.isArray(options.config.plugins) && Array.isArray(this.plugins)) {
// incoming config is v3 with plugin Map and this config is v2 with plugins array
Object.assign(this, options.config, {plugins: options.config.getPluginsList()})
} else {
// incoming config is v3 with plugin Map and this config is v3 with plugin Map
Object.assign(this, options.config)
}
}
}

static async load(opts: LoadOptions = module.filename || __dirname): Promise<Config> {
Expand Down

0 comments on commit b751bbe

Please sign in to comment.