@backstage/core-compat-api 0.3.6 → 0.3.7-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +66 -0
- package/dist/collectLegacyRoutes.esm.js +6 -11
- package/dist/collectLegacyRoutes.esm.js.map +1 -1
- package/dist/convertLegacyApp.esm.js +8 -5
- package/dist/convertLegacyApp.esm.js.map +1 -1
- package/dist/convertLegacyAppOptions.esm.js +133 -0
- package/dist/convertLegacyAppOptions.esm.js.map +1 -0
- package/dist/index.d.ts +16 -2
- package/dist/index.esm.js +1 -0
- package/dist/index.esm.js.map +1 -1
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,71 @@
|
|
|
1
1
|
# @backstage/core-compat-api
|
|
2
2
|
|
|
3
|
+
## 0.3.7-next.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d34e0e5: Added a new `convertLegacyAppOptions` helper that converts many of the options passed to `createApp` in the old frontend system to a module with app overrides for the new system. The supported options are `apis`, `icons`, `plugins`, `components`, and `themes`.
|
|
8
|
+
|
|
9
|
+
For example, given the following options for the old `createApp`:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { createApp } from '@backstage/app-deafults';
|
|
13
|
+
|
|
14
|
+
const app = createApp({
|
|
15
|
+
apis,
|
|
16
|
+
plugins,
|
|
17
|
+
icons: {
|
|
18
|
+
custom: MyIcon,
|
|
19
|
+
},
|
|
20
|
+
components: {
|
|
21
|
+
SignInPage: MySignInPage,
|
|
22
|
+
},
|
|
23
|
+
themes: [myTheme],
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
They can be converted to the new system like this:
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { createApp } from '@backstage/frontend-deafults';
|
|
31
|
+
import { convertLegacyAppOptions } from '@backstage/core-compat-api';
|
|
32
|
+
|
|
33
|
+
const app = createApp({
|
|
34
|
+
features: [
|
|
35
|
+
convertLegacyAppOptions({
|
|
36
|
+
apis,
|
|
37
|
+
plugins,
|
|
38
|
+
icons: {
|
|
39
|
+
custom: MyIcon,
|
|
40
|
+
},
|
|
41
|
+
components: {
|
|
42
|
+
SignInPage: MySignInPage,
|
|
43
|
+
},
|
|
44
|
+
themes: [myTheme],
|
|
45
|
+
}),
|
|
46
|
+
],
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
- 18faf65: The `convertLegacyApp` has received the following changes:
|
|
51
|
+
|
|
52
|
+
- `null` routes will now be ignored.
|
|
53
|
+
- Converted routes no longer need to belong to a plugin, falling back to a `converted-orphan-routes` plugin instead.
|
|
54
|
+
- The generate layout override extension is now properly attached to the `app/root` extension.
|
|
55
|
+
- Converted root elements are now automatically wrapped with `compatWrapper`.
|
|
56
|
+
|
|
57
|
+
- Updated dependencies
|
|
58
|
+
- @backstage/core-plugin-api@1.10.4
|
|
59
|
+
- @backstage/frontend-plugin-api@0.9.6-next.1
|
|
60
|
+
- @backstage/version-bridge@1.0.11
|
|
61
|
+
|
|
62
|
+
## 0.3.7-next.0
|
|
63
|
+
|
|
64
|
+
### Patch Changes
|
|
65
|
+
|
|
66
|
+
- Updated dependencies
|
|
67
|
+
- @backstage/frontend-plugin-api@0.9.6-next.0
|
|
68
|
+
|
|
3
69
|
## 0.3.6
|
|
4
70
|
|
|
5
71
|
### Patch Changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getComponentData } from '@backstage/core-plugin-api';
|
|
1
|
+
import { createPlugin, getComponentData } from '@backstage/core-plugin-api';
|
|
2
2
|
import { PageBlueprint, createExtensionInput, coreExtensionData, createFrontendPlugin, ApiBlueprint, createExtension } from '@backstage/frontend-plugin-api';
|
|
3
3
|
import React, { Children, isValidElement } from 'react';
|
|
4
4
|
import { Route, Routes } from 'react-router-dom';
|
|
@@ -73,6 +73,7 @@ function collectLegacyRoutes(flatRoutesElement) {
|
|
|
73
73
|
let currentIndex = 1;
|
|
74
74
|
return () => String(currentIndex++);
|
|
75
75
|
})();
|
|
76
|
+
const orphanRoutesPlugin = createPlugin({ id: "converted-orphan-routes" });
|
|
76
77
|
const getPluginExtensions = (plugin) => {
|
|
77
78
|
let extensions = pluginExtensions.get(plugin);
|
|
78
79
|
if (!extensions) {
|
|
@@ -84,6 +85,9 @@ function collectLegacyRoutes(flatRoutesElement) {
|
|
|
84
85
|
React.Children.forEach(
|
|
85
86
|
flatRoutesElement.props.children,
|
|
86
87
|
(route) => {
|
|
88
|
+
if (route === null) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
87
91
|
if (!React.isValidElement(route)) {
|
|
88
92
|
throw new Error(
|
|
89
93
|
`Invalid element inside FlatRoutes, expected Route but found element of type ${typeof route}.`
|
|
@@ -96,20 +100,11 @@ function collectLegacyRoutes(flatRoutesElement) {
|
|
|
96
100
|
}
|
|
97
101
|
const routeElement = route.props.element;
|
|
98
102
|
const path = route.props.path;
|
|
99
|
-
const plugin = getComponentData(
|
|
100
|
-
routeElement,
|
|
101
|
-
"core.plugin"
|
|
102
|
-
);
|
|
103
|
+
const plugin = getComponentData(routeElement, "core.plugin") ?? orphanRoutesPlugin;
|
|
103
104
|
const routeRef = getComponentData(
|
|
104
105
|
routeElement,
|
|
105
106
|
"core.mountPoint"
|
|
106
107
|
);
|
|
107
|
-
if (!plugin) {
|
|
108
|
-
throw new Error(
|
|
109
|
-
// TODO(vinzscam): add See <link-to-app-migration-docs> for more info
|
|
110
|
-
`Route with path ${path} has en element that can not be converted as it does not belong to a plugin. Make sure that the top-level React element of the element prop is an extension from a Backstage plugin, or remove the Route completely.`
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
108
|
if (path === void 0) {
|
|
114
109
|
throw new Error(
|
|
115
110
|
`Route element inside FlatRoutes had no path prop value given`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collectLegacyRoutes.esm.js","sources":["../src/collectLegacyRoutes.tsx"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n AnyRouteRefParams,\n BackstagePlugin as LegacyBackstagePlugin,\n RouteRef,\n getComponentData,\n} from '@backstage/core-plugin-api';\nimport {\n FrontendPlugin,\n ExtensionDefinition,\n coreExtensionData,\n createExtension,\n createExtensionInput,\n createFrontendPlugin,\n ApiBlueprint,\n PageBlueprint,\n} from '@backstage/frontend-plugin-api';\nimport React, { Children, ReactNode, isValidElement } from 'react';\nimport { Route, Routes } from 'react-router-dom';\nimport {\n convertLegacyRouteRef,\n convertLegacyRouteRefs,\n} from './convertLegacyRouteRef';\nimport { compatWrapper } from './compatWrapper';\n\n/*\n\n# Legacy interoperability\n\nUse-cases (prioritized):\n 1. Slowly migrate over an existing app to DI, piece by piece\n 2. Use a legacy plugin in a new DI app\n 3. Use DI in an existing legacy app\n\nStarting point: use-case #1\n\nPotential solutions:\n 1. Codemods (we're not considering this for now)\n 2. Legacy apps are migrated bottom-up, i.e. keep legacy root, replace pages with DI\n 3. Legacy apps are migrated top-down i.e. switch out base to DI, legacy adapter allows for usage of existing app structure\n\nChosen path: #3\n\nExisting tasks:\n - Adopters can migrate their existing app gradually (~4)\n - Example-app uses legacy base with DI adapters\n - Create an API that lets you inject DI into existing apps - working assumption is that this is enough\n - Adopters can use legacy plugins in DI through adapters (~8)\n - App-next uses DI base with legacy adapters\n - Create a legacy adapter that is able to take an existing extension tree\n\n*/\n\n// Creates a shim extension whose purpose is to build up the tree (anchored at\n// the root page) of paths/routeRefs so that the app can bind them properly.\nfunction makeRoutingShimExtension(options: {\n name: string;\n parentExtensionId: string;\n routePath?: string;\n routeRef?: RouteRef;\n}) {\n const { name, parentExtensionId, routePath, routeRef } = options;\n return createExtension({\n kind: 'routing-shim',\n name,\n attachTo: { id: parentExtensionId, input: 'childRoutingShims' },\n inputs: {\n childRoutingShims: createExtensionInput([\n coreExtensionData.routePath.optional(),\n coreExtensionData.routeRef.optional(),\n ]),\n },\n output: [\n coreExtensionData.routePath.optional(),\n coreExtensionData.routeRef.optional(),\n ],\n *factory() {\n if (routePath !== undefined) {\n yield coreExtensionData.routePath(routePath);\n }\n\n if (routeRef) {\n yield coreExtensionData.routeRef(convertLegacyRouteRef(routeRef));\n }\n },\n });\n}\n\nfunction visitRouteChildren(options: {\n children: ReactNode;\n parentExtensionId: string;\n context: {\n pluginId: string;\n extensions: ExtensionDefinition[];\n getUniqueName: () => string;\n discoverPlugin: (plugin: LegacyBackstagePlugin) => void;\n };\n}): void {\n const { children, parentExtensionId, context } = options;\n const { pluginId, extensions, getUniqueName, discoverPlugin } = context;\n\n Children.forEach(children, node => {\n if (!isValidElement(node)) {\n return;\n }\n\n const plugin = getComponentData<LegacyBackstagePlugin>(node, 'core.plugin');\n const routeRef = getComponentData<RouteRef<AnyRouteRefParams>>(\n node,\n 'core.mountPoint',\n );\n const routePath: string | undefined = node.props?.path;\n\n if (plugin) {\n // We just mark the plugin as discovered, but don't change the context\n discoverPlugin(plugin);\n }\n\n let nextParentExtensionId = parentExtensionId;\n if (routeRef || routePath) {\n const nextParentExtensionName = getUniqueName();\n nextParentExtensionId = `routing-shim:${pluginId}/${nextParentExtensionName}`;\n extensions.push(\n makeRoutingShimExtension({\n name: nextParentExtensionName,\n parentExtensionId,\n routePath,\n routeRef,\n }),\n );\n }\n\n visitRouteChildren({\n children: node.props.children,\n parentExtensionId: nextParentExtensionId,\n context,\n });\n });\n}\n\n/** @internal */\nexport function collectLegacyRoutes(\n flatRoutesElement: JSX.Element,\n): FrontendPlugin[] {\n const pluginExtensions = new Map<\n LegacyBackstagePlugin,\n ExtensionDefinition[]\n >();\n\n const getUniqueName = (() => {\n let currentIndex = 1;\n return () => String(currentIndex++);\n })();\n\n const getPluginExtensions = (plugin: LegacyBackstagePlugin) => {\n let extensions = pluginExtensions.get(plugin);\n if (!extensions) {\n extensions = [];\n pluginExtensions.set(plugin, extensions);\n }\n return extensions;\n };\n\n React.Children.forEach(\n flatRoutesElement.props.children,\n (route: ReactNode) => {\n // TODO(freben): Handle feature flag and permissions framework wrapper elements\n if (!React.isValidElement(route)) {\n throw new Error(\n `Invalid element inside FlatRoutes, expected Route but found element of type ${typeof route}.`,\n );\n }\n if (route.type !== Route) {\n throw new Error(\n `Invalid element inside FlatRoutes, expected Route but found ${route.type}.`,\n );\n }\n const routeElement = route.props.element;\n const path: string | undefined = route.props.path;\n const plugin = getComponentData<LegacyBackstagePlugin>(\n routeElement,\n 'core.plugin',\n );\n const routeRef = getComponentData<RouteRef>(\n routeElement,\n 'core.mountPoint',\n );\n if (!plugin) {\n throw new Error(\n // TODO(vinzscam): add See <link-to-app-migration-docs> for more info\n `Route with path ${path} has en element that can not be converted as it does not belong to a plugin. Make sure that the top-level React element of the element prop is an extension from a Backstage plugin, or remove the Route completely.`,\n );\n }\n if (path === undefined) {\n throw new Error(\n `Route element inside FlatRoutes had no path prop value given`,\n );\n }\n\n const extensions = getPluginExtensions(plugin);\n const pageExtensionName = extensions.length ? getUniqueName() : undefined;\n const pageExtensionId = `page:${plugin.getId()}${\n pageExtensionName ? `/${pageExtensionName}` : pageExtensionName\n }`;\n\n extensions.push(\n PageBlueprint.makeWithOverrides({\n name: pageExtensionName,\n inputs: {\n childRoutingShims: createExtensionInput([\n coreExtensionData.routePath.optional(),\n coreExtensionData.routeRef.optional(),\n ]),\n },\n factory(originalFactory, { inputs: _inputs }) {\n // todo(blam): why do we not use the inputs here?\n return originalFactory({\n defaultPath: path[0] === '/' ? path.slice(1) : path,\n routeRef: routeRef ? convertLegacyRouteRef(routeRef) : undefined,\n loader: async () =>\n compatWrapper(\n route.props.children ? (\n <Routes>\n <Route path=\"*\" element={routeElement}>\n <Route path=\"*\" element={route.props.children} />\n </Route>\n </Routes>\n ) : (\n routeElement\n ),\n ),\n });\n },\n }),\n );\n\n visitRouteChildren({\n children: route.props.children,\n parentExtensionId: pageExtensionId,\n context: {\n pluginId: plugin.getId(),\n extensions,\n getUniqueName,\n discoverPlugin: getPluginExtensions,\n },\n });\n },\n );\n\n return Array.from(pluginExtensions).map(([plugin, extensions]) =>\n createFrontendPlugin({\n id: plugin.getId(),\n extensions: [\n ...extensions,\n ...Array.from(plugin.getApis()).map(factory =>\n ApiBlueprint.make({\n name: factory.api.id,\n params: { factory },\n }),\n ),\n ],\n routes: convertLegacyRouteRefs(plugin.routes ?? {}),\n externalRoutes: convertLegacyRouteRefs(plugin.externalRoutes ?? {}),\n }),\n );\n}\n"],"names":[],"mappings":";;;;;;;AAsEA,SAAS,yBAAyB,OAK/B,EAAA;AACD,EAAA,MAAM,EAAE,IAAA,EAAM,iBAAmB,EAAA,SAAA,EAAW,UAAa,GAAA,OAAA;AACzD,EAAA,OAAO,eAAgB,CAAA;AAAA,IACrB,IAAM,EAAA,cAAA;AAAA,IACN,IAAA;AAAA,IACA,QAAU,EAAA,EAAE,EAAI,EAAA,iBAAA,EAAmB,OAAO,mBAAoB,EAAA;AAAA,IAC9D,MAAQ,EAAA;AAAA,MACN,mBAAmB,oBAAqB,CAAA;AAAA,QACtC,iBAAA,CAAkB,UAAU,QAAS,EAAA;AAAA,QACrC,iBAAA,CAAkB,SAAS,QAAS;AAAA,OACrC;AAAA,KACH;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,iBAAA,CAAkB,UAAU,QAAS,EAAA;AAAA,MACrC,iBAAA,CAAkB,SAAS,QAAS;AAAA,KACtC;AAAA,IACA,CAAC,OAAU,GAAA;AACT,MAAA,IAAI,cAAc,KAAW,CAAA,EAAA;AAC3B,QAAM,MAAA,iBAAA,CAAkB,UAAU,SAAS,CAAA;AAAA;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The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n AnyRouteRefParams,\n BackstagePlugin as LegacyBackstagePlugin,\n RouteRef,\n createPlugin,\n getComponentData,\n} from '@backstage/core-plugin-api';\nimport {\n FrontendPlugin,\n ExtensionDefinition,\n coreExtensionData,\n createExtension,\n createExtensionInput,\n createFrontendPlugin,\n ApiBlueprint,\n PageBlueprint,\n} from '@backstage/frontend-plugin-api';\nimport React, { Children, ReactNode, isValidElement } from 'react';\nimport { Route, Routes } from 'react-router-dom';\nimport {\n convertLegacyRouteRef,\n convertLegacyRouteRefs,\n} from './convertLegacyRouteRef';\nimport { compatWrapper } from './compatWrapper';\n\n/*\n\n# Legacy interoperability\n\nUse-cases (prioritized):\n 1. Slowly migrate over an existing app to DI, piece by piece\n 2. Use a legacy plugin in a new DI app\n 3. Use DI in an existing legacy app\n\nStarting point: use-case #1\n\nPotential solutions:\n 1. Codemods (we're not considering this for now)\n 2. Legacy apps are migrated bottom-up, i.e. keep legacy root, replace pages with DI\n 3. Legacy apps are migrated top-down i.e. switch out base to DI, legacy adapter allows for usage of existing app structure\n\nChosen path: #3\n\nExisting tasks:\n - Adopters can migrate their existing app gradually (~4)\n - Example-app uses legacy base with DI adapters\n - Create an API that lets you inject DI into existing apps - working assumption is that this is enough\n - Adopters can use legacy plugins in DI through adapters (~8)\n - App-next uses DI base with legacy adapters\n - Create a legacy adapter that is able to take an existing extension tree\n\n*/\n\n// Creates a shim extension whose purpose is to build up the tree (anchored at\n// the root page) of paths/routeRefs so that the app can bind them properly.\nfunction makeRoutingShimExtension(options: {\n name: string;\n parentExtensionId: string;\n routePath?: string;\n routeRef?: RouteRef;\n}) {\n const { name, parentExtensionId, routePath, routeRef } = options;\n return createExtension({\n kind: 'routing-shim',\n name,\n attachTo: { id: parentExtensionId, input: 'childRoutingShims' },\n inputs: {\n childRoutingShims: createExtensionInput([\n coreExtensionData.routePath.optional(),\n coreExtensionData.routeRef.optional(),\n ]),\n },\n output: [\n coreExtensionData.routePath.optional(),\n coreExtensionData.routeRef.optional(),\n ],\n *factory() {\n if (routePath !== undefined) {\n yield coreExtensionData.routePath(routePath);\n }\n\n if (routeRef) {\n yield coreExtensionData.routeRef(convertLegacyRouteRef(routeRef));\n }\n },\n });\n}\n\nfunction visitRouteChildren(options: {\n children: ReactNode;\n parentExtensionId: string;\n context: {\n pluginId: string;\n extensions: ExtensionDefinition[];\n getUniqueName: () => string;\n discoverPlugin: (plugin: LegacyBackstagePlugin) => void;\n };\n}): void {\n const { children, parentExtensionId, context } = options;\n const { pluginId, extensions, getUniqueName, discoverPlugin } = context;\n\n Children.forEach(children, node => {\n if (!isValidElement(node)) {\n return;\n }\n\n const plugin = getComponentData<LegacyBackstagePlugin>(node, 'core.plugin');\n const routeRef = getComponentData<RouteRef<AnyRouteRefParams>>(\n node,\n 'core.mountPoint',\n );\n const routePath: string | undefined = node.props?.path;\n\n if (plugin) {\n // We just mark the plugin as discovered, but don't change the context\n discoverPlugin(plugin);\n }\n\n let nextParentExtensionId = parentExtensionId;\n if (routeRef || routePath) {\n const nextParentExtensionName = getUniqueName();\n nextParentExtensionId = `routing-shim:${pluginId}/${nextParentExtensionName}`;\n extensions.push(\n makeRoutingShimExtension({\n name: nextParentExtensionName,\n parentExtensionId,\n routePath,\n routeRef,\n }),\n );\n }\n\n visitRouteChildren({\n children: node.props.children,\n parentExtensionId: nextParentExtensionId,\n context,\n });\n });\n}\n\n/** @internal */\nexport function collectLegacyRoutes(\n flatRoutesElement: JSX.Element,\n): FrontendPlugin[] {\n const pluginExtensions = new Map<\n LegacyBackstagePlugin,\n ExtensionDefinition[]\n >();\n\n const getUniqueName = (() => {\n let currentIndex = 1;\n return () => String(currentIndex++);\n })();\n\n // Placeholder plugin for any routes that don't belong to a plugin\n const orphanRoutesPlugin = createPlugin({ id: 'converted-orphan-routes' });\n\n const getPluginExtensions = (plugin: LegacyBackstagePlugin) => {\n let extensions = pluginExtensions.get(plugin);\n if (!extensions) {\n extensions = [];\n pluginExtensions.set(plugin, extensions);\n }\n return extensions;\n };\n\n React.Children.forEach(\n flatRoutesElement.props.children,\n (route: ReactNode) => {\n if (route === null) {\n return;\n }\n // TODO(freben): Handle feature flag and permissions framework wrapper elements\n if (!React.isValidElement(route)) {\n throw new Error(\n `Invalid element inside FlatRoutes, expected Route but found element of type ${typeof route}.`,\n );\n }\n if (route.type !== Route) {\n throw new Error(\n `Invalid element inside FlatRoutes, expected Route but found ${route.type}.`,\n );\n }\n const routeElement = route.props.element;\n const path: string | undefined = route.props.path;\n const plugin =\n getComponentData<LegacyBackstagePlugin>(routeElement, 'core.plugin') ??\n orphanRoutesPlugin;\n const routeRef = getComponentData<RouteRef>(\n routeElement,\n 'core.mountPoint',\n );\n if (path === undefined) {\n throw new Error(\n `Route element inside FlatRoutes had no path prop value given`,\n );\n }\n\n const extensions = getPluginExtensions(plugin);\n const pageExtensionName = extensions.length ? getUniqueName() : undefined;\n const pageExtensionId = `page:${plugin.getId()}${\n pageExtensionName ? `/${pageExtensionName}` : pageExtensionName\n }`;\n\n extensions.push(\n PageBlueprint.makeWithOverrides({\n name: pageExtensionName,\n inputs: {\n childRoutingShims: createExtensionInput([\n coreExtensionData.routePath.optional(),\n coreExtensionData.routeRef.optional(),\n ]),\n },\n factory(originalFactory, { inputs: _inputs }) {\n // todo(blam): why do we not use the inputs here?\n return originalFactory({\n defaultPath: path[0] === '/' ? path.slice(1) : path,\n routeRef: routeRef ? convertLegacyRouteRef(routeRef) : undefined,\n loader: async () =>\n compatWrapper(\n route.props.children ? (\n <Routes>\n <Route path=\"*\" element={routeElement}>\n <Route path=\"*\" element={route.props.children} />\n </Route>\n </Routes>\n ) : (\n routeElement\n ),\n ),\n });\n },\n }),\n );\n\n visitRouteChildren({\n children: route.props.children,\n parentExtensionId: pageExtensionId,\n context: {\n pluginId: plugin.getId(),\n extensions,\n getUniqueName,\n discoverPlugin: getPluginExtensions,\n },\n });\n },\n );\n\n return Array.from(pluginExtensions).map(([plugin, extensions]) =>\n createFrontendPlugin({\n id: plugin.getId(),\n extensions: [\n ...extensions,\n ...Array.from(plugin.getApis()).map(factory =>\n ApiBlueprint.make({\n name: factory.api.id,\n params: { factory },\n }),\n ),\n ],\n routes: convertLegacyRouteRefs(plugin.routes ?? {}),\n externalRoutes: convertLegacyRouteRefs(plugin.externalRoutes ?? {}),\n }),\n );\n}\n"],"names":[],"mappings":";;;;;;;AAuEA,SAAS,yBAAyB,OAK/B,EAAA;AACD,EAAA,MAAM,EAAE,IAAA,EAAM,iBAAmB,EAAA,SAAA,EAAW,UAAa,GAAA,OAAA;AACzD,EAAA,OAAO,eAAgB,CAAA;AAAA,IACrB,IAAM,EAAA,cAAA;AAAA,IACN,IAAA;AAAA,IACA,QAAU,EAAA,EAAE,EAAI,EAAA,iBAAA,EAAmB,OAAO,mBAAoB,EAAA;AAAA,IAC9D,MAAQ,EAAA;AAAA,MACN,mBAAmB,oBAAqB,CAAA;AAAA,QACtC,iBAAA,CAAkB,UAAU,QAAS,EAAA;AAAA,QACrC,iBAAA,CAAkB,SAAS,QAAS;AAAA,OACrC;AAAA,KACH;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,iBAAA,CAAkB,UAAU,QAAS,EAAA;AAAA,MACrC,iBAAA,CAAkB,SAAS,QAAS;AAAA,KACtC;AAAA,IACA,CAAC,OAAU,GAAA;AACT,MAAA,IAAI,cAAc,KAAW,CAAA,EAAA;AAC3B,QAAM,MAAA,iBAAA,CAAkB,UAAU,SAAS,CAAA;AAAA;AAG7C,MAAA,IAAI,QAAU,EAAA;AACZ,QAAA,MAAM,iBAAkB,CAAA,QAAA,C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,KAAA,EAAA,EAAM,MAAK,GAAI,EAAA,OAAA,EAAS,MAAM,KAAM,CAAA,QAAA,EAAU,CACjD,CACF,CAEA,GAAA;AAAA;AAEJ,aACH,CAAA;AAAA;AACH,SACD;AAAA,OACH;AAEA,MAAmB,kBAAA,CAAA;AAAA,QACjB,QAAA,EAAU,MAAM,KAAM,CAAA,QAAA;AAAA,QACtB,iBAAmB,EAAA,eAAA;AAAA,QACnB,OAAS,EAAA;AAAA,UACP,QAAA,EAAU,OAAO,KAAM,EAAA;AAAA,UACvB,UAAA;AAAA,UACA,aAAA;AAAA,UACA,cAAgB,EAAA;AAAA;AAClB,OACD,CAAA;AAAA;AACH,GACF;AAEA,EAAO,OAAA,KAAA,CAAM,IAAK,CAAA,gBAAgB,CAAE,CAAA,GAAA;AAAA,IAAI,CAAC,CAAC,MAAQ,EAAA,UAAU,MAC1D,oBAAqB,CAAA;AAAA,MACnB,EAAA,EAAI,OAAO,KAAM,EAAA;AAAA,MACjB,UAAY,EAAA;AAAA,QACV,GAAG,UAAA;AAAA,QACH,GAAG,KAAM,CAAA,IAAA,CAAK,MAAO,CAAA,OAAA,EAAS,CAAE,CAAA,GAAA;AAAA,UAAI,CAAA,OAAA,KAClC,aAAa,IAAK,CAAA;AAAA,YAChB,IAAA,EAAM,QAAQ,GAAI,CAAA,EAAA;AAAA,YAClB,MAAA,EAAQ,EAAE,OAAQ;AAAA,WACnB;AAAA;AACH,OACF;AAAA,MACA,MAAQ,EAAA,sBAAA,CAAuB,MAAO,CAAA,MAAA,IAAU,EAAE,CAAA;AAAA,MAClD,cAAgB,EAAA,sBAAA,CAAuB,MAAO,CAAA,cAAA,IAAkB,EAAE;AAAA,KACnE;AAAA,GACH;AACF;;;;"}
|
|
@@ -2,6 +2,7 @@ import React, { Children, isValidElement, Fragment } from 'react';
|
|
|
2
2
|
import { createExtension, createExtensionInput, coreExtensionData, createFrontendModule } from '@backstage/frontend-plugin-api';
|
|
3
3
|
import { getComponentData } from '@backstage/core-plugin-api';
|
|
4
4
|
import { collectLegacyRoutes } from './collectLegacyRoutes.esm.js';
|
|
5
|
+
import { compatWrapper } from './compatWrapper/compatWrapper.esm.js';
|
|
5
6
|
|
|
6
7
|
function selectChildren(rootNode, selector, strictError) {
|
|
7
8
|
return Children.toArray(rootNode).flatMap((node) => {
|
|
@@ -55,7 +56,7 @@ function convertLegacyApp(rootElement) {
|
|
|
55
56
|
const [routesEl] = routesEls;
|
|
56
57
|
const CoreLayoutOverride = createExtension({
|
|
57
58
|
name: "layout",
|
|
58
|
-
attachTo: { id: "app", input: "
|
|
59
|
+
attachTo: { id: "app/root", input: "children" },
|
|
59
60
|
inputs: {
|
|
60
61
|
content: createExtensionInput([coreExtensionData.reactElement], {
|
|
61
62
|
singleton: true
|
|
@@ -65,10 +66,12 @@ function convertLegacyApp(rootElement) {
|
|
|
65
66
|
factory({ inputs }) {
|
|
66
67
|
return [
|
|
67
68
|
coreExtensionData.reactElement(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
compatWrapper(
|
|
70
|
+
React.cloneElement(
|
|
71
|
+
rootEl,
|
|
72
|
+
void 0,
|
|
73
|
+
inputs.content.get(coreExtensionData.reactElement)
|
|
74
|
+
)
|
|
72
75
|
)
|
|
73
76
|
)
|
|
74
77
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertLegacyApp.esm.js","sources":["../src/convertLegacyApp.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, {\n Children,\n Fragment,\n ReactElement,\n ReactNode,\n isValidElement,\n} from 'react';\nimport {\n FrontendModule,\n FrontendPlugin,\n coreExtensionData,\n createExtension,\n ExtensionOverrides,\n createExtensionInput,\n createFrontendModule,\n} from '@backstage/frontend-plugin-api';\nimport { getComponentData } from '@backstage/core-plugin-api';\nimport { collectLegacyRoutes } from './collectLegacyRoutes';\n\nfunction selectChildren(\n rootNode: ReactNode,\n selector?: (element: ReactElement<{ children?: ReactNode }>) => boolean,\n strictError?: string,\n): Array<ReactElement<{ children?: ReactNode }>> {\n return Children.toArray(rootNode).flatMap(node => {\n if (!isValidElement<{ children?: ReactNode }>(node)) {\n return [];\n }\n\n if (node.type === Fragment) {\n return selectChildren(node.props.children, selector, strictError);\n }\n\n if (selector === undefined || selector(node)) {\n return [node];\n }\n\n if (strictError) {\n throw new Error(strictError);\n }\n\n return selectChildren(node.props.children, selector, strictError);\n });\n}\n\n/** @public */\nexport function convertLegacyApp(\n rootElement: React.JSX.Element,\n): (FrontendPlugin | FrontendModule | ExtensionOverrides)[] {\n if (getComponentData(rootElement, 'core.type') === 'FlatRoutes') {\n return collectLegacyRoutes(rootElement);\n }\n\n const appRouterEls = selectChildren(\n rootElement,\n el => getComponentData(el, 'core.type') === 'AppRouter',\n );\n if (appRouterEls.length !== 1) {\n throw new Error(\n \"Failed to convert legacy app, AppRouter element could not been found. Make sure it's at the top level of the App element tree\",\n );\n }\n\n const rootEls = selectChildren(\n appRouterEls[0].props.children,\n el =>\n Boolean(el.props.children) &&\n selectChildren(\n el.props.children,\n innerEl => getComponentData(innerEl, 'core.type') === 'FlatRoutes',\n ).length === 1,\n );\n if (rootEls.length !== 1) {\n throw new Error(\n \"Failed to convert legacy app, Root element containing FlatRoutes could not been found. Make sure it's within the AppRouter element of the App element tree\",\n );\n }\n const [rootEl] = rootEls;\n\n const routesEls = selectChildren(\n rootEls[0].props.children,\n el => getComponentData(el, 'core.type') === 'FlatRoutes',\n );\n if (routesEls.length !== 1) {\n throw new Error(\n 'Unexpectedly failed to find FlatRoutes in app element tree',\n );\n }\n const [routesEl] = routesEls;\n\n const CoreLayoutOverride = createExtension({\n name: 'layout',\n attachTo: { id: 'app', input: '
|
|
1
|
+
{"version":3,"file":"convertLegacyApp.esm.js","sources":["../src/convertLegacyApp.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, {\n Children,\n Fragment,\n ReactElement,\n ReactNode,\n isValidElement,\n} from 'react';\nimport {\n FrontendModule,\n FrontendPlugin,\n coreExtensionData,\n createExtension,\n ExtensionOverrides,\n createExtensionInput,\n createFrontendModule,\n} from '@backstage/frontend-plugin-api';\nimport { getComponentData } from '@backstage/core-plugin-api';\nimport { collectLegacyRoutes } from './collectLegacyRoutes';\nimport { compatWrapper } from './compatWrapper';\n\nfunction selectChildren(\n rootNode: ReactNode,\n selector?: (element: ReactElement<{ children?: ReactNode }>) => boolean,\n strictError?: string,\n): Array<ReactElement<{ children?: ReactNode }>> {\n return Children.toArray(rootNode).flatMap(node => {\n if (!isValidElement<{ children?: ReactNode }>(node)) {\n return [];\n }\n\n if (node.type === Fragment) {\n return selectChildren(node.props.children, selector, strictError);\n }\n\n if (selector === undefined || selector(node)) {\n return [node];\n }\n\n if (strictError) {\n throw new Error(strictError);\n }\n\n return selectChildren(node.props.children, selector, strictError);\n });\n}\n\n/** @public */\nexport function convertLegacyApp(\n rootElement: React.JSX.Element,\n): (FrontendPlugin | FrontendModule | ExtensionOverrides)[] {\n if (getComponentData(rootElement, 'core.type') === 'FlatRoutes') {\n return collectLegacyRoutes(rootElement);\n }\n\n const appRouterEls = selectChildren(\n rootElement,\n el => getComponentData(el, 'core.type') === 'AppRouter',\n );\n if (appRouterEls.length !== 1) {\n throw new Error(\n \"Failed to convert legacy app, AppRouter element could not been found. Make sure it's at the top level of the App element tree\",\n );\n }\n\n const rootEls = selectChildren(\n appRouterEls[0].props.children,\n el =>\n Boolean(el.props.children) &&\n selectChildren(\n el.props.children,\n innerEl => getComponentData(innerEl, 'core.type') === 'FlatRoutes',\n ).length === 1,\n );\n if (rootEls.length !== 1) {\n throw new Error(\n \"Failed to convert legacy app, Root element containing FlatRoutes could not been found. Make sure it's within the AppRouter element of the App element tree\",\n );\n }\n const [rootEl] = rootEls;\n\n const routesEls = selectChildren(\n rootEls[0].props.children,\n el => getComponentData(el, 'core.type') === 'FlatRoutes',\n );\n if (routesEls.length !== 1) {\n throw new Error(\n 'Unexpectedly failed to find FlatRoutes in app element tree',\n );\n }\n const [routesEl] = routesEls;\n\n const CoreLayoutOverride = createExtension({\n name: 'layout',\n attachTo: { id: 'app/root', input: 'children' },\n inputs: {\n content: createExtensionInput([coreExtensionData.reactElement], {\n singleton: true,\n }),\n },\n output: [coreExtensionData.reactElement],\n factory({ inputs }) {\n // Clone the root element, this replaces the FlatRoutes declared in the app with out content input\n return [\n coreExtensionData.reactElement(\n compatWrapper(\n React.cloneElement(\n rootEl,\n undefined,\n inputs.content.get(coreExtensionData.reactElement),\n ),\n ),\n ),\n ];\n },\n });\n const CoreNavOverride = createExtension({\n name: 'nav',\n attachTo: { id: 'app/layout', input: 'nav' },\n output: [],\n factory: () => [],\n disabled: true,\n });\n\n const collectedRoutes = collectLegacyRoutes(routesEl);\n\n return [\n ...collectedRoutes,\n createFrontendModule({\n pluginId: 'app',\n extensions: [CoreLayoutOverride, CoreNavOverride],\n }),\n ];\n}\n"],"names":[],"mappings":";;;;;;AAoCA,SAAS,cAAA,CACP,QACA,EAAA,QAAA,EACA,WAC+C,EAAA;AAC/C,EAAA,OAAO,QAAS,CAAA,OAAA,CAAQ,QAAQ,CAAA,CAA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AAA,EAAc,OAAO,KAAM,EAAA;AAAA,IAC3C,QAAQ,EAAC;AAAA,IACT,OAAA,EAAS,MAAM,EAAC;AAAA,IAChB,QAAU,EAAA;AAAA,GACX,CAAA;AAED,EAAM,MAAA,eAAA,GAAkB,oBAAoB,QAAQ,CAAA;AAEpD,EAAO,OAAA;AAAA,IACL,GAAG,eAAA;AAAA,IACH,oBAAqB,CAAA;AAAA,MACnB,QAAU,EAAA,KAAA;AAAA,MACV,UAAA,EAAY,CAAC,kBAAA,EAAoB,eAAe;AAAA,KACjD;AAAA,GACH;AACF;;;;"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ApiBlueprint, IconBundleBlueprint, createExtension, ThemeBlueprint, RouterBlueprint, SignInPageBlueprint, createComponentExtension, coreComponentRefs, createFrontendModule } from '@backstage/frontend-plugin-api';
|
|
3
|
+
import { toLegacyPlugin } from './compatWrapper/BackwardsCompatProvider.esm.js';
|
|
4
|
+
import { compatWrapper } from './compatWrapper/compatWrapper.esm.js';
|
|
5
|
+
|
|
6
|
+
function componentCompatWrapper(Component) {
|
|
7
|
+
return (props) => compatWrapper(/* @__PURE__ */ React.createElement(Component, { ...props }));
|
|
8
|
+
}
|
|
9
|
+
function convertLegacyAppOptions(options = {}) {
|
|
10
|
+
const { apis, icons, plugins, components, themes, featureFlags } = options;
|
|
11
|
+
const allApis = [
|
|
12
|
+
...plugins?.flatMap((plugin) => [...plugin.getApis()]) ?? [],
|
|
13
|
+
...apis ?? []
|
|
14
|
+
];
|
|
15
|
+
const deduplicatedApis = Array.from(
|
|
16
|
+
new Map(allApis.map((api) => [api.api.id, api])).values()
|
|
17
|
+
);
|
|
18
|
+
const extensions = deduplicatedApis.map(
|
|
19
|
+
(factory) => ApiBlueprint.make({ name: factory.api.id, params: { factory } })
|
|
20
|
+
);
|
|
21
|
+
if (icons) {
|
|
22
|
+
extensions.push(
|
|
23
|
+
IconBundleBlueprint.make({
|
|
24
|
+
name: "app-options",
|
|
25
|
+
params: { icons }
|
|
26
|
+
})
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
if (themes) {
|
|
30
|
+
for (const id of ["light", "dark"]) {
|
|
31
|
+
if (!themes.some((theme) => theme.id === id)) {
|
|
32
|
+
extensions.push(
|
|
33
|
+
createExtension({
|
|
34
|
+
kind: "theme",
|
|
35
|
+
name: id,
|
|
36
|
+
attachTo: { id: "api:app/app-theme", input: "themes" },
|
|
37
|
+
disabled: true,
|
|
38
|
+
output: [],
|
|
39
|
+
factory: () => []
|
|
40
|
+
})
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
extensions.push(
|
|
45
|
+
...themes.map(
|
|
46
|
+
(theme) => ThemeBlueprint.make({
|
|
47
|
+
name: theme.id,
|
|
48
|
+
params: { theme }
|
|
49
|
+
})
|
|
50
|
+
)
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
if (components) {
|
|
54
|
+
const {
|
|
55
|
+
BootErrorPage,
|
|
56
|
+
ErrorBoundaryFallback,
|
|
57
|
+
NotFoundErrorPage,
|
|
58
|
+
Progress,
|
|
59
|
+
Router,
|
|
60
|
+
SignInPage,
|
|
61
|
+
ThemeProvider
|
|
62
|
+
} = components;
|
|
63
|
+
if (BootErrorPage) {
|
|
64
|
+
throw new Error(
|
|
65
|
+
"components.BootErrorPage is not supported by convertLegacyAppOptions"
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
if (ThemeProvider) {
|
|
69
|
+
throw new Error(
|
|
70
|
+
"components.ThemeProvider is not supported by convertLegacyAppOptions"
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
if (Router) {
|
|
74
|
+
extensions.push(
|
|
75
|
+
RouterBlueprint.make({
|
|
76
|
+
params: { Component: componentCompatWrapper(Router) }
|
|
77
|
+
})
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
if (SignInPage) {
|
|
81
|
+
extensions.push(
|
|
82
|
+
SignInPageBlueprint.make({
|
|
83
|
+
params: {
|
|
84
|
+
loader: () => Promise.resolve(componentCompatWrapper(SignInPage))
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
if (Progress) {
|
|
90
|
+
extensions.push(
|
|
91
|
+
createComponentExtension({
|
|
92
|
+
ref: coreComponentRefs.progress,
|
|
93
|
+
loader: { sync: () => componentCompatWrapper(Progress) }
|
|
94
|
+
})
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
if (NotFoundErrorPage) {
|
|
98
|
+
extensions.push(
|
|
99
|
+
createComponentExtension({
|
|
100
|
+
ref: coreComponentRefs.notFoundErrorPage,
|
|
101
|
+
loader: { sync: () => componentCompatWrapper(NotFoundErrorPage) }
|
|
102
|
+
})
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
if (ErrorBoundaryFallback) {
|
|
106
|
+
const WrappedErrorBoundaryFallback = (props) => compatWrapper(
|
|
107
|
+
/* @__PURE__ */ React.createElement(
|
|
108
|
+
ErrorBoundaryFallback,
|
|
109
|
+
{
|
|
110
|
+
...props,
|
|
111
|
+
plugin: props.plugin && toLegacyPlugin(props.plugin)
|
|
112
|
+
}
|
|
113
|
+
)
|
|
114
|
+
);
|
|
115
|
+
extensions.push(
|
|
116
|
+
createComponentExtension({
|
|
117
|
+
ref: coreComponentRefs.errorBoundaryFallback,
|
|
118
|
+
loader: {
|
|
119
|
+
sync: () => componentCompatWrapper(WrappedErrorBoundaryFallback)
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return createFrontendModule({
|
|
126
|
+
pluginId: "app",
|
|
127
|
+
extensions,
|
|
128
|
+
featureFlags
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export { convertLegacyAppOptions };
|
|
133
|
+
//# sourceMappingURL=convertLegacyAppOptions.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertLegacyAppOptions.esm.js","sources":["../src/convertLegacyAppOptions.tsx"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from 'react';\nimport {\n ApiBlueprint,\n coreComponentRefs,\n CoreErrorBoundaryFallbackProps,\n createComponentExtension,\n createExtension,\n createFrontendModule,\n ExtensionDefinition,\n FrontendModule,\n IconBundleBlueprint,\n RouterBlueprint,\n SignInPageBlueprint,\n ThemeBlueprint,\n} from '@backstage/frontend-plugin-api';\nimport {\n AnyApiFactory,\n AppComponents,\n AppTheme,\n BackstagePlugin,\n FeatureFlag,\n IconComponent,\n} from '@backstage/core-plugin-api';\nimport { toLegacyPlugin } from './compatWrapper/BackwardsCompatProvider';\nimport { compatWrapper } from './compatWrapper';\n\nfunction componentCompatWrapper<TProps extends {}>(\n Component: React.ComponentType<TProps>,\n) {\n return (props: TProps) => compatWrapper(<Component {...props} />);\n}\n\n/**\n * @public\n */\nexport function convertLegacyAppOptions(\n options: {\n apis?: Iterable<AnyApiFactory>;\n\n icons?: { [key in string]: IconComponent };\n\n plugins?: Array<BackstagePlugin>;\n\n components?: Partial<AppComponents>;\n\n themes?: AppTheme[];\n\n featureFlags?: (FeatureFlag & Omit<FeatureFlag, 'pluginId'>)[];\n } = {},\n): FrontendModule {\n const { apis, icons, plugins, components, themes, featureFlags } = options;\n\n const allApis = [\n ...(plugins?.flatMap(plugin => [...plugin.getApis()]) ?? []),\n ...(apis ?? []),\n ];\n const deduplicatedApis = Array.from(\n new Map(allApis.map(api => [api.api.id, api])).values(),\n );\n const extensions: ExtensionDefinition[] = deduplicatedApis.map(factory =>\n ApiBlueprint.make({ name: factory.api.id, params: { factory } }),\n );\n\n if (icons) {\n extensions.push(\n IconBundleBlueprint.make({\n name: 'app-options',\n params: { icons },\n }),\n );\n }\n\n if (themes) {\n // IF any themes are provided we need to disable the default ones, unless they are overridden\n for (const id of ['light', 'dark']) {\n if (!themes.some(theme => theme.id === id)) {\n extensions.push(\n createExtension({\n kind: 'theme',\n name: id,\n attachTo: { id: 'api:app/app-theme', input: 'themes' },\n disabled: true,\n output: [],\n factory: () => [],\n }),\n );\n }\n }\n extensions.push(\n ...themes.map(theme =>\n ThemeBlueprint.make({\n name: theme.id,\n params: { theme },\n }),\n ),\n );\n }\n\n if (components) {\n const {\n BootErrorPage,\n ErrorBoundaryFallback,\n NotFoundErrorPage,\n Progress,\n Router,\n SignInPage,\n ThemeProvider,\n } = components;\n\n if (BootErrorPage) {\n throw new Error(\n 'components.BootErrorPage is not supported by convertLegacyAppOptions',\n );\n }\n if (ThemeProvider) {\n throw new Error(\n 'components.ThemeProvider is not supported by convertLegacyAppOptions',\n );\n }\n if (Router) {\n extensions.push(\n RouterBlueprint.make({\n params: { Component: componentCompatWrapper(Router) },\n }),\n );\n }\n if (SignInPage) {\n extensions.push(\n SignInPageBlueprint.make({\n params: {\n loader: () => Promise.resolve(componentCompatWrapper(SignInPage)),\n },\n }),\n );\n }\n if (Progress) {\n extensions.push(\n createComponentExtension({\n ref: coreComponentRefs.progress,\n loader: { sync: () => componentCompatWrapper(Progress) },\n }),\n );\n }\n if (NotFoundErrorPage) {\n extensions.push(\n createComponentExtension({\n ref: coreComponentRefs.notFoundErrorPage,\n loader: { sync: () => componentCompatWrapper(NotFoundErrorPage) },\n }),\n );\n }\n if (ErrorBoundaryFallback) {\n const WrappedErrorBoundaryFallback = (\n props: CoreErrorBoundaryFallbackProps,\n ) =>\n compatWrapper(\n <ErrorBoundaryFallback\n {...props}\n plugin={props.plugin && toLegacyPlugin(props.plugin)}\n />,\n );\n extensions.push(\n createComponentExtension({\n ref: coreComponentRefs.errorBoundaryFallback,\n loader: {\n sync: () => componentCompatWrapper(WrappedErrorBoundaryFallback),\n },\n }),\n );\n }\n }\n\n return createFrontendModule({\n pluginId: 'app',\n extensions,\n featureFlags,\n });\n}\n"],"names":[],"mappings":";;;;;AA0CA,SAAS,uBACP,SACA,EAAA;AACA,EAAA,OAAO,CAAC,KAAkB,KAAA,aAAA,qCAAe,SAAW,EAAA,EAAA,GAAG,OAAO,CAAE,CAAA;AAClE;AAKgB,SAAA,uBAAA,CACd,OAYI,GAAA,EACY,EAAA;AAChB,EAAA,MAAM,EAAE,IAAM,EAAA,KAAA,EAAO,SAAS,UAAY,EAAA,MAAA,EAAQ,cAAiB,GAAA,OAAA;AAEnE,EAAA,MAAM,OAAU,GAAA;AAAA,IACd,GAAI,OAAS,EAAA,OAAA,CAAQ,CAAU,MAAA,KAAA,CAAC,GAAG,MAAA,CAAO,OAAQ,EAAC,CAAC,CAAA,IAAK,EAAC;AAAA,IAC1D,GAAI,QAAQ;AAAC,GACf;AACA,EAAA,MAAM,mBAAmB,KAAM,CAAA,IAAA;AAAA,IAC7B,IAAI,GAAA,CAAI,OAAQ,CAAA,GAAA,CAAI,CAAO,GAAA,KAAA,CAAC,GAAI,CAAA,GAAA,CAAI,EAAI,EAAA,GAAG,CAAC,CAAC,EAAE,MAAO;AAAA,GACxD;AACA,EAAA,MAAM,aAAoC,gBAAiB,CAAA,GAAA;AAAA,IAAI,CAC7D,OAAA,KAAA,YAAA,CAAa,IAAK,CAAA,EAAE,IAAM,EAAA,OAAA,CAAQ,GAAI,CAAA,EAAA,EAAI,MAAQ,EAAA,EAAE,OAAQ,EAAA,EAAG;AAAA,GACjE;AAEA,EAAA,IAAI,KAAO,EAAA;AACT,IAAW,UAAA,CAAA,IAAA;AAAA,MACT,oBAAoB,IAAK,CAAA;AAAA,QACvB,IAAM,EAAA,aAAA;AAAA,QACN,MAAA,EAAQ,EAA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;AACF;AAGF,EAAA,OAAO,oBAAqB,CAAA;AAAA,IAC1B,QAAU,EAAA,KAAA;AAAA,IACV,UAAA;AAAA,IACA;AAAA,GACD,CAAA;AACH;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { ReactNode, ComponentType } from 'react';
|
|
2
|
-
import { AnalyticsApi, AnalyticsEvent, BackstagePlugin, RouteRef, SubRouteRef, ExternalRouteRef, AnyRouteRefParams } from '@backstage/core-plugin-api';
|
|
2
|
+
import { AnalyticsApi, AnalyticsEvent, AnyApiFactory, IconComponent, BackstagePlugin, AppComponents, AppTheme, FeatureFlag, RouteRef, SubRouteRef, ExternalRouteRef, AnyRouteRefParams } from '@backstage/core-plugin-api';
|
|
3
3
|
import { AnalyticsApi as AnalyticsApi$1, AnalyticsEvent as AnalyticsEvent$1, FrontendPlugin, FrontendModule, ExtensionOverrides, ExtensionDefinition, RouteRef as RouteRef$1, SubRouteRef as SubRouteRef$1, ExternalRouteRef as ExternalRouteRef$1 } from '@backstage/frontend-plugin-api';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -66,6 +66,20 @@ declare class NoOpAnalyticsApi implements AnalyticsApi, AnalyticsApi$1 {
|
|
|
66
66
|
/** @public */
|
|
67
67
|
declare function convertLegacyApp(rootElement: React.JSX.Element): (FrontendPlugin | FrontendModule | ExtensionOverrides)[];
|
|
68
68
|
|
|
69
|
+
/**
|
|
70
|
+
* @public
|
|
71
|
+
*/
|
|
72
|
+
declare function convertLegacyAppOptions(options?: {
|
|
73
|
+
apis?: Iterable<AnyApiFactory>;
|
|
74
|
+
icons?: {
|
|
75
|
+
[key in string]: IconComponent;
|
|
76
|
+
};
|
|
77
|
+
plugins?: Array<BackstagePlugin>;
|
|
78
|
+
components?: Partial<AppComponents>;
|
|
79
|
+
themes?: AppTheme[];
|
|
80
|
+
featureFlags?: (FeatureFlag & Omit<FeatureFlag, 'pluginId'>)[];
|
|
81
|
+
}): FrontendModule;
|
|
82
|
+
|
|
69
83
|
/** @public */
|
|
70
84
|
declare function convertLegacyPlugin(legacyPlugin: BackstagePlugin, options: {
|
|
71
85
|
extensions: ExtensionDefinition[];
|
|
@@ -149,4 +163,4 @@ declare function convertLegacyRouteRef<TParams extends AnyRouteRefParams>(ref: S
|
|
|
149
163
|
*/
|
|
150
164
|
declare function convertLegacyRouteRef<TParams extends AnyRouteRefParams>(ref: ExternalRouteRef$1<TParams>): ExternalRouteRef<TParams, true>;
|
|
151
165
|
|
|
152
|
-
export { MultipleAnalyticsApi, NoOpAnalyticsApi, type ToNewRouteRef, compatWrapper, convertLegacyApp, convertLegacyPageExtension, convertLegacyPlugin, convertLegacyRouteRef, convertLegacyRouteRefs };
|
|
166
|
+
export { MultipleAnalyticsApi, NoOpAnalyticsApi, type ToNewRouteRef, compatWrapper, convertLegacyApp, convertLegacyAppOptions, convertLegacyPageExtension, convertLegacyPlugin, convertLegacyRouteRef, convertLegacyRouteRefs };
|
package/dist/index.esm.js
CHANGED
|
@@ -2,6 +2,7 @@ export { compatWrapper } from './compatWrapper/compatWrapper.esm.js';
|
|
|
2
2
|
export { MultipleAnalyticsApi } from './apis/implementations/AnalyticsApi/MultipleAnalyticsApi.esm.js';
|
|
3
3
|
export { NoOpAnalyticsApi } from './apis/implementations/AnalyticsApi/NoOpAnalyticsApi.esm.js';
|
|
4
4
|
export { convertLegacyApp } from './convertLegacyApp.esm.js';
|
|
5
|
+
export { convertLegacyAppOptions } from './convertLegacyAppOptions.esm.js';
|
|
5
6
|
export { convertLegacyPlugin } from './convertLegacyPlugin.esm.js';
|
|
6
7
|
export { convertLegacyPageExtension } from './convertLegacyPageExtension.esm.js';
|
|
7
8
|
export { convertLegacyRouteRef, convertLegacyRouteRefs } from './convertLegacyRouteRef.esm.js';
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/core-compat-api",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.7-next.1",
|
|
4
4
|
"backstage": {
|
|
5
5
|
"role": "web-library"
|
|
6
6
|
},
|
|
@@ -31,21 +31,21 @@
|
|
|
31
31
|
"test": "backstage-cli package test"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@backstage/core-plugin-api": "
|
|
35
|
-
"@backstage/frontend-plugin-api": "
|
|
36
|
-
"@backstage/version-bridge": "
|
|
34
|
+
"@backstage/core-plugin-api": "1.10.4",
|
|
35
|
+
"@backstage/frontend-plugin-api": "0.9.6-next.1",
|
|
36
|
+
"@backstage/version-bridge": "1.0.11",
|
|
37
37
|
"lodash": "^4.17.21"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@backstage-community/plugin-puppetdb": "^0.1.18",
|
|
41
41
|
"@backstage-community/plugin-stackstorm": "^0.1.16",
|
|
42
|
-
"@backstage/cli": "
|
|
43
|
-
"@backstage/core-app-api": "
|
|
44
|
-
"@backstage/frontend-app-api": "
|
|
45
|
-
"@backstage/frontend-test-utils": "
|
|
46
|
-
"@backstage/plugin-catalog": "
|
|
47
|
-
"@backstage/test-utils": "
|
|
48
|
-
"@backstage/types": "
|
|
42
|
+
"@backstage/cli": "0.30.1-next.0",
|
|
43
|
+
"@backstage/core-app-api": "1.15.5",
|
|
44
|
+
"@backstage/frontend-app-api": "0.10.6-next.1",
|
|
45
|
+
"@backstage/frontend-test-utils": "0.2.7-next.1",
|
|
46
|
+
"@backstage/plugin-catalog": "1.28.0-next.1",
|
|
47
|
+
"@backstage/test-utils": "1.7.5",
|
|
48
|
+
"@backstage/types": "1.2.1",
|
|
49
49
|
"@oriflame/backstage-plugin-score-card": "^0.9.0",
|
|
50
50
|
"@testing-library/jest-dom": "^6.0.0",
|
|
51
51
|
"@testing-library/react": "^16.0.0",
|