Merge pull request #33955 from backstage/rugvip/deduplicate-joinpaths-in-frontend-app-api-routing
frontend-app-api: deduplicate joinPaths utility in routing
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/frontend-app-api': patch
|
||||
---
|
||||
|
||||
Internal cleanup of routing utilities.
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user