1- import { hasTracingEnabled } from '@sentry/core' ;
2- import type { Client , Hub , Integration } from '@sentry/types' ;
1+ import { convertIntegrationFnToClass , defineIntegration , hasTracingEnabled } from '@sentry/core' ;
2+ import type { Client , Integration , IntegrationClass , IntegrationFn } from '@sentry/types' ;
33import { GLOBAL_OBJ , arrayify , consoleSandbox } from '@sentry/utils' ;
44
55import { DEFAULT_HOOKS } from './constants' ;
@@ -18,55 +18,49 @@ const DEFAULT_CONFIG: VueOptions = {
1818 trackComponents : false ,
1919} ;
2020
21- /**
22- * Initialize Vue error & performance tracking.
23- */
24- export class VueIntegration implements Integration {
25- /**
26- * @inheritDoc
27- */
28- public static id : string = 'Vue' ;
29-
30- /**
31- * @inheritDoc
32- */
33- public name : string ;
34-
35- private readonly _options : Partial < VueOptions > ;
21+ const INTEGRATION_NAME = 'Vue' ;
3622
37- public constructor ( options : Partial < VueOptions > = { } ) {
38- this . name = VueIntegration . id ;
39- this . _options = options ;
40- }
23+ const _vueIntegration = ( ( integrationOptions : Partial < VueOptions > = { } ) => {
24+ return {
25+ name : INTEGRATION_NAME ,
26+ // TODO v8: Remove this
27+ setupOnce ( ) { } , // eslint-disable-line @typescript-eslint/no-empty-function
28+ setup ( client ) {
29+ _setupIntegration ( client , integrationOptions ) ;
30+ } ,
31+ } ;
32+ } ) satisfies IntegrationFn ;
4133
42- /** @inheritDoc */
43- public setupOnce ( _addGlobalEventProcessor : unknown , getCurrentHub : ( ) => Hub ) : void {
44- // eslint-disable-next-line deprecation/deprecation
45- this . _setupIntegration ( getCurrentHub ( ) . getClient ( ) ) ;
46- }
34+ export const vueIntegration = defineIntegration ( _vueIntegration ) ;
4735
48- /** Just here for easier testing */
49- protected _setupIntegration ( client : Client | undefined ) : void {
50- const options : Options = { ...DEFAULT_CONFIG , ...( client && client . getOptions ( ) ) , ...this . _options } ;
36+ /**
37+ * Initialize Vue error & performance tracking.
38+ */
39+ // eslint-disable-next-line deprecation/deprecation
40+ export const VueIntegration = convertIntegrationFnToClass (
41+ INTEGRATION_NAME ,
42+ vueIntegration ,
43+ ) as IntegrationClass < Integration > ;
5144
52- if ( ! options . Vue && ! options . app ) {
53- consoleSandbox ( ( ) => {
54- // eslint-disable-next-line no-console
55- console . warn (
56- `[@sentry/vue]: Misconfigured SDK. Vue specific errors will not be captured.
45+ function _setupIntegration ( client : Client , integrationOptions : Partial < VueOptions > ) : void {
46+ const options : Options = { ...DEFAULT_CONFIG , ...client . getOptions ( ) , ...integrationOptions } ;
47+ if ( ! options . Vue && ! options . app ) {
48+ consoleSandbox ( ( ) => {
49+ // eslint-disable-next-line no-console
50+ console . warn (
51+ `[@sentry/vue]: Misconfigured SDK. Vue specific errors will not be captured.
5752Update your \`Sentry.init\` call with an appropriate config option:
5853\`app\` (Application Instance - Vue 3) or \`Vue\` (Vue Constructor - Vue 2).` ,
59- ) ;
60- } ) ;
61- return ;
62- }
54+ ) ;
55+ } ) ;
56+ return ;
57+ }
6358
64- if ( options . app ) {
65- const apps = arrayify ( options . app ) ;
66- apps . forEach ( app => vueInit ( app , options ) ) ;
67- } else if ( options . Vue ) {
68- vueInit ( options . Vue , options ) ;
69- }
59+ if ( options . app ) {
60+ const apps = arrayify ( options . app ) ;
61+ apps . forEach ( app => vueInit ( app , options ) ) ;
62+ } else if ( options . Vue ) {
63+ vueInit ( options . Vue , options ) ;
7064 }
7165}
7266
0 commit comments