Skip to content

Commit 57a8997

Browse files
authored
ref(build): Parallelize integration bundling (#4707)
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
1 parent ec8da92 commit 57a8997

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

packages/integrations/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"scripts": {
2828
"build": "run-p build:cjs build:esm build:bundle",
29-
"build:bundle": "rollup --config",
29+
"build:bundle": "bash scripts/buildBundles.sh",
3030
"build:cjs": "tsc -p tsconfig.cjs.json",
3131
"build:dev": "run-s build:cjs build:esm",
3232
"build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***",
Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
1-
import * as fs from 'fs';
2-
31
import commonjs from '@rollup/plugin-commonjs';
42

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

75
const builds = [];
86

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

11-
integrationSourceFiles.forEach(file => {
12-
const baseBundleConfig = makeBaseBundleConfig({
13-
input: `src/${file}`,
14-
isAddOn: true,
15-
jsVersion: 'es5',
16-
licenseTitle: '@sentry/integrations',
17-
// TODO this doesn't currently need to be a template string, but soon will need to be, so leaving it in that form
18-
// for now
19-
outputFileBase: `${file.replace('.ts', '')}`,
20-
});
9+
const baseBundleConfig = makeBaseBundleConfig({
10+
input: `src/${file}`,
11+
isAddOn: true,
12+
jsVersion: 'es5',
13+
licenseTitle: '@sentry/integrations',
14+
// TODO this doesn't currently need to be a template string, but soon will need to be, so leaving it in that form
15+
// for now
16+
outputFileBase: `${file.replace('.ts', '')}`,
17+
});
2118

22-
// TODO We only need `commonjs` for localforage (used in the offline plugin). Once that's fixed, this can come out.
23-
baseBundleConfig.plugins = insertAt(baseBundleConfig.plugins, -2, commonjs());
19+
// TODO We only need `commonjs` for localforage (used in the offline plugin). Once that's fixed, this can come out.
20+
baseBundleConfig.plugins = insertAt(baseBundleConfig.plugins, -2, commonjs());
2421

25-
builds.push(...makeConfigVariants(baseBundleConfig));
26-
});
22+
builds.push(...makeConfigVariants(baseBundleConfig));
2723

2824
export default builds;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
for filepath in ./src/*; do
2+
file=$(basename $filepath)
3+
4+
# the index file is only there for the purposes of npm builds - for the CDN we create a separate bundle for each
5+
# integration - so we can skip it here
6+
if [[ $file == "index.ts" ]]; then
7+
continue
8+
fi
9+
10+
# run the build for each integration, pushing each build process into the background once it starts (that's what the
11+
# trailing `&` does) so that we can start another one
12+
echo -e "\nBuilding bundles for \`$file\`..."
13+
INTEGRATION_FILE=$file yarn --silent rollup -c rollup.config.js 2>/dev/null && echo -e "\nFinished building bundles for \`$file\`." &
14+
15+
done
16+
17+
# keep the process running until all backgrounded tasks have finished
18+
wait
19+
20+
echo "Integration bundles built successfully"

0 commit comments

Comments
 (0)