diff --git a/docs/migration/draft-v9-migration-guide.md b/docs/migration/draft-v9-migration-guide.md index 1b8cab48aec0..a3e197e4b47c 100644 --- a/docs/migration/draft-v9-migration-guide.md +++ b/docs/migration/draft-v9-migration-guide.md @@ -8,6 +8,7 @@ be removed in v9. - Deprecated `TransactionNamingScheme` type. - Deprecated `urlEncode`. No replacements. +- Deprecated `arrayify`. No replacements. ## `@sentry/core` diff --git a/packages/core/src/utils-hoist/index.ts b/packages/core/src/utils-hoist/index.ts index b6bb7151a7e3..1560187a90d9 100644 --- a/packages/core/src/utils-hoist/index.ts +++ b/packages/core/src/utils-hoist/index.ts @@ -40,6 +40,7 @@ export { addContextToFrame, addExceptionMechanism, addExceptionTypeValue, + // eslint-disable-next-line deprecation/deprecation arrayify, checkOrSetAlreadyCaught, getEventDescription, diff --git a/packages/core/src/utils-hoist/misc.ts b/packages/core/src/utils-hoist/misc.ts index ee48a2d60c2d..0f02b5ba14de 100644 --- a/packages/core/src/utils-hoist/misc.ts +++ b/packages/core/src/utils-hoist/misc.ts @@ -232,6 +232,8 @@ export function checkOrSetAlreadyCaught(exception: unknown): boolean { * * @param maybeArray Input to turn into an array, if necessary * @returns The input, if already an array, or an array with the input as the only element, if not + * + * @deprecated This function has been deprecated and will not be replaced. */ export function arrayify(maybeArray: T | T[]): T[] { return Array.isArray(maybeArray) ? maybeArray : [maybeArray]; diff --git a/packages/core/test/utils-hoist/misc.test.ts b/packages/core/test/utils-hoist/misc.test.ts index b2c37758e79c..679f0173ffca 100644 --- a/packages/core/test/utils-hoist/misc.test.ts +++ b/packages/core/test/utils-hoist/misc.test.ts @@ -366,16 +366,24 @@ describe('uuid4 generation', () => { describe('arrayify()', () => { it('returns arrays untouched', () => { + // eslint-disable-next-line deprecation/deprecation expect(arrayify([])).toEqual([]); + // eslint-disable-next-line deprecation/deprecation expect(arrayify(['dogs', 'are', 'great'])).toEqual(['dogs', 'are', 'great']); }); it('wraps non-arrays with an array', () => { + // eslint-disable-next-line deprecation/deprecation expect(arrayify(1231)).toEqual([1231]); + // eslint-disable-next-line deprecation/deprecation expect(arrayify('dogs are great')).toEqual(['dogs are great']); + // eslint-disable-next-line deprecation/deprecation expect(arrayify(true)).toEqual([true]); + // eslint-disable-next-line deprecation/deprecation expect(arrayify({})).toEqual([{}]); + // eslint-disable-next-line deprecation/deprecation expect(arrayify(null)).toEqual([null]); + // eslint-disable-next-line deprecation/deprecation expect(arrayify(undefined)).toEqual([undefined]); }); }); diff --git a/packages/nextjs/src/config/webpack.ts b/packages/nextjs/src/config/webpack.ts index 026622318e3f..445ef32ab1e3 100644 --- a/packages/nextjs/src/config/webpack.ts +++ b/packages/nextjs/src/config/webpack.ts @@ -3,7 +3,7 @@ import * as fs from 'fs'; import * as path from 'path'; -import { arrayify, escapeStringForRegex, loadModule, logger } from '@sentry/core'; +import { escapeStringForRegex, loadModule, logger } from '@sentry/core'; import { getSentryRelease } from '@sentry/node'; import * as chalk from 'chalk'; import { sync as resolveSync } from 'resolve'; @@ -491,7 +491,7 @@ function addFilesToWebpackEntryPoint( let newEntryPoint = currentEntryPoint; if (typeof currentEntryPoint === 'string' || Array.isArray(currentEntryPoint)) { - newEntryPoint = arrayify(currentEntryPoint); + newEntryPoint = Array.isArray(currentEntryPoint) ? currentEntryPoint : [currentEntryPoint]; if (newEntryPoint.some(entry => filesToInsert.includes(entry))) { return; } @@ -507,7 +507,7 @@ function addFilesToWebpackEntryPoint( // descriptor object (webpack 5+) else if (typeof currentEntryPoint === 'object' && 'import' in currentEntryPoint) { const currentImportValue = currentEntryPoint.import; - const newImportValue = arrayify(currentImportValue); + const newImportValue = Array.isArray(currentImportValue) ? currentImportValue : [currentImportValue]; if (newImportValue.some(entry => filesToInsert.includes(entry))) { return; } diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 17e2bb02aa99..126c7a08e36c 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -147,6 +147,7 @@ export { loadModule, flatten, memoBuilder, + // eslint-disable-next-line deprecation/deprecation arrayify, normalizeUrlToBase, // eslint-disable-next-line deprecation/deprecation diff --git a/packages/vue/src/integration.ts b/packages/vue/src/integration.ts index c7b7145ac4b1..1ffa6000f1ea 100644 --- a/packages/vue/src/integration.ts +++ b/packages/vue/src/integration.ts @@ -1,5 +1,5 @@ import { defineIntegration, hasTracingEnabled } from '@sentry/core'; -import { GLOBAL_OBJ, arrayify, consoleSandbox } from '@sentry/core'; +import { GLOBAL_OBJ, consoleSandbox } from '@sentry/core'; import type { Client, IntegrationFn } from '@sentry/types'; import { DEFAULT_HOOKS } from './constants'; @@ -48,7 +48,7 @@ Update your \`Sentry.init\` call with an appropriate config option: } if (options.app) { - const apps = arrayify(options.app); + const apps = Array.isArray(options.app) ? options.app : [options.app]; apps.forEach(app => vueInit(app, options)); } else if (options.Vue) { vueInit(options.Vue, options);