Skip to content

feat(build): Core packages into single output files #11030

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 3 commits into from
Mar 12, 2024
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
8 changes: 8 additions & 0 deletions packages/browser/rollup.npm.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,13 @@ export default makeNPMConfigVariants(
makeBaseNPMConfig({
// packages with bundles have a different build directory structure
hasBundles: true,
packageSpecificConfig: {
output: {
// set exports to 'named' or 'auto' so that rollup doesn't warn
exports: 'named',
// set preserveModules to false because we want to bundle everything into one file.
preserveModules: false,
},
},
}),
);
13 changes: 12 additions & 1 deletion packages/core/rollup.npm.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollup-utils';

export default makeNPMConfigVariants(makeBaseNPMConfig());
export default makeNPMConfigVariants(
makeBaseNPMConfig({
packageSpecificConfig: {
output: {
// set exports to 'named' or 'auto' so that rollup doesn't warn
exports: 'named',
// set preserveModules to false because we want to bundle everything into one file.
preserveModules: false,
},
},
}),
);
55 changes: 26 additions & 29 deletions packages/node-experimental/rollup.anr-worker.config.mjs
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
import { makeBaseBundleConfig } from '@sentry-internal/rollup-utils';

function createAnrWorkerConfig(destDir, esm) {
return makeBaseBundleConfig({
bundleType: 'node-worker',
entrypoints: ['src/integrations/anr/worker.ts'],
licenseTitle: '@sentry/node',
outputFileBase: () => 'worker-script.js',
packageSpecificConfig: {
output: {
dir: destDir,
sourcemap: false,
},
plugins: [
{
name: 'output-base64-worker-script',
renderChunk(code) {
const base64Code = Buffer.from(code).toString('base64');
if (esm) {
return `export const base64WorkerScript = '${base64Code}';`;
} else {
return `exports.base64WorkerScript = '${base64Code}';`;
}
},
export function createAnrWorkerCode() {
let base64Code;

return {
workerRollupConfig: makeBaseBundleConfig({
bundleType: 'node-worker',
entrypoints: ['src/integrations/anr/worker.ts'],
licenseTitle: '@sentry/node',
outputFileBase: () => 'worker-script.js',
packageSpecificConfig: {
output: {
dir: 'build/esm/integrations/anr',
sourcemap: false,
},
],
plugins: [
{
name: 'output-base64-worker-script',
renderChunk(code) {
base64Code = Buffer.from(code).toString('base64');
},
},
],
},
}),
getBase64Code() {
return base64Code;
},
});
};
}

export const anrWorkerConfigs = [
createAnrWorkerConfig('build/esm/integrations/anr', true),
createAnrWorkerConfig('build/cjs/integrations/anr', false),
];
32 changes: 28 additions & 4 deletions packages/node-experimental/rollup.npm.config.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
import replace from '@rollup/plugin-replace';
import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollup-utils';
import { anrWorkerConfigs } from './rollup.anr-worker.config.mjs';
import { createAnrWorkerCode } from './rollup.anr-worker.config.mjs';

const { workerRollupConfig, getBase64Code } = createAnrWorkerCode();

export default [
...makeNPMConfigVariants(makeBaseNPMConfig()),
// The ANR worker builds must come after the main build because they overwrite the worker-script.js file
...anrWorkerConfigs,
// The worker needs to be built first since it's output is used in the main bundle.
workerRollupConfig,
...makeNPMConfigVariants(
makeBaseNPMConfig({
packageSpecificConfig: {
output: {
// set exports to 'named' or 'auto' so that rollup doesn't warn
exports: 'named',
// set preserveModules to false because we want to bundle everything into one file.
preserveModules: false,
},
plugins: [
replace({
delimiters: ['###', '###'],
// removes some webpack warnings
preventAssignment: true,
values: {
base64WorkerScript: () => getBase64Code(),
},
}),
],
},
}),
),
];
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// This file is a placeholder that gets overwritten in the build directory.
export const base64WorkerScript = '';
// This string is a placeholder that gets overwritten with the worker code.
export const base64WorkerScript = '###base64WorkerScript###';
13 changes: 12 additions & 1 deletion packages/opentelemetry/rollup.npm.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollup-utils';

export default makeNPMConfigVariants(makeBaseNPMConfig());
export default makeNPMConfigVariants(
makeBaseNPMConfig({
packageSpecificConfig: {
output: {
// set exports to 'named' or 'auto' so that rollup doesn't warn
exports: 'named',
// set preserveModules to false because we want to bundle everything into one file.
preserveModules: false,
},
},
}),
);
13 changes: 12 additions & 1 deletion packages/tracing-internal/rollup.npm.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollup-utils';

export default makeNPMConfigVariants(makeBaseNPMConfig());
export default makeNPMConfigVariants(
makeBaseNPMConfig({
packageSpecificConfig: {
output: {
// set exports to 'named' or 'auto' so that rollup doesn't warn
exports: 'named',
// set preserveModules to false because we want to bundle everything into one file.
preserveModules: false,
},
},
}),
);
13 changes: 12 additions & 1 deletion packages/utils/rollup.npm.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollup-utils';

export default makeNPMConfigVariants(makeBaseNPMConfig());
export default makeNPMConfigVariants(
makeBaseNPMConfig({
packageSpecificConfig: {
output: {
// set exports to 'named' or 'auto' so that rollup doesn't warn
exports: 'named',
// set preserveModules to false because we want to bundle everything into one file.
preserveModules: false,
},
},
}),
);
4 changes: 2 additions & 2 deletions packages/utils/scripts/buildRollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ function run(cmd: string, options?: childProcess.ExecSyncOptions): string | Buff
run('yarn rollup -c rollup.npm.config.mjs');

// We want to distribute the README because it contains the MIT license blurb from Sucrase and Rollup
fs.copyFileSync('src/buildPolyfills/README.md', 'build/cjs/buildPolyfills/README.md');
fs.copyFileSync('src/buildPolyfills/README.md', 'build/esm/buildPolyfills/README.md');
fs.copyFileSync('src/buildPolyfills/README.md', 'build/cjs/build-polyfills-license.md');
fs.copyFileSync('src/buildPolyfills/README.md', 'build/esm/build-polyfills-license.md');