11import { addGlobalEventProcessor , getCurrentHub } from '@sentry/hub' ;
2- import { ClientOptions , Integration , Options } from '@sentry/types' ;
3- import { addNonEnumerableProperty , logger } from '@sentry/utils' ;
2+ import { Integration , Options } from '@sentry/types' ;
3+ import { logger } from '@sentry/utils' ;
44
55import { IS_DEBUG_BUILD } from './flags' ;
66
@@ -9,7 +9,7 @@ export const installedIntegrations: string[] = [];
99/** Map of integrations assigned to a client */
1010export type IntegrationIndex = {
1111 [ key : string ] : Integration ;
12- } & { initialized ?: boolean } ;
12+ } ;
1313
1414/**
1515 * @private
@@ -54,31 +54,24 @@ export function getIntegrationsToSetup(options: Options): Integration[] {
5454 return integrations ;
5555}
5656
57- /** Setup given integration */
58- export function setupIntegration ( integration : Integration ) : void {
59- if ( installedIntegrations . indexOf ( integration . name ) !== - 1 ) {
60- return ;
61- }
62- integration . setupOnce ( addGlobalEventProcessor , getCurrentHub ) ;
63- installedIntegrations . push ( integration . name ) ;
64- IS_DEBUG_BUILD && logger . log ( `Integration installed: ${ integration . name } ` ) ;
65- }
66-
6757/**
6858 * Given a list of integration instances this installs them all. When `withDefaults` is set to `true` then all default
6959 * integrations are added unless they were already provided before.
7060 * @param integrations array of integration instances
7161 * @param withDefault should enable default integrations
7262 */
73- export function setupIntegrations < O extends ClientOptions > ( options : O ) : IntegrationIndex {
74- const integrations : IntegrationIndex = { } ;
75- options . integrations . forEach ( integration => {
76- integrations [ integration . name ] = integration ;
77- setupIntegration ( integration ) ;
63+ export function setupIntegrations ( integrations : Integration [ ] ) : IntegrationIndex {
64+ const integrationIndex : IntegrationIndex = { } ;
65+
66+ integrations . forEach ( integration => {
67+ integrationIndex [ integration . name ] = integration ;
68+
69+ if ( installedIntegrations . indexOf ( integration . name ) === - 1 ) {
70+ integration . setupOnce ( addGlobalEventProcessor , getCurrentHub ) ;
71+ installedIntegrations . push ( integration . name ) ;
72+ IS_DEBUG_BUILD && logger . log ( `Integration installed: ${ integration . name } ` ) ;
73+ }
7874 } ) ;
79- // set the `initialized` flag so we don't run through the process again unecessarily; use `Object.defineProperty`
80- // because by default it creates a property which is nonenumerable, which we want since `initialized` shouldn't be
81- // considered a member of the index the way the actual integrations are
82- addNonEnumerableProperty ( integrations , 'initialized' , true ) ;
83- return integrations ;
75+
76+ return integrationIndex ;
8477}
0 commit comments