-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathclient.shared.js
93 lines (85 loc) · 3.44 KB
/
client.shared.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import merge from '~lodash.mergewith'
import * as CoreSdk from '~@sentry/core'
import { captureUserFeedback, forceLoad, onLoad, showReportDialog, wrap } from '~@sentry/browser'
<%
for (const [package, imports] of Object.entries(options.imports)) {
if (imports.length) {
%>import { <%= imports.join(', ') %> } from '<%= package %>'
<%
}
}
if (options.clientConfigPath) {%>import getClientConfig from '<%= options.clientConfigPath %>'
<%}
if (options.customClientIntegrations) {%>import getCustomIntegrations from '<%= options.customClientIntegrations %>'
<%}%>
export { init }
export const SentrySdk = { ...CoreSdk, ...{ captureUserFeedback, forceLoad, onLoad, showReportDialog, wrap } }
/** @type {string[]} */
const DISABLED_INTEGRATION_KEYS = <%= serialize(options.DISABLED_INTEGRATION_KEYS) %>
/**
* @typedef {Parameters<typeof init>[0]} InitConfig
* @param {import('@nuxt/types').Context} ctx
* @return {Promise<InitConfig>}
*/
export<%= (options.clientConfigPath || options.customClientIntegrations) ? ' async' : '' %> function getConfig (ctx) {
/** @type {InitConfig} */
const config = {
<%= Object
.entries(options.config)
.map(([key, option]) => {
const value = typeof option === 'function' ? serializeFunction(option) : serialize(option)
return `${key}:${value}`
})
.join(',\n ') %>,
}
/** @type {NonNullable<InitConfig>['integrations']} */
const resolvedIntegrations = [
<%= Object
.entries(options.integrations)
.filter(([name]) => name !== 'Vue')
.map(([name, integration]) => {
const integrationOptions = Object
.entries(integration)
.map(([key, option]) => {
const value = typeof option === 'function' ? serializeFunction(option) : serialize(option)
return `${key}:${value}`
})
return `${name}(${integrationOptions.length ? '{ ' + integrationOptions.join(',') + ' }' : ''})`
})
.join(',\n ') %>,
]
<%
if (options.tracing) {
const { browserTracing, vueOptions, vueRouterInstrumentationOptions, ...tracingOptions } = options.tracing
%>
resolvedIntegrations.push(browserTracingIntegration({
router: ctx.app.router,
...<%= serialize(vueRouterInstrumentationOptions) %>,
...<%= serialize(browserTracing) %>,
}))
merge(config, <%= serialize(vueOptions) %>, <%= serialize(tracingOptions) %>)
<% } %>
<% if (options.clientConfigPath) { %>
const clientConfig = await getClientConfig(ctx)
clientConfig ? merge(config, clientConfig) : console.error(`[@nuxtjs/sentry] Invalid value returned from the clientConfig plugin.`)
<% } %>
<% if (options.customClientIntegrations) { %>
const customIntegrations = await getCustomIntegrations(ctx)
if (Array.isArray(customIntegrations)) {
resolvedIntegrations.push(...customIntegrations)
} else {
console.error(`[@nuxtjs/sentry] Invalid value returned from customClientIntegrations plugin. Expected an array, got "${typeof customIntegrations}".`)
}
<% } %>
config.integrations = (defaultIntegrations) => {
return [
...defaultIntegrations.filter(integration => !DISABLED_INTEGRATION_KEYS.includes(integration.name)),
...resolvedIntegrations,
]
}
const runtimeConfigKey = <%= serialize(options.runtimeConfigKey) %>
if (ctx.$config && runtimeConfigKey && ctx.$config[runtimeConfigKey]) {
merge(config, ctx.$config[runtimeConfigKey].config, ctx.$config[runtimeConfigKey].clientConfig)
}
return config
}