Skip to content

Commit 8e08b29

Browse files
timfishHazAT
authored andcommitted
Fix: Ensure single instance of logger (#1954)
1 parent c33425a commit 8e08b29

File tree

15 files changed

+41
-42
lines changed

15 files changed

+41
-42
lines changed

packages/browser/src/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
7676
*/
7777
public showReportDialog(options: ReportDialogOptions = {}): void {
7878
// doesn't work without a document (React Native)
79-
const document = (getGlobalObject() as Window).document;
79+
const document = getGlobalObject<Window>().document;
8080
if (!document) {
8181
return;
8282
}

packages/browser/src/integrations/breadcrumbs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { BrowserClient } from '../client';
1111

1212
import { breadcrumbEventHandler, keypressEventHandler, wrap } from './helpers';
1313

14-
const global = getGlobalObject() as Window;
14+
const global = getGlobalObject<Window>();
1515
let lastHref: string | undefined;
1616

1717
/**

packages/browser/src/integrations/useragent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { addGlobalEventProcessor, getCurrentHub } from '@sentry/core';
22
import { Event, Integration } from '@sentry/types';
33
import { getGlobalObject } from '@sentry/utils/misc';
44

5-
const global = getGlobalObject() as Window;
5+
const global = getGlobalObject<Window>();
66

77
/** UserAgent */
88
export class UserAgent implements Integration {

packages/browser/src/tracekit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ interface ComputeStackTrace {
5555
* @namespace TraceKit
5656
*/
5757

58-
var window = getGlobalObject() as Window;
58+
var window = getGlobalObject<Window>();
5959

6060
interface TraceKit {
6161
report: any;

packages/browser/src/transports/fetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { supportsReferrerPolicy } from '@sentry/utils/supports';
44

55
import { BaseTransport } from './base';
66

7-
const global = getGlobalObject() as Window;
7+
const global = getGlobalObject<Window>();
88

99
/** `fetch` based transport */
1010
export class FetchTransport extends BaseTransport {

packages/hub/src/hub.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export class Hub implements HubInterface {
267267

268268
/** Returns the global shim registry. */
269269
export function getMainCarrier(): Carrier {
270-
const carrier: any = getGlobalObject();
270+
const carrier = getGlobalObject();
271271
carrier.__SENTRY__ = carrier.__SENTRY__ || {
272272
hub: undefined,
273273
};
@@ -333,7 +333,7 @@ export function getCurrentHub(): Hub {
333333
* This will tell whether a carrier has a hub on it or not
334334
* @param carrier object
335335
*/
336-
function hasHubOnCarrier(carrier: any): boolean {
336+
function hasHubOnCarrier(carrier: Carrier): boolean {
337337
if (carrier && carrier.__SENTRY__ && carrier.__SENTRY__.hub) {
338338
return true;
339339
}
@@ -346,7 +346,7 @@ function hasHubOnCarrier(carrier: any): boolean {
346346
* @param carrier object
347347
* @hidden
348348
*/
349-
export function getHubFromCarrier(carrier: any): Hub {
349+
export function getHubFromCarrier(carrier: Carrier): Hub {
350350
if (carrier && carrier.__SENTRY__ && carrier.__SENTRY__.hub) {
351351
return carrier.__SENTRY__.hub;
352352
}
@@ -360,7 +360,7 @@ export function getHubFromCarrier(carrier: any): Hub {
360360
* @param carrier object
361361
* @param hub Hub
362362
*/
363-
export function setHubOnCarrier(carrier: any, hub: Hub): boolean {
363+
export function setHubOnCarrier(carrier: Carrier, hub: Hub): boolean {
364364
if (!carrier) {
365365
return false;
366366
}

packages/hub/src/scope.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ export class Scope implements ScopeInterface {
282282
* Retruns the global event processors.
283283
*/
284284
function getGlobalEventProcessors(): EventProcessor[] {
285-
const global: any = getGlobalObject();
285+
const global = getGlobalObject<Window | NodeJS.Global>();
286286
global.__SENTRY__ = global.__SENTRY__ || {};
287287
global.__SENTRY__.globalEventProcessors = global.__SENTRY__.globalEventProcessors || [];
288288
return global.__SENTRY__.globalEventProcessors;

packages/hub/test/global.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ describe('global', () => {
88

99
test('getHubFromCarrier', () => {
1010
const bla = { a: 'b' };
11-
getHubFromCarrier(bla);
11+
getHubFromCarrier(bla as any);
1212
expect((bla as any).__SENTRY__.hub).toBeTruthy();
1313
expect((bla as any).__SENTRY__.hub).toBe((bla as any).__SENTRY__.hub);
14-
getHubFromCarrier(bla);
14+
getHubFromCarrier(bla as any);
1515
});
1616

1717
test('getGlobalHub', () => {

packages/integrations/src/angular.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,8 @@ export class Angular implements Integration {
3939
* @inheritDoc
4040
*/
4141
public constructor(options: { angular?: ng.IAngularStatic } = {}) {
42-
this._angular =
43-
options.angular ||
44-
(getGlobalObject() as {
45-
angular: ng.IAngularStatic;
46-
}).angular;
42+
// tslint:disable-next-line: no-unsafe-any
43+
this._angular = options.angular || (getGlobalObject().angular as ng.IAngularStatic);
4744
}
4845

4946
/**

packages/integrations/src/ember.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@ export class Ember implements Integration {
2121
* @inheritDoc
2222
*/
2323
public constructor(options: { Ember?: any } = {}) {
24-
this._Ember =
25-
options.Ember ||
26-
(getGlobalObject() as {
27-
Ember: any;
28-
}).Ember;
24+
// tslint:disable-next-line: no-unsafe-any
25+
this._Ember = options.Ember || getGlobalObject().Ember;
2926
}
3027

3128
/**

0 commit comments

Comments
 (0)