From ab20de0fc88562a3a16310a9a94f00c8fbb19760 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Tue, 19 Apr 2022 00:40:28 -0700 Subject: [PATCH 1/7] split up rollup code --- rollup.config.js | 270 -------------------------------- rollup/bundleHelpers.js | 144 +++++++++++++++++ rollup/index.js | 8 + rollup/plugins/bundlePlugins.js | 133 ++++++++++++++++ rollup/plugins/index.js | 1 + rollup/utils.js | 16 ++ 6 files changed, 302 insertions(+), 270 deletions(-) delete mode 100644 rollup.config.js create mode 100644 rollup/bundleHelpers.js create mode 100644 rollup/index.js create mode 100644 rollup/plugins/bundlePlugins.js create mode 100644 rollup/plugins/index.js create mode 100644 rollup/utils.js diff --git a/rollup.config.js b/rollup.config.js deleted file mode 100644 index 041f269f1095..000000000000 --- a/rollup.config.js +++ /dev/null @@ -1,270 +0,0 @@ -/** - * Code for generating config used by individual packages' Rollup configs - */ - -import assert from 'assert'; - -import deepMerge from 'deepmerge'; -import license from 'rollup-plugin-license'; -import resolve from '@rollup/plugin-node-resolve'; -import replace from '@rollup/plugin-replace'; -import { terser } from 'rollup-plugin-terser'; -import typescript from 'rollup-plugin-typescript2'; - -Error.stackTraceLimit = Infinity; - -/** - * Helper functions to compensate for the fact that JS can't handle negative array indices very well - * - * TODO `insertAt` is only exported so the integrations config can inject the `commonjs` plugin, for localforage (used - * in the offline plugin). Once that's fixed to no longer be necessary, this can stop being exported. - */ -const getLastElement = array => { - return array[array.length - 1]; -}; -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, ...insertees); - return newArr; -}; - -/** - * Create a plugin to add an identification banner to the top of stand-alone bundles. - * - * @param title The title to use for the SDK, if not the package name - * @returns An instance of the `rollup-plugin-license` plugin - */ -function makeLicensePlugin(title) { - const commitHash = require('child_process').execSync('git rev-parse --short HEAD', { encoding: 'utf-8' }).trim(); - - return license({ - banner: { - content: `/*! <%= data.title %> <%= pkg.version %> (${commitHash}) | https://github.com/getsentry/sentry-javascript */`, - data: { title }, - }, - }); -} - -function makeIsDebugBuildPlugin(includeDebugging) { - return replace({ - // __SENTRY_DEBUG__ should be save to replace in any case, so no checks for assignments necessary - preventAssignment: false, - values: { - __SENTRY_DEBUG__: includeDebugging, - }, - }); -} - -// `terser` options reference: https://github.com/terser/terser#api-reference -// `rollup-plugin-terser` options reference: https://github.com/TrySound/rollup-plugin-terser#options -export const terserPlugin = terser({ - 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. - // We need those full names to correctly detect our internal frames for stripping. - // I listed all of them here just for the clarity sake, as they are all used in the frames manipulation process. - reserved: ['captureException', 'captureMessage', 'sentryWrapped'], - properties: { - regex: /^_[^_]/, - reserved: ['_experiments'], - }, - }, - output: { - comments: false, - }, -}); - -export function makeBaseBundleConfig(options) { - const { input, isAddOn, jsVersion, licenseTitle, outputFileBase } = options; - - const baseTSPluginOptions = { - tsconfig: 'tsconfig.esm.json', - tsconfigOverride: { - compilerOptions: { - declaration: false, - declarationMap: false, - paths: { - '@sentry/browser': ['../browser/src'], - '@sentry/core': ['../core/src'], - '@sentry/hub': ['../hub/src'], - '@sentry/minimal': ['../minimal/src'], - '@sentry/types': ['../types/src'], - '@sentry/utils': ['../utils/src'], - }, - baseUrl: '.', - }, - }, - include: ['*.ts+(|x)', '**/*.ts+(|x)', '../**/*.ts+(|x)'], - // the typescript plugin doesn't handle concurrency very well, so clean the cache between builds - // (see https://github.com/ezolenko/rollup-plugin-typescript2/issues/15) - clean: true, - // TODO: For the moment, the above issue seems to have stopped spamming the build with (non-blocking) errors, as it - // was originally. If it starts again, this will suppress that output. If we get to the end of the bundle revamp and - // it still seems okay, we can take this out entirely. - // verbosity: 0, - }; - - const typescriptPluginES5 = typescript( - deepMerge(baseTSPluginOptions, { - tsconfigOverride: { - compilerOptions: { - target: 'es5', - }, - }, - }), - ); - - const typescriptPluginES6 = typescript( - deepMerge(baseTSPluginOptions, { - tsconfigOverride: { - compilerOptions: { - target: 'es6', - }, - }, - }), - ); - - const nodeResolvePlugin = resolve(); - - const markAsBrowserBuildPlugin = replace({ - // don't replace `__placeholder__` where it's followed immediately by a single `=` (to prevent ending up - // with something of the form `let "replacementValue" = "some assigned value"`, which would cause a - // syntax error) - preventAssignment: true, - // the replacement to make - values: { - __SENTRY_BROWSER_BUNDLE__: true, - }, - }); - - const licensePlugin = makeLicensePlugin(licenseTitle); - - // used by `@sentry/browser`, `@sentry/tracing`, and `@sentry/vue` (bundles which are a full SDK in and of themselves) - const standAloneBundleConfig = { - output: { - format: 'iife', - name: 'Sentry', - }, - context: 'window', - }; - - // used by `@sentry/integrations` and `@sentry/wasm` (bundles which need to be combined with a stand-alone SDK bundle) - const addOnBundleConfig = { - // These output settings are designed to mimic an IIFE. We don't use Rollup's `iife` format because we don't want to - // attach this code to a new global variable, but rather inject it into the existing SDK's `Integrations` object. - output: { - format: 'cjs', - - // code to add before the CJS wrapper - banner: '(function (__window) {', - - // code to add just inside the CJS wrapper, before any of the wrapped code - intro: 'var exports = {};', - - // code to add after all of the wrapped code, but still inside the CJS wrapper - outro: () => - [ - '', - " // Add this module's exports to the global `Sentry.Integrations`", - ' __window.Sentry = __window.Sentry || {};', - ' __window.Sentry.Integrations = __window.Sentry.Integrations || {};', - ' for (var key in exports) {', - ' if (Object.prototype.hasOwnProperty.call(exports, key)) {', - ' __window.Sentry.Integrations[key] = exports[key];', - ' }', - ' }', - ].join('\n'), - - // code to add after the CJS wrapper - footer: '}(window));', - }, - }; - - // used by all bundles - const sharedBundleConfig = { - input, - output: { - // a file extension will be added to this base value when we specify either a minified or non-minified build - file: `build/${outputFileBase}`, - sourcemap: true, - strict: false, - esModule: false, - }, - plugins: [ - jsVersion.toLowerCase() === 'es5' ? typescriptPluginES5 : typescriptPluginES6, - markAsBrowserBuildPlugin, - nodeResolvePlugin, - licensePlugin, - ], - treeshake: 'smallest', - }; - - return deepMerge(sharedBundleConfig, isAddOn ? addOnBundleConfig : standAloneBundleConfig); -} - -/** - * 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 - */ -export function makeConfigVariants(baseConfig) { - const configVariants = []; - - const { plugins } = baseConfig; - const includeDebuggingPlugin = makeIsDebugBuildPlugin(true); - 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( - getLastElement(plugins).name === 'rollup-plugin-license', - `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 - const variantSpecificConfigs = [ - { - output: { - file: `${baseConfig.output.file}.js`, - }, - 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, stripDebuggingPlugin), - // }, - { - output: { - file: `${baseConfig.output.file}.min.js`, - }, - plugins: insertAt(plugins, -2, stripDebuggingPlugin, terserPlugin), - }, - { - output: { - file: `${baseConfig.output.file}.debug.min.js`, - }, - plugins: insertAt(plugins, -2, includeDebuggingPlugin, terserPlugin), - }, - ]; - - 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 - arrayMerge: (first, second) => second, - }); - configVariants.push(mergedConfig); - }); - - return configVariants; -} diff --git a/rollup/bundleHelpers.js b/rollup/bundleHelpers.js new file mode 100644 index 000000000000..e7c1ea498e2a --- /dev/null +++ b/rollup/bundleHelpers.js @@ -0,0 +1,144 @@ +import assert from 'assert'; + +import deepMerge from 'deepmerge'; + +import { + makeBrowserBuildPlugin, + makeIsDebugBuildPlugin, + makeLicensePlugin, + makeNodeResolvePlugin, + makeTerserPlugin, + makeTSPlugin, +} from './plugins/index.js'; +import { getLastElement, insertAt } from './utils.js'; + +export function makeBaseBundleConfig(options) { + const { input, isAddOn, jsVersion, licenseTitle, outputFileBase } = options; + + const nodeResolvePlugin = makeNodeResolvePlugin(); + const markAsBrowserBuildPlugin = makeBrowserBuildPlugin(true); + const licensePlugin = makeLicensePlugin(licenseTitle); + const tsPlugin = makeTSPlugin(jsVersion.toLowerCase()); + + // used by `@sentry/browser`, `@sentry/tracing`, and `@sentry/vue` (bundles which are a full SDK in and of themselves) + const standAloneBundleConfig = { + output: { + format: 'iife', + name: 'Sentry', + }, + context: 'window', + }; + + // used by `@sentry/integrations` and `@sentry/wasm` (bundles which need to be combined with a stand-alone SDK bundle) + const addOnBundleConfig = { + // These output settings are designed to mimic an IIFE. We don't use Rollup's `iife` format because we don't want to + // attach this code to a new global variable, but rather inject it into the existing SDK's `Integrations` object. + output: { + format: 'cjs', + + // code to add before the CJS wrapper + banner: '(function (__window) {', + + // code to add just inside the CJS wrapper, before any of the wrapped code + intro: 'var exports = {};', + + // code to add after all of the wrapped code, but still inside the CJS wrapper + outro: () => + [ + '', + " // Add this module's exports to the global `Sentry.Integrations`", + ' __window.Sentry = __window.Sentry || {};', + ' __window.Sentry.Integrations = __window.Sentry.Integrations || {};', + ' for (var key in exports) {', + ' if (Object.prototype.hasOwnProperty.call(exports, key)) {', + ' __window.Sentry.Integrations[key] = exports[key];', + ' }', + ' }', + ].join('\n'), + + // code to add after the CJS wrapper + footer: '}(window));', + }, + }; + + // used by all bundles + const sharedBundleConfig = { + input, + output: { + // a file extension will be added to this base value when we specify either a minified or non-minified build + file: `build/${outputFileBase}`, + sourcemap: true, + strict: false, + esModule: false, + }, + plugins: [tsPlugin, markAsBrowserBuildPlugin, nodeResolvePlugin, licensePlugin], + treeshake: 'smallest', + }; + + return deepMerge(sharedBundleConfig, isAddOn ? addOnBundleConfig : standAloneBundleConfig); +} + +/** + * 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 + */ +export function makeConfigVariants(baseConfig) { + const configVariants = []; + + const { plugins: baseConfigPlugins } = baseConfig; + const includeDebuggingPlugin = makeIsDebugBuildPlugin(true); + const stripDebuggingPlugin = makeIsDebugBuildPlugin(false); + const terserPlugin = makeTerserPlugin(); + + // The license plugin has to be last, so it ends up after terser. Otherwise, terser will remove the license banner. + assert( + getLastElement(baseConfigPlugins).name === 'rollup-plugin-license', + `Last plugin in given options should be \`rollup-plugin-license\`. Found ${getLastElement(baseConfigPlugins).name}`, + ); + + // The additional options to use for each variant we're going to create + const variantSpecificConfigs = [ + { + output: { + file: `${baseConfig.output.file}.js`, + }, + plugins: insertAt(baseConfigPlugins, -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, stripDebuggingPlugin), + // }, + { + output: { + file: `${baseConfig.output.file}.min.js`, + }, + plugins: insertAt(baseConfigPlugins, -2, stripDebuggingPlugin, terserPlugin), + }, + { + output: { + file: `${baseConfig.output.file}.debug.min.js`, + }, + plugins: insertAt(baseConfigPlugins, -2, includeDebuggingPlugin, terserPlugin), + }, + ]; + + 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 + arrayMerge: (first, second) => second, + }); + configVariants.push(mergedConfig); + }); + + return configVariants; +} diff --git a/rollup/index.js b/rollup/index.js new file mode 100644 index 000000000000..51baa9ba247c --- /dev/null +++ b/rollup/index.js @@ -0,0 +1,8 @@ +Error.stackTraceLimit = Infinity; + +// TODO Is this necessary? +import * as plugins from './plugins/index.js'; +export { plugins }; + +export * from './bundleHelpers.js'; +export { insertAt } from './utils.js'; diff --git a/rollup/plugins/bundlePlugins.js b/rollup/plugins/bundlePlugins.js new file mode 100644 index 000000000000..0dbbaaa7a8a6 --- /dev/null +++ b/rollup/plugins/bundlePlugins.js @@ -0,0 +1,133 @@ +import deepMerge from 'deepmerge'; +import license from 'rollup-plugin-license'; +import resolve from '@rollup/plugin-node-resolve'; +import replace from '@rollup/plugin-replace'; +import { terser } from 'rollup-plugin-terser'; +import typescript from 'rollup-plugin-typescript2'; + +/** + * Create a plugin to add an identification banner to the top of stand-alone bundles. + * + * @param title The title to use for the SDK, if not the package name + * @returns An instance of the `rollup-plugin-license` plugin + */ +export function makeLicensePlugin(title) { + const commitHash = require('child_process').execSync('git rev-parse --short HEAD', { encoding: 'utf-8' }).trim(); + + return license({ + banner: { + content: `/*! <%= data.title %> <%= pkg.version %> (${commitHash}) | https://github.com/getsentry/sentry-javascript */`, + data: { title }, + }, + }); +} + +/** + * Create a plugin to set the value of the `__SENTRY_DEBUG__` magic string. + * + * @param includeDebugging Whether or not the resulting build should include log statements + * @returns An instance of the `replace` plugin to do the replacement of the magic string with `true` or 'false` + */ +export function makeIsDebugBuildPlugin(includeDebugging) { + return replace({ + // __SENTRY_DEBUG__ should be save to replace in any case, so no checks for assignments necessary + preventAssignment: false, + values: { + __SENTRY_DEBUG__: includeDebugging, + }, + }); +} + +/** + * Create a plugin to set the value of the `__SENTRY_BROWSER_BUNDLE__` magic string. + * + * @param isBrowserBuild Whether or not the resulting build will be run in the browser + * @returns An instance of the `replace` plugin to do the replacement of the magic string with `true` or 'false` + */ +export function makeBrowserBuildPlugin(isBrowserBuild) { + return replace({ + // TODO This will be the default in the next version of the `replace` plugin + preventAssignment: true, + values: { + __SENTRY_BROWSER_BUNDLE__: isBrowserBuild, + }, + }); +} + +// `terser` options reference: https://github.com/terser/terser#api-reference +// `rollup-plugin-terser` options reference: https://github.com/TrySound/rollup-plugin-terser#options + +/** + * Create a plugin to perform minification using `terser`. + * + * @returns An instance of the `terser` plugin + */ +export function makeTerserPlugin() { + return terser({ + mangle: { + // `captureException` and `captureMessage` are public API methods and they don't need to be listed here, as the + // mangler won't touch user-facing things, but `sentryWrapped` is not user-facing, and would be mangled during + // minification. (We need it in its original form to correctly detect our internal frames for stripping.) All three + // are all listed here just for the clarity's sake, as they are all used in the frames manipulation process. + reserved: ['captureException', 'captureMessage', 'sentryWrapped'], + properties: { + // allow mangling of private field names... + regex: /^_[^_]/, + // ...except for `_experiments`, which we want to remain usable from the outside + reserved: ['_experiments'], + }, + }, + output: { + comments: false, + }, + }); +} + +/** + * Create a TypeScript plugin, which will down-compile if necessary, based on the given JS version. + * + * @param jsVersion Either `es5` or `es6` + * @returns An instance of the `typescript` plugin + */ +export function makeTSPlugin(jsVersion) { + const baseTSPluginOptions = { + tsconfig: 'tsconfig.esm.json', + tsconfigOverride: { + compilerOptions: { + declaration: false, + declarationMap: false, + paths: { + '@sentry/browser': ['../browser/src'], + '@sentry/core': ['../core/src'], + '@sentry/hub': ['../hub/src'], + '@sentry/minimal': ['../minimal/src'], + '@sentry/types': ['../types/src'], + '@sentry/utils': ['../utils/src'], + }, + baseUrl: '.', + }, + }, + include: ['*.ts+(|x)', '**/*.ts+(|x)', '../**/*.ts+(|x)'], + // the typescript plugin doesn't handle concurrency very well, so clean the cache between builds + // (see https://github.com/ezolenko/rollup-plugin-typescript2/issues/15) + clean: true, + // TODO: For the moment, the above issue seems to have stopped spamming the build with (non-blocking) errors, as it + // was originally. If it starts again, this will suppress that output. If we get to the end of the bundle revamp and + // it still seems okay, we can take this out entirely. + // verbosity: 0, + }; + + return typescript( + deepMerge(baseTSPluginOptions, { + tsconfigOverride: { + compilerOptions: { + target: jsVersion, + }, + }, + }), + ); +} + +// We don't pass this plugin any options, so no need to wrap it in another factory function, as `resolve` is itself +// already a factory function. +export { resolve as makeNodeResolvePlugin }; diff --git a/rollup/plugins/index.js b/rollup/plugins/index.js new file mode 100644 index 000000000000..bb05969c2caf --- /dev/null +++ b/rollup/plugins/index.js @@ -0,0 +1 @@ +export * from './bundlePlugins'; diff --git a/rollup/utils.js b/rollup/utils.js new file mode 100644 index 000000000000..00a97e991edf --- /dev/null +++ b/rollup/utils.js @@ -0,0 +1,16 @@ +/** + * Helper functions to compensate for the fact that JS can't handle negative array indices very well + */ + +export const getLastElement = array => { + return array[array.length - 1]; +}; + +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, ...insertees); + return newArr; +}; From 3f0ce66160b0c1ed789d541b124748b033774d85 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Tue, 19 Apr 2022 00:40:57 -0700 Subject: [PATCH 2/7] add new files to eslint config --- .eslintrc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index da303c683c01..956f3681ba72 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -42,7 +42,7 @@ module.exports = { }, }, { - files: ['scenarios/**'], + files: ['scenarios/**', 'rollup/**'], parserOptions: { sourceType: 'module', }, From da102efc8e06a190f3644c9c475a6c28f3b3d29c Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Tue, 19 Apr 2022 00:41:35 -0700 Subject: [PATCH 3/7] fix imports in individual package rollup configs --- packages/browser/rollup.config.js | 2 +- packages/integrations/rollup.config.js | 2 +- packages/tracing/rollup.config.js | 2 +- packages/vue/rollup.config.js | 2 +- packages/wasm/rollup.config.js | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/browser/rollup.config.js b/packages/browser/rollup.config.js index d49892da07be..c01e9b86615f 100644 --- a/packages/browser/rollup.config.js +++ b/packages/browser/rollup.config.js @@ -1,4 +1,4 @@ -import { makeBaseBundleConfig, makeConfigVariants } from '../../rollup.config'; +import { makeBaseBundleConfig, makeConfigVariants } from '../../rollup/index.js'; const builds = []; diff --git a/packages/integrations/rollup.config.js b/packages/integrations/rollup.config.js index 7b23d698dfa2..a267ca4edb84 100644 --- a/packages/integrations/rollup.config.js +++ b/packages/integrations/rollup.config.js @@ -1,6 +1,6 @@ import commonjs from '@rollup/plugin-commonjs'; -import { insertAt, makeBaseBundleConfig, makeConfigVariants } from '../../rollup.config'; +import { insertAt, makeBaseBundleConfig, makeConfigVariants } from '../../rollup/index.js'; const builds = []; diff --git a/packages/tracing/rollup.config.js b/packages/tracing/rollup.config.js index 529ddea29a1b..d59d96b65dad 100644 --- a/packages/tracing/rollup.config.js +++ b/packages/tracing/rollup.config.js @@ -1,4 +1,4 @@ -import { makeBaseBundleConfig, makeConfigVariants } from '../../rollup.config'; +import { makeBaseBundleConfig, makeConfigVariants } from '../../rollup/index.js'; const builds = []; diff --git a/packages/vue/rollup.config.js b/packages/vue/rollup.config.js index 2185b2b716c5..d9563c5ad0bc 100644 --- a/packages/vue/rollup.config.js +++ b/packages/vue/rollup.config.js @@ -1,4 +1,4 @@ -import { makeBaseBundleConfig, makeConfigVariants } from '../../rollup.config'; +import { makeBaseBundleConfig, makeConfigVariants } from '../../rollup/index.js'; const baseBundleConfig = makeBaseBundleConfig({ input: 'src/index.bundle.ts', diff --git a/packages/wasm/rollup.config.js b/packages/wasm/rollup.config.js index edccdbd9287a..c239f2ec1e73 100644 --- a/packages/wasm/rollup.config.js +++ b/packages/wasm/rollup.config.js @@ -1,4 +1,4 @@ -import { makeBaseBundleConfig, makeConfigVariants } from '../../rollup.config'; +import { makeBaseBundleConfig, makeConfigVariants } from '../../rollup/index.js'; const baseBundleConfig = makeBaseBundleConfig({ input: 'src/index.ts', From 90688593acd8ed3d273e78d07d811e42d8921a85 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Tue, 19 Apr 2022 00:43:38 -0700 Subject: [PATCH 4/7] s/makeConfigVariants/makeBundleConfigVariants --- 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/bundleHelpers.js | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/browser/rollup.config.js b/packages/browser/rollup.config.js index c01e9b86615f..aec9560621b1 100644 --- a/packages/browser/rollup.config.js +++ b/packages/browser/rollup.config.js @@ -1,4 +1,4 @@ -import { makeBaseBundleConfig, makeConfigVariants } from '../../rollup/index.js'; +import { makeBaseBundleConfig, makeBundleConfigVariants } from '../../rollup/index.js'; const builds = []; @@ -11,7 +11,7 @@ const builds = []; outputFileBase: `bundles/bundle${jsVersion === 'es6' ? '.es6' : ''}`, }); - builds.push(...makeConfigVariants(baseBundleConfig)); + builds.push(...makeBundleConfigVariants(baseBundleConfig)); }); export default builds; diff --git a/packages/integrations/rollup.config.js b/packages/integrations/rollup.config.js index a267ca4edb84..de984497b9a8 100644 --- a/packages/integrations/rollup.config.js +++ b/packages/integrations/rollup.config.js @@ -1,6 +1,6 @@ import commonjs from '@rollup/plugin-commonjs'; -import { insertAt, makeBaseBundleConfig, makeConfigVariants } from '../../rollup/index.js'; +import { insertAt, makeBaseBundleConfig, makeBundleConfigVariants } from '../../rollup/index.js'; const builds = []; @@ -19,6 +19,6 @@ const baseBundleConfig = makeBaseBundleConfig({ baseBundleConfig.plugins = insertAt(baseBundleConfig.plugins, -2, commonjs()); // this makes non-minified, minified, and minified-with-debug-logging versions of each bundle -builds.push(...makeConfigVariants(baseBundleConfig)); +builds.push(...makeBundleConfigVariants(baseBundleConfig)); export default builds; diff --git a/packages/tracing/rollup.config.js b/packages/tracing/rollup.config.js index d59d96b65dad..66d79286f38c 100644 --- a/packages/tracing/rollup.config.js +++ b/packages/tracing/rollup.config.js @@ -1,4 +1,4 @@ -import { makeBaseBundleConfig, makeConfigVariants } from '../../rollup/index.js'; +import { makeBaseBundleConfig, makeBundleConfigVariants } from '../../rollup/index.js'; const builds = []; @@ -11,7 +11,7 @@ const builds = []; outputFileBase: `bundles/bundle.tracing${jsVersion === 'es6' ? '.es6' : ''}`, }); - builds.push(...makeConfigVariants(baseBundleConfig)); + builds.push(...makeBundleConfigVariants(baseBundleConfig)); }); export default builds; diff --git a/packages/vue/rollup.config.js b/packages/vue/rollup.config.js index d9563c5ad0bc..745205cda85f 100644 --- a/packages/vue/rollup.config.js +++ b/packages/vue/rollup.config.js @@ -1,4 +1,4 @@ -import { makeBaseBundleConfig, makeConfigVariants } from '../../rollup/index.js'; +import { makeBaseBundleConfig, makeBundleConfigVariants } from '../../rollup/index.js'; const baseBundleConfig = makeBaseBundleConfig({ input: 'src/index.bundle.ts', @@ -8,4 +8,4 @@ const baseBundleConfig = makeBaseBundleConfig({ outputFileBase: 'bundle.vue', }); -export default makeConfigVariants(baseBundleConfig); +export default makeBundleConfigVariants(baseBundleConfig); diff --git a/packages/wasm/rollup.config.js b/packages/wasm/rollup.config.js index c239f2ec1e73..265b557c76a7 100644 --- a/packages/wasm/rollup.config.js +++ b/packages/wasm/rollup.config.js @@ -1,4 +1,4 @@ -import { makeBaseBundleConfig, makeConfigVariants } from '../../rollup/index.js'; +import { makeBaseBundleConfig, makeBundleConfigVariants } from '../../rollup/index.js'; const baseBundleConfig = makeBaseBundleConfig({ input: 'src/index.ts', @@ -8,4 +8,4 @@ const baseBundleConfig = makeBaseBundleConfig({ outputFileBase: 'bundles/wasm', }); -export default makeConfigVariants(baseBundleConfig); +export default makeBundleConfigVariants(baseBundleConfig); diff --git a/rollup/bundleHelpers.js b/rollup/bundleHelpers.js index e7c1ea498e2a..56eb05664c40 100644 --- a/rollup/bundleHelpers.js +++ b/rollup/bundleHelpers.js @@ -87,7 +87,7 @@ export function makeBaseBundleConfig(options) { * @param baseConfig The rollup config shared by the entire package * @returns An array of versions of that config */ -export function makeConfigVariants(baseConfig) { +export function makeBundleConfigVariants(baseConfig) { const configVariants = []; const { plugins: baseConfigPlugins } = baseConfig; From 1dd69087d7b5222b90a5be417a530ba221f21811 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Tue, 19 Apr 2022 00:45:38 -0700 Subject: [PATCH 5/7] use `.map` rather than `.forEach` in `makeBaseBundleConfig` --- rollup/bundleHelpers.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/rollup/bundleHelpers.js b/rollup/bundleHelpers.js index 56eb05664c40..93e9b634131a 100644 --- a/rollup/bundleHelpers.js +++ b/rollup/bundleHelpers.js @@ -88,8 +88,6 @@ export function makeBaseBundleConfig(options) { * @returns An array of versions of that config */ export function makeBundleConfigVariants(baseConfig) { - const configVariants = []; - const { plugins: baseConfigPlugins } = baseConfig; const includeDebuggingPlugin = makeIsDebugBuildPlugin(true); const stripDebuggingPlugin = makeIsDebugBuildPlugin(false); @@ -131,14 +129,11 @@ export function makeBundleConfigVariants(baseConfig) { }, ]; - variantSpecificConfigs.forEach(variant => { - const mergedConfig = deepMerge(baseConfig, variant, { + return variantSpecificConfigs.map(variant => + 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, - }); - configVariants.push(mergedConfig); - }); - - return configVariants; + }), + ); } From 4b4f354f18a571c3c12c59ed14187f3a9ce68bc7 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Tue, 19 Apr 2022 00:48:07 -0700 Subject: [PATCH 6/7] add docstrings with links to docs --- rollup/bundleHelpers.js | 4 ++++ rollup/plugins/bundlePlugins.js | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/rollup/bundleHelpers.js b/rollup/bundleHelpers.js index 93e9b634131a..d4ddc0e706e2 100644 --- a/rollup/bundleHelpers.js +++ b/rollup/bundleHelpers.js @@ -1,3 +1,7 @@ +/** + * Rollup config docs: https://rollupjs.org/guide/en/#big-list-of-options + */ + import assert from 'assert'; import deepMerge from 'deepmerge'; diff --git a/rollup/plugins/bundlePlugins.js b/rollup/plugins/bundlePlugins.js index 0dbbaaa7a8a6..17c8d5977044 100644 --- a/rollup/plugins/bundlePlugins.js +++ b/rollup/plugins/bundlePlugins.js @@ -1,3 +1,12 @@ +/** + * License plugin docs: https://github.com/mjeanroy/rollup-plugin-license + * Replace plugin docs: https://github.com/rollup/plugins/tree/master/packages/replace + * Resolve plugin docs: https://github.com/rollup/plugins/tree/master/packages/node-resolve + * Terser plugin docs: https://github.com/TrySound/rollup-plugin-terser#options + * Terser docs: https://github.com/terser/terser#api-reference + * Typescript plugin docs: https://github.com/ezolenko/rollup-plugin-typescript2 + */ + import deepMerge from 'deepmerge'; import license from 'rollup-plugin-license'; import resolve from '@rollup/plugin-node-resolve'; From 93726c4291b7350fe4974883adffd015ecf61171 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Tue, 19 Apr 2022 00:53:42 -0700 Subject: [PATCH 7/7] s/rollup.config.js/rollup.bundle.config.js --- packages/browser/package.json | 2 +- packages/browser/{rollup.config.js => rollup.bundle.config.js} | 0 .../integrations/{rollup.config.js => rollup.bundle.config.js} | 0 packages/integrations/scripts/buildBundles.sh | 2 +- packages/tracing/package.json | 2 +- packages/tracing/{rollup.config.js => rollup.bundle.config.js} | 0 packages/vue/package.json | 2 +- packages/vue/{rollup.config.js => rollup.bundle.config.js} | 0 packages/wasm/package.json | 2 +- packages/wasm/{rollup.config.js => rollup.bundle.config.js} | 0 10 files changed, 5 insertions(+), 5 deletions(-) rename packages/browser/{rollup.config.js => rollup.bundle.config.js} (100%) rename packages/integrations/{rollup.config.js => rollup.bundle.config.js} (100%) rename packages/tracing/{rollup.config.js => rollup.bundle.config.js} (100%) rename packages/vue/{rollup.config.js => rollup.bundle.config.js} (100%) rename packages/wasm/{rollup.config.js => rollup.bundle.config.js} (100%) diff --git a/packages/browser/package.json b/packages/browser/package.json index 8ed9132b407e..8f9eb0013e26 100644 --- a/packages/browser/package.json +++ b/packages/browser/package.json @@ -44,7 +44,7 @@ }, "scripts": { "build": "run-p build:cjs build:esm build:bundle build:types", - "build:bundle": "rollup --config", + "build:bundle": "rollup --config rollup.bundle.config.js", "build:cjs": "tsc -p tsconfig.cjs.json", "build:dev": "run-p build:cjs build:esm build:types", "build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***", diff --git a/packages/browser/rollup.config.js b/packages/browser/rollup.bundle.config.js similarity index 100% rename from packages/browser/rollup.config.js rename to packages/browser/rollup.bundle.config.js diff --git a/packages/integrations/rollup.config.js b/packages/integrations/rollup.bundle.config.js similarity index 100% rename from packages/integrations/rollup.config.js rename to packages/integrations/rollup.bundle.config.js diff --git a/packages/integrations/scripts/buildBundles.sh b/packages/integrations/scripts/buildBundles.sh index 3e81a8e6e045..2b75b83ee670 100644 --- a/packages/integrations/scripts/buildBundles.sh +++ b/packages/integrations/scripts/buildBundles.sh @@ -11,7 +11,7 @@ for filepath in ./src/*; do fi # run the build for each integration - INTEGRATION_FILE=$file JS_VERSION=$js_version yarn --silent rollup -c rollup.config.js + INTEGRATION_FILE=$file JS_VERSION=$js_version yarn --silent rollup --config rollup.bundle.config.js done done diff --git a/packages/tracing/package.json b/packages/tracing/package.json index 782bd8bcc658..e77bfbadc5fa 100644 --- a/packages/tracing/package.json +++ b/packages/tracing/package.json @@ -28,7 +28,7 @@ }, "scripts": { "build": "run-p build:cjs build:esm build:types build:bundle && ts-node ../../scripts/prepack.ts #necessary for integration tests", - "build:bundle": "rollup --config", + "build:bundle": "rollup --config rollup.bundle.config.js", "build:cjs": "tsc -p tsconfig.cjs.json", "build:dev": "run-p build:cjs build:esm build:types", "build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***", diff --git a/packages/tracing/rollup.config.js b/packages/tracing/rollup.bundle.config.js similarity index 100% rename from packages/tracing/rollup.config.js rename to packages/tracing/rollup.bundle.config.js diff --git a/packages/vue/package.json b/packages/vue/package.json index 29452f54ce4c..b6eefc1ab6f3 100644 --- a/packages/vue/package.json +++ b/packages/vue/package.json @@ -28,7 +28,7 @@ }, "scripts": { "build": "run-p build:cjs build:esm build:types", - "build:bundle": "rollup --config", + "build:bundle": "rollup --config rollup.bundle.config.js", "build:cjs": "tsc -p tsconfig.cjs.json", "build:dev": "run-p build:cjs build:esm build:types", "build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***", diff --git a/packages/vue/rollup.config.js b/packages/vue/rollup.bundle.config.js similarity index 100% rename from packages/vue/rollup.config.js rename to packages/vue/rollup.bundle.config.js diff --git a/packages/wasm/package.json b/packages/wasm/package.json index 8c850944a72f..671ddad9c5f2 100644 --- a/packages/wasm/package.json +++ b/packages/wasm/package.json @@ -30,7 +30,7 @@ }, "scripts": { "build": "run-p build:cjs build:esm build:bundle build:types", - "build:bundle": "rollup --config", + "build:bundle": "rollup --config rollup.bundle.config.js", "build:cjs": "tsc -p tsconfig.cjs.json", "build:dev": "run-p build:cjs build:esm build:types", "build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***", diff --git a/packages/wasm/rollup.config.js b/packages/wasm/rollup.bundle.config.js similarity index 100% rename from packages/wasm/rollup.config.js rename to packages/wasm/rollup.bundle.config.js