From d8c8f17be80a3042e06dda4352d0d924f55d7b9a Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Wed, 9 Jun 2021 22:27:42 +0200 Subject: [PATCH] core-plugin-api: allow unknown plugin outputs for backwards compatibility Signed-off-by: Patrik Oldsberg --- packages/core-app-api/src/app/createApp.tsx | 3 ++- packages/core-app-api/src/app/types.ts | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/core-app-api/src/app/createApp.tsx b/packages/core-app-api/src/app/createApp.tsx index b93df63ff0..1670978791 100644 --- a/packages/core-app-api/src/app/createApp.tsx +++ b/packages/core-app-api/src/app/createApp.tsx @@ -35,6 +35,7 @@ import { BootErrorPageProps, ErrorBoundaryFallbackProps, } from './types'; +import { BackstagePlugin } from '@backstage/core-plugin-api'; /** * The default config loader, which expects that config is available at compile-time @@ -171,7 +172,7 @@ export function createApp(options?: AppOptions) { return new PrivateAppImpl({ apis, icons, - plugins, + plugins: plugins as BackstagePlugin[], components, themes, configLoader, diff --git a/packages/core-app-api/src/app/types.ts b/packages/core-app-api/src/app/types.ts index 02b62aef16..cf5811beae 100644 --- a/packages/core-app-api/src/app/types.ts +++ b/packages/core-app-api/src/app/types.ts @@ -24,6 +24,7 @@ import { RouteRef, SubRouteRef, ExternalRouteRef, + PluginOutput, } from '@backstage/core-plugin-api'; import { AppConfig } from '@backstage/config'; import { AppIcons } from './icons'; @@ -131,6 +132,21 @@ export type AppRouteBinder = < >, ) => void; +// Output from newer or older plugin API versions that might not be supported by +// this version of the app API, but we don't want to break at the type checking level. +// We only use this more permissive type for the `createApp` options, as we otherwise +// want to stick to using the type for the outputs that we know about in this version +// of the app api. +type UnknownPluginOutput = { + type: string; +}; +export type BackstagePluginWithAnyOutput = Omit< + BackstagePlugin, + 'output' +> & { + output(): (PluginOutput | UnknownPluginOutput)[]; +}; + export type AppOptions = { /** * A collection of ApiFactories to register in the application to either @@ -146,7 +162,7 @@ export type AppOptions = { /** * A list of all plugins to include in the app. */ - plugins?: BackstagePlugin[]; + plugins?: BackstagePluginWithAnyOutput[]; /** * Supply components to the app to override the default ones.