backend-defaults: Stop accepting callback BackendFeatures for backend.add

Co-authored-by: Camila Belo <camilaibs@gmail.com>
Signed-off-by: Johan Haals <johan.haals@gmail.com>
This commit is contained in:
Johan Haals
2024-08-14 13:52:45 +02:00
parent 87cd3d0b9e
commit 70e14b8ed2
3 changed files with 3 additions and 38 deletions
-8
View File
@@ -24,14 +24,6 @@ export interface Backend {
default: BackendFeature;
}>,
): void;
// @deprecated (undocumented)
add(
feature:
| (() => BackendFeature)
| Promise<{
default: () => BackendFeature;
}>,
): void;
// (undocumented)
start(): Promise<void>;
// (undocumented)
@@ -25,12 +25,7 @@ export class BackstageBackend implements Backend {
this.#initializer = new BackendInitializer(defaultServiceFactories);
}
add(
feature:
| BackendFeature
| (() => BackendFeature)
| Promise<{ default: BackendFeature | (() => BackendFeature) }>,
): void {
add(feature: BackendFeature | Promise<{ default: BackendFeature }>): void {
if (isPromise(feature)) {
this.#initializer.add(feature.then(f => unwrapFeature(f.default)));
} else {
@@ -57,15 +52,8 @@ function isPromise<T>(value: unknown | Promise<T>): value is Promise<T> {
}
function unwrapFeature(
feature:
| BackendFeature
| (() => BackendFeature)
| { default: BackendFeature | (() => BackendFeature) },
feature: BackendFeature | { default: BackendFeature },
): BackendFeature {
if (typeof feature === 'function') {
return feature();
}
if ('$$type' in feature) {
return feature;
}
@@ -75,10 +63,7 @@ function unwrapFeature(
// when importing using a dynamic import.
// TODO: This is a broader issue than just this piece of code, and should move away from CommonJS.
if ('default' in feature) {
const defaultFeature = feature.default;
return typeof defaultFeature === 'function'
? defaultFeature()
: defaultFeature;
return feature.default;
}
return feature;
@@ -26,18 +26,6 @@ import {
*/
export interface Backend {
add(feature: BackendFeature | Promise<{ default: BackendFeature }>): void;
/**
* @deprecated The ability to add features defined as a callback is being
* removed. Please update the installed feature to no longer be defined as a
* callback, typically this means updating it to use the latest version of
* `@backstage/backend-plugin-api`. If the feature is from a third-party
* package, please reach out to the package maintainer to update it.
*/
add(
feature:
| (() => BackendFeature)
| Promise<{ default: () => BackendFeature }>,
): void;
start(): Promise<void>;
stop(): Promise<void>;
}