From 7c8aad3c8c5e933447c1a2be49729fbaeb58ce05 Mon Sep 17 00:00:00 2001 From: HazA Date: Wed, 24 Oct 2018 09:07:31 +0200 Subject: [PATCH] fix: Do not reexport integration setup functions --- packages/core/src/baseclient.ts | 2 +- packages/core/src/integration.ts | 98 +++++++++++++++++++++++++ packages/core/src/integrations/index.ts | 98 ------------------------- 3 files changed, 99 insertions(+), 99 deletions(-) create mode 100644 packages/core/src/integration.ts diff --git a/packages/core/src/baseclient.ts b/packages/core/src/baseclient.ts index 525553222df7..00fd899bd7f3 100644 --- a/packages/core/src/baseclient.ts +++ b/packages/core/src/baseclient.ts @@ -16,7 +16,7 @@ import { consoleSandbox, uuid4 } from '@sentry/utils/misc'; import { truncate } from '@sentry/utils/string'; import { BackendClass } from './basebackend'; import { Dsn } from './dsn'; -import { IntegrationIndex, setupIntegrations } from './integrations'; +import { IntegrationIndex, setupIntegrations } from './integration'; import { Backend, Client, Options } from './interfaces'; /** diff --git a/packages/core/src/integration.ts b/packages/core/src/integration.ts new file mode 100644 index 000000000000..f981f74486c2 --- /dev/null +++ b/packages/core/src/integration.ts @@ -0,0 +1,98 @@ +import { Integration } from '@sentry/types'; +import { logger } from '@sentry/utils/logger'; +import { Options } from './interfaces'; + +export const installedIntegrations: string[] = []; + +/** Map of integrations assigned to a client */ +export interface IntegrationIndex { + [key: string]: Integration; +} + +/** Gets integration to install */ +export function getIntegrationsToSetup(options: Options): Integration[] { + const defaultIntegrations = (options.defaultIntegrations && [...options.defaultIntegrations]) || []; + const userIntegrations = options.integrations; + let integrations: Integration[] = []; + if (Array.isArray(userIntegrations)) { + const userIntegrationsNames = userIntegrations.map(i => i.name); + const pickedIntegrationsNames = []; + + // Leave only unique default integrations, that were not overridden with provided user integrations + for (const defaultIntegration of defaultIntegrations) { + if ( + userIntegrationsNames.indexOf(getIntegrationName(defaultIntegration)) === -1 && + pickedIntegrationsNames.indexOf(getIntegrationName(defaultIntegration)) === -1 + ) { + integrations.push(defaultIntegration); + pickedIntegrationsNames.push(getIntegrationName(defaultIntegration)); + } + } + + // Don't add same user integration twice + for (const userIntegration of userIntegrations) { + if (pickedIntegrationsNames.indexOf(getIntegrationName(userIntegration)) === -1) { + integrations.push(userIntegration); + pickedIntegrationsNames.push(getIntegrationName(userIntegration)); + } + } + } else if (typeof userIntegrations === 'function') { + integrations = userIntegrations(defaultIntegrations); + integrations = Array.isArray(integrations) ? integrations : [integrations]; + } else { + return [...defaultIntegrations]; + } + + return integrations; +} + +/** Setup given integration */ +export function setupIntegration(integration: Integration, options: Options): void { + if (installedIntegrations.indexOf(getIntegrationName(integration)) !== -1) { + return; + } + + try { + integration.setupOnce(); + } catch (_Oo) { + /** @deprecated */ + // TODO: Remove in v5 + logger.warn(`Integration ${getIntegrationName(integration)}: The install method is deprecated. Use "setupOnce".`); + + // tslint:disable:deprecation + if (integration.install) { + integration.install(options); + } + // tslint:enable:deprecation + } + + installedIntegrations.push(getIntegrationName(integration)); + logger.log(`Integration installed: ${getIntegrationName(integration)}`); +} + +/** + * Given a list of integration instances this installs them all. When `withDefaults` is set to `true` then all default + * integrations are added unless they were already provided before. + * @param integrations array of integration instances + * @param withDefault should enable default integrations + */ +export function setupIntegrations(options: O): IntegrationIndex { + const integrations: IntegrationIndex = {}; + getIntegrationsToSetup(options).forEach(integration => { + integrations[getIntegrationName(integration)] = integration; + setupIntegration(integration, options); + }); + return integrations; +} + +/** + * Returns the integration static id. + * @param integration Integration to retrieve id + */ +function getIntegrationName(integration: Integration): string { + /** + * @depracted + */ + // tslint:disable-next-line:no-unsafe-any + return (integration as any).constructor.id || integration.name; +} diff --git a/packages/core/src/integrations/index.ts b/packages/core/src/integrations/index.ts index b0bcbd8b4a37..52a16507d399 100644 --- a/packages/core/src/integrations/index.ts +++ b/packages/core/src/integrations/index.ts @@ -1,8 +1,3 @@ -// tslint:disable:deprecation -import { Integration } from '@sentry/types'; -import { logger } from '@sentry/utils/logger'; -import { Options } from '../interfaces'; - export { Dedupe } from './dedupe'; export { FunctionToString } from './functiontostring'; export { SDKInformation } from './sdkinformation'; @@ -10,96 +5,3 @@ export { InboundFilters } from './inboundfilters'; export { Debug } from './pluggable/debug'; export { RewriteFrames } from './pluggable/rewriteframes'; - -export const installedIntegrations: string[] = []; - -/** Map of integrations assigned to a client */ -export interface IntegrationIndex { - [key: string]: Integration; -} - -/** Gets integration to install */ -export function getIntegrationsToSetup(options: Options): Integration[] { - const defaultIntegrations = (options.defaultIntegrations && [...options.defaultIntegrations]) || []; - const userIntegrations = options.integrations; - let integrations: Integration[] = []; - if (Array.isArray(userIntegrations)) { - const userIntegrationsNames = userIntegrations.map(i => i.name); - const pickedIntegrationsNames = []; - - // Leave only unique default integrations, that were not overridden with provided user integrations - for (const defaultIntegration of defaultIntegrations) { - if ( - userIntegrationsNames.indexOf(getIntegrationName(defaultIntegration)) === -1 && - pickedIntegrationsNames.indexOf(getIntegrationName(defaultIntegration)) === -1 - ) { - integrations.push(defaultIntegration); - pickedIntegrationsNames.push(getIntegrationName(defaultIntegration)); - } - } - - // Don't add same user integration twice - for (const userIntegration of userIntegrations) { - if (pickedIntegrationsNames.indexOf(getIntegrationName(userIntegration)) === -1) { - integrations.push(userIntegration); - pickedIntegrationsNames.push(getIntegrationName(userIntegration)); - } - } - } else if (typeof userIntegrations === 'function') { - integrations = userIntegrations(defaultIntegrations); - integrations = Array.isArray(integrations) ? integrations : [integrations]; - } else { - return [...defaultIntegrations]; - } - - return integrations; -} - -/** Setup given integration */ -export function setupIntegration(integration: Integration, options: Options): void { - if (installedIntegrations.indexOf(getIntegrationName(integration)) !== -1) { - return; - } - - try { - integration.setupOnce(); - } catch (_Oo) { - /** @deprecated */ - // TODO: Remove in v5 - logger.warn(`Integration ${getIntegrationName(integration)}: The install method is deprecated. Use "setupOnce".`); - - if (integration.install) { - integration.install(options); - } - } - - installedIntegrations.push(getIntegrationName(integration)); - logger.log(`Integration installed: ${getIntegrationName(integration)}`); -} - -/** - * Given a list of integration instances this installs them all. When `withDefaults` is set to `true` then all default - * integrations are added unless they were already provided before. - * @param integrations array of integration instances - * @param withDefault should enable default integrations - */ -export function setupIntegrations(options: O): IntegrationIndex { - const integrations: IntegrationIndex = {}; - getIntegrationsToSetup(options).forEach(integration => { - integrations[getIntegrationName(integration)] = integration; - setupIntegration(integration, options); - }); - return integrations; -} - -/** - * Returns the integration static id. - * @param integration Integration to retrieve id - */ -function getIntegrationName(integration: Integration): string { - /** - * @depracted - */ - // tslint:disable-next-line:no-unsafe-any - return (integration as any).constructor.id || integration.name; -}