Skip to content

Commit 5a77ef3

Browse files
committed
consistent options serialization & filter out Vue integration options
1 parent f6e67a8 commit 5a77ef3

File tree

2 files changed

+56
-29
lines changed

2 files changed

+56
-29
lines changed

lib/plugin.client.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ export default async function (ctx, inject) {
2222
/* eslint-disable object-curly-spacing, quote-props, quotes, key-spacing, comma-spacing */
2323
const config = {
2424
Vue,
25-
<%= Object.entries(options.config).map(([key, option]) =>
26-
typeof option === 'function'
27-
? `${key}:${serializeFunction(option)}`
28-
: `${key}:${serialize(option)}`
29-
).join(',\n ') %>,
25+
<%= Object
26+
.entries(options.config)
27+
.map(([key, option]) => {
28+
const value = typeof option === 'function' ? serializeFunction(option) : serialize(option)
29+
return `${key}:${value}`
30+
})
31+
.join(',\n ') %>,
3032
}
3133

3234
const runtimeConfigKey = <%= serialize(options.runtimeConfigKey) %>
@@ -35,15 +37,20 @@ export default async function (ctx, inject) {
3537
}
3638

3739
config.integrations = [
38-
<%= Object.entries(options.integrations).map(([name, integration]) => {
39-
const integrationOptions = Object.entries(integration).map(([key, option]) =>
40-
typeof option === 'function'
41-
? `${key}:${serializeFunction(option)}`
42-
: `${key}:${serialize(option)}`
43-
)
40+
<%= Object
41+
.entries(options.integrations)
42+
.filter(([name]) => name !== 'Vue')
43+
.map(([name, integration]) => {
44+
const integrationOptions = Object
45+
.entries(integration)
46+
.map(([key, option]) => {
47+
const value = typeof option === 'function' ? serializeFunction(option) : serialize(option)
48+
return `${key}:${value}`
49+
})
4450

45-
return `new ${name}(${integrationOptions.length ? '{' + integrationOptions.join(',') + '}' : ''})`
46-
}).join(',\n ')%>,
51+
return `new ${name}(${integrationOptions.length ? '{' + integrationOptions.join(',') + '}' : ''})`
52+
})
53+
.join(',\n ') %>,
4754
]
4855
<% if (options.tracing) { %>
4956
// eslint-disable-next-line prefer-regex-literals

lib/plugin.lazy.js

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import VueLib from 'vue'
1+
import Vue from 'vue'
22

33
<% if (options.lazy.injectMock) { %>
44
/* eslint-enable object-curly-spacing, quote-props, quotes, key-spacing, comma-spacing */
@@ -20,16 +20,16 @@ const delayUnhandledRejection = function (event) {
2020
delayedUnhandledRejections.push('reason' in event ? event.reason : 'detail' in event && 'reason' in event.detail ? event.detail.reason : event)
2121
}
2222

23-
const vueErrorHandler = VueLib.config.errorHandler
23+
const vueErrorHandler = Vue.config.errorHandler
2424

25-
VueLib.config.errorHandler = (error, vm, info) => {
25+
Vue.config.errorHandler = (error, vm, info) => {
2626
if (!loadCompleted) {
2727
if (vm) {
2828
vm.$sentry.captureException(error)
2929
}
3030

31-
if (VueLib.util) {
32-
VueLib.util.warn(`Error in ${info}: "${error.toString()}"`, vm)
31+
if (Vue.util) {
32+
Vue.util.warn(`Error in ${info}: "${error.toString()}"`, vm)
3333
}
3434
console.error(error)
3535
}
@@ -119,10 +119,24 @@ async function loadSentry (ctx, inject) {
119119
integrations = options.BROWSER_INTEGRATIONS.filter(key => key in options.integrations)
120120
if (integrations.length) {%> const { <%= integrations.join(', ') %> } = Sentry.Integrations
121121
<%}
122+
123+
const serializedConfig = Object
124+
.entries({
125+
...options.config,
126+
...options.integrations.Vue,
127+
...(options.tracing ? options.tracing.vueOptions.tracingOptions : {}),
128+
})
129+
.map(([key, option]) => {
130+
const value = typeof option === 'function' ? serializeFunction(option) : serialize(option)
131+
return`${key}: ${value}`
132+
})
133+
.join(',\n ')
122134
%>
123135
/* eslint-disable object-curly-spacing, quote-props, quotes, key-spacing, comma-spacing */
124-
const config = <%= serialize(options.config) %>
125-
config.Vue = VueLib
136+
const config = {
137+
Vue,
138+
<%= serializedConfig %>
139+
}
126140

127141
const runtimeConfigKey = <%= serialize(options.runtimeConfigKey) %>
128142
if (ctx.$config && runtimeConfigKey && ctx.$config[runtimeConfigKey]) {
@@ -131,16 +145,22 @@ async function loadSentry (ctx, inject) {
131145
}
132146

133147
config.integrations = [
134-
<%= Object.entries(options.integrations).map(([name, integration]) => {
135-
const integrationOptions = Object.entries(integration).map(([key, option]) =>
136-
typeof option === 'function'
137-
? `${key}:${serializeFunction(option)}`
138-
: `${key}:${serialize(option)}`
139-
)
140-
141-
return `new ${name}(${integrationOptions.length ? '{' + integrationOptions.join(',') + '}' : ''})`
142-
}).join(',\n ')%>,
148+
<%= Object
149+
.entries(options.integrations)
150+
.filter(([name]) => name !== 'Vue')
151+
.map(([name, integration]) => {
152+
const integrationOptions = Object
153+
.entries(integration)
154+
.map(([key, option]) => {
155+
const value = typeof option === 'function' ? serializeFunction(option) : serialize(option)
156+
return `${key}:${value}`
157+
})
158+
159+
return `new ${name}(${integrationOptions.length ? '{' + integrationOptions.join(',') + '}' : ''})`
160+
}).join(',\n ')
161+
%>,
143162
]
163+
144164
<%if (options.customClientIntegrations) {%>
145165
const customIntegrations = (await import(/* <%= magicComments.join(', ') %> */ '<%= options.customClientIntegrations %>').then(m => m.default || m))(ctx)
146166
if (Array.isArray(customIntegrations)) {

0 commit comments

Comments
 (0)