From 49005a3ea1f27fdddaa42585d67e8e0d578e9fe8 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Mon, 25 Nov 2024 13:00:31 +0000 Subject: [PATCH] feat(core/utils): Deprecate `getNumberOfUrlSegments` --- docs/migration/draft-v9-migration-guide.md | 1 + packages/core/src/utils-hoist/index.ts | 1 + packages/core/src/utils-hoist/url.ts | 3 +++ packages/core/test/utils-hoist/url.test.ts | 1 + packages/react/src/reactrouterv6.tsx | 2 ++ packages/utils/src/index.ts | 1 + 6 files changed, 9 insertions(+) diff --git a/docs/migration/draft-v9-migration-guide.md b/docs/migration/draft-v9-migration-guide.md index dba02dcdd509..4fb68681190c 100644 --- a/docs/migration/draft-v9-migration-guide.md +++ b/docs/migration/draft-v9-migration-guide.md @@ -15,6 +15,7 @@ - Deprecated `extractRequestData`. Instead manually extract relevant data off request. - Deprecated `arrayify`. No replacements. - Deprecated `memoBuilder`. No replacements. +- Deprecated `getNumberOfUrlSegments`. No replacements. - Deprecated `BAGGAGE_HEADER_NAME`. No replacements. - Deprecated `makeFifoCache`. No replacements. diff --git a/packages/core/src/utils-hoist/index.ts b/packages/core/src/utils-hoist/index.ts index c04f314c40f2..ce6be00849df 100644 --- a/packages/core/src/utils-hoist/index.ts +++ b/packages/core/src/utils-hoist/index.ts @@ -159,6 +159,7 @@ export { parseBaggageHeader, } from './baggage'; +// eslint-disable-next-line deprecation/deprecation export { getNumberOfUrlSegments, getSanitizedUrlString, parseUrl, stripUrlQueryAndFragment } from './url'; // eslint-disable-next-line deprecation/deprecation export { makeFifoCache } from './cache'; diff --git a/packages/core/src/utils-hoist/url.ts b/packages/core/src/utils-hoist/url.ts index e324f41f82a3..44dc669da93a 100644 --- a/packages/core/src/utils-hoist/url.ts +++ b/packages/core/src/utils-hoist/url.ts @@ -50,7 +50,10 @@ export function stripUrlQueryAndFragment(urlPath: string): string { /** * Returns number of URL segments of a passed string URL. + * + * @deprecated This function will be removed in the next major version. */ +// TODO(v9): Hoist this function into the places where we use it. (as it stands only react router v6 instrumentation) export function getNumberOfUrlSegments(url: string): number { // split at '/' or at '\/' to split regex urls correctly return url.split(/\\?\//).filter(s => s.length > 0 && s !== ',').length; diff --git a/packages/core/test/utils-hoist/url.test.ts b/packages/core/test/utils-hoist/url.test.ts index fd8b861516ab..cd793e1d3d0c 100644 --- a/packages/core/test/utils-hoist/url.test.ts +++ b/packages/core/test/utils-hoist/url.test.ts @@ -33,6 +33,7 @@ describe('getNumberOfUrlSegments', () => { ['multi param parameterized path', '/stores/:storeId/products/:productId', 4], ['regex path', String(/\/api\/post[0-9]/), 2], ])('%s', (_: string, input, output) => { + // eslint-disable-next-line deprecation/deprecation expect(getNumberOfUrlSegments(input)).toEqual(output); }); }); diff --git a/packages/react/src/reactrouterv6.tsx b/packages/react/src/reactrouterv6.tsx index b209391f1dda..341470b0002a 100644 --- a/packages/react/src/reactrouterv6.tsx +++ b/packages/react/src/reactrouterv6.tsx @@ -197,6 +197,8 @@ function getNormalizedName( // If the route defined on the element is something like // Product} /> // We should check against the branch.pathname for the number of / separators + // TODO(v9): Put the implementation of `getNumberOfUrlSegments` in this file + // eslint-disable-next-line deprecation/deprecation getNumberOfUrlSegments(pathBuilder) !== getNumberOfUrlSegments(branch.pathname) && // We should not count wildcard operators in the url segments calculation pathBuilder.slice(-2) !== '/*' diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 28629a1b240e..0a3a5a88f23f 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -666,6 +666,7 @@ export const _optionalChainDelete = _optionalChainDelete_imported; export const BAGGAGE_HEADER_NAME = BAGGAGE_HEADER_NAME_imported; /** @deprecated Import from `@sentry/core` instead. */ +// eslint-disable-next-line deprecation/deprecation export const getNumberOfUrlSegments = getNumberOfUrlSegments_imported; /** @deprecated Import from `@sentry/core` instead. */