Skip to content

Commit

Permalink
ref(build): Turn on isolatedModules TS option (#4896)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lobsterkatie authored Apr 14, 2022
1 parent 292075f commit 5fa71bb
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 82 deletions.
4 changes: 3 additions & 1 deletion packages/angular/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export type { ErrorHandlerOptions } from './errorhandler';

export * from '@sentry/browser';

export { init } from './sdk';
export { createErrorHandler, ErrorHandlerOptions, SentryErrorHandler } from './errorhandler';
export { createErrorHandler, SentryErrorHandler } from './errorhandler';
export {
getActiveTransaction,
// TODO `instrumentAngularRouting` is just an alias for `routingInstrumentation`; deprecate the latter at some point
Expand Down
10 changes: 6 additions & 4 deletions packages/browser/src/exports.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export {
export type {
Breadcrumb,
BreadcrumbHint,
Request,
Expand All @@ -17,6 +17,9 @@ export {
User,
} from '@sentry/types';

export type { BrowserOptions } from './client';
export type { ReportDialogOptions } from './helpers';

export {
addGlobalEventProcessor,
addBreadcrumb,
Expand All @@ -41,8 +44,7 @@ export {
withScope,
} from '@sentry/core';

export { BrowserClient, BrowserOptions } from './client';

export { BrowserClient } from './client';
export {
defaultStackParsers,
chromeStackParser,
Expand All @@ -51,6 +53,6 @@ export {
opera11StackParser,
winjsStackParser,
} from './stack-parsers';
export { injectReportDialog, ReportDialogOptions } from './helpers';
export { injectReportDialog } from './helpers';
export { defaultIntegrations, forceLoad, init, lastEventId, onLoad, showReportDialog, flush, close, wrap } from './sdk';
export { SDK_NAME } from './version';
22 changes: 12 additions & 10 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
export type { APIDetails } from './api';
export type { ClientClass } from './sdk';
export type {
BaseTransportOptions,
NewTransport,
TransportMakeRequestResponse,
TransportRequest,
TransportRequestExecutor,
} from './transports/base';

export {
addBreadcrumb,
captureException,
Expand All @@ -15,7 +25,6 @@ export {
} from '@sentry/minimal';
export { addGlobalEventProcessor, getCurrentHub, getHubFromCarrier, Hub, makeMain, Scope, Session } from '@sentry/hub';
export {
APIDetails,
getEnvelopeEndpointWithUrlEncodedAuth,
getStoreEndpointWithUrlEncodedAuth,
getRequestHeaders,
Expand All @@ -24,16 +33,9 @@ export {
} from './api';
export { BaseClient } from './baseclient';
export { eventToSentryRequest, sessionToSentryRequest } from './request';
export { initAndBind, ClientClass } from './sdk';
export { initAndBind } from './sdk';
export { NoopTransport } from './transports/noop';
export {
BaseTransportOptions,
createTransport,
NewTransport,
TransportMakeRequestResponse,
TransportRequest,
TransportRequestExecutor,
} from './transports/base';
export { createTransport } from './transports/base';
export { SDK_VERSION } from './version';

import * as Integrations from './integrations';
Expand Down
13 changes: 3 additions & 10 deletions packages/hub/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
export type { Carrier, Layer } from './hub';

export { addGlobalEventProcessor, Scope } from './scope';
export { Session } from './session';
export { SessionFlusher } from './sessionflusher';
export {
getCurrentHub,
getHubFromCarrier,
getMainCarrier,
Hub,
makeMain,
setHubOnCarrier,
Carrier,
Layer,
} from './hub';
export { getCurrentHub, getHubFromCarrier, getMainCarrier, Hub, makeMain, setHubOnCarrier } from './hub';
2 changes: 1 addition & 1 deletion packages/nextjs/src/index.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ function filterTransactions(event: Event): Event | null {
return event.type === 'transaction' && event.transaction === '/404' ? null : event;
}

export type { SentryWebpackPluginOptions } from './config/types';
export { withSentryConfig } from './config';
export { SentryWebpackPluginOptions } from './config/types';
export { withSentry } from './utils/withSentry';

// Wrap various server methods to enable error monitoring and tracing. (Note: This only happens for non-Vercel
Expand Down
5 changes: 3 additions & 2 deletions packages/node/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export {
export type {
Breadcrumb,
BreadcrumbHint,
Request,
Expand All @@ -17,6 +17,8 @@ export {
User,
} from '@sentry/types';

export type { NodeOptions } from './types';

export {
addGlobalEventProcessor,
addBreadcrumb,
Expand All @@ -41,7 +43,6 @@ export {
withScope,
} from '@sentry/core';

export { NodeOptions } from './types';
export { NodeClient } from './client';
export { defaultIntegrations, init, lastEventId, flush, close, getSentryRelease } from './sdk';
export { deepReadDirSync } from './utils';
Expand Down
4 changes: 3 additions & 1 deletion packages/node/src/transports/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export type { NodeTransportOptions } from './new';

export { BaseTransport } from './base';
export { HTTPTransport } from './http';
export { HTTPSTransport } from './https';
export { makeNodeTransport, NodeTransportOptions } from './new';
export { makeNodeTransport } from './new';
2 changes: 1 addition & 1 deletion packages/serverless/src/gcpfunction/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ export function configureScopeWithContext(scope: Scope, context: Context): void
scope.setContext('gcp.function.context', { ...context } as SentryContext);
}

export { Request, Response };
export type { Request, Response };
8 changes: 3 additions & 5 deletions packages/tracing/src/browser/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export type { RequestInstrumentationOptions } from './request';

export { BrowserTracing } from './browsertracing';
export {
instrumentOutgoingRequests,
RequestInstrumentationOptions,
defaultRequestInstrumentationOptions,
} from './request';
export { instrumentOutgoingRequests, defaultRequestInstrumentationOptions } from './request';
7 changes: 4 additions & 3 deletions packages/tracing/src/index.bundle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export {
export type {
Breadcrumb,
Request,
SdkInfo,
Expand All @@ -15,6 +15,8 @@ export {
User,
} from '@sentry/types';

export type { BrowserOptions, ReportDialogOptions } from '@sentry/browser';

export {
addGlobalEventProcessor,
addBreadcrumb,
Expand All @@ -37,8 +39,7 @@ export {
withScope,
} from '@sentry/browser';

export { BrowserOptions } from '@sentry/browser';
export { BrowserClient, ReportDialogOptions } from '@sentry/browser';
export { BrowserClient } from '@sentry/browser';
export {
defaultIntegrations,
forceLoad,
Expand Down
11 changes: 5 additions & 6 deletions packages/tracing/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { addExtensionMethods } from './hubextensions';
import * as Integrations from './integrations';

export type { RequestInstrumentationOptions } from './browser';
export type { SpanStatusType } from './span';

export { Integrations };

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

export { Span, SpanStatusType, spanStatusfromHttpCode } from './span';
export { Span, spanStatusfromHttpCode } from './span';
// eslint-disable-next-line deprecation/deprecation
export { SpanStatus } from './spanstatus';
export { Transaction } from './transaction';
export {
instrumentOutgoingRequests,
RequestInstrumentationOptions,
defaultRequestInstrumentationOptions,
} from './browser';
export { instrumentOutgoingRequests, defaultRequestInstrumentationOptions } from './browser';
export { IdleTransaction } from './idletransaction';
export { startIdleTransaction } from './hubextensions';

Expand Down
70 changes: 35 additions & 35 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export { Breadcrumb, BreadcrumbHint } from './breadcrumb';
export { Client } from './client';
export { ClientReport } from './clientreport';
export { Context, Contexts } from './context';
export { DsnComponents, DsnLike, DsnProtocol } from './dsn';
export { DebugImage, DebugImageType, DebugMeta } from './debugMeta';
export {
export type { Breadcrumb, BreadcrumbHint } from './breadcrumb';
export type { Client } from './client';
export type { ClientReport } from './clientreport';
export type { Context, Contexts } from './context';
export type { DsnComponents, DsnLike, DsnProtocol } from './dsn';
export type { DebugImage, DebugImageType, DebugMeta } from './debugMeta';
export type {
AttachmentItem,
BaseEnvelopeHeaders,
BaseEnvelopeItemHeaders,
Expand All @@ -17,25 +17,25 @@ export {
SessionItem,
UserFeedbackItem,
} from './envelope';
export { ExtendedError } from './error';
export { Event, EventHint } from './event';
export { EventStatus } from './eventstatus';
export { EventProcessor } from './eventprocessor';
export { Exception } from './exception';
export { Extra, Extras } from './extra';
export { Hub } from './hub';
export { Integration, IntegrationClass } from './integration';
export { Mechanism } from './mechanism';
export { ExtractedNodeRequestData, Primitive, WorkerLocation } from './misc';
export { Options } from './options';
export { Package } from './package';
export { QueryParams, Request, SentryRequest, SentryRequestType } from './request';
export { Response } from './response';
export { Runtime } from './runtime';
export { CaptureContext, Scope, ScopeContext } from './scope';
export { SdkInfo } from './sdkinfo';
export { SdkMetadata } from './sdkmetadata';
export {
export type { ExtendedError } from './error';
export type { Event, EventHint } from './event';
export type { EventStatus } from './eventstatus';
export type { EventProcessor } from './eventprocessor';
export type { Exception } from './exception';
export type { Extra, Extras } from './extra';
export type { Hub } from './hub';
export type { Integration, IntegrationClass } from './integration';
export type { Mechanism } from './mechanism';
export type { ExtractedNodeRequestData, Primitive, WorkerLocation } from './misc';
export type { Options } from './options';
export type { Package } from './package';
export type { QueryParams, Request, SentryRequest, SentryRequestType } from './request';
export type { Response } from './response';
export type { Runtime } from './runtime';
export type { CaptureContext, Scope, ScopeContext } from './scope';
export type { SdkInfo } from './sdkinfo';
export type { SdkMetadata } from './sdkmetadata';
export type {
SessionAggregates,
AggregationCounts,
Session,
Expand All @@ -47,11 +47,11 @@ export {
} from './session';

// eslint-disable-next-line deprecation/deprecation
export { Severity, SeverityLevel } from './severity';
export { Span, SpanContext } from './span';
export { StackFrame } from './stackframe';
export { Stacktrace, StackParser, StackLineParser, StackLineParserFn } from './stacktrace';
export {
export type { Severity, SeverityLevel } from './severity';
export type { Span, SpanContext } from './span';
export type { StackFrame } from './stackframe';
export type { Stacktrace, StackParser, StackLineParser, StackLineParserFn } from './stacktrace';
export type {
CustomSamplingContext,
Measurements,
SamplingContext,
Expand All @@ -61,7 +61,7 @@ export {
TransactionMetadata,
TransactionSamplingMethod,
} from './transaction';
export { Thread } from './thread';
export { Outcome, Transport, TransportOptions, TransportClass } from './transport';
export { User, UserFeedback } from './user';
export { WrappedFunction } from './wrappedfunction';
export type { Thread } from './thread';
export type { Outcome, Transport, TransportOptions, TransportClass } from './transport';
export type { User, UserFeedback } from './user';
export type { WrappedFunction } from './wrappedfunction';
1 change: 1 addition & 0 deletions packages/typescript/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"downlevelIteration": true,
"importHelpers": true,
"inlineSources": true,
"isolatedModules": true,
"lib": ["es6", "dom"],
// "module": "commonjs", // implied by "target" : "es5"
"moduleResolution": "node",
Expand Down
6 changes: 3 additions & 3 deletions packages/vue/src/index.bundle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export {
export type {
Breadcrumb,
Request,
SdkInfo,
Expand All @@ -13,9 +13,10 @@ export {
User,
} from '@sentry/types';

export type { BrowserOptions, ReportDialogOptions } from '@sentry/browser';

export {
BrowserClient,
BrowserOptions,
defaultIntegrations,
forceLoad,
lastEventId,
Expand All @@ -24,7 +25,6 @@ export {
flush,
close,
wrap,
ReportDialogOptions,
addGlobalEventProcessor,
addBreadcrumb,
captureException,
Expand Down

0 comments on commit 5fa71bb

Please sign in to comment.