Skip to content
Draft
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
12 changes: 12 additions & 0 deletions .size-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ module.exports = [
gzip: true,
disablePlugins: ['@size-limit/esbuild'],
},
// esbuild drops dead code differently from webpack + terser, so measure one bundle with it too.
{
name: '@sentry/browser (incl. Tracing) - esbuild with treeshaking flags',
path: 'packages/browser/build/npm/esm/prod/index.js',
import: createImport('init', 'browserTracingIntegration'),
gzip: true,
disablePlugins: ['@size-limit/webpack'],
modifyEsbuildConfig: function (config) {
config.define = { __SENTRY_DEBUG__: 'false' };
return config;
},
},
{
name: '@sentry/browser (incl. Tracing + Span Streaming)',
path: 'packages/browser/build/npm/esm/prod/index.js',
Expand Down
4 changes: 3 additions & 1 deletion dev-packages/rollup-utils/npmHelpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import deepMerge from 'deepmerge';

import { defineConfig } from 'rolldown';
import {
makeDebugBuildInlinePlugin,
makeDebugBuildStatementReplacePlugin,
makeEsmCjsReplacePlugin,
makeProductionReplacePlugin,
Expand Down Expand Up @@ -136,6 +137,7 @@ export function makeBaseNPMConfig(options = {}) {
// the runtime lookup, so the guard is evaluated by the consumer as it always was.
define: {
'process.env.NODE_ENV': 'process.env.NODE_ENV',
DEBUG_BUILD: "(typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__)",
},
},

Expand Down Expand Up @@ -203,7 +205,7 @@ export function makeBaseNPMConfig(options = {}) {
},
},

plugins: [debugBuildStatementReplacePlugin, rrwebBuildPlugin],
plugins: [makeDebugBuildInlinePlugin(), debugBuildStatementReplacePlugin, rrwebBuildPlugin],

// don't include imported modules from outside the package in the final output
// also treat subpath exports (e.g. `@sentry/core/browser`) as external
Expand Down
24 changes: 24 additions & 0 deletions dev-packages/rollup-utils/plugins/npmPlugins.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,30 @@ export function makeDebugBuildStatementReplacePlugin() {
);
}

// Leaves the newline in place: no line moves, so `map: null` keeps the existing mappings right.
const DEBUG_BUILD_IMPORT = /^import \{ DEBUG_BUILD \} from '[^']*debug[-_]build';$/m;

/**
* Drops `import { DEBUG_BUILD } from './debug-build'`, so that `DEBUG_BUILD` is left as a free
* identifier that the `DEBUG_BUILD` define in `makeBaseNPMConfig` replaces at every use site.
*
* esbuild inlines an imported constant only after it has removed dead code, and won't inline a
* module-local const in a module with imports at all. So with `__SENTRY_DEBUG__: false` defined,
* only the inlined expression lets it drop the guarded code.
*/
export function makeDebugBuildInlinePlugin() {
return {
name: 'inline-debug-build',
transform(code) {
if (!code.includes('DEBUG_BUILD')) return null;

const replaced = code.replace(DEBUG_BUILD_IMPORT, '');

return replaced === code ? null : { code: replaced, map: null };
},
};
}

// Markers use the `/*! ... */` legal-comment syntax so rolldown's transpile preserves them.
// We run as a `transform` (per-module) hook rather than `renderChunk`: the block typically uses
// imports declared at the module top, and stripping it before the module graph is analysed lets
Expand Down
Loading