Skip to content

Commit

Permalink
ref(build): Parallelize integration bundling (#4707)
Browse files Browse the repository at this point in the history
Given that now most of our testing runs in parallel in CI, the biggest bottleneck has become the build step. Within that step, the single slowest thing we do is build integration bundles, simply because of the number of bundles which need to be created. (This is especially true now that we're creating three versions of each bundle rather than two[1].)

To speed things up a bit, this parallelizes the building of those bundles. Though it ends up not being as dramatic a time savings as one might hope (because the typescript plugin's caching mechanism doesn't play nicely with concurrent builds[2]), it nonetheless drops the total build time from roughly two minutes down to 70-80 seconds in my local testing.

[1] #4699
[2] ezolenko/rollup-plugin-typescript2#15
  • Loading branch information
lobsterkatie authored Mar 15, 2022
1 parent ec8da92 commit 57a8997
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/integrations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"scripts": {
"build": "run-p build:cjs build:esm build:bundle",
"build:bundle": "rollup --config",
"build:bundle": "bash scripts/buildBundles.sh",
"build:cjs": "tsc -p tsconfig.cjs.json",
"build:dev": "run-s build:cjs build:esm",
"build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***",
Expand Down
30 changes: 13 additions & 17 deletions packages/integrations/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
import * as fs from 'fs';

import commonjs from '@rollup/plugin-commonjs';

import { insertAt, makeBaseBundleConfig, makeConfigVariants } from '../../rollup.config';

const builds = [];

const integrationSourceFiles = fs.readdirSync('./src').filter(file => file != 'index.ts');
const file = process.env.INTEGRATION_FILE;

integrationSourceFiles.forEach(file => {
const baseBundleConfig = makeBaseBundleConfig({
input: `src/${file}`,
isAddOn: true,
jsVersion: 'es5',
licenseTitle: '@sentry/integrations',
// TODO this doesn't currently need to be a template string, but soon will need to be, so leaving it in that form
// for now
outputFileBase: `${file.replace('.ts', '')}`,
});
const baseBundleConfig = makeBaseBundleConfig({
input: `src/${file}`,
isAddOn: true,
jsVersion: 'es5',
licenseTitle: '@sentry/integrations',
// TODO this doesn't currently need to be a template string, but soon will need to be, so leaving it in that form
// for now
outputFileBase: `${file.replace('.ts', '')}`,
});

// 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());
// 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(...makeConfigVariants(baseBundleConfig));
});
builds.push(...makeConfigVariants(baseBundleConfig));

export default builds;
20 changes: 20 additions & 0 deletions packages/integrations/scripts/buildBundles.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
for filepath in ./src/*; do
file=$(basename $filepath)

# the index file is only there for the purposes of npm builds - for the CDN we create a separate bundle for each
# integration - so we can skip it here
if [[ $file == "index.ts" ]]; then
continue
fi

# run the build for each integration, pushing each build process into the background once it starts (that's what the
# trailing `&` does) so that we can start another one
echo -e "\nBuilding bundles for \`$file\`..."
INTEGRATION_FILE=$file yarn --silent rollup -c rollup.config.js 2>/dev/null && echo -e "\nFinished building bundles for \`$file\`." &

done

# keep the process running until all backgrounded tasks have finished
wait

echo "Integration bundles built successfully"

0 comments on commit 57a8997

Please sign in to comment.