Index features on id instead of object.

This will allow features added from an external package location
to be loaded correctly.,
without the requirement of making backstage packages singletons.

Signed-off-by: David Festal <dfestal@redhat.com>
This commit is contained in:
David Festal
2023-08-29 15:47:59 +02:00
parent cc68b59e4c
commit 3fc64b9e2f
2 changed files with 12 additions and 7 deletions
+8
View File
@@ -0,0 +1,8 @@
---
'@backstage/backend-app-api': patch
---
Index features on id instead of object.
This will allow features added from an external package location to be loaded correctly,
without the requirement of making backstage packages singletons.
@@ -44,10 +44,7 @@ export interface BackendRegisterInit {
export class BackendInitializer {
#startPromise?: Promise<void>;
#features = new Array<InternalBackendFeature>();
#extensionPoints = new Map<
ExtensionPoint<unknown>,
{ impl: unknown; pluginId: string }
>();
#extensionPoints = new Map<string, { impl: unknown; pluginId: string }>();
#serviceHolder: EnumerableServiceHolder | undefined;
#providedServiceFactories = new Array<ServiceFactory>();
#defaultApiFactories: ServiceFactory[];
@@ -64,7 +61,7 @@ export class BackendInitializer {
const missingRefs = new Set<ServiceOrExtensionPoint>();
for (const [name, ref] of Object.entries(deps)) {
const ep = this.#extensionPoints.get(ref as ExtensionPoint<unknown>);
const ep = this.#extensionPoints.get(ref.id);
if (ep) {
if (ep.pluginId !== pluginId) {
throw new Error(
@@ -201,12 +198,12 @@ export class BackendInitializer {
if (r.type === 'plugin' || r.type === 'module') {
for (const [extRef, extImpl] of r.extensionPoints) {
if (this.#extensionPoints.has(extRef)) {
if (this.#extensionPoints.has(extRef.id)) {
throw new Error(
`ExtensionPoint with ID '${extRef.id}' is already registered`,
);
}
this.#extensionPoints.set(extRef, {
this.#extensionPoints.set(extRef.id, {
impl: extImpl,
pluginId: r.pluginId,
});