forked from plone/volto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack-sentry-plugin.js
81 lines (74 loc) · 2.12 KB
/
webpack-sentry-plugin.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
const webpack = require('webpack');
const SentryCliPlugin = require('@sentry/webpack-plugin');
const SENTRY_KEYS = [
'SENTRY_AUTH_TOKEN',
'SENTRY_URL',
'SENTRY_ORG',
'SENTRY_PROJECT',
'SENTRY_RELEASE',
];
function validateSentryCliConfiguration(env) {
return SENTRY_KEYS.findIndex((k) => env[k] === undefined) === -1;
}
module.exports = {
modifyWebpackConfig({
env: { target, dev },
webpackConfig: config,
webpackObject,
options: { pluginOptions, razzleOptions, webpackOptions },
paths,
}) {
let SENTRY = undefined;
if (process.env.SENTRY_DSN) {
SENTRY = {
SENTRY_DSN: process.env.SENTRY_DSN,
};
}
if (target === 'web') {
if (SENTRY && process.env.SENTRY_FRONTEND_CONFIG) {
if (validateSentryCliConfiguration(process.env)) {
config.plugins.push(
new SentryCliPlugin({
include: './build/public',
ignore: ['node_modules', 'webpack.config.js'],
release: process.env.SENTRY_RELEASE,
}),
);
}
try {
SENTRY.SENTRY_CONFIG = JSON.parse(process.env.SENTRY_FRONTEND_CONFIG);
if (process.env.SENTRY_RELEASE !== undefined) {
SENTRY.SENTRY_CONFIG.release = process.env.SENTRY_RELEASE;
}
} catch (e) {
console.log('Error parsing SENTRY_FRONTEND_CONFIG');
throw e;
}
}
}
if (target === 'node') {
if (SENTRY) {
SENTRY.SENTRY_CONFIG = undefined;
if (process.env.SENTRY_BACKEND_CONFIG) {
try {
SENTRY.SENTRY_CONFIG = JSON.parse(
process.env.SENTRY_BACKEND_CONFIG,
);
if (process.env.SENTRY_RELEASE !== undefined) {
SENTRY.SENTRY_CONFIG.release = process.env.SENTRY_RELEASE;
}
} catch (e) {
console.log('Error parsing SENTRY_BACKEND_CONFIG');
throw e;
}
}
}
}
config.plugins.unshift(
new webpack.DefinePlugin({
__SENTRY__: SENTRY ? JSON.stringify(SENTRY) : undefined,
}),
);
return config;
},
};