( plugin: string, scope: InstallableScope = 'user', deleteDataDir = true, )
| 425 | * @returns Result indicating success/failure |
| 426 | */ |
| 427 | export async function uninstallPluginOp( |
| 428 | plugin: string, |
| 429 | scope: InstallableScope = 'user', |
| 430 | deleteDataDir = true, |
| 431 | ): Promise<PluginOperationResult> { |
| 432 | // Validate scope at runtime for early error detection |
| 433 | assertInstallableScope(scope) |
| 434 | |
| 435 | const { enabled, disabled } = await loadAllPlugins() |
| 436 | const allPlugins = [...enabled, ...disabled] |
| 437 | |
| 438 | // Find the plugin |
| 439 | const foundPlugin = findPluginByIdentifier(plugin, allPlugins) |
| 440 | |
| 441 | const settingSource = scopeToSettingSource(scope) |
| 442 | const settings = getSettingsForSource(settingSource) |
| 443 | |
| 444 | let pluginId: string |
| 445 | let pluginName: string |
| 446 | |
| 447 | if (foundPlugin) { |
| 448 | // Find the matching settings key for this plugin (may differ from `plugin` |
| 449 | // if user gave short name but settings has plugin@marketplace) |
| 450 | pluginId = |
| 451 | Object.keys(settings?.enabledPlugins ?? {}).find( |
| 452 | k => |
| 453 | k === plugin || |
| 454 | k === foundPlugin.name || |
| 455 | k.startsWith(`${foundPlugin.name}@`), |
| 456 | ) ?? (plugin.includes('@') ? plugin : foundPlugin.name) |
| 457 | pluginName = foundPlugin.name |
| 458 | } else { |
| 459 | // Plugin not found via marketplace lookup — it may have been delisted. |
| 460 | // Fall back to installed_plugins.json (V2) which tracks installations |
| 461 | // independently of marketplace state. |
| 462 | const resolved = resolveDelistedPluginId(plugin) |
| 463 | if (!resolved) { |
| 464 | return { |
| 465 | success: false, |
| 466 | message: `Plugin "${plugin}" not found in installed plugins`, |
| 467 | } |
| 468 | } |
| 469 | pluginId = resolved.pluginId |
| 470 | pluginName = resolved.pluginName |
| 471 | } |
| 472 | |
| 473 | // Check if the plugin is installed in this scope (in V2 file) |
| 474 | const projectPath = getProjectPathForScope(scope) |
| 475 | const installedData = loadInstalledPluginsV2() |
| 476 | const installations = installedData.plugins[pluginId] |
| 477 | const scopeInstallation = installations?.find( |
| 478 | i => i.scope === scope && i.projectPath === projectPath, |
| 479 | ) |
| 480 | |
| 481 | if (!scopeInstallation) { |
| 482 | // Try to find where the plugin is actually installed to provide a helpful error |
| 483 | const { scope: actualScope } = getPluginInstallationFromV2(pluginId) |
| 484 | if (actualScope !== scope && installations && installations.length > 0) { |
no test coverage detected