Skip to content

Commit ed6fd1c

Browse files
authored
fix(types): restore type for process.sentry and improve $sentry types (#534)
1 parent 4dcbeb3 commit ed6fd1c

File tree

7 files changed

+303
-287
lines changed

7 files changed

+303
-287
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@
7676
"jest": "29.5.0",
7777
"nuxt": "2.16.3",
7878
"playwright-chromium": "1.32.0",
79-
"release-it": "15.9.1",
79+
"release-it": "15.9.3",
80+
"sass": "^1.60.0",
8081
"sentry-testkit": "5.0.5",
8182
"ts-jest": "29.0.5",
8283
"ts-node": "10.9.1",

src/hooks.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ export async function initializeServerSentry (nuxt: Nuxt, moduleOptions: ModuleC
153153
await import('@sentry/tracing')
154154
sentryHandlerProxy.tracingHandler = Sentry.Handlers.tracingHandler()
155155
}
156-
}
157156

158-
process.sentry = Sentry
157+
process.sentry = Sentry.getCurrentHub().getClient() as Sentry.NodeClient
158+
}
159159
}
160160

161161
export async function shutdownServerSentry (): Promise<void> {

src/options.ts

+2
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,10 @@ export async function resolveServerOptions (nuxt: Nuxt, moduleOptions: ModuleCon
253253
const opt = options.serverIntegrations[name]
254254
try {
255255
if (isServerDefaultIntegration(name)) {
256+
// @ts-expect-error Some integrations don't take arguments but it doesn't hurt to pass one.
256257
return Object.keys(opt as Record<string, unknown>).length ? new ServerIntegrations[name](opt) : new ServerIntegrations[name]()
257258
} else if (isServerPlugabbleIntegration(name)) {
259+
// @ts-expect-error Some integrations don't take arguments but it doesn't hurt to pass one.
258260
// eslint-disable-next-line import/namespace
259261
return Object.keys(opt as Record<string, unknown>).length ? new PluggableIntegrations[name](opt) : new PluggableIntegrations[name]()
260262
} else {

src/types/extend.d.ts

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
import 'vue'
22
import 'vuex'
33
import '@nuxt/types'
4-
import * as SentryTypes from '@sentry/core'
4+
import { Client } from '@sentry/types'
55
import { DeepPartialModuleConfiguration } from './configuration'
66

77
export type ModulePublicRuntimeConfig = Pick<DeepPartialModuleConfiguration, 'config' | 'clientConfig' | 'serverConfig'>
88

99
// add type to Vue context
1010
declare module 'vue/types/vue' {
1111
interface Vue {
12-
readonly $sentry: typeof SentryTypes
12+
readonly $sentry: Client
1313
$sentryLoad(): Promise<void>
14-
$sentryReady(): Promise<typeof SentryTypes>
14+
$sentryReady(): Promise<Client>
1515
}
1616
}
1717

1818
// App Context and NuxtAppOptions
1919
declare module '@nuxt/types' {
2020
interface Context {
21-
readonly $sentry: typeof SentryTypes
21+
readonly $sentry: Client
2222
$sentryLoad(): Promise<void>
23-
$sentryReady(): Promise<typeof SentryTypes>
23+
$sentryReady(): Promise<Client>
2424
}
2525

2626
interface NuxtOptions {
2727
sentry?: DeepPartialModuleConfiguration
2828
}
2929

3030
interface NuxtAppOptions {
31-
readonly $sentry: typeof SentryTypes
31+
readonly $sentry: Client
3232
$sentryLoad(): Promise<void>
33-
$sentryReady(): Promise<typeof SentryTypes>
33+
$sentryReady(): Promise<Client>
3434
}
3535
}
3636

@@ -43,8 +43,16 @@ declare module '@nuxt/types/config/runtime' {
4343
// add types for Vuex Store
4444
declare module 'vuex/types' {
4545
interface Store<S> {
46-
readonly $sentry: typeof SentryTypes
46+
readonly $sentry: Client
4747
$sentryLoad(): Promise<void>
48-
$sentryReady(): Promise<typeof SentryTypes>
48+
$sentryReady(): Promise<Client>
49+
}
50+
}
51+
52+
declare global {
53+
namespace NodeJS {
54+
interface Process {
55+
sentry: Client
56+
}
4957
}
5058
}

src/types/index.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { DeepPartialModuleConfiguration, ModuleConfiguration } from './configuration'
22
import { ModulePublicRuntimeConfig } from './extend'
3-
import './node'
43

54
type ModuleOptions = DeepPartialModuleConfiguration
65

src/types/node.d.ts

-5
This file was deleted.

0 commit comments

Comments
 (0)