frontend-plugin-api: add OverridableFrontendPlugin type
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -88,8 +88,12 @@ export type FrontendPluginInfoOptions = {
|
||||
manifest?: () => Promise<JsonObject>;
|
||||
};
|
||||
|
||||
/** @public */
|
||||
export interface FrontendPlugin<
|
||||
/**
|
||||
* A variant of the {@link FrontendPlugin} interface that can also be used to install overrides for the plugin.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface OverridableFrontendPlugin<
|
||||
TRoutes extends { [name in string]: RouteRef | SubRouteRef } = {
|
||||
[name in string]: RouteRef | SubRouteRef;
|
||||
},
|
||||
@@ -99,6 +103,26 @@ export interface FrontendPlugin<
|
||||
TExtensionMap extends { [id in string]: ExtensionDefinition } = {
|
||||
[id in string]: ExtensionDefinition;
|
||||
},
|
||||
> extends FrontendPlugin<TRoutes, TExternalRoutes> {
|
||||
getExtension<TId extends keyof TExtensionMap>(id: TId): TExtensionMap[TId];
|
||||
withOverrides(options: {
|
||||
extensions: Array<ExtensionDefinition>;
|
||||
|
||||
/**
|
||||
* Overrides the original info loaders of the plugin one by one.
|
||||
*/
|
||||
info?: FrontendPluginInfoOptions;
|
||||
}): OverridableFrontendPlugin<TRoutes, TExternalRoutes, TExtensionMap>;
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export interface FrontendPlugin<
|
||||
TRoutes extends { [name in string]: RouteRef | SubRouteRef } = {
|
||||
[name in string]: RouteRef | SubRouteRef;
|
||||
},
|
||||
TExternalRoutes extends { [name in string]: ExternalRouteRef } = {
|
||||
[name in string]: ExternalRouteRef;
|
||||
},
|
||||
> {
|
||||
readonly $$type: '@backstage/FrontendPlugin';
|
||||
readonly id: string;
|
||||
@@ -109,15 +133,6 @@ export interface FrontendPlugin<
|
||||
* Loads the plugin info.
|
||||
*/
|
||||
info(): Promise<FrontendPluginInfo>;
|
||||
getExtension<TId extends keyof TExtensionMap>(id: TId): TExtensionMap[TId];
|
||||
withOverrides(options: {
|
||||
extensions: Array<ExtensionDefinition>;
|
||||
|
||||
/**
|
||||
* Overrides the original info loaders of the plugin one by one.
|
||||
*/
|
||||
info?: FrontendPluginInfoOptions;
|
||||
}): FrontendPlugin<TRoutes, TExternalRoutes, TExtensionMap>;
|
||||
}
|
||||
|
||||
/** @public */
|
||||
@@ -172,7 +187,7 @@ export function createFrontendPlugin<
|
||||
TExtensions extends readonly ExtensionDefinition[] = [],
|
||||
>(
|
||||
options: PluginOptions<TId, TRoutes, TExternalRoutes, TExtensions>,
|
||||
): FrontendPlugin<
|
||||
): OverridableFrontendPlugin<
|
||||
TRoutes,
|
||||
TExternalRoutes,
|
||||
MakeSortedExtensionsMap<TExtensions[number], TId>
|
||||
|
||||
@@ -39,6 +39,7 @@ export {
|
||||
export {
|
||||
createFrontendPlugin,
|
||||
type FrontendPlugin,
|
||||
type OverridableFrontendPlugin,
|
||||
type PluginOptions,
|
||||
type FrontendPluginInfo,
|
||||
type FrontendPluginInfoOptions,
|
||||
|
||||
Reference in New Issue
Block a user