Skip to content

Commit 5981644

Browse files
committed
fix(core): Avoid showing success message if nothing was uploaded
1 parent fc1f540 commit 5981644

File tree

1 file changed

+44
-23
lines changed

1 file changed

+44
-23
lines changed

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

Lines changed: 44 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,39 @@ 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+
} else if (isDevMode) {
732+
logger.debug("Running in development mode. Will not upload sourcemaps.");
733+
return false;
734+
} else if (!options.authToken) {
735+
logger.warn(
736+
"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/" +
737+
getTurborepoEnvPassthroughWarning("SENTRY_AUTH_TOKEN")
738+
);
739+
return false;
740+
} else if (!options.org && !options.authToken.startsWith("sntrys_")) {
741+
logger.warn(
742+
"No org provided. Will not upload source maps. Please set the `org` option to your Sentry organization slug." +
743+
getTurborepoEnvPassthroughWarning("SENTRY_ORG")
744+
);
745+
return false;
746+
} else if (!options.project) {
747+
logger.warn(
748+
"No project provided. Will not upload source maps. Please set the `project` option to your Sentry project slug." +
749+
getTurborepoEnvPassthroughWarning("SENTRY_PROJECT")
750+
);
751+
return false;
752+
}
753+
754+
return true;
755+
}

0 commit comments

Comments
 (0)