From 732923257d5d910ba21965e7f9bdd7592ac7844f Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Fri, 10 Mar 2023 08:58:29 +0100 Subject: [PATCH] fix(core): Avoid using `Array.findIndex()` as it is ES5 incompatible --- packages/core/src/integration.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/core/src/integration.ts b/packages/core/src/integration.ts index 58b63dacc199..d60bb857bbd5 100644 --- a/packages/core/src/integration.ts +++ b/packages/core/src/integration.ts @@ -69,7 +69,7 @@ export function getIntegrationsToSetup(options: Options): Integration[] { // `beforeSendTransaction`. It therefore has to run after all other integrations, so that the changes of all event // processors will be reflected in the printed values. For lack of a more elegant way to guarantee that, we therefore // locate it and, assuming it exists, pop it out of its current spot and shove it onto the end of the array. - const debugIndex = finalIntegrations.findIndex(integration => integration.name === 'Debug'); + const debugIndex = findIndex(finalIntegrations, integration => integration.name === 'Debug'); if (debugIndex !== -1) { const [debugInstance] = finalIntegrations.splice(debugIndex, 1); finalIntegrations.push(debugInstance); @@ -107,3 +107,14 @@ export function setupIntegration(integration: Integration, integrationIndex: Int __DEBUG_BUILD__ && logger.log(`Integration installed: ${integration.name}`); } } + +// Polyfill for Array.findIndex(), which is not supported in ES5 +function findIndex(arr: T[], callback: (item: T) => boolean): number { + for (let i = 0; i < arr.length; i++) { + if (callback(arr[i]) === true) { + return i; + } + } + + return -1; +}