From 5bdae05d17df0e791ea78bef45ef7223d77e3902 Mon Sep 17 00:00:00 2001 From: Cristian Dominguez Date: Tue, 30 Jul 2024 16:22:12 -0300 Subject: [PATCH 1/2] feat: add `plugins:post`* hooks --- src/commands/plugins/install.ts | 8 +++++++- src/commands/plugins/uninstall.ts | 11 ++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/commands/plugins/install.ts b/src/commands/plugins/install.ts index 8b876f99..bf1e28b7 100644 --- a/src/commands/plugins/install.ts +++ b/src/commands/plugins/install.ts @@ -1,5 +1,5 @@ /* eslint-disable no-await-in-loop */ -import {Args, Command, Errors, Flags, Interfaces, ux} from '@oclif/core' +import {Args, Command, Errors, Flags, Interfaces, Plugin, ux} from '@oclif/core' import {bold, cyan} from 'ansis' import validate from 'validate-npm-package-name' @@ -195,6 +195,12 @@ Use the <%= config.scopedEnvVarKey('NPM_REGISTRY') %> environment variable to se throw error } + const pluginInstance = new Plugin(plugin) + await pluginInstance.load() + this.config.plugins.set(pluginInstance.name, pluginInstance) + + await this.config.runHook('plugins:postinstall', {}) + ux.action.stop(`installed v${plugin.version}`) } } diff --git a/src/commands/plugins/uninstall.ts b/src/commands/plugins/uninstall.ts index 66766130..4cf202b4 100644 --- a/src/commands/plugins/uninstall.ts +++ b/src/commands/plugins/uninstall.ts @@ -48,6 +48,8 @@ export default class PluginsUninstall extends Command { logLevel: determineLogLevel(this.config, flags, 'silent'), }) + let pluginNameToDelete: string | undefined + if (argv.length === 0) argv.push('.') for (const plugin of argv as string[]) { const friendly = removeTags(plugins.friendlyName(plugin)) @@ -64,9 +66,10 @@ export default class PluginsUninstall extends Command { try { const {name} = unfriendly - const displayName = friendly === '.' ? name : friendly ?? name + const displayName = friendly === '.' ? name : (friendly ?? name) ux.action.start(`${this.config.name}: Uninstalling ${displayName}`) await plugins.uninstall(name) + pluginNameToDelete = name } catch (error) { ux.action.stop(bold.red('failed')) throw error @@ -74,5 +77,11 @@ export default class PluginsUninstall extends Command { ux.action.stop() } + + if (pluginNameToDelete) { + this.config.plugins.delete(pluginNameToDelete) + } + + await this.config.runHook('plugins:postuninstall', {}) } } From 1eff0f5818ace23fa6edb372fef1db5728aa19de Mon Sep 17 00:00:00 2001 From: Cristian Dominguez Date: Tue, 30 Jul 2024 16:58:45 -0300 Subject: [PATCH 2/2] fix: handle multiple uninstalls --- src/commands/plugins/uninstall.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/commands/plugins/uninstall.ts b/src/commands/plugins/uninstall.ts index 4cf202b4..6dd076f8 100644 --- a/src/commands/plugins/uninstall.ts +++ b/src/commands/plugins/uninstall.ts @@ -48,7 +48,7 @@ export default class PluginsUninstall extends Command { logLevel: determineLogLevel(this.config, flags, 'silent'), }) - let pluginNameToDelete: string | undefined + const pluginNameToDelete: string[] = [] if (argv.length === 0) argv.push('.') for (const plugin of argv as string[]) { @@ -69,7 +69,7 @@ export default class PluginsUninstall extends Command { const displayName = friendly === '.' ? name : (friendly ?? name) ux.action.start(`${this.config.name}: Uninstalling ${displayName}`) await plugins.uninstall(name) - pluginNameToDelete = name + pluginNameToDelete.push(name) } catch (error) { ux.action.stop(bold.red('failed')) throw error @@ -78,8 +78,8 @@ export default class PluginsUninstall extends Command { ux.action.stop() } - if (pluginNameToDelete) { - this.config.plugins.delete(pluginNameToDelete) + for (const p of pluginNameToDelete) { + this.config.plugins.delete(p) } await this.config.runHook('plugins:postuninstall', {})