Skip to content

Commit 30d32a5

Browse files
committed
fix exports etc.
1 parent 12fd86b commit 30d32a5

File tree

8 files changed

+29
-39
lines changed

8 files changed

+29
-39
lines changed

packages/core/src/carrier.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export interface Carrier {
1313
__SENTRY__?: VersionedCarrier;
1414
}
1515

16-
export type VersionedCarrier = {
16+
type VersionedCarrier = {
1717
version?: string;
1818
} & Record<Exclude<string, 'version'>, SentryCarrier>;
1919

@@ -57,3 +57,23 @@ export function getSentryCarrier(carrier: Carrier): SentryCarrier {
5757
// rather than what's set in .version so that "this" SDK always gets its carrier
5858
return (__SENTRY__[SDK_VERSION] = __SENTRY__[SDK_VERSION] || {});
5959
}
60+
61+
/**
62+
* Returns a global singleton contained in the global `__SENTRY__[]` object.
63+
*
64+
* If the singleton doesn't already exist in `__SENTRY__`, it will be created using the given factory
65+
* function and added to the `__SENTRY__` object.
66+
*
67+
* @param name name of the global singleton on __SENTRY__
68+
* @param creator creator Factory function to create the singleton if it doesn't already exist on `__SENTRY__`
69+
* @param obj (Optional) The global object on which to look for `__SENTRY__`, if not `GLOBAL_OBJ`'s return value
70+
* @returns the singleton
71+
*/
72+
export function getGlobalSingleton<Prop extends keyof SentryCarrier>(
73+
name: Prop,
74+
creator: () => NonNullable<SentryCarrier[Prop]>,
75+
obj = GLOBAL_OBJ,
76+
): NonNullable<SentryCarrier[Prop]> {
77+
const carrier = getSentryCarrier(obj);
78+
return carrier[name] || (carrier[name] = creator());
79+
}

packages/core/src/currentScopes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { getAsyncContextStrategy } from './asyncContext';
22
import { getMainCarrier } from './carrier';
3+
import { getGlobalSingleton } from './carrier';
34
import { Scope as ScopeClass } from './scope';
45
import type { Client, Scope, TraceContext } from './types-hoist';
56
import { dropUndefinedKeys } from './utils-hoist/object';
6-
import { getGlobalSingleton } from './utils-hoist/worldwide';
77

88
/**
99
* Get the currently active scope.

packages/core/src/defaultScopes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { getGlobalSingleton } from './carrier';
12
import { Scope as ScopeClass } from './scope';
23
import type { Scope } from './types-hoist';
3-
import { getGlobalSingleton } from './utils-hoist/worldwide';
44

55
/** Get the default current scope. */
66
export function getDefaultCurrentScope(): Scope {

packages/core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export {
4545
getDefaultIsolationScope,
4646
} from './defaultScopes';
4747
export { setAsyncContextStrategy } from './asyncContext';
48-
export { getMainCarrier } from './carrier';
48+
export { getGlobalSingleton, getMainCarrier } from './carrier';
4949
export { makeSession, closeSession, updateSession } from './session';
5050
// eslint-disable-next-line deprecation/deprecation
5151
export { SessionFlusher } from './sessionflusher';

packages/core/src/metrics/exports.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { getGlobalSingleton } from '../carrier';
12
import { getClient } from '../currentScopes';
23
import { DEBUG_BUILD } from '../debug-build';
34
import { startSpanManual } from '../tracing';
45
import type { Client, DurationUnit, MetricData, MetricsAggregator as MetricsAggregatorInterface } from '../types-hoist';
56
import { logger } from '../utils-hoist/logger';
67
import { timestampInSeconds } from '../utils-hoist/time';
7-
import { getGlobalSingleton } from '../utils-hoist/worldwide';
88
import { handleCallbackErrors } from '../utils/handleCallbackErrors';
99
import { getActiveSpan, getRootSpan, spanToJSON } from '../utils/spanUtils';
1010
import { COUNTER_METRIC_TYPE, DISTRIBUTION_METRIC_TYPE, GAUGE_METRIC_TYPE, SET_METRIC_TYPE } from './constants';

packages/core/src/utils-hoist/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export { getBreadcrumbLogLevelFromHttpStatusCode } from './breadcrumb-log-level'
55
export { getComponentName, getDomElement, getLocationHref, htmlTreeAsString } from './browser';
66
export { dsnFromString, dsnToString, makeDsn } from './dsn';
77
export { SentryError } from './error';
8-
export { GLOBAL_OBJ, getGlobalSingleton } from './worldwide';
8+
export { GLOBAL_OBJ } from './worldwide';
99
export type { InternalGlobal } from './worldwide';
1010
export { addConsoleInstrumentationHandler } from './instrument/console';
1111
export { addFetchEndInstrumentationHandler, addFetchInstrumentationHandler } from './instrument/fetch';

packages/core/src/utils-hoist/logger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { getGlobalSingleton } from '../carrier';
12
import type { ConsoleLevel } from '../types-hoist';
2-
33
import { DEBUG_BUILD } from './debug-build';
4-
import { GLOBAL_OBJ, getGlobalSingleton } from './worldwide';
4+
import { GLOBAL_OBJ } from './worldwide';
55

66
/** Prefix for logging strings */
77
const PREFIX = 'Sentry Logger ';

packages/core/src/utils-hoist/worldwide.ts

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212

1313
/* eslint-disable @typescript-eslint/no-explicit-any */
1414

15-
import type { Carrier, SentryCarrier, VersionedCarrier } from '../carrier';
15+
import type { Carrier } from '../carrier';
1616
import type { SdkSource } from './env';
17-
import { SDK_VERSION } from './version';
1817

1918
/** Internal global with common properties and Sentry extensions */
2019
export type InternalGlobal = {
@@ -53,32 +52,3 @@ export type InternalGlobal = {
5352

5453
/** Get's the global object for the current JavaScript runtime */
5554
export const GLOBAL_OBJ = globalThis as unknown as InternalGlobal;
56-
57-
/**
58-
* Returns a global singleton contained in the global `__SENTRY__[]` object.
59-
*
60-
* If the singleton doesn't already exist in `__SENTRY__`, it will be created using the given factory
61-
* function and added to the `__SENTRY__` object.
62-
*
63-
* @param name name of the global singleton on __SENTRY__
64-
* @param creator creator Factory function to create the singleton if it doesn't already exist on `__SENTRY__`
65-
* @param obj (Optional) The global object on which to look for `__SENTRY__`, if not `GLOBAL_OBJ`'s return value
66-
* @returns the singleton
67-
*/
68-
export function getGlobalSingleton<Prop extends keyof SentryCarrier>(
69-
name: Prop,
70-
creator: () => NonNullable<SentryCarrier[Prop]>,
71-
obj = GLOBAL_OBJ,
72-
): NonNullable<SentryCarrier[Prop]> {
73-
const __SENTRY__ = getSentryCarrierObj(obj);
74-
const versionedCarrier = (__SENTRY__[SDK_VERSION] = __SENTRY__[SDK_VERSION] || {});
75-
76-
return versionedCarrier[name] || (versionedCarrier[name] = creator());
77-
}
78-
79-
function getSentryCarrierObj(
80-
obj: Omit<InternalGlobal, '__SENTRY__'> & Partial<Pick<InternalGlobal, '__SENTRY__'>>,
81-
): VersionedCarrier {
82-
// Set the Sentry carrier, if it does not exist yet
83-
return obj.__SENTRY__ || (obj.__SENTRY__ = {});
84-
}

0 commit comments

Comments
 (0)