Skip to content

Commit 16bc644

Browse files
authored
fix(types): restore original client types which have more methods (#540)
1 parent 8a04ad7 commit 16bc644

File tree

6 files changed

+44
-29
lines changed

6 files changed

+44
-29
lines changed

Diff for: src/hooks.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export async function initializeServerSentry (nuxt: Nuxt, moduleOptions: ModuleC
154154
sentryHandlerProxy.tracingHandler = Sentry.Handlers.tracingHandler()
155155
}
156156

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

Diff for: src/templates/plugin.client.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/* eslint-disable import/order */
22
import Vue from 'vue'
33
import merge from '~lodash.mergewith'
4+
import * as Sentry from '~@sentry/vue'
45
<%
5-
const vueImports = ['getCurrentHub', 'init', 'Integrations', ...(options.tracing ? ['vueRouterInstrumentation'] : [])]
6-
%>import { <%= vueImports.join(', ') %> } from '~@sentry/vue'
7-
<%
8-
if (options.tracing) {%>import { BrowserTracing } from '~@sentry/tracing'
6+
if (options.tracing) {
7+
%>import { BrowserTracing } from '~@sentry/tracing'
8+
import { vueRouterInstrumentation } from '~@sentry/vue'
99
<%}
1010
let integrations = options.BROWSER_PLUGGABLE_INTEGRATIONS.filter(key => key in options.integrations)
1111
if (integrations.length) {%>import { <%= integrations.join(', ') %> } from '~@sentry/integrations'
@@ -16,7 +16,7 @@ if (options.customClientIntegrations) {%>import getCustomIntegrations from '<%=
1616
<%}
1717
integrations = options.BROWSER_INTEGRATIONS.filter(key => key in options.integrations)
1818
if (integrations.length) {%>
19-
const { <%= integrations.join(', ') %> } = Integrations
19+
const { <%= integrations.join(', ') %> } = Sentry.Integrations
2020
<%}
2121
%>
2222

@@ -79,8 +79,7 @@ export default async function (ctx, inject) {
7979
}
8080

8181
/* eslint-enable object-curly-spacing, quote-props, quotes, key-spacing, comma-spacing */
82-
init(config)
83-
const sentryClient = getCurrentHub().getClient()
84-
inject('sentry', sentryClient)
85-
ctx.$sentry = sentryClient
82+
Sentry.init(config)
83+
inject('sentry', Sentry)
84+
ctx.$sentry = Sentry
8685
}

Diff for: src/types/extend.d.ts

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,40 @@
11
import 'vue'
22
import 'vuex'
33
import '@nuxt/types'
4-
import { Client } from '@sentry/types'
4+
import * as SentryNode from '@sentry/node'
5+
import * as SentryTypes from '@sentry/core'
56
import { PartialModuleConfiguration } from './configuration'
67

78
export type ModulePublicRuntimeConfig = Pick<PartialModuleConfiguration, 'config' | 'clientConfig' | 'serverConfig'>
89

10+
type Sentry = typeof SentryTypes
11+
type NodeSentry = typeof SentryNode
12+
913
// add type to Vue context
1014
declare module 'vue/types/vue' {
1115
interface Vue {
12-
readonly $sentry: Client
16+
readonly $sentry: Sentry
1317
$sentryLoad(): Promise<void>
14-
$sentryReady(): Promise<Client>
18+
$sentryReady(): Promise<Sentry>
1519
}
1620
}
1721

1822
// App Context and NuxtAppOptions
1923
declare module '@nuxt/types' {
2024
interface Context {
21-
readonly $sentry: Client
25+
readonly $sentry: Sentry
2226
$sentryLoad(): Promise<void>
23-
$sentryReady(): Promise<Client>
27+
$sentryReady(): Promise<Sentry>
2428
}
2529

2630
interface NuxtOptions {
2731
sentry?: PartialModuleConfiguration
2832
}
2933

3034
interface NuxtAppOptions {
31-
readonly $sentry: Client
35+
readonly $sentry: Sentry
3236
$sentryLoad(): Promise<void>
33-
$sentryReady(): Promise<Client>
37+
$sentryReady(): Promise<Sentry>
3438
}
3539
}
3640

@@ -43,16 +47,16 @@ declare module '@nuxt/types/config/runtime' {
4347
// add types for Vuex Store
4448
declare module 'vuex/types' {
4549
interface Store<S> {
46-
readonly $sentry: Client
50+
readonly $sentry: Sentry
4751
$sentryLoad(): Promise<void>
48-
$sentryReady(): Promise<Client>
52+
$sentryReady(): Promise<Sentry>
4953
}
5054
}
5155

5256
declare global {
5357
namespace NodeJS {
5458
interface Process {
55-
sentry: Client
59+
sentry: NodeSentry
5660
}
5761
}
5862
}

Diff for: test/fixture/default/pages/index.vue

+7-3
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,20 @@
1414

1515
<script>
1616
export default {
17+
asyncData ({ $sentry }) {
18+
if (process.server) {
19+
return {
20+
serverSentryPresent: Boolean($sentry?.captureException),
21+
}
22+
}
23+
},
1724
data () {
1825
return {
1926
clientSentryPresent: false,
2027
serverSentryPresent: false,
2128
}
2229
},
2330
created () {
24-
if (process.server) {
25-
this.serverSentryPresent = Boolean(this.$sentry?.captureException)
26-
}
2731
if (process.client) {
2832
this.clientSentryPresent = Boolean(this.$sentry?.captureException)
2933
}

Diff for: test/fixture/lazy/pages/index.vue

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,20 @@
99

1010
<script>
1111
export default {
12+
asyncData ({ $sentry }) {
13+
if (process.server) {
14+
return {
15+
serverSentryPresent: Boolean($sentry?.captureException),
16+
}
17+
}
18+
},
1219
data () {
1320
return {
1421
isSentryReady: false,
1522
serverSentryPresent: false,
1623
}
1724
},
1825
created () {
19-
if (process.server) {
20-
this.serverSentryPresent = Boolean(this.$sentry?.captureException)
21-
}
2226
if (process.client) {
2327
this.$sentryReady().then(() => {
2428
this.isSentryReady = true

Diff for: test/fixture/with-lazy-config/pages/index.vue

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,20 @@
99

1010
<script>
1111
export default {
12+
asyncData ({ $sentry }) {
13+
if (process.server) {
14+
return {
15+
serverSentryPresent: Boolean($sentry?.captureException),
16+
}
17+
}
18+
},
1219
data () {
1320
return {
1421
isSentryReady: false,
1522
serverSentryPresent: false,
1623
}
1724
},
1825
created () {
19-
if (process.server) {
20-
this.serverSentryPresent = Boolean(this.$sentry?.captureException)
21-
}
2226
if (process.client) {
2327
this.$sentryReady().then(() => {
2428
this.isSentryReady = true

0 commit comments

Comments
 (0)