Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => {
"sentry-cli-mock.json": "["release","create","CURRENT_SHA","--project","fake-project"],
["release","set-commits","CURRENT_SHA","--auto"],
["release","finalize","CURRENT_SHA"],
["sourcemap","upload","-p","fake-project","--release","CURRENT_SHA","sentry-bundler-plugin-upload-path"],
",
}
`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => {
"sentry-cli-mock.json": "["release","create","CURRENT_SHA","--project","fake-project"],
["release","set-commits","CURRENT_SHA","--auto"],
["release","finalize","CURRENT_SHA"],
["sourcemap","upload","-p","fake-project","--release","CURRENT_SHA","sentry-bundler-plugin-upload-path"],
",
}
`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ test(import.meta.url, ({ runBundler, readOutputFiles }) => {
",
"sentry-cli-mock.json": "["release","set-commits","CURRENT_SHA","--auto"],
["release","finalize","CURRENT_SHA"],
["sourcemap","upload","-p","fake-project","--release","CURRENT_SHA","sentry-bundler-plugin-upload-path"],
",
}
`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => {
"sentry-cli-mock.json": "["release","create","CURRENT_SHA","--project","fake-project"],
["release","set-commits","CURRENT_SHA","--auto"],
["release","finalize","CURRENT_SHA"],
["sourcemap","upload","-p","fake-project","--release","CURRENT_SHA","sentry-bundler-plugin-upload-path"],
",
}
`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => {
"sentry-cli-mock.json": "["release","create","CURRENT_SHA","--project","fake-project"],
["release","set-commits","CURRENT_SHA","--auto"],
["release","finalize","CURRENT_SHA"],
["sourcemap","upload","-p","fake-project","--release","CURRENT_SHA","sentry-bundler-plugin-upload-path"],
",
}
`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ test(import.meta.url, ({ runBundler, readOutputFiles }) => {
",
"sentry-cli-mock.json": "["release","set-commits","CURRENT_SHA","--auto"],
["release","finalize","CURRENT_SHA"],
["sourcemap","upload","-p","fake-project","--release","CURRENT_SHA","sentry-bundler-plugin-upload-path"],
",
}
`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => {
"sentry-cli-mock.json": "["release","create","CURRENT_SHA","--project","fake-project"],
["release","set-commits","CURRENT_SHA","--auto"],
["release","finalize","CURRENT_SHA"],
["sourcemap","upload","-p","fake-project","--release","CURRENT_SHA","sentry-bundler-plugin-upload-path"],
",
}
`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => {
"sentry-cli-mock.json": "["release","create","CURRENT_SHA","--project","fake-project"],
["release","set-commits","CURRENT_SHA","--auto"],
["release","finalize","CURRENT_SHA"],
["sourcemap","upload","-p","fake-project","--release","CURRENT_SHA","sentry-bundler-plugin-upload-path"],
",
}
`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ test(import.meta.url, ({ runBundler, readOutputFiles }) => {
",
"sentry-cli-mock.json": "["release","set-commits","CURRENT_SHA","--auto"],
["release","finalize","CURRENT_SHA"],
["sourcemap","upload","-p","fake-project","--release","CURRENT_SHA","sentry-bundler-plugin-upload-path"],
",
}
`);
Expand Down
1 change: 1 addition & 0 deletions packages/astro/src/integration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
...sourcemaps,
assets: sourcemaps?.assets ?? getSourcemapsAssetsGlobs(config),
filesToDeleteAfterUpload: sourcemaps?.filesToDeleteAfterUpload ?? updatedFilesToDeleteAfterUpload,
deleteSourcemapsAfterUpload: false,
},
bundleSizeOptimizations: {
...bundleSizeOptimizations,
Expand Down
4 changes: 4 additions & 0 deletions packages/astro/test/integration/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ describe('sentryAstro integration', () => {
'./dist/**/_astro/**/*.map',
'./dist/**/.prerender/**/*.map',
],
deleteSourcemapsAfterUpload: false,
},
_metaOptions: {
telemetry: {
Expand Down Expand Up @@ -163,6 +164,7 @@ describe('sentryAstro integration', () => {
'./dist/**/_astro/**/*.map',
'./dist/**/.prerender/**/*.map',
],
deleteSourcemapsAfterUpload: false,
},
_metaOptions: {
telemetry: {
Expand Down Expand Up @@ -207,6 +209,7 @@ describe('sentryAstro integration', () => {
'./dist/**/_astro/**/*.map',
'./dist/**/.prerender/**/*.map',
],
deleteSourcemapsAfterUpload: false,
},
_metaOptions: {
telemetry: {
Expand Down Expand Up @@ -251,6 +254,7 @@ describe('sentryAstro integration', () => {
'./dist/**/_astro/**/*.map',
'./dist/**/.prerender/**/*.map',
],
deleteSourcemapsAfterUpload: false,
},
_metaOptions: {
telemetry: {
Expand Down
69 changes: 55 additions & 14 deletions packages/bundler-plugins/src/rollup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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,
Expand All @@ -105,7 +110,10 @@ export function _rollupPluginInternal(

if (options.disable) {
return {
name: 'sentry-noop-plugin',
main: {
name: 'sentry-noop-plugin',
},
post: undefined,
};
}

Expand All @@ -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();

Expand Down Expand Up @@ -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 = [
Expand All @@ -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 });
Comment thread
cursor[bot] marked this conversation as resolved.
} else {
stagingHandedOver = true;
await staging?.discard();
Comment thread
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();
Expand All @@ -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];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silent Rollup source map default change

Medium Severity

Rollup builds with an unset sourcemap option and a runnable upload now turn on hidden source maps, upload them, and strip them from the output. That is a silent default change for existing apps, and this review flags it because the project review rules require a changelog or migration note for that kind of shift. silent: true also hides the runtime info log that mentions deleteSourcemapsAfterUpload: false.

Fix in Cursor Fix in Web

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';
Loading
Loading