8000 [v7] Remove integration-base and move integrations installation to Ba… · xiaohuoni/sentry-javascript@5ad895b · GitHub
[go: up one dir, main page]

Skip to content

Commit 5ad895b

Browse files
committed
[v7] Remove integration-base and move integrations installation to BaseClient
1 parent 8b462de commit 5ad895b

File tree

14 files changed

+19
-173
lines changed

14 files changed

+19
-173
lines changed

packages/core/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"access": "public"
1717
},
1818
"dependencies": {
19-
"@sentry/integration-base": "7.0.0-alpha.0",
2019
"@sentry/minimal": "6.2.3",
2120
"@sentry/scope": "7.0.0-alpha.0",
2221
"@sentry/transport-base": "7.0.0-alpha.0",

packages/core/src/baseclient.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
Options,
88
ScopeLike,
99
SessionStatus,
10+
Integration,
1011
} from '@sentry/types';
1112
import {
1213
dateTimestampInSeconds,
@@ -26,7 +27,8 @@ import {
2627
TransportRequest,
2728
Transport,
2829
} from '@sentry/transport-base';
29-
import { IntegrationIndex, setupIntegrations } from '@sentry/integration-base';
30+
31+
import { getIntegrationsToSetup } from './integrations';
3032

3133
/**
3234
* Base implementation for all JavaScript SDK clients.
@@ -68,8 +70,7 @@ export abstract class BaseClient<O extends Options> implements ClientLike<O> {
6870
/** The client Dsn, if specified in options. Without this Dsn, the SDK will be disabled. */
6971
public readonly dsn?: Dsn;
7072

71-
/** Array of used integrations. */
72-
protected _integrations: IntegrationIndex = {};
73+
protected _integrations: Record<string, Integration> = {};
7374

7475
protected _transport: Transport;
7576

@@ -94,7 +95,7 @@ export abstract class BaseClient<O extends Options> implements ClientLike<O> {
9495
}
9596

9697
this._transport = this._setupTransport();
97-
this._integrations = setupIntegrations(this);
98+
this._integrations = this._setupIntegrations();
9899
}
99100

100101
public lastEventId(): string | undefined {
@@ -195,6 +196,16 @@ export abstract class BaseClient<O extends Options> implements ClientLike<O> {
195196
});
196197
}
197198

199+
protected _setupIntegrations(): Record<string, Integration> {
200+
const integrationsToSetup = getIntegrationsToSetup(this.options);
201+
return integrationsToSetup.reduce((integrationsIndex: Record<string, Integration>, integration) => {
202+
integrationsIndex[integration.name] = integration;
203+
integration.install(this);
204+
logger.log(`Integration installed: ${integration.name}`);
205+
return integrationsIndex;
206+
}, {});
207+
}
208+
198209
/**
199210
* @inheritDoc
200211
*/
Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1-
import { ClientLike, Integration, Options } from '@sentry/types';
2-
import { logger } from '@sentry/utils';
1+
import { Integration, Options } from '@sentry/types';
32

4-
export const installedIntegrations: string[] = [];
5-
6-
/** Map of integrations assigned to a client */
7-
export interface IntegrationIndex {
8-
[key: string]: Integration;
9-
}
10-
11-
/** Gets integration to install */
123
export function getIntegrationsToSetup(options: Options): Integration[] {
134
const defaultIntegrations = (options.defaultIntegrations && [...options.defaultIntegrations]) || [];
145
const userIntegrations = options.integrations;
6+
157
let integrations: Integration[] = [];
168
if (Array.isArray(userIntegrations)) {
179
const userIntegrationsNames = userIntegrations.map(i => i.name);
@@ -42,32 +34,5 @@ export function getIntegrationsToSetup(options: Options): Integration[] {
4234
integrations = [...defaultIntegrations];
4335
}
4436

45-
// Make sure that if present, `Debug` integration will always run last
46-
const integrationsNames = integrations.map(i => i.name);
47-
const alwaysLastToRun = 'Debug';
48-
if (integrationsNames.indexOf(alwaysLastToRun) !== -1) {
49-
integrations.push(...integrations.splice(integrationsNames.indexOf(alwaysLastToRun), 1));
50-
}
51-
52-
return integrations;
53-
}
54-
55-
/**
56-
* Given a list of integration instances this installs them all. When `withDefaults` is set to `true` then all default
57-
* integrations are added unless they were already provided before.
58-
* @param integrations array of integration instances
59-
* @param withDefault should enable default integrations
60-
*/
61-
export function setupIntegrations(client: ClientLike): IntegrationIndex {
62-
const integrations: IntegrationIndex = {};
63-
getIntegrationsToSetup(client.options).forEach(integration => {
64-
integrations[integration.name] = integration;
65-
if (installedIntegrations.indexOf(integration.name) !== -1) {
66-
return;
67-
}
68-
integration.install(client);
69-
installedIntegrations.push(integration.name);
70-
logger.log(`Integration installed: ${integration.name}`);
71-
});
7237
return integrations;
7338
}
File renamed without changes.

packages/integration-base/test/index.test.ts renamed to packages/core/test/integrations.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Integration } from '@sentry/types';
22

3-
import { getIntegrationsToSetup } from '../src/index';
3+
import { getIntegrationsToSetup } from '../src/integrations';
44

55
class MockIntegration implements Integration {
66
public name: string;
@@ -9,7 +9,7 @@ class MockIntegration implements Integration {
99
this.name = name;
1010
}
1111

12-
public setupOnce(): void {
12+
public install(): void {
1313
// noop
1414
}
1515
}
File renamed without changes.

packages/integration-base/.eslintrc.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/integration-base/.npmignore

Lines changed: 0 additions & 4 deletions
This file was deleted.

packages/integration-base/LICENSE

Lines changed: 0 additions & 29 deletions
This file was deleted.

packages/integration-base/README.md

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)
0