1 | import { addGlobalEventProcessor, getCurrentHub } from '@sentry/hub';
|
2 | import { logger } from '@sentry/utils';
|
3 |
|
4 | var installedIntegrations = [];
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | function filterDuplicates(integrations) {
|
12 | return integrations.reduce((acc, integrations) => {
|
13 | if (acc.every(accIntegration => integrations.name !== accIntegration.name)) {
|
14 | acc.push(integrations);
|
15 | }
|
16 | return acc;
|
17 | }, [] );
|
18 | }
|
19 |
|
20 |
|
21 | function getIntegrationsToSetup(options) {
|
22 | var defaultIntegrations = (options.defaultIntegrations && [...options.defaultIntegrations]) || [];
|
23 | var userIntegrations = options.integrations;
|
24 |
|
25 | let integrations = [...filterDuplicates(defaultIntegrations)];
|
26 |
|
27 | if (Array.isArray(userIntegrations)) {
|
28 |
|
29 | integrations = [
|
30 | ...integrations.filter(integrations =>
|
31 | userIntegrations.every(userIntegration => userIntegration.name !== integrations.name),
|
32 | ),
|
33 |
|
34 | ...filterDuplicates(userIntegrations),
|
35 | ];
|
36 | } else if (typeof userIntegrations === 'function') {
|
37 | integrations = userIntegrations(integrations);
|
38 | integrations = Array.isArray(integrations) ? integrations : [integrations];
|
39 | }
|
40 |
|
41 |
|
42 | var integrationsNames = integrations.map(i => i.name);
|
43 | var alwaysLastToRun = 'Debug';
|
44 | if (integrationsNames.indexOf(alwaysLastToRun) !== -1) {
|
45 | integrations.push(...integrations.splice(integrationsNames.indexOf(alwaysLastToRun), 1));
|
46 | }
|
47 |
|
48 | return integrations;
|
49 | }
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | function setupIntegrations(integrations) {
|
58 | var integrationIndex = {};
|
59 |
|
60 | integrations.forEach(integration => {
|
61 | integrationIndex[integration.name] = integration;
|
62 |
|
63 | if (installedIntegrations.indexOf(integration.name) === -1) {
|
64 | integration.setupOnce(addGlobalEventProcessor, getCurrentHub);
|
65 | installedIntegrations.push(integration.name);
|
66 | (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.log(`Integration installed: ${integration.name}`);
|
67 | }
|
68 | });
|
69 |
|
70 | return integrationIndex;
|
71 | }
|
72 |
|
73 | export { getIntegrationsToSetup, installedIntegrations, setupIntegrations };
|
74 |
|