Skip to content

Commit 5fa71bb

Browse files
authored
ref(build): Turn on isolatedModules TS option (#4896)
Note: This and #4926 are together a (slightly updated) repeat of #4497, to get it onto the main v7 branch. This applies [the TypeScript `isolatedModules` setting[1] to all packages in the repo, which is necessary in order for us to use any compiler other than `tsc`. (All other compilers handle each file separately, without understanding the relationships between them the way `tsc` does, so we need TS to warn us if we're doing anything which would make that a problem). It also makes the second of two code changes necessary in order to be compatible with the `isolatedModules` flag: all re-exported types and interfaces (anything that will get stripped away when compiling from TS to JS) are now exported using `export type`. This lets non-`tsc` compilers know that the exported types are eligible for stripping, in spite of the fact that said compilers can't follow the export path backwards to see the types' implementation. (The other code change, eliminating our usage of the `Severity` enum, was split off into the PR linked above.) [1] https://www.typescriptlang.org/tsconfig#isolatedModules
1 parent 292075f commit 5fa71bb

File tree

14 files changed

+83
-82
lines changed

14 files changed

+83
-82
lines changed

packages/angular/src/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
export type { ErrorHandlerOptions } from './errorhandler';
2+
13
export * from '@sentry/browser';
24

35
export { init } from './sdk';
4-
export { createErrorHandler, ErrorHandlerOptions, SentryErrorHandler } from './errorhandler';
6+
export { createErrorHandler, SentryErrorHandler } from './errorhandler';
57
export {
68
getActiveTransaction,
79
// TODO `instrumentAngularRouting` is just an alias for `routingInstrumentation`; deprecate the latter at some point

packages/browser/src/exports.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export {
1+
export type {
22
Breadcrumb,
33
BreadcrumbHint,
44
Request,
@@ -17,6 +17,9 @@ export {
1717
User,
1818
} from '@sentry/types';
1919

20+
export type { BrowserOptions } from './client';
21+
export type { ReportDialogOptions } from './helpers';
22+
2023
export {
2124
addGlobalEventProcessor,
2225
addBreadcrumb,
@@ -41,8 +44,7 @@ export {
4144
withScope,
4245
} from '@sentry/core';
4346

44-
export { BrowserClient, BrowserOptions } from './client';
45-
47+
export { BrowserClient } from './client';
4648
export {
4749
defaultStackParsers,
4850
chromeStackParser,
@@ -51,6 +53,6 @@ export {
5153
opera11StackParser,
5254
winjsStackParser,
5355
} from './stack-parsers';
54-
export { injectReportDialog, ReportDialogOptions } from './helpers';
56+
export { injectReportDialog } from './helpers';
5557
export { defaultIntegrations, forceLoad, init, lastEventId, onLoad, showReportDialog, flush, close, wrap } from './sdk';
5658
export { SDK_NAME } from './version';

packages/core/src/index.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
export type { APIDetails } from './api';
2+
export type { ClientClass } from './sdk';
3+
export type {
4+
BaseTransportOptions,
5+
NewTransport,
6+
TransportMakeRequestResponse,
7+
TransportRequest,
8+
TransportRequestExecutor,
9+
} from './transports/base';
10+
111
export {
212
addBreadcrumb,
313
captureException,
@@ -15,7 +25,6 @@ export {
1525
} from '@sentry/minimal';
1626
export { addGlobalEventProcessor, getCurrentHub, getHubFromCarrier, Hub, makeMain, Scope, Session } from '@sentry/hub';
1727
export {
18-
APIDetails,
1928
getEnvelopeEndpointWithUrlEncodedAuth,
2029
getStoreEndpointWithUrlEncodedAuth,
2130
getRequestHeaders,
@@ -24,16 +33,9 @@ export {
2433
} from './api';
2534
export { BaseClient } from './baseclient';
2635
export { eventToSentryRequest, sessionToSentryRequest } from './request';
27-
export { initAndBind, ClientClass } from './sdk';
36+
export { initAndBind } from './sdk';
2837
export { NoopTransport } from './transports/noop';
29-
export {
30-
BaseTransportOptions,
31-
createTransport,
32-
NewTransport,
33-
TransportMakeRequestResponse,
34-
TransportRequest,
35-
TransportRequestExecutor,
36-
} from './transports/base';
38+
export { createTransport } from './transports/base';
3739
export { SDK_VERSION } from './version';
3840

3941
import * as Integrations from './integrations';

packages/hub/src/index.ts

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1+
export type { Carrier, Layer } from './hub';
2+
13
export { addGlobalEventProcessor, Scope } from './scope';
24
export { Session } from './session';
35
export { SessionFlusher } from './sessionflusher';
4-
export {
5-
getCurrentHub,
6-
getHubFromCarrier,
7-
getMainCarrier,
8-
Hub,
9-
makeMain,
10-
setHubOnCarrier,
11-
Carrier,
12-
Layer,
13-
} from './hub';
6+
export { getCurrentHub, getHubFromCarrier, getMainCarrier, Hub, makeMain, setHubOnCarrier } from './hub';

packages/nextjs/src/index.server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ function filterTransactions(event: Event): Event | null {
135135
return event.type === 'transaction' && event.transaction === '/404' ? null : event;
136136
}
137137

138+
export type { SentryWebpackPluginOptions } from './config/types';
138139
export { withSentryConfig } from './config';
139-
export { SentryWebpackPluginOptions } from './config/types';
140140
export { withSentry } from './utils/withSentry';
141141

142142
// Wrap various server methods to enable error monitoring and tracing. (Note: This only happens for non-Vercel

packages/node/src/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export {
1+
export type {
22
Breadcrumb,
33
BreadcrumbHint,
44
Request,
@@ -17,6 +17,8 @@ export {
1717
User,
1818
} from '@sentry/types';
1919

20+
export type { NodeOptions } from './types';
21+
2022
export {
2123
addGlobalEventProcessor,
2224
addBreadcrumb,
@@ -41,7 +43,6 @@ export {
4143
withScope,
4244
} from '@sentry/core';
4345

44-
export { NodeOptions } from './types';
4546
export { NodeClient } from './client';
4647
export { defaultIntegrations, init, lastEventId, flush, close, getSentryRelease } from './sdk';
4748
export { deepReadDirSync } from './utils';

packages/node/src/transports/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
export type { NodeTransportOptions } from './new';
2+
13
export { BaseTransport } from './base';
24
export { HTTPTransport } from './http';
35
export { HTTPSTransport } from './https';
4-
export { makeNodeTransport, NodeTransportOptions } from './new';
6+
export { makeNodeTransport } from './new';

packages/serverless/src/gcpfunction/general.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ export function configureScopeWithContext(scope: Scope, context: Context): void
6262
scope.setContext('gcp.function.context', { ...context } as SentryContext);
6363
}
6464

65-
export { Request, Response };
65+
export type { Request, Response };

packages/tracing/src/browser/index.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1+
export type { RequestInstrumentationOptions } from './request';
2+
13
export { BrowserTracing } from './browsertracing';
2-
export {
3-
instrumentOutgoingRequests,
4-
RequestInstrumentationOptions,
5-
defaultRequestInstrumentationOptions,
6-
} from './request';
4+
export { instrumentOutgoingRequests, defaultRequestInstrumentationOptions } from './request';

packages/tracing/src/index.bundle.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export {
1+
export type {
22
Breadcrumb,
33
Request,
44
SdkInfo,
@@ -15,6 +15,8 @@ export {
1515
User,
1616
} from '@sentry/types';
1717

18+
export type { BrowserOptions, ReportDialogOptions } from '@sentry/browser';
19+
1820
export {
1921
addGlobalEventProcessor,
2022
addBreadcrumb,
@@ -37,8 +39,7 @@ export {
3739
withScope,
3840
} from '@sentry/browser';
3941

40-
export { BrowserOptions } from '@sentry/browser';
41-
export { BrowserClient, ReportDialogOptions } from '@sentry/browser';
42+
export { BrowserClient } from '@sentry/browser';
4243
export {
4344
defaultIntegrations,
4445
forceLoad,

packages/tracing/src/index.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { addExtensionMethods } from './hubextensions';
22
import * as Integrations from './integrations';
33

4+
export type { RequestInstrumentationOptions } from './browser';
5+
export type { SpanStatusType } from './span';
6+
47
export { Integrations };
58

69
// This is already exported as part of `Integrations` above (and for the moment will remain so for
@@ -21,15 +24,11 @@ export { Integrations };
2124
// For an example of of the new usage of BrowserTracing, see @sentry/nextjs index.client.ts
2225
export { BrowserTracing } from './browser';
2326

24-
export { Span, SpanStatusType, spanStatusfromHttpCode } from './span';
27+
export { Span, spanStatusfromHttpCode } from './span';
2528
// eslint-disable-next-line deprecation/deprecation
2629
export { SpanStatus } from './spanstatus';
2730
export { Transaction } from './transaction';
28-
export {
29-
instrumentOutgoingRequests,
30-
RequestInstrumentationOptions,
31-
defaultRequestInstrumentationOptions,
32-
} from './browser';
31+
export { instrumentOutgoingRequests, defaultRequestInstrumentationOptions } from './browser';
3332
export { IdleTransaction } from './idletransaction';
3433
export { startIdleTransaction } from './hubextensions';
3534

packages/types/src/index.ts

+35-35
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
export { Breadcrumb, BreadcrumbHint } from './breadcrumb';
2-
export { Client } from './client';
3-
export { ClientReport } from './clientreport';
4-
export { Context, Contexts } from './context';
5-
export { DsnComponents, DsnLike, DsnProtocol } from './dsn';
6-
export { DebugImage, DebugImageType, DebugMeta } from './debugMeta';
7-
export {
1+
export type { Breadcrumb, BreadcrumbHint } from './breadcrumb';
2+
export type { Client } from './client';
3+
export type { ClientReport } from './clientreport';
4+
export type { Context, Contexts } from './context';
5+
export type { DsnComponents, DsnLike, DsnProtocol } from './dsn';
6+
export type { DebugImage, DebugImageType, DebugMeta } from './debugMeta';
7+
export type {
88
AttachmentItem,
99
BaseEnvelopeHeaders,
1010
BaseEnvelopeItemHeaders,
@@ -17,25 +17,25 @@ export {
1717
SessionItem,
1818
UserFeedbackItem,
1919
} from './envelope';
20-
export { ExtendedError } from './error';
21-
export { Event, EventHint } from './event';
22-
export { EventStatus } from './eventstatus';
23-
export { EventProcessor } from './eventprocessor';
24-
export { Exception } from './exception';
25-
export { Extra, Extras } from './extra';
26-
export { Hub } from './hub';
27-
export { Integration, IntegrationClass } from './integration';
28-
export { Mechanism } from './mechanism';
29-
export { ExtractedNodeRequestData, Primitive, WorkerLocation } from './misc';
30-
export { Options } from './options';
31-
export { Package } from './package';
32-
export { QueryParams, Request, SentryRequest, SentryRequestType } from './request';
33-
export { Response } from './response';
34-
export { Runtime } from './runtime';
35-
export { CaptureContext, Scope, ScopeContext } from './scope';
36-
export { SdkInfo } from './sdkinfo';
37-
export { SdkMetadata } from './sdkmetadata';
38-
export {
20+
export type { ExtendedError } from './error';
21+
export type { Event, EventHint } from './event';
22+
export type { EventStatus } from './eventstatus';
23+
export type { EventProcessor } from './eventprocessor';
24+
export type { Exception } from './exception';
25+
export type { Extra, Extras } from './extra';
26+
export type { Hub } from './hub';
27+
export type { Integration, IntegrationClass } from './integration';
28+
export type { Mechanism } from './mechanism';
29+
export type { ExtractedNodeRequestData, Primitive, WorkerLocation } from './misc';
30+
export type { Options } from './options';
31+
export type { Package } from './package';
32+
export type { QueryParams, Request, SentryRequest, SentryRequestType } from './request';
33+
export type { Response } from './response';
34+
export type { Runtime } from './runtime';
35+
export type { CaptureContext, Scope, ScopeContext } from './scope';
36+
export type { SdkInfo } from './sdkinfo';
37+
export type { SdkMetadata } from './sdkmetadata';
38+
export type {
3939
SessionAggregates,
4040
AggregationCounts,
4141
Session,
@@ -47,11 +47,11 @@ export {
4747
} from './session';
4848

4949
// eslint-disable-next-line deprecation/deprecation
50-
export { Severity, SeverityLevel } from './severity';
51-
export { Span, SpanContext } from './span';
52-
export { StackFrame } from './stackframe';
53-
export { Stacktrace, StackParser, StackLineParser, StackLineParserFn } from './stacktrace';
54-
export {
50+
export type { Severity, SeverityLevel } from './severity';
51+
export type { Span, SpanContext } from './span';
52+
export type { StackFrame } from './stackframe';
53+
export type { Stacktrace, StackParser, StackLineParser, StackLineParserFn } from './stacktrace';
54+
export type {
5555
CustomSamplingContext,
5656
Measurements,
5757
SamplingContext,
@@ -61,7 +61,7 @@ export {
6161
TransactionMetadata,
6262
TransactionSamplingMethod,
6363
} from './transaction';
64-
export { Thread } from './thread';
65-
export { Outcome, Transport, TransportOptions, TransportClass } from './transport';
66-
export { User, UserFeedback } from './user';
67-
export { WrappedFunction } from './wrappedfunction';
64+
export type { Thread } from './thread';
65+
export type { Outcome, Transport, TransportOptions, TransportClass } from './transport';
66+
export type { User, UserFeedback } from './user';
67+
export type { WrappedFunction } from './wrappedfunction';

packages/typescript/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"downlevelIteration": true,
77
"importHelpers": true,
88
"inlineSources": true,
9+
"isolatedModules": true,
910
"lib": ["es6", "dom"],
1011
// "module": "commonjs", // implied by "target" : "es5"
1112
"moduleResolution": "node",

packages/vue/src/index.bundle.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export {
1+
export type {
22
Breadcrumb,
33
Request,
44
SdkInfo,
@@ -13,9 +13,10 @@ export {
1313
User,
1414
} from '@sentry/types';
1515

16+
export type { BrowserOptions, ReportDialogOptions } from '@sentry/browser';
17+
1618
export {
1719
BrowserClient,
18-
BrowserOptions,
1920
defaultIntegrations,
2021
forceLoad,
2122
lastEventId,
@@ -24,7 +25,6 @@ export {
2425
flush,
2526
close,
2627
wrap,
27-
ReportDialogOptions,
2828
addGlobalEventProcessor,
2929
addBreadcrumb,
3030
captureException,

0 commit comments

Comments
 (0)