@@ -34,19 +34,6 @@ interface SentryCarrier {
34
34
decodePolyfill ?: ( input : Uint8Array ) => string ;
35
35
}
36
36
37
- // TODO(v9): Clean up or remove this type
38
- type BackwardsCompatibleSentryCarrier = SentryCarrier & {
39
- // pre-v7 hub (replaced by .stack)
40
- hub : any ;
41
- integrations ?: any [ ] ;
42
- logger : any ;
43
- extensions ?: {
44
- /** Extension methods for the hub, which are bound to the current Hub instance */
45
- // eslint-disable-next-line @typescript-eslint/ban-types
46
- [ key : string ] : Function ;
47
- } ;
48
- } ;
49
-
50
37
/** Internal global with common properties and Sentry extensions */
51
38
export type InternalGlobal = {
52
39
navigator ?: { userAgent ?: string } ;
@@ -75,7 +62,7 @@ export type InternalGlobal = {
75
62
_sentryDebugIds ?: Record < string , string > ;
76
63
__SENTRY__ : Record < Exclude < string , 'version' > , SentryCarrier > & {
77
64
version ?: string ;
78
- } & BackwardsCompatibleSentryCarrier ;
65
+ } ;
79
66
/**
80
67
* Raw module metadata that is injected by bundler plugins.
81
68
*
@@ -99,9 +86,15 @@ export const GLOBAL_OBJ = globalThis as unknown as InternalGlobal;
99
86
* @param obj (Optional) The global object on which to look for `__SENTRY__`, if not `GLOBAL_OBJ`'s return value
100
87
* @returns the singleton
101
88
*/
102
- export function getGlobalSingleton < T > ( name : keyof SentryCarrier , creator : ( ) => T , obj ?: unknown ) : T {
103
- const gbl = ( obj || GLOBAL_OBJ ) as InternalGlobal ;
104
- const __SENTRY__ = ( gbl . __SENTRY__ = gbl . __SENTRY__ || { } ) ;
89
+ export function getGlobalSingleton < T > ( name : keyof SentryCarrier , creator : ( ) => T , obj = GLOBAL_OBJ ) : T {
90
+ const __SENTRY__ = getSentryCarrierObj ( obj ) ;
105
91
const versionedCarrier = ( __SENTRY__ [ SDK_VERSION ] = __SENTRY__ [ SDK_VERSION ] || { } ) ;
106
92
return versionedCarrier [ name ] || ( versionedCarrier [ name ] = creator ( ) ) ;
107
93
}
94
+
95
+ function getSentryCarrierObj (
96
+ obj : Omit < InternalGlobal , '__SENTRY__' > & Partial < Pick < InternalGlobal , '__SENTRY__' > > ,
97
+ ) : InternalGlobal [ '__SENTRY__' ] {
98
+ // Set the Sentry carrier, if it does not exist yet
99
+ return obj . __SENTRY__ || ( obj . __SENTRY__ = { } ) ;
100
+ }
0 commit comments