core-plugin-api: Deprecate Plugin register and output
Co-authored-by: blam <ben@blam.sh> Co-authored-by: Patrik Oldsberg <poldsberg@gmail.com> Signed-off-by: Johan Haals <johan.haals@gmail.com>
This commit is contained in:
@@ -272,17 +272,26 @@ export class AppManager implements BackstageApp {
|
||||
const featureFlagsApi = this.getApiHolder().get(featureFlagsApiRef)!;
|
||||
|
||||
for (const plugin of this.plugins.values()) {
|
||||
for (const output of plugin.output()) {
|
||||
switch (output.type) {
|
||||
case 'feature-flag': {
|
||||
featureFlagsApi.registerFlag({
|
||||
name: output.name,
|
||||
pluginId: plugin.getId(),
|
||||
});
|
||||
break;
|
||||
if ('getFeatureFlags' in plugin) {
|
||||
for (const flag of plugin.getFeatureFlags()) {
|
||||
featureFlagsApi.registerFlag({
|
||||
name: flag.name,
|
||||
pluginId: plugin.getId(),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
for (const output of plugin.output()) {
|
||||
switch (output.type) {
|
||||
case 'feature-flag': {
|
||||
featureFlagsApi.registerFlag({
|
||||
name: output.name,
|
||||
pluginId: plugin.getId(),
|
||||
});
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
Extension,
|
||||
AnyRoutes,
|
||||
AnyExternalRoutes,
|
||||
PluginFeatureFlagConfig,
|
||||
} from './types';
|
||||
import { AnyApiFactory } from '../apis';
|
||||
|
||||
@@ -44,6 +45,14 @@ export class PluginImpl<
|
||||
return this.config.apis ?? [];
|
||||
}
|
||||
|
||||
getFeatureFlags(): Iterable<PluginFeatureFlagConfig> {
|
||||
const registeredFlags = this.output()
|
||||
.filter(({ type }) => type === 'feature-flag')
|
||||
.map(({ name }) => ({ name }));
|
||||
|
||||
return registeredFlags;
|
||||
}
|
||||
|
||||
get routes(): Routes {
|
||||
return this.config.routes ?? ({} as Routes);
|
||||
}
|
||||
@@ -56,11 +65,18 @@ export class PluginImpl<
|
||||
if (this.storedOutput) {
|
||||
return this.storedOutput;
|
||||
}
|
||||
if (!this.config.register) {
|
||||
return [];
|
||||
const outputs = new Array<PluginOutput>();
|
||||
this.storedOutput = outputs;
|
||||
|
||||
if (this.config.featureFlags) {
|
||||
for (const flag of this.config.featureFlags) {
|
||||
outputs.push({ type: 'feature-flag', name: flag.name });
|
||||
}
|
||||
}
|
||||
|
||||
const outputs = new Array<PluginOutput>();
|
||||
if (!this.config.register) {
|
||||
return outputs;
|
||||
}
|
||||
|
||||
this.config.register({
|
||||
featureFlags: {
|
||||
@@ -70,7 +86,6 @@ export class PluginImpl<
|
||||
},
|
||||
});
|
||||
|
||||
this.storedOutput = outputs;
|
||||
return this.storedOutput;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import { AnyApiFactory } from '../apis/system';
|
||||
|
||||
/**
|
||||
* Replace with using {@link RouteRef}s.
|
||||
*
|
||||
* @deprecated
|
||||
* @public
|
||||
*/
|
||||
export type FeatureFlagOutput = {
|
||||
@@ -31,6 +31,7 @@ export type FeatureFlagOutput = {
|
||||
* {@link FeatureFlagOutput} type.
|
||||
*
|
||||
* @public
|
||||
* @deprecated Use {@link BackstagePlugin.getFeatureFlags} instead.
|
||||
*/
|
||||
export type PluginOutput = FeatureFlagOutput;
|
||||
|
||||
@@ -71,13 +72,30 @@ export type BackstagePlugin<
|
||||
ExternalRoutes extends AnyExternalRoutes = {},
|
||||
> = {
|
||||
getId(): string;
|
||||
/**
|
||||
* @deprecated use getFeatureFlags instead.
|
||||
* */
|
||||
output(): PluginOutput[];
|
||||
getApis(): Iterable<AnyApiFactory>;
|
||||
/**
|
||||
* Returns all registered feature flags for this plugin.
|
||||
*/
|
||||
getFeatureFlags(): Iterable<PluginFeatureFlagConfig>;
|
||||
provide<T>(extension: Extension<T>): T;
|
||||
routes: Routes;
|
||||
externalRoutes: ExternalRoutes;
|
||||
};
|
||||
|
||||
/**
|
||||
* Plugin feature flag configuration.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type PluginFeatureFlagConfig = {
|
||||
/** Feature flag name */
|
||||
name: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Plugin descriptor type.
|
||||
*
|
||||
@@ -89,14 +107,17 @@ export type PluginConfig<
|
||||
> = {
|
||||
id: string;
|
||||
apis?: Iterable<AnyApiFactory>;
|
||||
/** @deprecated use featureFlags property instead for defining feature flags */
|
||||
register?(hooks: PluginHooks): void;
|
||||
routes?: Routes;
|
||||
externalRoutes?: ExternalRoutes;
|
||||
featureFlags?: PluginFeatureFlagConfig[];
|
||||
};
|
||||
|
||||
/**
|
||||
* Holds hooks registered by the plugin.
|
||||
*
|
||||
* @deprecated - feature flags are now registered in plugin config under featureFlags
|
||||
* @public
|
||||
*/
|
||||
export type PluginHooks = {
|
||||
|
||||
@@ -34,9 +34,7 @@ export const unlabeledDataflowAlertRef = createRouteRef({
|
||||
|
||||
export const costInsightsPlugin = createPlugin({
|
||||
id: 'cost-insights',
|
||||
register({ featureFlags }) {
|
||||
featureFlags.register('cost-insights-currencies');
|
||||
},
|
||||
featureFlags: [{ name: 'cost-insights-currencies' }],
|
||||
routes: {
|
||||
root: rootRouteRef,
|
||||
growthAlerts: projectGrowthAlertRef,
|
||||
|
||||
Reference in New Issue
Block a user