Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: forwards compatibility for config reload #773

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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