From 80442558f675e49224511248483b55a1d750745d Mon Sep 17 00:00:00 2001 From: Vincenzo Scamporlino Date: Mon, 13 Nov 2023 23:44:58 +0100 Subject: [PATCH] core-compat-api: move over convertLegacyRouteRef Signed-off-by: Vincenzo Scamporlino --- packages/core-compat-api/package.json | 2 +- .../src/collectLegacyRoutes.tsx | 2 +- .../src}/convertLegacyRouteRef.ts | 45 ++++++------------- packages/core-compat-api/src/index.ts | 1 + packages/core-plugin-api/src/alpha.ts | 1 - 5 files changed, 17 insertions(+), 34 deletions(-) rename packages/{core-plugin-api/src/routing => core-compat-api/src}/convertLegacyRouteRef.ts (74%) diff --git a/packages/core-compat-api/package.json b/packages/core-compat-api/package.json index a9bdfe2ff9..73266cb587 100644 --- a/packages/core-compat-api/package.json +++ b/packages/core-compat-api/package.json @@ -25,7 +25,6 @@ }, "devDependencies": { "@backstage/cli": "workspace:^", - "@backstage/core-app-api": "workspace:^", "@backstage/plugin-puppetdb": "workspace:^", "@backstage/plugin-stackstorm": "workspace:^", "@oriflame/backstage-plugin-score-card": "^0.7.0", @@ -39,6 +38,7 @@ "react-router-dom": "6.0.0-beta.0 || ^6.3.0" }, "dependencies": { + "@backstage/core-app-api": "workspace:^", "@backstage/core-plugin-api": "workspace:^", "@backstage/frontend-plugin-api": "workspace:^" } diff --git a/packages/core-compat-api/src/collectLegacyRoutes.tsx b/packages/core-compat-api/src/collectLegacyRoutes.tsx index 8178de2876..037107bfda 100644 --- a/packages/core-compat-api/src/collectLegacyRoutes.tsx +++ b/packages/core-compat-api/src/collectLegacyRoutes.tsx @@ -28,7 +28,7 @@ import { RouteRef, getComponentData, } from '@backstage/core-plugin-api'; -import { convertLegacyRouteRef } from '@backstage/core-plugin-api/alpha'; +import { convertLegacyRouteRef } from './convertLegacyRouteRef'; /* diff --git a/packages/core-plugin-api/src/routing/convertLegacyRouteRef.ts b/packages/core-compat-api/src/convertLegacyRouteRef.ts similarity index 74% rename from packages/core-plugin-api/src/routing/convertLegacyRouteRef.ts rename to packages/core-compat-api/src/convertLegacyRouteRef.ts index 940a4174a9..6047ccc60d 100644 --- a/packages/core-plugin-api/src/routing/convertLegacyRouteRef.ts +++ b/packages/core-compat-api/src/convertLegacyRouteRef.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -import { routeRefType } from './types'; import { RouteRef as LegacyRouteRef, SubRouteRef as LegacySubRouteRef, @@ -22,9 +21,9 @@ import { AnyRouteRefParams, } from '@backstage/core-plugin-api'; -// Relative imports to avoid dependency, at least for now +// eslint-disable-next-line @backstage/no-forbidden-package-imports +import { routeRefType } from '@backstage/core-plugin-api/src/routing/types'; -// eslint-disable-next-line @backstage/no-relative-monorepo-imports import { RouteRef, SubRouteRef, @@ -32,29 +31,13 @@ import { createRouteRef, createSubRouteRef, createExternalRouteRef, -} from '../../../frontend-plugin-api/src/routing'; -// eslint-disable-next-line @backstage/no-relative-monorepo-imports -import { toInternalRouteRef } from '../../../frontend-plugin-api/src/routing/RouteRef'; -// eslint-disable-next-line @backstage/no-relative-monorepo-imports -import { toInternalSubRouteRef } from '../../../frontend-plugin-api/src/routing/SubRouteRef'; -// eslint-disable-next-line @backstage/no-relative-monorepo-imports -import { toInternalExternalRouteRef } from '../../../frontend-plugin-api/src/routing/ExternalRouteRef'; - -// TODO(Rugvip): Once this is moved to a compat package these aliases can be removed and imported from frontend- instead - -/** @ignore */ -type NewRouteRef = - RouteRef; - -/** @ignore */ -type NewSubRouteRef = - SubRouteRef; - -/** @ignore */ -type NewExternalRouteRef< - TParams extends AnyRouteRefParams = AnyRouteRefParams, - TOptional extends boolean = boolean, -> = ExternalRouteRef; +} from '@backstage/frontend-plugin-api'; +// eslint-disable-next-line @backstage/no-forbidden-package-imports +import { toInternalRouteRef } from '@backstage/frontend-plugin-api/src/routing/RouteRef'; +// eslint-disable-next-line @backstage/no-forbidden-package-imports +import { toInternalSubRouteRef } from '@backstage/frontend-plugin-api/src/routing/SubRouteRef'; +// eslint-disable-next-line @backstage/no-forbidden-package-imports +import { toInternalExternalRouteRef } from '@backstage/frontend-plugin-api/src/routing/ExternalRouteRef'; /** * A temporary helper to convert a legacy route ref to the new system. @@ -66,7 +49,7 @@ type NewExternalRouteRef< */ export function convertLegacyRouteRef( ref: LegacyRouteRef, -): NewRouteRef; +): RouteRef; /** * A temporary helper to convert a legacy sub route ref to the new system. @@ -78,7 +61,7 @@ export function convertLegacyRouteRef( */ export function convertLegacyRouteRef( ref: LegacySubRouteRef, -): NewSubRouteRef; +): SubRouteRef; /** * A temporary helper to convert a legacy external route ref to the new system. @@ -93,14 +76,14 @@ export function convertLegacyRouteRef< TOptional extends boolean, >( ref: LegacyExternalRouteRef, -): NewExternalRouteRef; +): ExternalRouteRef; export function convertLegacyRouteRef( ref: LegacyRouteRef | LegacySubRouteRef | LegacyExternalRouteRef, -): NewRouteRef | NewSubRouteRef | NewExternalRouteRef { +): RouteRef | SubRouteRef | ExternalRouteRef { // Ref has already been converted if ('$$type' in ref) { - return ref as unknown as NewRouteRef | NewSubRouteRef | NewExternalRouteRef; + return ref as unknown as RouteRef | SubRouteRef | ExternalRouteRef; } const type = (ref as unknown as { [routeRefType]: unknown })[routeRefType]; diff --git a/packages/core-compat-api/src/index.ts b/packages/core-compat-api/src/index.ts index e5f61119a3..421ced7054 100644 --- a/packages/core-compat-api/src/index.ts +++ b/packages/core-compat-api/src/index.ts @@ -15,3 +15,4 @@ */ export { collectLegacyRoutes } from './collectLegacyRoutes'; export { convertLegacyApp } from './convertLegacyApp'; +export { convertLegacyRouteRef } from './convertLegacyRouteRef'; diff --git a/packages/core-plugin-api/src/alpha.ts b/packages/core-plugin-api/src/alpha.ts index 540b4ed22a..ebcbcf34c0 100644 --- a/packages/core-plugin-api/src/alpha.ts +++ b/packages/core-plugin-api/src/alpha.ts @@ -16,4 +16,3 @@ export * from './translation'; export * from './apis/alpha'; -export { convertLegacyRouteRef } from './routing/convertLegacyRouteRef';