diff --git a/packages/core/server/src/commands/pm.ts b/packages/core/server/src/commands/pm.ts index 9befc0112..b420500f2 100644 --- a/packages/core/server/src/commands/pm.ts +++ b/packages/core/server/src/commands/pm.ts @@ -12,7 +12,7 @@ export default (app: Application) => { pm.command('add') .arguments('plugin') .action(async (plugin) => { - await app.pm.add(plugin); + await app.pm.add(plugin, {}, true); }); pm.command('enable') diff --git a/packages/core/server/src/plugin-manager/plugin-manager.ts b/packages/core/server/src/plugin-manager/plugin-manager.ts index 83f955686..c1f516572 100644 --- a/packages/core/server/src/plugin-manager/plugin-manager.ts +++ b/packages/core/server/src/plugin-manager/plugin-manager.ts @@ -189,7 +189,7 @@ export class PluginManager { await run('yarn', ['install']); } - async add(plugin?: any, options: any = {}) { + async add(plugin?: any, options: any = {}, insert = false) { if (this.has(plugin)) { const name = typeof plugin === 'string' ? plugin : plugin.name; this.app.log.warn(`plugin [${name}] added`); @@ -211,6 +211,17 @@ export class PluginManager { if (options.name) { this.pluginAliases.set(options.name, instance); } + if (insert && options.name) { + const packageName = PluginManager.getPackageName(options.name); + const packageJson = PluginManager.getPackageJson(packageName); + await this.repository.updateOrCreate({ + values: { + ...options, + version: packageJson.version, + }, + filterKeys: ['name'], + }); + } await instance.afterAdd(); }