From 5a3eb4a8045d4072938b181efe58232ca1197cc0 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Tue, 8 Mar 2022 17:54:00 -0800 Subject: [PATCH 1/7] make `insertAt` able to insert multiple elements --- rollup.config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rollup.config.js b/rollup.config.js index 8b8bddcad948..3a33763c0b19 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -20,12 +20,12 @@ import typescript from 'rollup-plugin-typescript2'; const getLastElement = array => { return array[array.length - 1]; }; -export const insertAt = (arr, index, insertee) => { +export const insertAt = (arr, index, ...insertees) => { const newArr = [...arr]; // Add 1 to the array length so that the inserted element ends up in the right spot with respect to the length of the // new array (which will be one element longer), rather than that of the current array const destinationIndex = index >= 0 ? index : arr.length + 1 + index; - newArr.splice(destinationIndex, 0, insertee); + newArr.splice(destinationIndex, 0, ...insertees); return newArr; }; From cedc63f9671f37d4f6da5ab050544db7e9ffee78 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Tue, 8 Mar 2022 19:09:21 -0800 Subject: [PATCH 2/7] make `makeMinificationVariants` take a single base config --- rollup.config.js | 57 ++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/rollup.config.js b/rollup.config.js index 3a33763c0b19..56095bc8e651 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -190,44 +190,39 @@ export function makeBaseBundleConfig(options) { return deepMerge(sharedBundleConfig, isAddOn ? addOnBundleConfig : standAloneBundleConfig); } -export function makeMinificationVariants(existingConfigs) { +export function makeMinificationVariants(baseConfig) { const newConfigs = []; - // ensure we've got an array of configs rather than a single config - existingConfigs = Array.isArray(existingConfigs) ? existingConfigs : [existingConfigs]; + const { plugins } = baseConfig; - existingConfigs.forEach(existingConfig => { - const { plugins } = existingConfig; - - // The license plugin has to be last, so it ends up after terser. Otherwise, terser will remove the license banner. - assert( - getLastElement(plugins).name === 'rollup-plugin-license', - `Last plugin in given options should be \`rollup-plugin-license\`. Found ${getLastElement(plugins).name}`, - ); + // The license plugin has to be last, so it ends up after terser. Otherwise, terser will remove the license banner. + assert( + getLastElement(plugins).name === 'rollup-plugin-license', + `Last plugin in given options should be \`rollup-plugin-license\`. Found ${getLastElement(plugins).name}`, + ); - const bundleVariants = [ - { - output: { - file: `${existingConfig.output.file}.js`, - }, - plugins, + const bundleVariants = [ + { + output: { + file: `${baseConfig.output.file}.js`, }, - { - output: { - file: `${existingConfig.output.file}.min.js`, - }, - plugins: insertAt(plugins, -2, terserPlugin), + plugins, + }, + { + output: { + file: `${baseConfig.output.file}.min.js`, }, - ]; - - bundleVariants.forEach(variant => { - const mergedConfig = deepMerge(existingConfig, variant, { - // this makes it so that instead of concatenating the `plugin` properties of the two objects, the first value is - // just overwritten by the second value - arrayMerge: (first, second) => second, - }); - newConfigs.push(mergedConfig); + plugins: insertAt(plugins, -2, terserPlugin), + }, + ]; + + bundleVariants.forEach(variant => { + const mergedConfig = deepMerge(baseConfig, variant, { + // this makes it so that instead of concatenating the `plugin` properties of the two objects, the first value is + // just overwritten by the second value + arrayMerge: (first, second) => second, }); + newConfigs.push(mergedConfig); }); return newConfigs; From 6543b9b0b8fbd5484d8f3121f2b9067ca0ee7bb9 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Tue, 8 Mar 2022 19:13:58 -0800 Subject: [PATCH 3/7] s/makeMinificationVariants/makeConfigVariants, s/newConfigs/configVariants, s/bundleVariants/variantSpecificOptionsVariants --- packages/browser/rollup.config.js | 4 ++-- packages/integrations/rollup.config.js | 4 ++-- packages/tracing/rollup.config.js | 4 ++-- packages/vue/rollup.config.js | 4 ++-- packages/wasm/rollup.config.js | 4 ++-- rollup.config.js | 19 +++++++++++++------ 6 files changed, 23 insertions(+), 16 deletions(-) diff --git a/packages/browser/rollup.config.js b/packages/browser/rollup.config.js index 36882b0d0c4b..ce0e07a67a0d 100644 --- a/packages/browser/rollup.config.js +++ b/packages/browser/rollup.config.js @@ -1,4 +1,4 @@ -import { makeBaseBundleConfig, makeMinificationVariants } from '../../rollup.config'; +import { makeBaseBundleConfig, makeConfigVariants } from '../../rollup.config'; const builds = []; @@ -11,7 +11,7 @@ const builds = []; outputFileBase: `build/bundle${jsVersion === 'es6' ? '.es6' : ''}`, }); - builds.push(...makeMinificationVariants(baseBundleConfig)); + builds.push(...makeConfigVariants(baseBundleConfig)); }); export default builds; diff --git a/packages/integrations/rollup.config.js b/packages/integrations/rollup.config.js index d136df8b1ec1..0ffe58b68d32 100644 --- a/packages/integrations/rollup.config.js +++ b/packages/integrations/rollup.config.js @@ -2,7 +2,7 @@ import * as fs from 'fs'; import commonjs from '@rollup/plugin-commonjs'; -import { insertAt, makeBaseBundleConfig, makeMinificationVariants } from '../../rollup.config'; +import { insertAt, makeBaseBundleConfig, makeConfigVariants } from '../../rollup.config'; const builds = []; @@ -20,7 +20,7 @@ integrationSourceFiles.forEach(file => { // TODO We only need `commonjs` for localforage (used in the offline plugin). Once that's fixed, this can come out. baseBundleConfig.plugins = insertAt(baseBundleConfig.plugins, -2, commonjs()); - builds.push(...makeMinificationVariants(baseBundleConfig)); + builds.push(...makeConfigVariants(baseBundleConfig)); }); export default builds; diff --git a/packages/tracing/rollup.config.js b/packages/tracing/rollup.config.js index 7729573881e4..c04d025c2f61 100644 --- a/packages/tracing/rollup.config.js +++ b/packages/tracing/rollup.config.js @@ -1,4 +1,4 @@ -import { makeBaseBundleConfig, makeMinificationVariants } from '../../rollup.config'; +import { makeBaseBundleConfig, makeConfigVariants } from '../../rollup.config'; const builds = []; @@ -11,7 +11,7 @@ const builds = []; outputFileBase: `build/bundle.tracing${jsVersion === 'es6' ? '.es6' : ''}`, }); - builds.push(...makeMinificationVariants(baseBundleConfig)); + builds.push(...makeConfigVariants(baseBundleConfig)); }); export default builds; diff --git a/packages/vue/rollup.config.js b/packages/vue/rollup.config.js index 9980b428820e..22d66faf05ed 100644 --- a/packages/vue/rollup.config.js +++ b/packages/vue/rollup.config.js @@ -1,4 +1,4 @@ -import { makeBaseBundleConfig, makeMinificationVariants } from '../../rollup.config'; +import { makeBaseBundleConfig, makeConfigVariants } from '../../rollup.config'; const baseBundleConfig = makeBaseBundleConfig({ input: 'src/index.bundle.ts', @@ -8,4 +8,4 @@ const baseBundleConfig = makeBaseBundleConfig({ outputFileBase: 'build/bundle.vue', }); -export default makeMinificationVariants(baseBundleConfig); +export default makeConfigVariants(baseBundleConfig); diff --git a/packages/wasm/rollup.config.js b/packages/wasm/rollup.config.js index 614b861622dd..28ef64086913 100644 --- a/packages/wasm/rollup.config.js +++ b/packages/wasm/rollup.config.js @@ -1,4 +1,4 @@ -import { makeBaseBundleConfig, makeMinificationVariants } from '../../rollup.config'; +import { makeBaseBundleConfig, makeConfigVariants } from '../../rollup.config'; const baseBundleConfig = makeBaseBundleConfig({ input: 'src/index.ts', @@ -8,4 +8,4 @@ const baseBundleConfig = makeBaseBundleConfig({ outputFileBase: 'build/wasm', }); -export default makeMinificationVariants(baseBundleConfig); +export default makeConfigVariants(baseBundleConfig); diff --git a/rollup.config.js b/rollup.config.js index 56095bc8e651..1f75a6b232fb 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -190,8 +190,14 @@ export function makeBaseBundleConfig(options) { return deepMerge(sharedBundleConfig, isAddOn ? addOnBundleConfig : standAloneBundleConfig); } -export function makeMinificationVariants(baseConfig) { - const newConfigs = []; +/** + * Takes the CDN rollup config for a given package and produces configs for both minified and unminified bundles. + * + * @param baseConfig The rollup config shared by the entire package + * @returns An array of versions of that config + */ +export function makeConfigVariants(baseConfig) { + const configVariants = []; const { plugins } = baseConfig; @@ -201,7 +207,8 @@ export function makeMinificationVariants(baseConfig) { `Last plugin in given options should be \`rollup-plugin-license\`. Found ${getLastElement(plugins).name}`, ); - const bundleVariants = [ + // The additional options to use for each variant we're going to create #namingishard + const variantSpecificOptionsVariants = [ { output: { file: `${baseConfig.output.file}.js`, @@ -216,14 +223,14 @@ export function makeMinificationVariants(baseConfig) { }, ]; - bundleVariants.forEach(variant => { + variantSpecificOptionsVariants.forEach(variant => { const mergedConfig = deepMerge(baseConfig, variant, { // this makes it so that instead of concatenating the `plugin` properties of the two objects, the first value is // just overwritten by the second value arrayMerge: (first, second) => second, }); - newConfigs.push(mergedConfig); + configVariants.push(mergedConfig); }); - return newConfigs; + return configVariants; } From 45b7865ac011e578f6a8b458d62a297506444373 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Tue, 8 Mar 2022 23:43:41 -0800 Subject: [PATCH 4/7] remove terser config for controlling debug logging --- rollup.config.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/rollup.config.js b/rollup.config.js index 1f75a6b232fb..7d399290eb38 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -47,13 +47,6 @@ function makeLicensePlugin(title) { } export const terserPlugin = terser({ - compress: { - // Tell env.ts that we're building a browser bundle and that we do not - // want to have unnecessary debug functionality. - global_defs: { - __SENTRY_NO_DEBUG__: false, - }, - }, mangle: { // captureExceptions and captureMessage are public API methods and they don't need to be listed here // as mangler doesn't touch user-facing thing, however sentryWrapped is not, and it would be mangled into a minified version. From 4c46536bdbb1d9df19fc4fe82e38248e8ed39ea6 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Tue, 8 Mar 2022 18:50:43 -0800 Subject: [PATCH 5/7] add function to create plugin to control inclusion of debug logging --- rollup.config.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/rollup.config.js b/rollup.config.js index 7d399290eb38..7fe3eefb7d17 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -46,6 +46,17 @@ function makeLicensePlugin(title) { }); } +function makeIsDebugBuildPlugin(includeDebugging) { + return replace({ + // don't turn `const __SENTRY_DEBUG__ = false` into `const false = false` + preventAssignment: true, + // everywhere else, replace it with the value of `includeDebugging` + values: { + __SENTRY_DEBUG__: includeDebugging, + }, + }); +} + export const terserPlugin = terser({ mangle: { // captureExceptions and captureMessage are public API methods and they don't need to be listed here From 1b3afc82b6599e5d19ae50b0f58906445ac38c06 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Tue, 8 Mar 2022 23:56:31 -0800 Subject: [PATCH 6/7] create default (no-debug) and debug variants of minified bundles --- rollup.config.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/rollup.config.js b/rollup.config.js index 7fe3eefb7d17..c83f8fcd52a5 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -195,7 +195,10 @@ export function makeBaseBundleConfig(options) { } /** - * Takes the CDN rollup config for a given package and produces configs for both minified and unminified bundles. + * Takes the CDN rollup config for a given package and produces three versions of it: + * - non-minified, including debug logging, + * - minified, including debug logging, + * - minified, with debug logging stripped * * @param baseConfig The rollup config shared by the entire package * @returns An array of versions of that config @@ -204,6 +207,8 @@ export function makeConfigVariants(baseConfig) { const configVariants = []; const { plugins } = baseConfig; + const includeDebuggingPlugin = makeIsDebugBuildPlugin(true); + const noDebuggingPlugin = makeIsDebugBuildPlugin(false); // The license plugin has to be last, so it ends up after terser. Otherwise, terser will remove the license banner. assert( @@ -217,13 +222,27 @@ export function makeConfigVariants(baseConfig) { output: { file: `${baseConfig.output.file}.js`, }, - plugins, + plugins: insertAt(plugins, -2, includeDebuggingPlugin), }, + // This variant isn't particularly helpful for an SDK user, as it strips logging while making no other minification + // changes, so by default we don't create it. It is however very useful when debugging rollup's treeshaking, so it's + // left here for that purpose. + // { + // output: { file: `${baseConfig.output.file}.no-debug.js`, + // }, + // plugins: insertAt(plugins, -2, noDebuggingPlugin), + // }, { output: { file: `${baseConfig.output.file}.min.js`, }, - plugins: insertAt(plugins, -2, terserPlugin), + plugins: insertAt(plugins, -2, noDebuggingPlugin, terserPlugin), + }, + { + output: { + file: `${baseConfig.output.file}.debug.min.js`, + }, + plugins: insertAt(plugins, -2, includeDebuggingPlugin, terserPlugin), }, ]; From 2eb646717db2394b153ba3a64c9378854fada71c Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Fri, 11 Mar 2022 06:32:43 -0800 Subject: [PATCH 7/7] fix names --- rollup.config.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/rollup.config.js b/rollup.config.js index c83f8fcd52a5..3c9f5d9cc2ee 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -208,7 +208,7 @@ export function makeConfigVariants(baseConfig) { const { plugins } = baseConfig; const includeDebuggingPlugin = makeIsDebugBuildPlugin(true); - const noDebuggingPlugin = makeIsDebugBuildPlugin(false); + const stripDebuggingPlugin = makeIsDebugBuildPlugin(false); // The license plugin has to be last, so it ends up after terser. Otherwise, terser will remove the license banner. assert( @@ -216,8 +216,8 @@ export function makeConfigVariants(baseConfig) { `Last plugin in given options should be \`rollup-plugin-license\`. Found ${getLastElement(plugins).name}`, ); - // The additional options to use for each variant we're going to create #namingishard - const variantSpecificOptionsVariants = [ + // The additional options to use for each variant we're going to create + const variantSpecificConfigs = [ { output: { file: `${baseConfig.output.file}.js`, @@ -230,13 +230,13 @@ export function makeConfigVariants(baseConfig) { // { // output: { file: `${baseConfig.output.file}.no-debug.js`, // }, - // plugins: insertAt(plugins, -2, noDebuggingPlugin), + // plugins: insertAt(plugins, -2, stripDebuggingPlugin), // }, { output: { file: `${baseConfig.output.file}.min.js`, }, - plugins: insertAt(plugins, -2, noDebuggingPlugin, terserPlugin), + plugins: insertAt(plugins, -2, stripDebuggingPlugin, terserPlugin), }, { output: { @@ -246,7 +246,7 @@ export function makeConfigVariants(baseConfig) { }, ]; - variantSpecificOptionsVariants.forEach(variant => { + variantSpecificConfigs.forEach(variant => { const mergedConfig = deepMerge(baseConfig, variant, { // this makes it so that instead of concatenating the `plugin` properties of the two objects, the first value is // just overwritten by the second value