From 59816443cf8db6fda5fe6dabd59f82da5c38ddf5 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Fri, 11 Jul 2025 14:52:49 +0200 Subject: [PATCH 1/3] fix(core): Avoid showing success message if nothing was uploaded --- .../src/build-plugin-manager.ts | 67 ++++++++++++------- 1 file changed, 44 insertions(+), 23 deletions(-) diff --git a/packages/bundler-plugin-core/src/build-plugin-manager.ts b/packages/bundler-plugin-core/src/build-plugin-manager.ts index 1eda94c2..af1dd67b 100644 --- a/packages/bundler-plugin-core/src/build-plugin-manager.ts +++ b/packages/bundler-plugin-core/src/build-plugin-manager.ts @@ -503,27 +503,8 @@ export function createSentryBuildPluginManager( * Uploads sourcemaps using the "Debug ID" method. This function takes a list of build artifact paths that will be uploaded */ async uploadSourcemaps(buildArtifactPaths: string[]) { - if (options.sourcemaps?.disable) { - logger.debug( - "Source map upload was disabled. Will not upload sourcemaps using debug ID process." - ); - } else if (isDevMode) { - logger.debug("Running in development mode. Will not upload sourcemaps."); - } else if (!options.authToken) { - logger.warn( - "No auth token provided. Will not upload source maps. Please set the `authToken` option. You can find information on how to generate a Sentry auth token here: https://docs.sentry.io/api/auth/" + - getTurborepoEnvPassthroughWarning("SENTRY_AUTH_TOKEN") - ); - } else if (!options.org && !options.authToken.startsWith("sntrys_")) { - logger.warn( - "No org provided. Will not upload source maps. Please set the `org` option to your Sentry organization slug." + - getTurborepoEnvPassthroughWarning("SENTRY_ORG") - ); - } else if (!options.project) { - logger.warn( - "No project provided. Will not upload source maps. Please set the `project` option to your Sentry project slug." + - getTurborepoEnvPassthroughWarning("SENTRY_PROJECT") - ); + if (!canUploadSourceMaps(options, logger, isDevMode)) { + return; } await startSpan( @@ -589,7 +570,7 @@ export function createSentryBuildPluginManager( "Didn't find any matching sources for debug ID upload. Please check the `sourcemaps.assets` option." ); } else { - await startSpan( + const numUploadedFiles = await startSpan( { name: "prepare-bundles", scope: sentryScope }, async (prepBundlesSpan) => { // Preparing the bundles can be a lot of work and doing it all at once has the potential of nuking the heap so @@ -664,10 +645,14 @@ export function createSentryBuildPluginManager( } ); }); + + return files.length; } ); - logger.info("Successfully uploaded source maps to Sentry"); + if (numUploadedFiles > 0) { + logger.info("Successfully uploaded source maps to Sentry"); + } } } catch (e) { sentryScope.captureException('Error in "debugIdUploadPlugin" writeBundle hook'); @@ -732,3 +717,39 @@ export function createSentryBuildPluginManager( createDependencyOnBuildArtifacts, }; } + +function canUploadSourceMaps( + options: NormalizedOptions, + logger: Logger, + isDevMode: boolean +): boolean { + if (options.sourcemaps?.disable) { + logger.debug( + "Source map upload was disabled. Will not upload sourcemaps using debug ID process." + ); + return false; + } else if (isDevMode) { + logger.debug("Running in development mode. Will not upload sourcemaps."); + return false; + } else if (!options.authToken) { + logger.warn( + "No auth token provided. Will not upload source maps. Please set the `authToken` option. You can find information on how to generate a Sentry auth token here: https://docs.sentry.io/api/auth/" + + getTurborepoEnvPassthroughWarning("SENTRY_AUTH_TOKEN") + ); + return false; + } else if (!options.org && !options.authToken.startsWith("sntrys_")) { + logger.warn( + "No org provided. Will not upload source maps. Please set the `org` option to your Sentry organization slug." + + getTurborepoEnvPassthroughWarning("SENTRY_ORG") + ); + return false; + } else if (!options.project) { + logger.warn( + "No project provided. Will not upload source maps. Please set the `project` option to your Sentry project slug." + + getTurborepoEnvPassthroughWarning("SENTRY_PROJECT") + ); + return false; + } + + return true; +} From 061345bb0471ab95556d69ce7fb577112067f204 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Fri, 11 Jul 2025 15:00:58 +0200 Subject: [PATCH 2/3] remove elseIf --- .../bundler-plugin-core/src/build-plugin-manager.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/bundler-plugin-core/src/build-plugin-manager.ts b/packages/bundler-plugin-core/src/build-plugin-manager.ts index af1dd67b..c692a19f 100644 --- a/packages/bundler-plugin-core/src/build-plugin-manager.ts +++ b/packages/bundler-plugin-core/src/build-plugin-manager.ts @@ -728,22 +728,26 @@ function canUploadSourceMaps( "Source map upload was disabled. Will not upload sourcemaps using debug ID process." ); return false; - } else if (isDevMode) { + } + if (isDevMode) { logger.debug("Running in development mode. Will not upload sourcemaps."); return false; - } else if (!options.authToken) { + } + if (!options.authToken) { logger.warn( "No auth token provided. Will not upload source maps. Please set the `authToken` option. You can find information on how to generate a Sentry auth token here: https://docs.sentry.io/api/auth/" + getTurborepoEnvPassthroughWarning("SENTRY_AUTH_TOKEN") ); return false; - } else if (!options.org && !options.authToken.startsWith("sntrys_")) { + } + if (!options.org && !options.authToken.startsWith("sntrys_")) { logger.warn( "No org provided. Will not upload source maps. Please set the `org` option to your Sentry organization slug." + getTurborepoEnvPassthroughWarning("SENTRY_ORG") ); return false; - } else if (!options.project) { + } + if (!options.project) { logger.warn( "No project provided. Will not upload source maps. Please set the `project` option to your Sentry project slug." + getTurborepoEnvPassthroughWarning("SENTRY_PROJECT") From 4ff806d9815c0e910ab3644fe38247f9be5688c4 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Tue, 15 Jul 2025 12:21:33 +0200 Subject: [PATCH 3/3] fix tests --- .../input/rollup4/rollup.config.js | 9 ++++++++- .../input/vite6/vite.config.js | 9 ++++++++- .../input/webpack5/webpack.config.js | 9 ++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/packages/integration-tests/fixtures/debug-ids-already-injected/input/rollup4/rollup.config.js b/packages/integration-tests/fixtures/debug-ids-already-injected/input/rollup4/rollup.config.js index e5453246..2a43368b 100644 --- a/packages/integration-tests/fixtures/debug-ids-already-injected/input/rollup4/rollup.config.js +++ b/packages/integration-tests/fixtures/debug-ids-already-injected/input/rollup4/rollup.config.js @@ -11,5 +11,12 @@ export default defineConfig({ sourcemap: true, sourcemapDebugIds: true, }, - plugins: [sentryRollupPlugin({ telemetry: false })], + plugins: [ + sentryRollupPlugin({ + telemetry: false, + authToken: "fake-auth", + org: "fake-org", + project: "fake-project", + }), + ], }); diff --git a/packages/integration-tests/fixtures/debug-ids-already-injected/input/vite6/vite.config.js b/packages/integration-tests/fixtures/debug-ids-already-injected/input/vite6/vite.config.js index 39e04917..0d763cdb 100644 --- a/packages/integration-tests/fixtures/debug-ids-already-injected/input/vite6/vite.config.js +++ b/packages/integration-tests/fixtures/debug-ids-already-injected/input/vite6/vite.config.js @@ -17,5 +17,12 @@ export default defineConfig({ }, }, }, - plugins: [sentryVitePlugin({ telemetry: false })], + plugins: [ + sentryVitePlugin({ + telemetry: false, + authToken: "fake-auth", + org: "fake-org", + project: "fake-project", + }), + ], }); diff --git a/packages/integration-tests/fixtures/debug-ids-already-injected/input/webpack5/webpack.config.js b/packages/integration-tests/fixtures/debug-ids-already-injected/input/webpack5/webpack.config.js index 5ef92798..fa294910 100644 --- a/packages/integration-tests/fixtures/debug-ids-already-injected/input/webpack5/webpack.config.js +++ b/packages/integration-tests/fixtures/debug-ids-already-injected/input/webpack5/webpack.config.js @@ -14,5 +14,12 @@ export default { }, }, mode: "production", - plugins: [sentryWebpackPlugin({ telemetry: false })], + plugins: [ + sentryWebpackPlugin({ + telemetry: false, + authToken: "fake-auth", + org: "fake-org", + project: "fake-project", + }), + ], };