Skip to content

Commit 2e2acf1

Browse files
authored
fix: Use ts-node rather than bash for scripting integration bundling (#5789)
1 parent 974f137 commit 2e2acf1

File tree

4 files changed

+67
-20
lines changed

4 files changed

+67
-20
lines changed

packages/integrations/.eslintrc.js

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
module.exports = {
22
extends: ['../../.eslintrc.js'],
3+
overrides: [
4+
{
5+
files: ['scripts/**/*.ts'],
6+
parserOptions: {
7+
project: ['../../tsconfig.dev.json'],
8+
},
9+
},
10+
],
311
};

packages/integrations/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"scripts": {
2828
"build": "run-p build:rollup build:types build:bundle",
29-
"build:bundle": "yarn ts-node ../../scripts/ensure-bundle-deps.ts && bash scripts/buildBundles.sh",
29+
"build:bundle": "ts-node ../../scripts/ensure-bundle-deps.ts && ts-node scripts/buildBundles.ts --parallel",
3030
"build:dev": "run-p build:rollup build:types",
3131
"build:rollup": "rollup -c rollup.npm.config.js",
3232
"build:types": "tsc -p tsconfig.types.json",

packages/integrations/scripts/buildBundles.sh

-19
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { spawn } from 'child_process';
2+
import { readdirSync } from 'fs';
3+
import { join } from 'path';
4+
5+
const runParallel = process.argv.includes('--parallel');
6+
7+
/** Gets a list of src filenames, one for each integration and excludes the index.ts */
8+
function getIntegrations(): string[] {
9+
const srcDir = join(__dirname, '..', 'src');
10+
const srcFiles = readdirSync(srcDir);
11+
// The index file is only there for the purposes of npm builds
12+
// (for the CDN we create a separate bundle for each integration)
13+
return srcFiles.filter(file => file !== 'index.ts');
14+
}
15+
16+
/** Builds a bundle for a specific integration and JavaScript ES version */
17+
async function buildBundle(integration: string, jsVersion: string): Promise<void> {
18+
return new Promise((resolve, reject) => {
19+
const child = spawn('yarn', ['--silent', 'rollup', '--config', 'rollup.bundle.config.js'], {
20+
env: { ...process.env, INTEGRATION_FILE: integration, JS_VERSION: jsVersion },
21+
});
22+
23+
child.on('exit', exitcode => {
24+
if (exitcode !== 0) {
25+
reject(new Error(`Failed to build bundle for integration "${integration}" with exit code: ${exitcode}`));
26+
} else {
27+
resolve();
28+
}
29+
});
30+
});
31+
}
32+
33+
if (runParallel) {
34+
// We're building a bundle for each integration and each JavaScript version.
35+
const tasks = getIntegrations().reduce(
36+
(tasks, integration) => [...tasks, buildBundle(integration, 'ES5'), buildBundle(integration, 'ES6')],
37+
[] as Promise<void>[],
38+
);
39+
40+
Promise.all(tasks)
41+
// eslint-disable-next-line no-console
42+
.then(_ => console.log('\nIntegration bundles built successfully'))
43+
.catch(error => {
44+
// eslint-disable-next-line no-console
45+
console.error(error);
46+
// Important to exit with a non-zero exit code, so that the build fails.
47+
process.exit(1);
48+
});
49+
} else {
50+
void (async () => {
51+
for (const integration of getIntegrations()) {
52+
await buildBundle(integration, 'ES5');
53+
await buildBundle(integration, 'ES6');
54+
}
55+
// eslint-disable-next-line no-console
56+
console.log('\nIntegration bundles built successfully');
57+
})();
58+
}

0 commit comments

Comments
 (0)