Skip to content

Commit fc79e97

Browse files
authored
feat(core): Deprecate arrayify (#14405)
1 parent 7a10218 commit fc79e97

File tree

7 files changed

+18
-5
lines changed

7 files changed

+18
-5
lines changed

docs/migration/draft-v9-migration-guide.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
be removed in v9.
99
- Deprecated `TransactionNamingScheme` type.
1010
- Deprecated `urlEncode`. No replacements.
11+
- Deprecated `arrayify`. No replacements.
1112

1213
## `@sentry/core`
1314

packages/core/src/utils-hoist/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export {
4040
addContextToFrame,
4141
addExceptionMechanism,
4242
addExceptionTypeValue,
43+
// eslint-disable-next-line deprecation/deprecation
4344
arrayify,
4445
checkOrSetAlreadyCaught,
4546
getEventDescription,

packages/core/src/utils-hoist/misc.ts

+2
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ export function checkOrSetAlreadyCaught(exception: unknown): boolean {
232232
*
233233
* @param maybeArray Input to turn into an array, if necessary
234234
* @returns The input, if already an array, or an array with the input as the only element, if not
235+
*
236+
* @deprecated This function has been deprecated and will not be replaced.
235237
*/
236238
export function arrayify<T = unknown>(maybeArray: T | T[]): T[] {
237239
return Array.isArray(maybeArray) ? maybeArray : [maybeArray];

packages/core/test/utils-hoist/misc.test.ts

+8
Original file line numberDiff line numberDiff line change
@@ -366,16 +366,24 @@ describe('uuid4 generation', () => {
366366

367367
describe('arrayify()', () => {
368368
it('returns arrays untouched', () => {
369+
// eslint-disable-next-line deprecation/deprecation
369370
expect(arrayify([])).toEqual([]);
371+
// eslint-disable-next-line deprecation/deprecation
370372
expect(arrayify(['dogs', 'are', 'great'])).toEqual(['dogs', 'are', 'great']);
371373
});
372374

373375
it('wraps non-arrays with an array', () => {
376+
// eslint-disable-next-line deprecation/deprecation
374377
expect(arrayify(1231)).toEqual([1231]);
378+
// eslint-disable-next-line deprecation/deprecation
375379
expect(arrayify('dogs are great')).toEqual(['dogs are great']);
380+
// eslint-disable-next-line deprecation/deprecation
376381
expect(arrayify(true)).toEqual([true]);
382+
// eslint-disable-next-line deprecation/deprecation
377383
expect(arrayify({})).toEqual([{}]);
384+
// eslint-disable-next-line deprecation/deprecation
378385
expect(arrayify(null)).toEqual([null]);
386+
// eslint-disable-next-line deprecation/deprecation
379387
expect(arrayify(undefined)).toEqual([undefined]);
380388
});
381389
});

packages/nextjs/src/config/webpack.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import * as fs from 'fs';
55
import * as path from 'path';
6-
import { arrayify, escapeStringForRegex, loadModule, logger } from '@sentry/core';
6+
import { escapeStringForRegex, loadModule, logger } from '@sentry/core';
77
import { getSentryRelease } from '@sentry/node';
88
import * as chalk from 'chalk';
99
import { sync as resolveSync } from 'resolve';
@@ -491,7 +491,7 @@ function addFilesToWebpackEntryPoint(
491491
let newEntryPoint = currentEntryPoint;
492492

493493
if (typeof currentEntryPoint === 'string' || Array.isArray(currentEntryPoint)) {
494-
newEntryPoint = arrayify(currentEntryPoint);
494+
newEntryPoint = Array.isArray(currentEntryPoint) ? currentEntryPoint : [currentEntryPoint];
495495
if (newEntryPoint.some(entry => filesToInsert.includes(entry))) {
496496
return;
497497
}
@@ -507,7 +507,7 @@ function addFilesToWebpackEntryPoint(
507507
// descriptor object (webpack 5+)
508508
else if (typeof currentEntryPoint === 'object' && 'import' in currentEntryPoint) {
509509
const currentImportValue = currentEntryPoint.import;
510-
const newImportValue = arrayify(currentImportValue);
510+
const newImportValue = Array.isArray(currentImportValue) ? currentImportValue : [currentImportValue];
511511
if (newImportValue.some(entry => filesToInsert.includes(entry))) {
512512
return;
513513
}

packages/utils/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ export {
147147
loadModule,
148148
flatten,
149149
memoBuilder,
150+
// eslint-disable-next-line deprecation/deprecation
150151
arrayify,
151152
normalizeUrlToBase,
152153
// eslint-disable-next-line deprecation/deprecation

packages/vue/src/integration.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { defineIntegration, hasTracingEnabled } from '@sentry/core';
2-
import { GLOBAL_OBJ, arrayify, consoleSandbox } from '@sentry/core';
2+
import { GLOBAL_OBJ, consoleSandbox } from '@sentry/core';
33
import type { Client, IntegrationFn } from '@sentry/types';
44

55
import { DEFAULT_HOOKS } from './constants';
@@ -48,7 +48,7 @@ Update your \`Sentry.init\` call with an appropriate config option:
4848
}
4949

5050
if (options.app) {
51-
const apps = arrayify(options.app);
51+
const apps = Array.isArray(options.app) ? options.app : [options.app];
5252
apps.forEach(app => vueInit(app, options));
5353
} else if (options.Vue) {
5454
vueInit(options.Vue, options);

0 commit comments

Comments
 (0)