Skip to content

Commit 88f486c

Browse files
authored
feat(deno): Stop inlining types from core (#14729)
Extracted out from #14721 Today, we inline all the types into `deno/build/index.d.ts`. This used to work "OK" previously, where all the types came from `@sentry/types` and where thus all "simple types". If we want to replace some of this with actual classes, e.g. `Scope` or `Client` classes, this starts to fail, because now we have separate definitions that do not match. So to fix this, we now stop inlining all the types, but instead re-export them from `@sentry/core`. While at this, I also updated the test setup to ignore utils/types and just use core for everything. With this change, `deno/build/index.d.ts` looks something like this: ```ts import * as _sentry_core from '@sentry/core'; import { BaseTransportOptions, Options, TracePropagationTargets, ClientOptions, ServerRuntimeClient, Integration, Client } from '@sentry/core'; export { ... } from '@sentry/core'; // additional types from deno go here... ``` I do not _think_ this should be breaking, but 🤷 hard to say for sure with these things.
1 parent bf323b1 commit 88f486c

File tree

9 files changed

+44
-102
lines changed

9 files changed

+44
-102
lines changed

packages/deno/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,14 @@
4141
"build:types:bundle": "rollup -c rollup.types.config.mjs",
4242
"build:tarball": "node ./scripts/prepack.js && npm pack ./build",
4343
"circularDepCheck": "madge --circular src/index.ts",
44-
"clean": "rimraf build build-types build-test coverage sentry-deno-*.tgz",
44+
"clean": "rimraf build build-types build-test coverage node_modules/.deno sentry-deno-*.tgz",
4545
"prefix": "yarn deno-types",
4646
"fix": "eslint . --format stylish --fix",
4747
"prelint": "yarn deno-types",
4848
"lint": "eslint . --format stylish",
4949
"install:deno": "node ./scripts/install-deno.mjs",
50-
"pretest": "run-s deno-types test:build",
50+
"pretest": "run-s deno-types",
5151
"test": "run-s install:deno test:types test:unit",
52-
"test:build": "tsc -p tsconfig.test.types.json && rollup -c rollup.test.config.mjs",
5352
"test:types": "deno check ./build/index.mjs",
5453
"test:unit": "deno test --allow-read --allow-run",
5554
"test:unit:update": "deno test --allow-read --allow-write --allow-run -- --update",

packages/deno/rollup.test.config.mjs

Lines changed: 0 additions & 45 deletions
This file was deleted.

packages/deno/rollup.types.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default defineConfig({
66
input: './build-types/index.d.ts',
77
output: [{ file: 'build/index.d.ts', format: 'es' }],
88
plugins: [
9-
dts({ respectExternal: true }),
9+
dts({ respectExternal: false }),
1010
// The bundled types contain a declaration for the __DEBUG_BUILD__ global
1111
// This can result in errors about duplicate global declarations so we strip it out!
1212
{

packages/deno/test/__snapshots__/mod.test.ts.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ snapshot[`captureException 1`] = `
4848
filename: "app:///test/mod.test.ts",
4949
function: "?",
5050
in_app: true,
51-
lineno: 46,
51+
lineno: 44,
5252
post_context: [
5353
"",
5454
" await delay(200);",
5555
" await assertSnapshot(t, ev);",
5656
"});",
5757
"",
5858
"Deno.test('captureMessage', async t => {",
59-
" let ev: sentryTypes.Event | undefined;",
59+
" let ev: Event | undefined;",
6060
],
6161
pre_context: [
6262
" ev = event;",
@@ -74,7 +74,7 @@ snapshot[`captureException 1`] = `
7474
filename: "app:///test/mod.test.ts",
7575
function: "something",
7676
in_app: true,
77-
lineno: 43,
77+
lineno: 41,
7878
post_context: [
7979
" }",
8080
"",
@@ -86,7 +86,7 @@ snapshot[`captureException 1`] = `
8686
],
8787
pre_context: [
8888
"Deno.test('captureException', async t => {",
89-
" let ev: sentryTypes.Event | undefined;",
89+
" let ev: Event | undefined;",
9090
" const client = getTestClient(event => {",
9191
" ev = event;",
9292
" });",

packages/deno/test/build.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

packages/deno/test/mod.test.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
import { assertEquals } from 'https://deno.land/std@0.202.0/assert/assert_equals.ts';
22
import { assertSnapshot } from 'https://deno.land/std@0.202.0/testing/snapshot.ts';
33

4-
import type { sentryTypes } from '../build-test/index.js';
5-
import { sentryUtils } from '../build-test/index.js';
4+
import type { Event } from '@sentry/core';
5+
import { createStackParser, nodeStackLineParser } from '@sentry/core';
66
import { DenoClient, getCurrentScope, getDefaultIntegrations } from '../build/index.mjs';
7+
78
import { getNormalizedEvent } from './normalize.ts';
89
import { makeTestTransport } from './transport.ts';
910

10-
function getTestClient(
11-
callback: (event?: sentryTypes.Event) => void,
12-
integrations: sentryTypes.Integration[] = [],
13-
): DenoClient {
11+
function getTestClient(callback: (event?: Event) => void): DenoClient {
1412
const client = new DenoClient({
1513
dsn: 'https://233a45e5efe34c47a3536797ce15dafa@nothing.here/5650507',
1614
debug: true,
17-
integrations: [...getDefaultIntegrations({}), ...integrations],
18-
stackParser: sentryUtils.createStackParser(sentryUtils.nodeStackLineParser()),
15+
integrations: getDefaultIntegrations({}),
16+
stackParser: createStackParser(nodeStackLineParser()),
1917
transport: makeTestTransport(envelope => {
2018
callback(getNormalizedEvent(envelope));
2119
}),
@@ -34,7 +32,7 @@ function delay(time: number): Promise<void> {
3432
}
3533

3634
Deno.test('captureException', async t => {
37-
let ev: sentryTypes.Event | undefined;
35+
let ev: Event | undefined;
3836
const client = getTestClient(event => {
3937
ev = event;
4038
});
@@ -50,7 +48,7 @@ Deno.test('captureException', async t => {
5048
});
5149

5250
Deno.test('captureMessage', async t => {
53-
let ev: sentryTypes.Event | undefined;
51+
let ev: Event | undefined;
5452
const client = getTestClient(event => {
5553
ev = event;
5654
});
@@ -62,7 +60,7 @@ Deno.test('captureMessage', async t => {
6260
});
6361

6462
Deno.test('captureMessage twice', async t => {
65-
let ev: sentryTypes.Event | undefined;
63+
let ev: Event | undefined;
6664
const client = getTestClient(event => {
6765
ev = event;
6866
});

packages/deno/test/normalize.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
/* eslint-disable complexity */
2-
import type { sentryTypes } from '../build-test/index.js';
3-
import { sentryUtils } from '../build-test/index.js';
2+
import type { Envelope, Event, Session } from '@sentry/core';
3+
import { forEachEnvelopeItem } from '@sentry/core';
44

5-
type EventOrSession = sentryTypes.Event | sentryTypes.Session;
5+
type EventOrSession = Event | Session;
66

7-
export function getNormalizedEvent(envelope: sentryTypes.Envelope): sentryTypes.Event | undefined {
8-
let event: sentryTypes.Event | undefined;
7+
export function getNormalizedEvent(envelope: Envelope): Event | undefined {
8+
let event: Event | undefined;
99

10-
sentryUtils.forEachEnvelopeItem(envelope, item => {
10+
forEachEnvelopeItem(envelope, item => {
1111
const [headers, body] = item;
1212

1313
if (headers.type === 'event') {
14-
event = body as sentryTypes.Event;
14+
event = body as Event;
1515
}
1616
});
1717

18-
return normalize(event) as sentryTypes.Event | undefined;
18+
return normalize(event) as Event | undefined;
1919
}
2020

2121
export function normalize(event: EventOrSession | undefined): EventOrSession | undefined {
@@ -24,14 +24,14 @@ export function normalize(event: EventOrSession | undefined): EventOrSession | u
2424
}
2525

2626
if (eventIsSession(event)) {
27-
return normalizeSession(event as sentryTypes.Session);
27+
return normalizeSession(event as Session);
2828
} else {
29-
return normalizeEvent(event as sentryTypes.Event);
29+
return normalizeEvent(event as Event);
3030
}
3131
}
3232

3333
export function eventIsSession(data: EventOrSession): boolean {
34-
return !!(data as sentryTypes.Session)?.sid;
34+
return !!(data as Session)?.sid;
3535
}
3636

3737
/**
@@ -40,7 +40,7 @@ export function eventIsSession(data: EventOrSession): boolean {
4040
* All properties that are timestamps, versions, ids or variables that may vary
4141
* by platform are replaced with placeholder strings
4242
*/
43-
function normalizeSession(session: sentryTypes.Session): sentryTypes.Session {
43+
function normalizeSession(session: Session): Session {
4444
if (session.sid) {
4545
session.sid = '{{id}}';
4646
}
@@ -66,7 +66,7 @@ function normalizeSession(session: sentryTypes.Session): sentryTypes.Session {
6666
* All properties that are timestamps, versions, ids or variables that may vary
6767
* by platform are replaced with placeholder strings
6868
*/
69-
function normalizeEvent(event: sentryTypes.Event): sentryTypes.Event {
69+
function normalizeEvent(event: Event): Event {
7070
if (event.sdk?.version) {
7171
event.sdk.version = '{{version}}';
7272
}

packages/deno/test/transport.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
1-
import type { sentryTypes } from '../build-test/index.js';
2-
import { sentryCore, sentryUtils } from '../build-test/index.js';
1+
import type {
2+
BaseTransportOptions,
3+
Envelope,
4+
Transport,
5+
TransportMakeRequestResponse,
6+
TransportRequest,
7+
} from '@sentry/core';
8+
import { createTransport, parseEnvelope } from '@sentry/core';
39

4-
export interface TestTransportOptions extends sentryTypes.BaseTransportOptions {
5-
callback: (envelope: sentryTypes.Envelope) => void;
10+
export interface TestTransportOptions extends BaseTransportOptions {
11+
callback: (envelope: Envelope) => void;
612
}
713

814
/**
915
* Creates a Transport that uses the Fetch API to send events to Sentry.
1016
*/
11-
export function makeTestTransport(callback: (envelope: sentryTypes.Envelope) => void) {
12-
return (options: sentryTypes.BaseTransportOptions): sentryTypes.Transport => {
13-
async function doCallback(
14-
request: sentryTypes.TransportRequest,
15-
): Promise<sentryTypes.TransportMakeRequestResponse> {
16-
await callback(sentryUtils.parseEnvelope(request.body));
17+
export function makeTestTransport(callback: (envelope: Envelope) => void) {
18+
return (options: BaseTransportOptions): Transport => {
19+
async function doCallback(request: TransportRequest): Promise<TransportMakeRequestResponse> {
20+
await callback(parseEnvelope(request.body));
1721

1822
return Promise.resolve({
1923
statusCode: 200,
2024
});
2125
}
2226

23-
return sentryCore.createTransport(options, doCallback);
27+
return createTransport(options, doCallback);
2428
};
2529
}

packages/deno/tsconfig.test.types.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)