( pluginId: string, metadata: InstalledPlugin, scope: PersistableScope = 'user', projectPath?: string, )
| 882 | * @param projectPath - Project path (for project/local scopes) |
| 883 | */ |
| 884 | export function addInstalledPlugin( |
| 885 | pluginId: string, |
| 886 | metadata: InstalledPlugin, |
| 887 | scope: PersistableScope = 'user', |
| 888 | projectPath?: string, |
| 889 | ): void { |
| 890 | const v2Data = loadInstalledPluginsFromDisk() |
| 891 | const v2Entry: PluginInstallationEntry = { |
| 892 | scope, |
| 893 | installPath: metadata.installPath, |
| 894 | version: metadata.version, |
| 895 | installedAt: metadata.installedAt, |
| 896 | lastUpdated: metadata.lastUpdated, |
| 897 | gitCommitSha: metadata.gitCommitSha, |
| 898 | ...(projectPath && { projectPath }), |
| 899 | } |
| 900 | |
| 901 | // Get or create array for this plugin (preserves other scope installations) |
| 902 | const installations = v2Data.plugins[pluginId] || [] |
| 903 | |
| 904 | // Find existing entry for this scope+projectPath |
| 905 | const existingIndex = installations.findIndex( |
| 906 | entry => entry.scope === scope && entry.projectPath === projectPath, |
| 907 | ) |
| 908 | |
| 909 | const isUpdate = existingIndex >= 0 |
| 910 | if (isUpdate) { |
| 911 | installations[existingIndex] = v2Entry |
| 912 | } else { |
| 913 | installations.push(v2Entry) |
| 914 | } |
| 915 | |
| 916 | v2Data.plugins[pluginId] = installations |
| 917 | saveInstalledPluginsV2(v2Data) |
| 918 | |
| 919 | logForDebugging( |
| 920 | `${isUpdate ? 'Updated' : 'Added'} installed plugin: ${pluginId} (scope: ${scope})`, |
| 921 | ) |
| 922 | } |
| 923 | |
| 924 | /** |
| 925 | * Remove a plugin from the installed plugins registry |
no test coverage detected