@backstage/core-compat-api 0.4.4 → 0.4.5-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 +19 -0
- package/dist/collectLegacyRoutes.esm.js +1 -1
- package/dist/collectLegacyRoutes.esm.js.map +1 -1
- package/dist/convertLegacyAppOptions.esm.js +4 -1
- package/dist/convertLegacyAppOptions.esm.js.map +1 -1
- package/dist/convertLegacyPlugin.esm.js +4 -1
- package/dist/convertLegacyPlugin.esm.js.map +1 -1
- package/package.json +12 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @backstage/core-compat-api
|
|
2
2
|
|
|
3
|
+
## 0.4.5-next.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- f2f133c: Internal update to use the new variant of `ApiBlueprint`.
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @backstage/plugin-catalog-react@1.20.0-next.1
|
|
10
|
+
- @backstage/frontend-plugin-api@0.11.0-next.0
|
|
11
|
+
- @backstage/core-plugin-api@1.10.9
|
|
12
|
+
- @backstage/version-bridge@1.0.11
|
|
13
|
+
|
|
14
|
+
## 0.4.5-next.0
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies
|
|
19
|
+
- @backstage/plugin-catalog-react@1.19.2-next.0
|
|
20
|
+
- @backstage/frontend-plugin-api@0.10.4
|
|
21
|
+
|
|
3
22
|
## 0.4.4
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
|
@@ -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 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 FrontendModule,\n createFrontendModule,\n} from '@backstage/frontend-plugin-api';\nimport { Children, ReactNode, isValidElement } from 'react';\nimport { Route, Routes } from 'react-router-dom';\nimport {\n convertLegacyRouteRef,\n convertLegacyRouteRefs,\n} from './convertLegacyRouteRef';\nimport { compatWrapper } from './compatWrapper';\nimport { collectEntityPageContents } from './collectEntityPageContents';\nimport { normalizeRoutePath } from './normalizeRoutePath';\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\nexport function 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 entityPage?: JSX.Element,\n): (FrontendPlugin | FrontendModule)[] {\n const output = new Array<FrontendPlugin | FrontendModule>();\n\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 Children.forEach(flatRoutesElement.props.children, (route: ReactNode) => {\n if (route === null) {\n return;\n }\n // TODO(freben): Handle feature flag and permissions framework wrapper elements\n if (!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: normalizeRoutePath(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 if (entityPage) {\n collectEntityPageContents(entityPage, {\n discoverExtension(extension, plugin) {\n if (!plugin || plugin.getId() === 'catalog') {\n getPluginExtensions(orphanRoutesPlugin).push(extension);\n } else {\n getPluginExtensions(plugin).push(extension);\n }\n },\n });\n\n const extensions = new Array<ExtensionDefinition>();\n visitRouteChildren({\n children: entityPage,\n parentExtensionId: `page:catalog/entity`,\n context: {\n pluginId: 'catalog',\n extensions,\n getUniqueName,\n discoverPlugin(plugin) {\n if (plugin.getId() !== 'catalog') {\n getPluginExtensions(plugin);\n }\n },\n },\n });\n\n output.push(\n createFrontendModule({\n pluginId: 'catalog',\n extensions,\n }),\n );\n }\n\n for (const [plugin, extensions] of pluginExtensions) {\n output.push(\n createFrontendPlugin({\n pluginId: 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\n return output;\n}\n"],"names":[],"mappings":";;;;;;;;;;AA2EA,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,mBA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ectLegacyRoutes.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 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 FrontendModule,\n createFrontendModule,\n} from '@backstage/frontend-plugin-api';\nimport { Children, ReactNode, isValidElement } from 'react';\nimport { Route, Routes } from 'react-router-dom';\nimport {\n convertLegacyRouteRef,\n convertLegacyRouteRefs,\n} from './convertLegacyRouteRef';\nimport { compatWrapper } from './compatWrapper';\nimport { collectEntityPageContents } from './collectEntityPageContents';\nimport { normalizeRoutePath } from './normalizeRoutePath';\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\nexport function 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 entityPage?: JSX.Element,\n): (FrontendPlugin | FrontendModule)[] {\n const output = new Array<FrontendPlugin | FrontendModule>();\n\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 Children.forEach(flatRoutesElement.props.children, (route: ReactNode) => {\n if (route === null) {\n return;\n }\n // TODO(freben): Handle feature flag and permissions framework wrapper elements\n if (!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: normalizeRoutePath(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 if (entityPage) {\n collectEntityPageContents(entityPage, {\n discoverExtension(extension, plugin) {\n if (!plugin || plugin.getId() === 'catalog') {\n getPluginExtensions(orphanRoutesPlugin).push(extension);\n } else {\n getPluginExtensions(plugin).push(extension);\n }\n },\n });\n\n const extensions = new Array<ExtensionDefinition>();\n visitRouteChildren({\n children: entityPage,\n parentExtensionId: `page:catalog/entity`,\n context: {\n pluginId: 'catalog',\n extensions,\n getUniqueName,\n discoverPlugin(plugin) {\n if (plugin.getId() !== 'catalog') {\n getPluginExtensions(plugin);\n }\n },\n },\n });\n\n output.push(\n createFrontendModule({\n pluginId: 'catalog',\n extensions,\n }),\n );\n }\n\n for (const [plugin, extensions] of pluginExtensions) {\n output.push(\n createFrontendPlugin({\n pluginId: plugin.getId(),\n extensions: [\n ...extensions,\n ...Array.from(plugin.getApis()).map(factory =>\n ApiBlueprint.make({\n name: factory.api.id,\n params: define => define(factory),\n }),\n ),\n ],\n routes: convertLegacyRouteRefs(plugin.routes ?? {}),\n externalRoutes: convertLegacyRouteRefs(plugin.externalRoutes ?? {}),\n }),\n );\n }\n\n return output;\n}\n"],"names":[],"mappings":";;;;;;;;;;AA2EA,SAAS,yBAAyB,OAK/B,EAAA;AACD,EAAA,MAAM,EAAE,IAAA,EAAM,iBAAmB,EAAA,SAAA,EAAW,UAAa,GAAA,OAAA;AACzD,EAAA,OAAO,eAAgB,CAAA;AAA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QAClD,cAAgB,EAAA,sBAAA,CAAuB,MAAO,CAAA,cAAA,IAAkB,EAAE;AAAA,OACnE;AAAA,KACH;AAAA;AAGF,EAAO,OAAA,MAAA;AACT;;;;"}
|
|
@@ -16,7 +16,10 @@ function convertLegacyAppOptions(options = {}) {
|
|
|
16
16
|
new Map(allApis.map((api) => [api.api.id, api])).values()
|
|
17
17
|
);
|
|
18
18
|
const extensions = deduplicatedApis.map(
|
|
19
|
-
(factory) => ApiBlueprint.make({
|
|
19
|
+
(factory) => ApiBlueprint.make({
|
|
20
|
+
name: factory.api.id,
|
|
21
|
+
params: (define) => define(factory)
|
|
22
|
+
})
|
|
20
23
|
);
|
|
21
24
|
if (icons) {
|
|
22
25
|
extensions.push(
|
|
@@ -1 +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 { ComponentType } 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: 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({
|
|
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 { ComponentType } 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: 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({\n name: factory.api.id,\n params: define => define(factory),\n }),\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,qBAAe,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,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ACvB,QAAQ,EAAE,IAAA,EAAM,MAAM,sBAAA,CAAuB,iBAAiB,CAAE;AAAA,SACjE;AAAA,OACH;AAAA;AAEF,IAAA,IAAI,qBAAuB,EAAA;AACzB,MAAM,MAAA,4BAAA,GAA+B,CACnC,KAEA,KAAA,aAAA;AAAA,wBACE,GAAA;AAAA,UAAC,qBAAA;AAAA,UAAA;AAAA,YACE,GAAG,KAAA;AAAA,YACJ,MAAQ,EAAA,KAAA,CAAM,MAAU,IAAA,cAAA,CAAe,MAAM,MAAM;AAAA;AAAA;AACrD,OACF;AACF,MAAW,UAAA,CAAA,IAAA;AAAA,QACT,wBAAyB,CAAA;AAAA,UACvB,KAAK,iBAAkB,CAAA,qBAAA;AAAA,UACvB,MAAQ,EAAA;AAAA,YACN,IAAA,EAAM,MAAM,sBAAA,CAAuB,4BAA4B;AAAA;AACjE,SACD;AAAA,OACH;AAAA;AACF;AAGF,EAAA,OAAO,oBAAqB,CAAA;AAAA,IAC1B,QAAU,EAAA,KAAA;AAAA,IACV,UAAA;AAAA,IACA;AAAA,GACD,CAAA;AACH;;;;"}
|
|
@@ -3,7 +3,10 @@ import { convertLegacyRouteRefs } from './convertLegacyRouteRef.esm.js';
|
|
|
3
3
|
|
|
4
4
|
function convertLegacyPlugin(legacyPlugin, options) {
|
|
5
5
|
const apiExtensions = Array.from(legacyPlugin.getApis()).map(
|
|
6
|
-
(factory) => ApiBlueprint.make({
|
|
6
|
+
(factory) => ApiBlueprint.make({
|
|
7
|
+
name: factory.api.id,
|
|
8
|
+
params: (define) => define(factory)
|
|
9
|
+
})
|
|
7
10
|
);
|
|
8
11
|
return createFrontendPlugin({
|
|
9
12
|
pluginId: legacyPlugin.getId(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertLegacyPlugin.esm.js","sources":["../src/convertLegacyPlugin.ts"],"sourcesContent":["/*\n * Copyright 2024 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 { BackstagePlugin as LegacyBackstagePlugin } from '@backstage/core-plugin-api';\nimport {\n ApiBlueprint,\n ExtensionDefinition,\n FrontendPlugin as NewBackstagePlugin,\n createFrontendPlugin,\n} from '@backstage/frontend-plugin-api';\nimport { convertLegacyRouteRefs } from './convertLegacyRouteRef';\n\n/** @public */\nexport function convertLegacyPlugin(\n legacyPlugin: LegacyBackstagePlugin,\n options: { extensions: ExtensionDefinition[] },\n): NewBackstagePlugin {\n const apiExtensions = Array.from(legacyPlugin.getApis()).map(factory =>\n ApiBlueprint.make({
|
|
1
|
+
{"version":3,"file":"convertLegacyPlugin.esm.js","sources":["../src/convertLegacyPlugin.ts"],"sourcesContent":["/*\n * Copyright 2024 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 { BackstagePlugin as LegacyBackstagePlugin } from '@backstage/core-plugin-api';\nimport {\n ApiBlueprint,\n ExtensionDefinition,\n FrontendPlugin as NewBackstagePlugin,\n createFrontendPlugin,\n} from '@backstage/frontend-plugin-api';\nimport { convertLegacyRouteRefs } from './convertLegacyRouteRef';\n\n/** @public */\nexport function convertLegacyPlugin(\n legacyPlugin: LegacyBackstagePlugin,\n options: { extensions: ExtensionDefinition[] },\n): NewBackstagePlugin {\n const apiExtensions = Array.from(legacyPlugin.getApis()).map(factory =>\n ApiBlueprint.make({\n name: factory.api.id,\n params: define => define(factory),\n }),\n );\n return createFrontendPlugin({\n pluginId: legacyPlugin.getId(),\n featureFlags: [...legacyPlugin.getFeatureFlags()],\n routes: convertLegacyRouteRefs(legacyPlugin.routes ?? {}),\n externalRoutes: convertLegacyRouteRefs(legacyPlugin.externalRoutes ?? {}),\n extensions: [...apiExtensions, ...options.extensions],\n });\n}\n"],"names":[],"mappings":";;;AA0BgB,SAAA,mBAAA,CACd,cACA,OACoB,EAAA;AACpB,EAAA,MAAM,gBAAgB,KAAM,CAAA,IAAA,CAAK,YAAa,CAAA,OAAA,EAAS,CAAE,CAAA,GAAA;AAAA,IAAI,CAAA,OAAA,KAC3D,aAAa,IAAK,CAAA;AAAA,MAChB,IAAA,EAAM,QAAQ,GAAI,CAAA,EAAA;AAAA,MAClB,MAAA,EAAQ,CAAU,MAAA,KAAA,MAAA,CAAO,OAAO;AAAA,KACjC;AAAA,GACH;AACA,EAAA,OAAO,oBAAqB,CAAA;AAAA,IAC1B,QAAA,EAAU,aAAa,KAAM,EAAA;AAAA,IAC7B,YAAc,EAAA,CAAC,GAAG,YAAA,CAAa,iBAAiB,CAAA;AAAA,IAChD,MAAQ,EAAA,sBAAA,CAAuB,YAAa,CAAA,MAAA,IAAU,EAAE,CAAA;AAAA,IACxD,cAAgB,EAAA,sBAAA,CAAuB,YAAa,CAAA,cAAA,IAAkB,EAAE,CAAA;AAAA,IACxE,YAAY,CAAC,GAAG,aAAe,EAAA,GAAG,QAAQ,UAAU;AAAA,GACrD,CAAA;AACH;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/core-compat-api",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.5-next.1",
|
|
4
4
|
"backstage": {
|
|
5
5
|
"role": "web-library"
|
|
6
6
|
},
|
|
@@ -31,20 +31,20 @@
|
|
|
31
31
|
"test": "backstage-cli package test"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@backstage/core-plugin-api": "
|
|
35
|
-
"@backstage/frontend-plugin-api": "
|
|
36
|
-
"@backstage/plugin-catalog-react": "
|
|
37
|
-
"@backstage/version-bridge": "
|
|
34
|
+
"@backstage/core-plugin-api": "1.10.9",
|
|
35
|
+
"@backstage/frontend-plugin-api": "0.11.0-next.0",
|
|
36
|
+
"@backstage/plugin-catalog-react": "1.20.0-next.1",
|
|
37
|
+
"@backstage/version-bridge": "1.0.11",
|
|
38
38
|
"lodash": "^4.17.21"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@backstage/cli": "
|
|
42
|
-
"@backstage/core-app-api": "
|
|
43
|
-
"@backstage/frontend-app-api": "
|
|
44
|
-
"@backstage/frontend-test-utils": "
|
|
45
|
-
"@backstage/plugin-catalog": "
|
|
46
|
-
"@backstage/test-utils": "
|
|
47
|
-
"@backstage/types": "
|
|
41
|
+
"@backstage/cli": "0.33.2-next.0",
|
|
42
|
+
"@backstage/core-app-api": "1.18.0",
|
|
43
|
+
"@backstage/frontend-app-api": "0.11.5-next.1",
|
|
44
|
+
"@backstage/frontend-test-utils": "0.3.5-next.1",
|
|
45
|
+
"@backstage/plugin-catalog": "1.31.2-next.1",
|
|
46
|
+
"@backstage/test-utils": "1.7.11-next.0",
|
|
47
|
+
"@backstage/types": "1.2.1",
|
|
48
48
|
"@testing-library/jest-dom": "^6.0.0",
|
|
49
49
|
"@testing-library/react": "^16.0.0",
|
|
50
50
|
"@types/react": "^18.0.0",
|