diff --git a/.changeset/stupid-deers-wonder.md b/.changeset/stupid-deers-wonder.md
new file mode 100644
index 0000000000..e65e01dd5e
--- /dev/null
+++ b/.changeset/stupid-deers-wonder.md
@@ -0,0 +1,5 @@
+---
+'@backstage/core-compat-api': minor
+---
+
+The `collectLegacyRoutes` has been removed and is replaced by `convertLegacyApp` now being able to convert a `FlatRoutes` element directly.
diff --git a/packages/core-compat-api/api-report.md b/packages/core-compat-api/api-report.md
index 58d5a2f094..a764d8c091 100644
--- a/packages/core-compat-api/api-report.md
+++ b/packages/core-compat-api/api-report.md
@@ -3,8 +3,6 @@
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
-///
-
import { AnyRouteRefParams } from '@backstage/core-plugin-api';
import { BackstagePlugin } from '@backstage/frontend-plugin-api';
import { ExtensionOverrides } from '@backstage/frontend-plugin-api';
@@ -17,11 +15,6 @@ import { RouteRef as RouteRef_2 } from '@backstage/frontend-plugin-api';
import { SubRouteRef } from '@backstage/core-plugin-api';
import { SubRouteRef as SubRouteRef_2 } from '@backstage/frontend-plugin-api';
-// @public (undocumented)
-export function collectLegacyRoutes(
- flatRoutesElement: JSX.Element,
-): BackstagePlugin[];
-
// @public
export function compatWrapper(element: ReactNode): React_2.JSX.Element;
diff --git a/packages/core-compat-api/src/collectLegacyRoutes.tsx b/packages/core-compat-api/src/collectLegacyRoutes.tsx
index 729ead2786..b4af6ac01a 100644
--- a/packages/core-compat-api/src/collectLegacyRoutes.tsx
+++ b/packages/core-compat-api/src/collectLegacyRoutes.tsx
@@ -144,7 +144,7 @@ function visitRouteChildren(options: {
});
}
-/** @public */
+/** @internal */
export function collectLegacyRoutes(
flatRoutesElement: JSX.Element,
): BackstagePlugin[] {
diff --git a/packages/core-compat-api/src/convertLegacyApp.test.tsx b/packages/core-compat-api/src/convertLegacyApp.test.tsx
index 9fae0128b0..a8d6cb2dbc 100644
--- a/packages/core-compat-api/src/convertLegacyApp.test.tsx
+++ b/packages/core-compat-api/src/convertLegacyApp.test.tsx
@@ -126,4 +126,37 @@ describe('convertLegacyApp', () => {
},
]);
});
+
+ it('should find and extract just routes', () => {
+ const collected = convertLegacyApp(
+
+ } />
+ } />
+ } />
+ } />
+ ,
+ );
+
+ expect(
+ collected.map((p: any /* TODO */) => ({
+ id: p.id,
+ extensions: p.extensions.map((e: any) => ({
+ id: e.id,
+ attachTo: e.attachTo,
+ disabled: e.disabled,
+ defaultConfig: e.configSchema?.parse({}),
+ })),
+ })),
+ ).toEqual([
+ expect.objectContaining({
+ id: 'score-card',
+ }),
+ expect.objectContaining({
+ id: 'stackstorm',
+ }),
+ expect.objectContaining({
+ id: 'puppetDb',
+ }),
+ ]);
+ });
});
diff --git a/packages/core-compat-api/src/convertLegacyApp.ts b/packages/core-compat-api/src/convertLegacyApp.ts
index 9fe07cc783..8055a7b72e 100644
--- a/packages/core-compat-api/src/convertLegacyApp.ts
+++ b/packages/core-compat-api/src/convertLegacyApp.ts
@@ -62,6 +62,10 @@ function selectChildren(
export function convertLegacyApp(
rootElement: React.JSX.Element,
): (ExtensionOverrides | BackstagePlugin)[] {
+ if (getComponentData(rootElement, 'core.type') === 'FlatRoutes') {
+ return collectLegacyRoutes(rootElement);
+ }
+
const appRouterEls = selectChildren(
rootElement,
el => getComponentData(el, 'core.type') === 'AppRouter',
diff --git a/packages/core-compat-api/src/index.ts b/packages/core-compat-api/src/index.ts
index cb62654684..68e5d9cf19 100644
--- a/packages/core-compat-api/src/index.ts
+++ b/packages/core-compat-api/src/index.ts
@@ -15,6 +15,5 @@
*/
export * from './compatWrapper';
-export { collectLegacyRoutes } from './collectLegacyRoutes';
export { convertLegacyApp } from './convertLegacyApp';
export { convertLegacyRouteRef } from './convertLegacyRouteRef';