Skip to content

Commit ee08ff0

Browse files
committed
add domain to extensions interface and active to domain interface
1 parent 618c11a commit ee08ff0

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

packages/hub/src/hub.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,7 @@ export function getCurrentHub(): Hub {
465465
export function getActiveDomain(): DomainAsCarrier | undefined {
466466
const sentry = getMainCarrier().__SENTRY__;
467467

468-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
469-
return sentry && sentry.extensions && sentry.extensions.domain && (sentry.extensions.domain as any).active;
468+
return sentry && sentry.extensions && sentry.extensions.domain && sentry.extensions.domain.active;
470469
}
471470

472471
/**

packages/hub/src/interfaces.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,22 @@ export interface Carrier {
2121
__SENTRY__?: {
2222
hub?: Hub;
2323
/**
24-
* These are extension methods for the hub, the current instance of the hub will be bound to it
24+
* Extra Hub properties injected by various SDKs
2525
*/
26-
// eslint-disable-next-line @typescript-eslint/ban-types
27-
extensions?: { [key: string]: Function };
26+
extensions?: {
27+
/** Hack to prevent bundlers from breaking our usage of the domain package in the cross-platform Hub package */
28+
domain?: typeof domain & {
29+
/**
30+
* The currently active domain. This is part of the domain package, but for some reason not declared in the
31+
* package's typedef.
32+
*/
33+
active?: domain.Domain;
34+
};
35+
} & {
36+
/** Extension methods for the hub, which are bound to the current Hub instance */
37+
// eslint-disable-next-line @typescript-eslint/ban-types
38+
[key: string]: Function;
39+
};
2840
};
2941
}
3042

packages/node/src/index.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,10 @@ const INTEGRATIONS = {
5757

5858
export { INTEGRATIONS as Integrations, Transports, Handlers };
5959

60-
// We need to patch domain on the global __SENTRY__ object to make it work for node
61-
// if we don't do this, browser bundlers will have troubles resolving require('domain')
60+
// We need to patch domain on the global __SENTRY__ object to make it work for node in cross-platform packages like
61+
// @sentry/hub. If we don't do this, browser bundlers will have troubles resolving `require('domain')`.
6262
const carrier = getMainCarrier();
6363
if (carrier.__SENTRY__) {
6464
carrier.__SENTRY__.extensions = carrier.__SENTRY__.extensions || {};
65-
if (!carrier.__SENTRY__.extensions.domain) {
66-
// @ts-ignore domain is missing from extensions Type
67-
carrier.__SENTRY__.extensions.domain = domain;
68-
}
65+
carrier.__SENTRY__.extensions.domain = carrier.__SENTRY__.extensions.domain || domain;
6966
}

0 commit comments

Comments
 (0)