Skip to content

Commit e333882

Browse files
committed
properly parallelize builds
1 parent b6b4d6f commit e333882

8 files changed

Lines changed: 122 additions & 101 deletions

File tree

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,8 @@
2929
"[typescript]": {
3030
"editor.defaultFormatter": "oxc.oxc-vscode"
3131
},
32-
"oxc.suppressProgramErrors": true
32+
"oxc.suppressProgramErrors": true,
33+
"[javascript]": {
34+
"editor.defaultFormatter": "oxc.oxc-vscode"
35+
}
3336
}

dev-packages/rollup-utils/bundleHelpers.mjs

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -135,55 +135,69 @@ export function makeBaseBundleConfig(options) {
135135
});
136136
}
137137

138+
/**
139+
* @param {import('rollup').RollupOptions} baseConfig
140+
* @param {string} variant
141+
*/
142+
function getVariantSpecificBundleConfig(baseConfig, variant) {
143+
const baseEntryNames = baseConfig.output.entryFileNames;
144+
145+
switch (variant) {
146+
case '.js':
147+
return {
148+
output: {
149+
entryFileNames: chunkInfo => `${baseEntryNames(chunkInfo)}.js`,
150+
},
151+
plugins: [makeIsDebugBuildPlugin(true), makeSetSDKSourcePlugin('cdn')],
152+
};
153+
case '.min.js':
154+
return {
155+
output: {
156+
entryFileNames: chunkInfo => `${baseEntryNames(chunkInfo)}.min.js`,
157+
},
158+
plugins: [makeIsDebugBuildPlugin(false), makeSetSDKSourcePlugin('cdn'), makeTerserPlugin()],
159+
};
160+
case '.debug.min.js':
161+
return {
162+
output: {
163+
entryFileNames: chunkInfo => `${baseEntryNames(chunkInfo)}.debug.min.js`,
164+
},
165+
plugins: [makeIsDebugBuildPlugin(true), makeSetSDKSourcePlugin('cdn'), makeTerserPlugin()],
166+
};
167+
default:
168+
throw new Error(`Unknown bundle variant requested: ${variant}`);
169+
}
170+
}
171+
138172
/**
139173
* Takes the CDN rollup config for a given package and produces three versions of it:
140174
* - non-minified, including debug logging,
141175
* - minified, including debug logging,
142176
* - minified, with debug logging stripped
143177
*
144-
* @param baseConfig The rollup config shared by the entire package
145-
* @returns An array of versions of that config
178+
* Pass `() => makeBaseBundleConfig({ ... })` so each variant gets a fresh base config (new plugin instances). That
179+
* avoids sharing stateful Rollup plugins when `rollupParallel` runs multiple `rollup()` calls concurrently. Passing a
180+
* plain config object is supported for backwards compatibility but only shallow-clones plugin shells.
181+
*
182+
* @param {(() => import('rollup').RollupOptions) | import('rollup').RollupOptions} getBaseConfigOrConfig
183+
* @param {{ variants?: string[] }} [options]
146184
*/
147-
export function makeBundleConfigVariants(baseConfig, options = {}) {
185+
export function makeBundleConfigVariants(getBaseConfigOrConfig, options = {}) {
148186
const { variants = BUNDLE_VARIANTS } = options;
149-
150-
const includeDebuggingPlugin = makeIsDebugBuildPlugin(true);
151-
const stripDebuggingPlugin = makeIsDebugBuildPlugin(false);
152-
const terserPlugin = makeTerserPlugin();
153-
const setSdkSourcePlugin = makeSetSDKSourcePlugin('cdn');
154-
155-
// The additional options to use for each variant we're going to create.
156-
const variantSpecificConfigMap = {
157-
'.js': {
158-
output: {
159-
entryFileNames: chunkInfo => `${baseConfig.output.entryFileNames(chunkInfo)}.js`,
160-
},
161-
plugins: [includeDebuggingPlugin, setSdkSourcePlugin],
162-
},
163-
164-
'.min.js': {
165-
output: {
166-
entryFileNames: chunkInfo => `${baseConfig.output.entryFileNames(chunkInfo)}.min.js`,
167-
},
168-
plugins: [stripDebuggingPlugin, setSdkSourcePlugin, terserPlugin],
169-
},
170-
171-
'.debug.min.js': {
172-
output: {
173-
entryFileNames: chunkInfo => `${baseConfig.output.entryFileNames(chunkInfo)}.debug.min.js`,
174-
},
175-
plugins: [includeDebuggingPlugin, setSdkSourcePlugin, terserPlugin],
176-
},
177-
};
187+
const resolveBase = typeof getBaseConfigOrConfig === 'function' ? getBaseConfigOrConfig : () => getBaseConfigOrConfig;
178188

179189
return variants.map(variant => {
180190
if (!BUNDLE_VARIANTS.includes(variant)) {
181191
throw new Error(`Unknown bundle variant requested: ${variant}`);
182192
}
183-
return deepMerge(baseConfig, variantSpecificConfigMap[variant], {
193+
const baseConfig = resolveBase();
194+
const merged = deepMerge(baseConfig, getVariantSpecificBundleConfig(baseConfig, variant), {
184195
// Merge the plugin arrays and make sure the end result is in the correct order. Everything else can use the
185196
// default merge strategy.
186197
customMerge: key => (key === 'plugins' ? mergePlugins : undefined),
187198
});
199+
return {
200+
...merged,
201+
};
188202
});
189203
}

docs/adding-cdn-bundle.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,18 @@ describe('index.bundle.{FEATURE_COMBO}', () => {
130130
Add bundle config before `builds.push(...)`:
131131

132132
```javascript
133-
const {featureCombo}BaseBundleConfig = makeBaseBundleConfig({
133+
const {featureCombo}BaseBundleOptions = {
134134
bundleType: 'standalone',
135135
entrypoints: ['src/index.bundle.{FEATURE_COMBO}.ts'],
136136
licenseTitle: '@sentry/browser ({Human Readable Feature List})',
137137
outputFileBase: () => 'bundles/bundle.{FEATURE_COMBO}',
138-
});
138+
};
139139
```
140140

141141
Add to `builds.push(...)`:
142142

143143
```javascript
144-
...makeBundleConfigVariants({featureCombo}BaseBundleConfig),
144+
...makeBundleConfigVariants(() => makeBaseBundleConfig({featureCombo}BaseBundleOptions)),
145145
```
146146

147147
### 4. `.size-limit.js`

packages/browser/rollup.bundle.config.mjs

Lines changed: 57 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,35 @@ const reexportedPluggableIntegrationFiles = [
2222
];
2323

2424
browserPluggableIntegrationFiles.forEach(integrationName => {
25-
const integrationsBundleConfig = makeBaseBundleConfig({
26-
bundleType: 'addon',
27-
entrypoints: [`src/integrations/${integrationName}.ts`],
28-
licenseTitle: `@sentry/browser - ${integrationName}`,
29-
outputFileBase: () => `bundles/${integrationName}`,
30-
});
31-
32-
builds.push(...makeBundleConfigVariants(integrationsBundleConfig));
25+
builds.push(
26+
...makeBundleConfigVariants(() =>
27+
makeBaseBundleConfig({
28+
bundleType: 'addon',
29+
entrypoints: [`src/integrations/${integrationName}.ts`],
30+
licenseTitle: `@sentry/browser - ${integrationName}`,
31+
outputFileBase: () => `bundles/${integrationName}`,
32+
}),
33+
),
34+
);
3335
});
3436

3537
reexportedPluggableIntegrationFiles.forEach(integrationName => {
36-
const integrationsBundleConfig = makeBaseBundleConfig({
37-
bundleType: 'addon',
38-
entrypoints: [`src/integrations-bundle/index.${integrationName}.ts`],
39-
licenseTitle: `@sentry/browser - ${integrationName}`,
40-
outputFileBase: () => `bundles/${integrationName}`,
41-
});
42-
43-
builds.push(...makeBundleConfigVariants(integrationsBundleConfig));
38+
builds.push(
39+
...makeBundleConfigVariants(() =>
40+
makeBaseBundleConfig({
41+
bundleType: 'addon',
42+
entrypoints: [`src/integrations-bundle/index.${integrationName}.ts`],
43+
licenseTitle: `@sentry/browser - ${integrationName}`,
44+
outputFileBase: () => `bundles/${integrationName}`,
45+
}),
46+
),
47+
);
4448
});
4549

4650
// Bundle config for additional exports we don't want to include in the main SDK bundle
4751
// if we need more of these, we can generalize the config as for pluggable integrations
4852
builds.push(
49-
...makeBundleConfigVariants(
53+
...makeBundleConfigVariants(() =>
5054
makeBaseBundleConfig({
5155
bundleType: 'addon',
5256
entrypoints: ['src/pluggable-exports-bundle/index.multiplexedtransport.ts'],
@@ -56,104 +60,104 @@ builds.push(
5660
),
5761
);
5862

59-
const baseBundleConfig = makeBaseBundleConfig({
63+
const baseBundleOptions = {
6064
bundleType: 'standalone',
6165
entrypoints: ['src/index.bundle.ts'],
6266
licenseTitle: '@sentry/browser',
6367
outputFileBase: () => 'bundles/bundle',
64-
});
68+
};
6569

66-
const feedbackBaseBundleConfig = makeBaseBundleConfig({
70+
const feedbackBaseBundleOptions = {
6771
bundleType: 'standalone',
6872
entrypoints: ['src/index.bundle.feedback.ts'],
6973
licenseTitle: '@sentry/browser & @sentry/feedback',
7074
outputFileBase: () => 'bundles/bundle.feedback',
71-
});
75+
};
7276

73-
const logsMetricsBaseBundleConfig = makeBaseBundleConfig({
77+
const logsMetricsBaseBundleOptions = {
7478
bundleType: 'standalone',
7579
entrypoints: ['src/index.bundle.logs.metrics.ts'],
7680
licenseTitle: '@sentry/browser (Logs and Metrics)',
7781
outputFileBase: () => 'bundles/bundle.logs.metrics',
78-
});
82+
};
7983

80-
const replayBaseBundleConfig = makeBaseBundleConfig({
84+
const replayBaseBundleOptions = {
8185
bundleType: 'standalone',
8286
entrypoints: ['src/index.bundle.replay.ts'],
8387
licenseTitle: '@sentry/browser (Replay)',
8488
outputFileBase: () => 'bundles/bundle.replay',
85-
});
89+
};
8690

87-
const replayFeedbackBaseBundleConfig = makeBaseBundleConfig({
91+
const replayFeedbackBaseBundleOptions = {
8892
bundleType: 'standalone',
8993
entrypoints: ['src/index.bundle.replay.feedback.ts'],
9094
licenseTitle: '@sentry/browser (Replay, and Feedback)',
9195
outputFileBase: () => 'bundles/bundle.replay.feedback',
92-
});
96+
};
9397

94-
const replayLogsMetricsBaseBundleConfig = makeBaseBundleConfig({
98+
const replayLogsMetricsBaseBundleOptions = {
9599
bundleType: 'standalone',
96100
entrypoints: ['src/index.bundle.replay.logs.metrics.ts'],
97101
licenseTitle: '@sentry/browser (Replay, Logs, and Metrics)',
98102
outputFileBase: () => 'bundles/bundle.replay.logs.metrics',
99-
});
103+
};
100104

101105
// Tracing
102-
const tracingBaseBundleConfig = makeBaseBundleConfig({
106+
const tracingBaseBundleOptions = {
103107
bundleType: 'standalone',
104108
entrypoints: ['src/index.bundle.tracing.ts'],
105109
licenseTitle: '@sentry/browser (Performance Monitoring)',
106110
outputFileBase: () => 'bundles/bundle.tracing',
107-
});
111+
};
108112

109-
const tracingLogsMetricsBaseBundleConfig = makeBaseBundleConfig({
113+
const tracingLogsMetricsBaseBundleOptions = {
110114
bundleType: 'standalone',
111115
entrypoints: ['src/index.bundle.tracing.logs.metrics.ts'],
112116
licenseTitle: '@sentry/browser (Performance Monitoring, Logs, and Metrics)',
113117
outputFileBase: () => 'bundles/bundle.tracing.logs.metrics',
114-
});
118+
};
115119

116-
const tracingReplayBaseBundleConfig = makeBaseBundleConfig({
120+
const tracingReplayBaseBundleOptions = {
117121
bundleType: 'standalone',
118122
entrypoints: ['src/index.bundle.tracing.replay.ts'],
119123
licenseTitle: '@sentry/browser (Performance Monitoring and Replay)',
120124
outputFileBase: () => 'bundles/bundle.tracing.replay',
121-
});
125+
};
122126

123-
const tracingReplayLogsMetricsBaseBundleConfig = makeBaseBundleConfig({
127+
const tracingReplayLogsMetricsBaseBundleOptions = {
124128
bundleType: 'standalone',
125129
entrypoints: ['src/index.bundle.tracing.replay.logs.metrics.ts'],
126130
licenseTitle: '@sentry/browser (Performance Monitoring, Replay, Logs, and Metrics)',
127131
outputFileBase: () => 'bundles/bundle.tracing.replay.logs.metrics',
128-
});
132+
};
129133

130-
const tracingReplayFeedbackBaseBundleConfig = makeBaseBundleConfig({
134+
const tracingReplayFeedbackBaseBundleOptions = {
131135
bundleType: 'standalone',
132136
entrypoints: ['src/index.bundle.tracing.replay.feedback.ts'],
133137
licenseTitle: '@sentry/browser (Performance Monitoring, Replay, and Feedback)',
134138
outputFileBase: () => 'bundles/bundle.tracing.replay.feedback',
135-
});
139+
};
136140

137-
const tracingReplayFeedbackLogsMetricsBaseBundleConfig = makeBaseBundleConfig({
141+
const tracingReplayFeedbackLogsMetricsBaseBundleOptions = {
138142
bundleType: 'standalone',
139143
entrypoints: ['src/index.bundle.tracing.replay.feedback.logs.metrics.ts'],
140144
licenseTitle: '@sentry/browser (Performance Monitoring, Replay, Feedback, Logs, and Metrics)',
141145
outputFileBase: () => 'bundles/bundle.tracing.replay.feedback.logs.metrics',
142-
});
146+
};
143147

144148
builds.push(
145-
...makeBundleConfigVariants(baseBundleConfig),
146-
...makeBundleConfigVariants(feedbackBaseBundleConfig),
147-
...makeBundleConfigVariants(logsMetricsBaseBundleConfig),
148-
...makeBundleConfigVariants(replayBaseBundleConfig),
149-
...makeBundleConfigVariants(replayFeedbackBaseBundleConfig),
150-
...makeBundleConfigVariants(replayLogsMetricsBaseBundleConfig),
151-
...makeBundleConfigVariants(tracingBaseBundleConfig),
152-
...makeBundleConfigVariants(tracingLogsMetricsBaseBundleConfig),
153-
...makeBundleConfigVariants(tracingReplayBaseBundleConfig),
154-
...makeBundleConfigVariants(tracingReplayLogsMetricsBaseBundleConfig),
155-
...makeBundleConfigVariants(tracingReplayFeedbackBaseBundleConfig),
156-
...makeBundleConfigVariants(tracingReplayFeedbackLogsMetricsBaseBundleConfig),
149+
...makeBundleConfigVariants(() => makeBaseBundleConfig(baseBundleOptions)),
150+
...makeBundleConfigVariants(() => makeBaseBundleConfig(feedbackBaseBundleOptions)),
151+
...makeBundleConfigVariants(() => makeBaseBundleConfig(logsMetricsBaseBundleOptions)),
152+
...makeBundleConfigVariants(() => makeBaseBundleConfig(replayBaseBundleOptions)),
153+
...makeBundleConfigVariants(() => makeBaseBundleConfig(replayFeedbackBaseBundleOptions)),
154+
...makeBundleConfigVariants(() => makeBaseBundleConfig(replayLogsMetricsBaseBundleOptions)),
155+
...makeBundleConfigVariants(() => makeBaseBundleConfig(tracingBaseBundleOptions)),
156+
...makeBundleConfigVariants(() => makeBaseBundleConfig(tracingLogsMetricsBaseBundleOptions)),
157+
...makeBundleConfigVariants(() => makeBaseBundleConfig(tracingReplayBaseBundleOptions)),
158+
...makeBundleConfigVariants(() => makeBaseBundleConfig(tracingReplayLogsMetricsBaseBundleOptions)),
159+
...makeBundleConfigVariants(() => makeBaseBundleConfig(tracingReplayFeedbackBaseBundleOptions)),
160+
...makeBundleConfigVariants(() => makeBaseBundleConfig(tracingReplayFeedbackLogsMetricsBaseBundleOptions)),
157161
);
158162

159163
export default builds;

packages/feedback/rollup.bundle.config.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { makeBaseBundleConfig, makeBundleConfigVariants } from '@sentry-internal
33
export default [
44
// The core `feedback` bundle is built in the browser package
55
// Sub-bundles are built here
6-
...makeBundleConfigVariants(
6+
...makeBundleConfigVariants(() =>
77
makeBaseBundleConfig({
88
bundleType: 'addon',
99
entrypoints: ['src/screenshot/integration.ts'],
@@ -19,7 +19,7 @@ export default [
1919
},
2020
}),
2121
),
22-
...makeBundleConfigVariants(
22+
...makeBundleConfigVariants(() =>
2323
makeBaseBundleConfig({
2424
bundleType: 'addon',
2525
entrypoints: ['src/modal/integration.tsx'],
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { makeBaseBundleConfig, makeBundleConfigVariants } from '@sentry-internal/rollup-utils';
22

3-
const baseBundleConfig = makeBaseBundleConfig({
3+
const baseBundleOptions = {
44
bundleType: 'addon',
55
entrypoints: ['src/index.ts'],
66
licenseTitle: '@sentry-internal/replay-canvas',
77
outputFileBase: () => 'bundles/replay-canvas',
8-
});
8+
};
99

10-
const builds = makeBundleConfigVariants(baseBundleConfig);
10+
const builds = makeBundleConfigVariants(() => makeBaseBundleConfig(baseBundleOptions));
1111

1212
export default builds;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { makeBaseBundleConfig, makeBundleConfigVariants } from '@sentry-internal/rollup-utils';
22

3-
const baseBundleConfig = makeBaseBundleConfig({
3+
const baseBundleOptions = {
44
bundleType: 'addon',
55
entrypoints: ['src/index.ts'],
66
licenseTitle: '@sentry-internal/replay',
77
outputFileBase: () => 'bundles/replay',
8-
});
8+
};
99

10-
const builds = makeBundleConfigVariants(baseBundleConfig);
10+
const builds = makeBundleConfigVariants(() => makeBaseBundleConfig(baseBundleOptions));
1111

1212
export default builds;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { makeBaseBundleConfig, makeBundleConfigVariants } from '@sentry-internal/rollup-utils';
22

3-
const baseBundleConfig = makeBaseBundleConfig({
3+
const baseBundleOptions = {
44
bundleType: 'addon',
55
entrypoints: ['src/index.ts'],
66
licenseTitle: '@sentry/wasm',
77
outputFileBase: () => 'bundles/wasm',
8-
});
8+
};
99

10-
export default makeBundleConfigVariants(baseBundleConfig);
10+
export default makeBundleConfigVariants(() => makeBaseBundleConfig(baseBundleOptions));

0 commit comments

Comments
 (0)