diff --git a/packages/frontend-app-api/package.json b/packages/frontend-app-api/package.json index 5fb84070d4..477cf8f736 100644 --- a/packages/frontend-app-api/package.json +++ b/packages/frontend-app-api/package.json @@ -42,6 +42,7 @@ "@backstage/plugin-graphiql": "workspace:^", "@backstage/theme": "workspace:^", "@backstage/types": "workspace:^", + "@backstage/version-bridge": "workspace:^", "@material-ui/core": "^4.12.4", "@material-ui/icons": "^4.11.3", "@types/react": "^16.13.1 || ^17.0.0", diff --git a/packages/frontend-app-api/src/wiring/createApp.tsx b/packages/frontend-app-api/src/wiring/createApp.tsx index 4f32bc2219..540b47849f 100644 --- a/packages/frontend-app-api/src/wiring/createApp.tsx +++ b/packages/frontend-app-api/src/wiring/createApp.tsx @@ -85,6 +85,7 @@ import { BrowserRouter, Route } from 'react-router-dom'; import { SidebarItem } from '@backstage/core-components'; import { DarkTheme, LightTheme } from '../extensions/themes'; import { extractRouteInfoFromInstanceTree } from '../routing/extractRouteInfoFromInstanceTree'; +import { getOrCreateGlobalSingleton } from '@backstage/version-bridge'; /** @public */ export interface ExtensionTreeNode { @@ -336,25 +337,40 @@ export function createApp(options: { }; } +// Make sure that we only convert each new plugin instance to its legacy equivalent once +const legacyPluginStore = getOrCreateGlobalSingleton( + 'legacy-plugin-compatibility-store', + () => new WeakMap(), +); + export function toLegacyPlugin(plugin: BackstagePlugin): LegacyBackstagePlugin { + let legacy = legacyPluginStore.get(plugin); + if (legacy) { + return legacy; + } + const errorMsg = 'Not implemented in legacy plugin compatibility layer'; const notImplemented = () => { throw new Error(errorMsg); }; - return { + + legacy = { getId(): string { return plugin.id; }, - get routes(): never { - throw new Error(errorMsg); + get routes() { + return {}; }, - get externalRoutes(): never { - throw new Error(errorMsg); + get externalRoutes() { + return {}; }, getApis: notImplemented, getFeatureFlags: notImplemented, provide: notImplemented, }; + + legacyPluginStore.set(plugin, legacy); + return legacy; } function createLegacyAppContext(plugins: BackstagePlugin[]): AppContext { diff --git a/yarn.lock b/yarn.lock index 8f0279aff3..37455d3e56 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4311,6 +4311,7 @@ __metadata: "@backstage/test-utils": "workspace:^" "@backstage/theme": "workspace:^" "@backstage/types": "workspace:^" + "@backstage/version-bridge": "workspace:^" "@material-ui/core": ^4.12.4 "@material-ui/icons": ^4.11.3 "@testing-library/jest-dom": ^5.10.1