Skip to content

Commit 33a18f9

Browse files
authored
fix(core): Avoid showing success message if upload was disabled or nothing was uploaded (#757)
1 parent fc1f540 commit 33a18f9

File tree

4 files changed

+72
-26
lines changed

4 files changed

+72
-26
lines changed

packages/bundler-plugin-core/src/build-plugin-manager.ts

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -503,27 +503,8 @@ export function createSentryBuildPluginManager(
503503
* Uploads sourcemaps using the "Debug ID" method. This function takes a list of build artifact paths that will be uploaded
504504
*/
505505
async uploadSourcemaps(buildArtifactPaths: string[]) {
506-
if (options.sourcemaps?.disable) {
507-
logger.debug(
508-
"Source map upload was disabled. Will not upload sourcemaps using debug ID process."
509-
);
510-
} else if (isDevMode) {
511-
logger.debug("Running in development mode. Will not upload sourcemaps.");
512-
} else if (!options.authToken) {
513-
logger.warn(
514-
"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/" +
515-
getTurborepoEnvPassthroughWarning("SENTRY_AUTH_TOKEN")
516-
);
517-
} else if (!options.org && !options.authToken.startsWith("sntrys_")) {
518-
logger.warn(
519-
"No org provided. Will not upload source maps. Please set the `org` option to your Sentry organization slug." +
520-
getTurborepoEnvPassthroughWarning("SENTRY_ORG")
521-
);
522-
} else if (!options.project) {
523-
logger.warn(
524-
"No project provided. Will not upload source maps. Please set the `project` option to your Sentry project slug." +
525-
getTurborepoEnvPassthroughWarning("SENTRY_PROJECT")
526-
);
506+
if (!canUploadSourceMaps(options, logger, isDevMode)) {
507+
return;
527508
}
528509

529510
await startSpan(
@@ -589,7 +570,7 @@ export function createSentryBuildPluginManager(
589570
"Didn't find any matching sources for debug ID upload. Please check the `sourcemaps.assets` option."
590571
);
591572
} else {
592-
await startSpan(
573+
const numUploadedFiles = await startSpan(
593574
{ name: "prepare-bundles", scope: sentryScope },
594575
async (prepBundlesSpan) => {
595576
// 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(
664645
}
665646
);
666647
});
648+
649+
return files.length;
667650
}
668651
);
669652

670-
logger.info("Successfully uploaded source maps to Sentry");
653+
if (numUploadedFiles > 0) {
654+
logger.info("Successfully uploaded source maps to Sentry");
655+
}
671656
}
672657
} catch (e) {
673658
sentryScope.captureException('Error in "debugIdUploadPlugin" writeBundle hook');
@@ -732,3 +717,43 @@ export function createSentryBuildPluginManager(
732717
createDependencyOnBuildArtifacts,
733718
};
734719
}
720+
721+
function canUploadSourceMaps(
722+
options: NormalizedOptions,
723+
logger: Logger,
724+
isDevMode: boolean
725+
): boolean {
726+
if (options.sourcemaps?.disable) {
727+
logger.debug(
728+
"Source map upload was disabled. Will not upload sourcemaps using debug ID process."
729+
);
730+
return false;
731+
}
732+
if (isDevMode) {
733+
logger.debug("Running in development mode. Will not upload sourcemaps.");
734+
return false;
735+
}
736+
if (!options.authToken) {
737+
logger.warn(
738+
"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/" +
739+
getTurborepoEnvPassthroughWarning("SENTRY_AUTH_TOKEN")
740+
);
741+
return false;
742+
}
743+
if (!options.org && !options.authToken.startsWith("sntrys_")) {
744+
logger.warn(
745+
"No org provided. Will not upload source maps. Please set the `org` option to your Sentry organization slug." +
746+
getTurborepoEnvPassthroughWarning("SENTRY_ORG")
747+
);
748+
return false;
749+
}
750+
if (!options.project) {
751+
logger.warn(
752+
"No project provided. Will not upload source maps. Please set the `project` option to your Sentry project slug." +
753+
getTurborepoEnvPassthroughWarning("SENTRY_PROJECT")
754+
);
755+
return false;
756+
}
757+
758+
return true;
759+
}

packages/integration-tests/fixtures/debug-ids-already-injected/input/rollup4/rollup.config.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,12 @@ export default defineConfig({
1111
sourcemap: true,
1212
sourcemapDebugIds: true,
1313
},
14-
plugins: [sentryRollupPlugin({ telemetry: false })],
14+
plugins: [
15+
sentryRollupPlugin({
16+
telemetry: false,
17+
authToken: "fake-auth",
18+
org: "fake-org",
19+
project: "fake-project",
20+
}),
21+
],
1522
});

packages/integration-tests/fixtures/debug-ids-already-injected/input/vite6/vite.config.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,12 @@ export default defineConfig({
1717
},
1818
},
1919
},
20-
plugins: [sentryVitePlugin({ telemetry: false })],
20+
plugins: [
21+
sentryVitePlugin({
22+
telemetry: false,
23+
authToken: "fake-auth",
24+
org: "fake-org",
25+
project: "fake-project",
26+
}),
27+
],
2128
});

packages/integration-tests/fixtures/debug-ids-already-injected/input/webpack5/webpack.config.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,12 @@ export default {
1414
},
1515
},
1616
mode: "production",
17-
plugins: [sentryWebpackPlugin({ telemetry: false })],
17+
plugins: [
18+
sentryWebpackPlugin({
19+
telemetry: false,
20+
authToken: "fake-auth",
21+
org: "fake-org",
22+
project: "fake-project",
23+
}),
24+
],
1825
};

0 commit comments

Comments
 (0)