Skip to content

ref(build): Parallelize integration bundling #4707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"