diff --git a/packages/frontend-app-api/src/createApp.tsx b/packages/frontend-app-api/src/createApp.tsx index 728610679d..988681e6a9 100644 --- a/packages/frontend-app-api/src/createApp.tsx +++ b/packages/frontend-app-api/src/createApp.tsx @@ -32,6 +32,7 @@ import { } from './wiring/parameters'; import { RoutingProvider } from './routing/RoutingContext'; import { RouteRef } from '@backstage/core-plugin-api'; +import { getAvailablePlugins } from './discover'; /** @public */ export function createApp(options: { plugins: BackstagePlugin[] }): { @@ -40,11 +41,12 @@ export function createApp(options: { plugins: BackstagePlugin[] }): { const appConfig = ConfigReader.fromConfigs(process.env.APP_CONFIG as any); const builtinExtensions = [CoreRouter]; + const discoveredPlugins = getAvailablePlugins(); // pull in default extension instance from discovered packages // apply config to adjust default extension instances and add more const extensionParams = mergeExtensionParameters({ - sources: options.plugins, + sources: [...options.plugins, ...discoveredPlugins], builtinExtensions, parameters: readAppExtensionParameters(appConfig), }); diff --git a/packages/frontend-app-api/src/discover/discover-plugins.d.ts b/packages/frontend-app-api/src/discover/discover-plugins.d.ts new file mode 100644 index 0000000000..a5af550743 --- /dev/null +++ b/packages/frontend-app-api/src/discover/discover-plugins.d.ts @@ -0,0 +1,22 @@ +/* + * Copyright 2023 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +declare module '__backstage-autodetected-plugins__' { + type DetectedModule = { + name: string; + module: Record; + }; + const modules: Array<{ name: string; module: Record }>; +} diff --git a/packages/frontend-app-api/src/discover/index.ts b/packages/frontend-app-api/src/discover/index.ts new file mode 100644 index 0000000000..bde5242505 --- /dev/null +++ b/packages/frontend-app-api/src/discover/index.ts @@ -0,0 +1,36 @@ +/* + * Copyright 2023 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { BackstagePlugin } from '@backstage/frontend-plugin-api'; + +// eslint-disable-next-line @backstage/no-undeclared-imports +import { modules } from '__backstage-autodetected-plugins__'; + +/** + * @public + */ +export function getAvailablePlugins(): BackstagePlugin[] { + return modules.flatMap(({ module: mod }) => + Object.values(mod).flatMap(val => (isBackstagePlugin(val) ? [val] : [])), + ); +} + +function isBackstagePlugin(obj: unknown): obj is BackstagePlugin { + if (obj !== null && typeof obj === 'object' && '$$type' in obj) { + return obj.$$type === 'backstage-plugin'; + } + return false; +}