From 3fc64b9e2f8ffadc7da7b6c70186d397eff24c45 Mon Sep 17 00:00:00 2001 From: David Festal Date: Tue, 29 Aug 2023 15:47:59 +0200 Subject: [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. Signed-off-by: David Festal --- .changeset/silent-icons-deny.md | 8 ++++++++ .../backend-app-api/src/wiring/BackendInitializer.ts | 11 ++++------- 2 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 .changeset/silent-icons-deny.md diff --git a/.changeset/silent-icons-deny.md b/.changeset/silent-icons-deny.md new file mode 100644 index 0000000000..7a75a6c974 --- /dev/null +++ b/.changeset/silent-icons-deny.md @@ -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. diff --git a/packages/backend-app-api/src/wiring/BackendInitializer.ts b/packages/backend-app-api/src/wiring/BackendInitializer.ts index 93d2f6942a..39c4bca265 100644 --- a/packages/backend-app-api/src/wiring/BackendInitializer.ts +++ b/packages/backend-app-api/src/wiring/BackendInitializer.ts @@ -44,10 +44,7 @@ export interface BackendRegisterInit { export class BackendInitializer { #startPromise?: Promise; #features = new Array(); - #extensionPoints = new Map< - ExtensionPoint, - { impl: unknown; pluginId: string } - >(); + #extensionPoints = new Map(); #serviceHolder: EnumerableServiceHolder | undefined; #providedServiceFactories = new Array(); #defaultApiFactories: ServiceFactory[]; @@ -64,7 +61,7 @@ export class BackendInitializer { const missingRefs = new Set(); for (const [name, ref] of Object.entries(deps)) { - const ep = this.#extensionPoints.get(ref as ExtensionPoint); + 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, });