cli: switch package discovery to use global

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-09-05 16:24:58 +02:00
parent 1e5238ceae
commit e036ff862e
2 changed files with 12 additions and 5 deletions
@@ -16,15 +16,22 @@
import { BackstagePlugin } from '@backstage/frontend-plugin-api';
// eslint-disable-next-line @backstage/no-undeclared-imports
import { modules } from '__backstage-autodetected-plugins__';
interface DiscoveryGlobal {
modules: Array<{ name: string; module: object }>;
}
/**
* @public
*/
export function getAvailablePlugins(): BackstagePlugin[] {
return modules.flatMap(({ module: mod }) =>
Object.values(mod).flatMap(val => (isBackstagePlugin(val) ? [val] : [])),
const discovered = (
window as { '__@backstage/discovered__'?: DiscoveryGlobal }
)['__@backstage/discovered__'];
return (
discovered?.modules.flatMap(({ module: mod }) =>
Object.values(mod).flatMap(val => (isBackstagePlugin(val) ? [val] : [])),
) ?? []
);
}