fix(plugin-manager): make plugin search resilient to bad queries and fetch errors (#11956)

This commit is contained in:
Rajkamal authored and GitHub committed 2026-11-23 23:39:13 +01:00
1 parent 7c89270367
commit 24a38c4089
2 files changed
+17 -4

No files matched your search

@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'
import { BehaviorSubject, Observable, debounceTime, distinctUntilChanged, first, tap, switchMap, map } from 'rxjs'
import { BehaviorSubject, Observable, debounceTime, distinctUntilChanged, first, finalize, switchMap, map } from 'rxjs'
import semverGt from 'semver/functions/gt'
import { Component, HostBinding, Input } from '@angular/core'
@@ -50,7 +50,7 @@ export class PluginsSettingsTabComponent {
distinctUntilChanged(),
switchMap(query => {
this.availablePluginsReady = false
return this.pluginManager.listAvailable(query).pipe(tap(() => {
return this.pluginManager.listAvailable(query).pipe(finalize(() => {
this.availablePluginsReady = true
}))
}),
@@ -1,5 +1,5 @@
import { compare as semverCompare, valid as semverValid } from 'semver'
import { Observable, from, forkJoin, map, of } from 'rxjs'
import { Observable, from, forkJoin, map, of, catchError } from 'rxjs'
import { Injectable, Inject } from '@angular/core'
import { Logger, LogService, PlatformService, BOOTSTRAP_DATA, BootstrapData, PluginInfo } from 'tabby-core'
import { PLUGIN_BLACKLIST } from '../../../app/src/pluginBlacklist'
@@ -50,7 +50,16 @@ export class PluginManagerService {
_listAvailableInternal (namePrefix: string, keyword: string, query?: string): Observable<PluginInfo[]> {
return from(
fetch(`https://registry.npmjs.com/-/v1/search?text=keywords%3A${keyword}%20${query}&size=250`).then(r => r.json()),
fetch(`https://registry.npmjs.com/-/v1/search?text=${encodeURIComponent(`keywords:${keyword} ${query ?? ''}`)}&size=250`).then(async r => {
if (!r.ok) {
throw new Error(`npm search failed: ${r.status}`)
}
const response = await r.json()
if (!Array.isArray(response.objects)) {
throw new Error('npm search returned an invalid response')
}
return response
}),
).pipe(
map(response => response.objects
.filter(item => !item.keywords?.includes('tabby-dummy-transition-plugin'))
@@ -80,6 +89,10 @@ export class PluginManagerService {
})
}),
map(plugins => plugins.sort((a, b) => a.name.localeCompare(b.name))),
catchError(err => {
this.logger.error('Failed to search available plugins', err)
return of<PluginInfo[]>([])
}),
)
}