Skip to content

Commit c78fbf2

Browse files
authored
fix(utils): Remove WINDOW from utils (#6024)
This issue is caused by the fact that `Window` ends up in the utils type definitions. This PR: - Removes `WINDOW` from utils - In utils, it's usage is replaced with the following at the top of the appropriate files: ```ts // eslint-disable-next-line deprecation/deprecation. const WINDOW = getGlobalObject<Window>(); ``` - Adds `WINDOW` to: - `@sentry/browser` where it is exported for use elsewhere - `@sentry/tracing/browser` - Can be removed once tracing is split into browser/node code - The `Offline` and `ReportingObserver` integrations since they don't have any dependencies other than utils - These could probably just use `window` since they're not used outside the browser - All downstream SDKs then import `WINDOW` from `@sentry/browser` or `@sentry/react`
1 parent d8751dc commit c78fbf2

37 files changed

+74
-57
lines changed

packages/angular/src/tracing.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* eslint-disable max-lines */
22
import { AfterViewInit, Directive, Injectable, Input, NgModule, OnDestroy, OnInit } from '@angular/core';
33
import { ActivatedRouteSnapshot, Event, NavigationEnd, NavigationStart, ResolveEnd, Router } from '@angular/router';
4-
import { getCurrentHub } from '@sentry/browser';
4+
import { getCurrentHub, WINDOW } from '@sentry/browser';
55
import { Span, Transaction, TransactionContext } from '@sentry/types';
6-
import { logger, stripUrlQueryAndFragment, timestampWithMs, WINDOW } from '@sentry/utils';
6+
import { logger, stripUrlQueryAndFragment, timestampWithMs } from '@sentry/utils';
77
import { Observable, Subscription } from 'rxjs';
88
import { filter, tap } from 'rxjs/operators';
99

packages/browser/src/client.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
import { BaseClient, getCurrentHub, getEnvelopeEndpointWithUrlEncodedAuth, Scope, SDK_VERSION } from '@sentry/core';
22
import { ClientOptions, Event, EventHint, Options, Severity, SeverityLevel } from '@sentry/types';
3-
import {
4-
createClientReportEnvelope,
5-
dsnToString,
6-
getEventDescription,
7-
logger,
8-
serializeEnvelope,
9-
WINDOW,
10-
} from '@sentry/utils';
3+
import { createClientReportEnvelope, dsnToString, getEventDescription, logger, serializeEnvelope } from '@sentry/utils';
114

125
import { eventFromException, eventFromMessage } from './eventbuilder';
6+
import { WINDOW } from './helpers';
137
import { Breadcrumbs } from './integrations';
148
import { BREADCRUMB_INTEGRATION_ID } from './integrations/breadcrumbs';
159
import { BrowserTransportOptions } from './transports/types';

packages/browser/src/exports.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export {
4545
InboundFilters,
4646
} from '@sentry/core';
4747

48+
export { WINDOW } from './helpers';
4849
export { BrowserClient } from './client';
4950
export { makeFetchTransport, makeXHRTransport } from './transports';
5051
export {

packages/browser/src/helpers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import {
55
addExceptionTypeValue,
66
addNonEnumerableProperty,
77
getOriginalFunction,
8+
GLOBAL_OBJ,
89
markFunctionWrapped,
910
} from '@sentry/utils';
1011

12+
export const WINDOW = GLOBAL_OBJ as typeof GLOBAL_OBJ & Window;
13+
1114
let ignoreOnError: number = 0;
1215

1316
/**

packages/browser/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export * from './exports';
22

33
import { Integrations as CoreIntegrations } from '@sentry/core';
4-
import { WINDOW } from '@sentry/utils';
54

5+
import { WINDOW } from './helpers';
66
import * as BrowserIntegrations from './integrations';
77

88
let windowIntegrations = {};

packages/browser/src/integrations/breadcrumbs.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import {
88
parseUrl,
99
safeJoin,
1010
severityLevelFromString,
11-
WINDOW,
1211
} from '@sentry/utils';
1312

13+
import { WINDOW } from '../helpers';
14+
1415
/** JSDoc */
1516
interface BreadcrumbsOptions {
1617
console: boolean;

packages/browser/src/integrations/httpcontext.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { addGlobalEventProcessor, getCurrentHub } from '@sentry/core';
22
import { Event, Integration } from '@sentry/types';
3-
import { WINDOW } from '@sentry/utils';
3+
4+
import { WINDOW } from '../helpers';
45

56
/** HttpContext integration collects information about HTTP request headers */
67
export class HttpContext implements Integration {

packages/browser/src/integrations/trycatch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Integration, WrappedFunction } from '@sentry/types';
2-
import { fill, getFunctionName, getOriginalFunction, WINDOW } from '@sentry/utils';
2+
import { fill, getFunctionName, getOriginalFunction } from '@sentry/utils';
33

4-
import { wrap } from '../helpers';
4+
import { WINDOW, wrap } from '../helpers';
55

66
const DEFAULT_EVENT_TARGET = [
77
'EventTarget',

packages/browser/src/sdk.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ import {
1212
resolvedSyncPromise,
1313
stackParserFromStackParserOptions,
1414
supportsFetch,
15-
WINDOW,
1615
} from '@sentry/utils';
1716

1817
import { BrowserClient, BrowserClientOptions, BrowserOptions } from './client';
19-
import { ReportDialogOptions, wrap as internalWrap } from './helpers';
18+
import { ReportDialogOptions, WINDOW, wrap as internalWrap } from './helpers';
2019
import { Breadcrumbs, Dedupe, GlobalHandlers, HttpContext, LinkedErrors, TryCatch } from './integrations';
2120
import { defaultStackParser } from './stack-parsers';
2221
import { makeFetchTransport, makeXHRTransport } from './transports';

packages/browser/src/transports/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { isNativeFetch, logger, WINDOW } from '@sentry/utils';
1+
import { isNativeFetch, logger } from '@sentry/utils';
2+
3+
import { WINDOW } from '../helpers';
24

35
let cachedFetchImpl: FetchImpl;
46

0 commit comments

Comments
 (0)