( plugin: string, scope: InstallableScope = 'user', )
| 319 | * @returns Result indicating success/failure |
| 320 | */ |
| 321 | export async function installPluginOp( |
| 322 | plugin: string, |
| 323 | scope: InstallableScope = 'user', |
| 324 | ): Promise<PluginOperationResult> { |
| 325 | assertInstallableScope(scope) |
| 326 | |
| 327 | const { name: pluginName, marketplace: marketplaceName } = |
| 328 | parsePluginIdentifier(plugin) |
| 329 | |
| 330 | // ── Search materialized marketplaces for the plugin ── |
| 331 | let foundPlugin: PluginMarketplaceEntry | undefined |
| 332 | let foundMarketplace: string | undefined |
| 333 | let marketplaceInstallLocation: string | undefined |
| 334 | |
| 335 | if (marketplaceName) { |
| 336 | const pluginInfo = await getPluginById(plugin) |
| 337 | if (pluginInfo) { |
| 338 | foundPlugin = pluginInfo.entry |
| 339 | foundMarketplace = marketplaceName |
| 340 | marketplaceInstallLocation = pluginInfo.marketplaceInstallLocation |
| 341 | } |
| 342 | } else { |
| 343 | const marketplaces = await loadKnownMarketplacesConfig() |
| 344 | for (const [mktName, mktConfig] of Object.entries(marketplaces)) { |
| 345 | try { |
| 346 | const marketplace = await getMarketplace(mktName) |
| 347 | const pluginEntry = marketplace.plugins.find(p => p.name === pluginName) |
| 348 | if (pluginEntry) { |
| 349 | foundPlugin = pluginEntry |
| 350 | foundMarketplace = mktName |
| 351 | marketplaceInstallLocation = mktConfig.installLocation |
| 352 | break |
| 353 | } |
| 354 | } catch (error) { |
| 355 | logError(toError(error)) |
| 356 | continue |
| 357 | } |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | if (!foundPlugin || !foundMarketplace) { |
| 362 | const location = marketplaceName |
| 363 | ? `marketplace "${marketplaceName}"` |
| 364 | : 'any configured marketplace' |
| 365 | return { |
| 366 | success: false, |
| 367 | message: `Plugin "${pluginName}" not found in ${location}`, |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | const entry = foundPlugin |
| 372 | const pluginId = `${entry.name}@${foundMarketplace}` |
| 373 | |
| 374 | const result = await installResolvedPlugin({ |
| 375 | pluginId, |
| 376 | entry, |
| 377 | scope, |
| 378 | marketplaceInstallLocation, |
no test coverage detected