Skip to content

Commit 72ce5da

Browse files
committed
Undo global change?
1 parent 32bb45a commit 72ce5da

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

packages/types/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export type { Event, EventHint } from './event';
2929
export type { EventProcessor } from './eventprocessor';
3030
export type { Exception } from './exception';
3131
export type { Extra, Extras } from './extra';
32-
export type {} from './globals';
32+
import './globals';
3333
export type { Hub } from './hub';
3434
export type { Integration, IntegrationClass } from './integration';
3535
export type { Mechanism } from './mechanism';

packages/utils/src/global.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ export function getGlobalObject<T>(): T & SentryGlobal {
5757
* @returns the singleton
5858
*/
5959
export function getGlobalSingleton<T>(name: keyof SentryGlobal['__SENTRY__'], creator: () => T, obj?: unknown): T {
60-
const globalObject = (obj || getGlobalObject()) as SentryGlobal;
61-
const __SENTRY__ = (globalObject.__SENTRY__ = globalObject.__SENTRY__ || {});
60+
const global = (obj || getGlobalObject()) as SentryGlobal;
61+
const __SENTRY__ = (global.__SENTRY__ = global.__SENTRY__ || {});
6262
const singleton = __SENTRY__[name] || (__SENTRY__[name] = creator());
6363
return singleton;
6464
}

packages/utils/src/logger.ts

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

33
import { getGlobalObject, getGlobalSingleton } from './global';
44

5+
// TODO: Implement different loggers for different environments
6+
const global = getGlobalObject<Window | NodeJS.Global>();
7+
58
/** Prefix for logging strings */
69
const PREFIX = 'Sentry Logger ';
710

@@ -23,21 +26,21 @@ interface Logger extends LoggerConsoleMethods {
2326
* @returns The results of the callback
2427
*/
2528
export function consoleSandbox<T>(callback: () => T): T {
26-
const globalObject = getGlobalObject<Window>();
29+
const global = getGlobalObject<Window>();
2730

28-
if (!('console' in globalObject)) {
31+
if (!('console' in global)) {
2932
return callback();
3033
}
3134

32-
const originalConsole = globalObject.console as Console & Record<string, unknown>;
35+
const originalConsole = global.console as Console & Record<string, unknown>;
3336
const wrappedLevels: Partial<LoggerConsoleMethods> = {};
3437

3538
// Restore all wrapped console methods
3639
CONSOLE_LEVELS.forEach(level => {
3740
// TODO(v7): Remove this check as it's only needed for Node 6
3841
const originalWrappedFunc =
3942
originalConsole[level] && (originalConsole[level] as WrappedFunction).__sentry_original__;
40-
if (level in globalObject.console && originalWrappedFunc) {
43+
if (level in global.console && originalWrappedFunc) {
4144
wrappedLevels[level] = originalConsole[level] as LoggerConsoleMethods[typeof level];
4245
originalConsole[level] = originalWrappedFunc as Console[typeof level];
4346
}
@@ -54,9 +57,6 @@ export function consoleSandbox<T>(callback: () => T): T {
5457
}
5558

5659
function makeLogger(): Logger {
57-
// TODO: Implement different loggers for different environments
58-
const globalObject = getGlobalObject<Window | NodeJS.Global>();
59-
6060
let enabled = false;
6161
const logger: Partial<Logger> = {
6262
enable: () => {
@@ -73,7 +73,7 @@ function makeLogger(): Logger {
7373
logger[name] = (...args: any[]) => {
7474
if (enabled) {
7575
consoleSandbox(() => {
76-
globalObject.console[name](`${PREFIX}[${name}]:`, ...args);
76+
global.console[name](`${PREFIX}[${name}]:`, ...args);
7777
});
7878
}
7979
};

0 commit comments

Comments
 (0)