diff --git a/.changeset/deduplicate-joinpaths-routing.md b/.changeset/deduplicate-joinpaths-routing.md new file mode 100644 index 0000000000..8a17fbc17b --- /dev/null +++ b/.changeset/deduplicate-joinpaths-routing.md @@ -0,0 +1,5 @@ +--- +'@backstage/frontend-app-api': patch +--- + +Internal cleanup of routing utilities. diff --git a/packages/frontend-app-api/src/routing/RouteResolver.ts b/packages/frontend-app-api/src/routing/RouteResolver.ts index 7fd7ef934c..a19105b387 100644 --- a/packages/frontend-app-api/src/routing/RouteResolver.ts +++ b/packages/frontend-app-api/src/routing/RouteResolver.ts @@ -31,15 +31,7 @@ import { OpaqueSubRouteRef, } from '@internal/frontend'; import { RouteAliasResolver } from './RouteAliasResolver'; - -// Joins a list of paths together, avoiding trailing and duplicate slashes -export function joinPaths(...paths: string[]): string { - const normalized = paths.join('/').replace(/\/\/+/g, '/'); - if (normalized !== '/' && normalized.endsWith('/')) { - return normalized.slice(0, -1); - } - return normalized; -} +import { joinPaths } from './joinPaths'; /** * Resolves the absolute route ref that our target route ref is pointing pointing to, as well diff --git a/packages/frontend-app-api/src/routing/extractRouteInfoFromAppNode.ts b/packages/frontend-app-api/src/routing/extractRouteInfoFromAppNode.ts index 4d88fb5fb1..062a54f709 100644 --- a/packages/frontend-app-api/src/routing/extractRouteInfoFromAppNode.ts +++ b/packages/frontend-app-api/src/routing/extractRouteInfoFromAppNode.ts @@ -21,6 +21,7 @@ import { createExactRouteAliasResolver, RouteAliasResolver, } from './RouteAliasResolver'; +import { joinPaths } from './joinPaths'; /** @internal */ export type RouteInfo = { @@ -41,15 +42,6 @@ export const MATCH_ALL_ROUTE: BackstageRouteObject = { routeRefs: new Set(), }; -// Joins a list of paths together, avoiding trailing and duplicate slashes -export function joinPaths(...paths: string[]): string { - const normalized = paths.join('/').replace(/\/\/+/g, '/'); - if (normalized !== '/' && normalized.endsWith('/')) { - return normalized.slice(0, -1); - } - return normalized; -} - export function extractRouteInfoFromAppNode( node: AppNode, routeAliasResolver: RouteAliasResolver, diff --git a/packages/frontend-app-api/src/routing/joinPaths.ts b/packages/frontend-app-api/src/routing/joinPaths.ts new file mode 100644 index 0000000000..89b84bb51c --- /dev/null +++ b/packages/frontend-app-api/src/routing/joinPaths.ts @@ -0,0 +1,24 @@ +/* + * Copyright 2023 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Joins a list of paths together, avoiding trailing and duplicate slashes +export function joinPaths(...paths: string[]): string { + const normalized = paths.join('/').replace(/\/\/+/g, '/'); + if (normalized !== '/' && normalized.endsWith('/')) { + return normalized.slice(0, -1); + } + return normalized; +}