Skip to content

Commit 32edb0b

Browse files
authored
ref(build): Centralize identical CDN rollup config (#4637)
There is a great deal of overlap between the rollup config files we use to generate our CDN bundles. As part of moving to the new bundling process, this pulls the most obvious pieces of shared config into a central file. (In this case, “most obvious” means that they are strictly identical across files, with no tweaks needed. A follow-up PR will handle the places where there are slight differences between one rollup config and another.) As one would hope when moving things without changing them, there is no effect on the content of the bundles produced.
1 parent 0a4f278 commit 32edb0b

File tree

6 files changed

+205
-333
lines changed

6 files changed

+205
-333
lines changed

packages/browser/rollup.config.js

Lines changed: 19 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import { terser } from 'rollup-plugin-terser';
22
import typescript from 'rollup-plugin-typescript2';
3-
import license from 'rollup-plugin-license';
4-
import resolve from '@rollup/plugin-node-resolve';
5-
import replace from '@rollup/plugin-replace';
63

7-
const commitHash = require('child_process')
8-
.execSync('git rev-parse --short HEAD', { encoding: 'utf-8' })
9-
.trim();
4+
import {
5+
baseBundleConfig,
6+
makeLicensePlugin,
7+
markAsBrowserBuild,
8+
nodeResolvePlugin,
9+
paths,
10+
typescriptPluginES5,
11+
} from '../../rollup.config';
12+
13+
const licensePlugin = makeLicensePlugin();
1014

1115
const terserInstance = terser({
1216
compress: {
@@ -37,60 +41,23 @@ const terserInstance = terser({
3741
},
3842
});
3943

40-
const paths = {
41-
'@sentry/utils': ['../utils/src'],
42-
'@sentry/core': ['../core/src'],
43-
'@sentry/hub': ['../hub/src'],
44-
'@sentry/types': ['../types/src'],
45-
'@sentry/minimal': ['../minimal/src'],
46-
};
47-
4844
const plugins = [
49-
typescript({
50-
tsconfig: 'tsconfig.esm.json',
51-
tsconfigOverride: {
52-
compilerOptions: {
53-
declaration: false,
54-
declarationMap: false,
55-
paths,
56-
baseUrl: '.',
57-
},
58-
},
59-
include: ['*.ts+(|x)', '**/*.ts+(|x)', '../**/*.ts+(|x)'],
60-
}),
61-
replace({
62-
// don't replace `__placeholder__` where it's followed immediately by a single `=` (to prevent ending up
63-
// with something of the form `let "replacementValue" = "some assigned value"`, which would cause a
64-
// syntax error)
65-
preventAssignment: true,
66-
// the replacements to make
67-
values: {
68-
__SENTRY_BROWSER_BUNDLE__: true,
69-
},
70-
}),
71-
resolve({
72-
mainFields: ['module'],
73-
}),
45+
typescriptPluginES5,
46+
// replace `__SENTRY_BROWSER_BUNDLE__` with `true` to enable treeshaking of non-browser code
47+
markAsBrowserBuild,
48+
nodeResolvePlugin,
7449
];
7550

7651
const bundleConfig = {
52+
...baseBundleConfig,
7753
input: 'src/index.ts',
7854
output: {
55+
...baseBundleConfig.output,
7956
format: 'iife',
8057
name: 'Sentry',
81-
sourcemap: true,
82-
strict: false,
83-
esModule: false,
8458
},
8559
context: 'window',
86-
plugins: [
87-
...plugins,
88-
license({
89-
sourcemap: true,
90-
banner: `/*! @sentry/browser <%= pkg.version %> (${commitHash}) | https://github.com/getsentry/sentry-javascript */`,
91-
}),
92-
],
93-
treeshake: 'smallest',
60+
plugins: [...plugins, licensePlugin],
9461
};
9562

9663
export default [
@@ -109,10 +76,7 @@ export default [
10976
file: 'build/bundle.min.js',
11077
},
11178
// Uglify has to be at the end of compilation, BUT before the license banner
112-
plugins: bundleConfig.plugins
113-
.slice(0, -1)
114-
.concat(terserInstance)
115-
.concat(bundleConfig.plugins.slice(-1)),
79+
plugins: bundleConfig.plugins.slice(0, -1).concat(terserInstance).concat(bundleConfig.plugins.slice(-1)),
11680
},
11781
// ------------------
11882
// ES6 Browser Bundle
@@ -159,11 +123,7 @@ export default [
159123
},
160124
include: ['*.ts+(|x)', '**/*.ts+(|x)', '../**/*.ts+(|x)'],
161125
}),
162-
...plugins
163-
.slice(1)
164-
.slice(0, -1)
165-
.concat(terserInstance)
166-
.concat(bundleConfig.plugins.slice(-1)),
126+
...plugins.slice(1).slice(0, -1).concat(terserInstance).concat(bundleConfig.plugins.slice(-1)),
167127
],
168128
},
169129
// ------------------

