Repository navigation
feat(bundler-plugins): Enable hidden source maps and remove them after upload in the Rollup plugin #25645
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
feat(bundler-plugins): Enable hidden source maps and remove them after upload in the Rollup plugin #25645
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ import * as path from 'node:path'; | |
| import { createRequire } from 'node:module'; | ||
| import { finalizeRolldownDebugIds, getDebugIdForChunk, hasExistingDebugID } from './debug-id-injection'; | ||
| import { stampDebugIds, type OutputBundle } from './debug-id-stamping'; | ||
| import { createSourceMapHandling, type OutputDestinationOptions } from './source-map-handling'; | ||
|
|
||
| // The subset of Rollup's `TransformResult` that this plugin's `transform` | ||
| // hook actually returns. Defined locally instead of imported from `rollup` | ||
|
|
@@ -81,10 +82,14 @@ function getViteParseAstAsync(): Promise<ViteParseAstAsync | null> { | |
| } | ||
|
|
||
| /** | ||
| * @ignore - this is the internal plugin factory function only used for the Vite plugin! | ||
| * @ignore - internal plugin factory shared by the Rollup and Vite plugins. | ||
| * | ||
| * `main` carries injection, release creation and the upload. `post` runs last in `generateBundle`, | ||
| * copies chunks and their source maps into the upload staging folder and drops the map assets | ||
| * from the bundle, so the bundler never writes them. | ||
| */ | ||
| // eslint-disable-next-line @typescript-eslint/explicit-function-return-type | ||
| export function _rollupPluginInternal( | ||
| export function _createRollupPluginInternals( | ||
| userOptions: Options = {}, | ||
| buildTool: 'rollup' | 'vite', | ||
| buildToolMajorVersion?: string, | ||
|
|
@@ -105,7 +110,10 @@ export function _rollupPluginInternal( | |
|
|
||
| if (options.disable) { | ||
| return { | ||
| name: 'sentry-noop-plugin', | ||
| main: { | ||
| name: 'sentry-noop-plugin', | ||
| }, | ||
| post: undefined, | ||
| }; | ||
| } | ||
|
|
||
|
|
@@ -116,6 +124,7 @@ export function _rollupPluginInternal( | |
| const freeGlobalDependencyOnBuildArtifacts = createDependencyOnBuildArtifacts(); | ||
| const upload = createDebugIdUploadFunction({ sentryBuildPluginManager }); | ||
| const sourcemapsEnabled = options.sourcemaps?.disable !== true; | ||
| const sourceMapHandling = createSourceMapHandling(sentryBuildPluginManager); | ||
| const releaseInjectionCode = new CodeInjection(); | ||
| const chunkInjectionCode = new CodeInjection(); | ||
|
|
||
|
|
@@ -255,14 +264,15 @@ export function _rollupPluginInternal( | |
| stampDebugIds(bundle, true); | ||
| } | ||
|
|
||
| async function writeBundle( | ||
| outputOptions: { dir?: string; file?: string }, | ||
| bundle: { [fileName: string]: unknown }, | ||
| ): Promise<void> { | ||
| async function writeBundle(outputOptions: OutputDestinationOptions, bundle: OutputBundle | undefined): Promise<void> { | ||
| const staging = await sourceMapHandling.takeStaging(outputOptions, bundle); | ||
| let stagingHandedOver = false; | ||
|
|
||
| try { | ||
| await sentryBuildPluginManager.createRelease(); | ||
|
|
||
| if (sourcemapsEnabled && options.sourcemaps?.disable !== 'disable-upload') { | ||
| let buildArtifacts: string[]; | ||
| if (outputOptions.dir) { | ||
| const outputDir = outputOptions.dir; | ||
| const JS_AND_MAP_PATTERNS = [ | ||
|
|
@@ -273,15 +283,23 @@ export function _rollupPluginInternal( | |
| '/**/*.mjs.map', | ||
| '/**/*.cjs.map', | ||
| ].map(q => `${q}?(\\?*)?(#*)`); // We want to allow query and hash strings at the end of files | ||
| const buildArtifacts = await globFiles(JS_AND_MAP_PATTERNS, { root: outputDir }); | ||
| await upload(buildArtifacts); | ||
| buildArtifacts = await globFiles(JS_AND_MAP_PATTERNS, { root: outputDir }); | ||
| } else if (outputOptions.file) { | ||
| await upload([outputOptions.file]); | ||
| buildArtifacts = [outputOptions.file]; | ||
| } else { | ||
| const buildArtifacts = Object.keys(bundle).map(asset => path.join(path.resolve(), asset)); | ||
| await upload(buildArtifacts); | ||
| buildArtifacts = Object.keys(bundle ?? {}).map(asset => path.join(path.resolve(), asset)); | ||
| } | ||
| stagingHandedOver = true; | ||
| await upload(buildArtifacts, { staging }); | ||
| } else { | ||
| stagingHandedOver = true; | ||
| await staging?.discard(); | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| } | ||
| } catch (e) { | ||
| if (!stagingHandedOver) { | ||
| await staging?.keep('The source map upload did not run.'); | ||
| } | ||
| throw e; | ||
| } finally { | ||
| freeGlobalDependencyOnBuildArtifacts(); | ||
| await sentryBuildPluginManager.deleteArtifacts(); | ||
|
|
@@ -297,21 +315,44 @@ export function _rollupPluginInternal( | |
| } | ||
| : transform; | ||
|
|
||
| return { | ||
| const main = { | ||
| name, | ||
| buildStart, | ||
| ...(shouldTransform ? { transform: transformHook } : {}), | ||
| // Vite warns about `rollupOptions.output.sourcemap`, so the Vite plugin | ||
| // decides in its `config` hook instead. | ||
| ...(buildTool === 'rollup' ? { outputOptions: sourceMapHandling.outputOptions } : {}), | ||
| renderChunk, | ||
| generateBundle: { order: 'pre' as const, handler: generateBundle }, | ||
| writeBundle, | ||
| }; | ||
|
|
||
| const post = { | ||
| name: `sentry-${buildTool}-upload-staging`, | ||
| generateBundle: { order: 'post' as const, handler: sourceMapHandling.stageSourceMaps }, | ||
| }; | ||
|
|
||
| return { main, post }; | ||
| } | ||
|
|
||
| /** | ||
| * @ignore - this is the internal plugin factory function only used for the Vite plugin! | ||
| */ | ||
| // eslint-disable-next-line @typescript-eslint/explicit-function-return-type | ||
| export function _rollupPluginInternal( | ||
| userOptions: Options = {}, | ||
| buildTool: 'rollup' | 'vite', | ||
| buildToolMajorVersion?: string, | ||
| ) { | ||
| return _createRollupPluginInternals(userOptions, buildTool, buildToolMajorVersion).main; | ||
| } | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/no-explicit-any | ||
| export function sentryRollupPlugin(userOptions: Options = {}): any { | ||
| const { main, post } = _createRollupPluginInternals(userOptions, 'rollup'); | ||
| // We return an array here so we don't break backwards compatibility with what | ||
| // unplugin used to return | ||
| return [_rollupPluginInternal(userOptions, 'rollup')]; | ||
| return post ? [main, post] : [main]; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Silent Rollup source map default changeMedium Severity Rollup builds with an unset Triggered by project rule: PR Review Guidelines for Cursor Bot Reviewed by Cursor Bugbot for commit 50c03bf. Configure here. |
||
| } | ||
|
|
||
| export type { Options as SentryRollupPluginOptions } from '../core'; | ||


Uh oh!
There was an error while loading. Please reload this page.