packages/integrations/rollup.config.js

Lines changed: 15 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import * as fs from 'fs';
22

33
import { terser } from 'rollup-plugin-terser';
4-
import typescript from 'rollup-plugin-typescript2';
5-
import resolve from '@rollup/plugin-node-resolve';
64
import commonjs from '@rollup/plugin-commonjs';
7-
import replace from '@rollup/plugin-replace';
5+
6+
import {
7+
addOnBundleConfig,
8+
baseBundleConfig,
9+
markAsBrowserBuild,
10+
nodeResolvePlugin,
11+
typescriptPluginES5,
12+
} from '../../rollup.config';
813

914
const terserInstance = terser({
1015
mangle: {
@@ -21,52 +26,13 @@ const terserInstance = terser({
2126
});
2227

2328
const plugins = [
24-
typescript({
25-
tsconfig: 'tsconfig.esm.json',
26-
tsconfigOverride: {
27-
compilerOptions: {
28-
declaration: false,
29-
declarationMap: false,
30-
paths: {
31-
'@sentry/utils': ['../utils/src'],
32-
'@sentry/core': ['../core/src'],
33-
'@sentry/hub': ['../hub/src'],
34-
'@sentry/types': ['../types/src'],
35-
'@sentry/minimal': ['../minimal/src'],
36-
},
37-
baseUrl: '.',
38-
},
39-
},
40-
include: ['*.ts+(|x)', '**/*.ts+(|x)', '../**/*.ts+(|x)'],
41-
}),
42-
replace({
43-
// don't replace `__placeholder__` where it's followed immediately by a single `=` (to prevent ending up
44-
// with something of the form `let "replacementValue" = "some assigned value"`, which would cause a
45-
// syntax error)
46-
preventAssignment: true,
47-
// the replacements to make
48-
values: {
49-
__SENTRY_BROWSER_BUNDLE__: true,
50-
},
51-
}),
52-
resolve({
53-
mainFields: ['module'],
54-
}),
29+
typescriptPluginES5,
30+
// replace `__SENTRY_BROWSER_BUNDLE__` with `true` to enable treeshaking of non-browser code
31+
markAsBrowserBuild,
32+
nodeResolvePlugin,
5533
commonjs(),
5634
];
5735

58-
function mergeIntoSentry() {
59-
return `
60-
__window.Sentry = __window.Sentry || {};
61-
__window.Sentry.Integrations = __window.Sentry.Integrations || {};
62-
for (var key in exports) {
63-
if (Object.prototype.hasOwnProperty.call(exports, key)) {
64-
__window.Sentry.Integrations[key] = exports[key];
65-
}
66-
}
67-
`;
68-
}
69-
7036
function allIntegrations() {
7137
return fs.readdirSync('./src').filter(file => file != 'index.ts');
7238
}
@@ -85,20 +51,14 @@ function loadAllIntegrations() {
8551
].forEach(build => {
8652
builds.push(
8753
...allIntegrations().map(file => ({
54+
...baseBundleConfig,
8855
input: `src/${file}`,
8956
output: {
90-
banner: '(function (__window) {',
91-
intro: 'var exports = {};',
92-
outro: mergeIntoSentry(),
93-
footer: '}(window));',
57+
...baseBundleConfig.output,
58+
...addOnBundleConfig.output,
9459
file: `build/${file.replace('.ts', build.extension)}`,
95-
format: 'cjs',
96-
sourcemap: true,
97-
strict: false,
98-
esModule: false,
9960
},
10061
plugins: build.plugins,
101-
treeshake: 'smallest',
10262
})),
10363
);
10464
});

packages/tracing/rollup.config.js

Lines changed: 18 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,32 @@
1-
import { terser } from 'rollup-plugin-terser';
2-
import typescript from 'rollup-plugin-typescript2';
3-
import license from 'rollup-plugin-license';
4-
import resolve from '@rollup/plugin-node-resolve';
5-
import replace from '@rollup/plugin-replace';
1+
import {
2+
baseBundleConfig,
3+
makeLicensePlugin,
4+
markAsBrowserBuild,
5+
nodeResolvePlugin,
6+
terserPlugin,
7+
typescriptPluginES5,
8+
} from '../../rollup.config';
69

7-
const commitHash = require('child_process')
8-
.execSync('git rev-parse --short HEAD', { encoding: 'utf-8' })
9-
.trim();
10-
11-
const terserInstance = terser({
12-
mangle: {
13-
// captureExceptions and captureMessage are public API methods and they don't need to be listed here
14-
// as mangler doesn't touch user-facing thing, however sentryWrapped is not, and it would be mangled into a minified version.
15-
// We need those full names to correctly detect our internal frames for stripping.
16-
// I listed all of them here just for the clarity sake, as they are all used in the frames manipulation process.
17-
reserved: ['captureException', 'captureMessage', 'sentryWrapped'],
18-
properties: {
19-
regex: /^_[^_]/,
20-
},
21-
},
22-
output: {
23-
comments: false,
24-
},
25-
});
26-
27-
const paths = {
28-
'@sentry/utils': ['../utils/src'],
29-
'@sentry/core': ['../core/src'],
30-
'@sentry/hub': ['../hub/src'],
31-
'@sentry/types': ['../types/src'],
32-
'@sentry/minimal': ['../minimal/src'],
33-
'@sentry/browser': ['../browser/src'],
34-
};
10+
const licensePlugin = makeLicensePlugin('@sentry/tracing & @sentry/browser');
3511

3612
const plugins = [
37-
typescript({
38-
tsconfig: 'tsconfig.esm.json',
39-
tsconfigOverride: {
40-
compilerOptions: {
41-
declaration: false,
42-
declarationMap: false,
43-
paths,
44-
baseUrl: '.',
45-
},
46-
},
47-
include: ['*.ts+(|x)', '**/*.ts+(|x)', '../**/*.ts+(|x)'],
48-
}),
49-
replace({
50-
// don't replace `__placeholder__` where it's followed immediately by a single `=` (to prevent ending up
51-
// with something of the form `let "replacementValue" = "some assigned value"`, which would cause a
52-
// syntax error)
53-
preventAssignment: true,
54-
// the replacements to make
55-
values: {
56-
__SENTRY_BROWSER_BUNDLE__: true,
57-
},
58-
}),
59-
resolve({
60-
mainFields: ['module'],
61-
}),
13+
typescriptPluginES5,
14+
// replace `__SENTRY_BROWSER_BUNDLE__` with `true` to enable treeshaking of non-browser code
15+
markAsBrowserBuild,
16+
nodeResolvePlugin,
17+
licensePlugin,
6218
];
6319

6420
const bundleConfig = {
21+
...baseBundleConfig,
6522
input: 'src/index.ts',
6623
output: {
24+
...baseBundleConfig.output,
6725
format: 'iife',
6826
name: 'Sentry',
69-
sourcemap: true,
70-
strict: false,
71-
esModule: false,
7227
},
7328
context: 'window',
74-
plugins: [
75-
...plugins,
76-
license({
77-
sourcemap: true,
78-
banner: `/*! @sentry/tracing & @sentry/browser <%= pkg.version %> (${commitHash}) | https://github.com/getsentry/sentry-javascript */`,
79-
}),
80-
],
81-
treeshake: 'smallest',
29+
plugins,
8230
};
8331

8432
export default [
@@ -100,9 +48,6 @@ export default [
10048
file: 'build/bundle.tracing.min.js',
10149
},
10250
// Uglify has to be at the end of compilation, BUT before the license banner
103-
plugins: bundleConfig.plugins
104-
.slice(0, -1)
105-
.concat(terserInstance)
106-
.concat(bundleConfig.plugins.slice(-1)),
51+
plugins: bundleConfig.plugins.slice(0, -1).concat(terserPlugin).concat(bundleConfig.plugins.slice(-1)),
10752
},
10853
];

0 commit comments

Comments
 (0)