@@ -9,6 +9,10 @@ import {
99 spawnJavaScript ,
1010 spawnJavaScriptSync ,
1111} from './utils/runtime' ;
12+ import {
13+ resolveSentryReleaseAndDist ,
14+ type SentryReleaseOptions ,
15+ } from './utils/sentry-release' ;
1216
1317const g2js = require ( 'gradle-to-js/lib/parser' ) ;
1418const properties = require ( 'properties' ) ;
@@ -55,6 +59,23 @@ type ResolvedExpoCli = {
5559 usingExpo : boolean ;
5660} ;
5761
62+ type SentryUploadArtifacts = {
63+ bundlePath : string ;
64+ sourcemapPath : string ;
65+ } ;
66+
67+ type BuildSentrySourcemapsUploadArgsOptions = {
68+ sentryCliPath : string ;
69+ bundlePath : string ;
70+ sourcemapPath : string ;
71+ release : string ;
72+ dist ?: string ;
73+ stripPrefix ?: string ;
74+ useStandaloneSourcemapsCommand ?: boolean ;
75+ } ;
76+
77+ const ANDROID_SENTRY_BUNDLE_NAME = 'index.android.bundle' ;
78+
5879export function hasProjectDependency (
5980 dependencyName : string ,
6081 projectRoot = process . cwd ( ) ,
@@ -557,27 +578,59 @@ export async function copyDebugidForSentry(
557578 fs . removeSync ( path . join ( outputFolder , `${ bundleName } .txt.map` ) ) ;
558579}
559580
560- export function buildSentrySourcemapsUploadArgs (
561- sentryCliPath : string ,
581+ export function prepareSentryUploadArtifacts (
562582 bundleName : string ,
563583 outputFolder : string ,
564- version : string ,
584+ platform : string ,
585+ ) : SentryUploadArtifacts {
586+ const bundlePath = path . join ( outputFolder , bundleName ) ;
587+ const sourcemapPath = path . join ( outputFolder , `${ bundleName } .map` ) ;
588+
589+ if ( platform !== 'android' || bundleName === ANDROID_SENTRY_BUNDLE_NAME ) {
590+ return {
591+ bundlePath,
592+ sourcemapPath,
593+ } ;
594+ }
595+
596+ const androidBundlePath = path . join ( outputFolder , ANDROID_SENTRY_BUNDLE_NAME ) ;
597+ const androidSourcemapPath = path . join (
598+ outputFolder ,
599+ `${ ANDROID_SENTRY_BUNDLE_NAME } .map` ,
600+ ) ;
601+ fs . copyFileSync ( bundlePath , androidBundlePath ) ;
602+
603+ const sourcemap = JSON . parse (
604+ fs . readFileSync ( sourcemapPath , 'utf8' ) ,
605+ ) as Record < string , unknown > ;
606+ sourcemap . file = ANDROID_SENTRY_BUNDLE_NAME ;
607+ fs . writeFileSync ( androidSourcemapPath , JSON . stringify ( sourcemap ) ) ;
608+
609+ return {
610+ bundlePath : androidBundlePath ,
611+ sourcemapPath : androidSourcemapPath ,
612+ } ;
613+ }
614+
615+ export function buildSentrySourcemapsUploadArgs ( {
616+ sentryCliPath,
617+ bundlePath,
618+ sourcemapPath,
619+ release,
620+ dist,
621+ stripPrefix = process . cwd ( ) ,
565622 useStandaloneSourcemapsCommand = true ,
566- ) : string [ ] {
567- const uploadArgs = [
568- '--strip-prefix' ,
569- path . join ( process . cwd ( ) , outputFolder ) ,
570- path . join ( outputFolder , bundleName ) ,
571- path . join ( outputFolder , `${ bundleName } .map` ) ,
572- ] ;
623+ } : BuildSentrySourcemapsUploadArgsOptions ) : string [ ] {
624+ const uploadArgs = [ '--strip-prefix' , stripPrefix , bundlePath , sourcemapPath ] ;
573625
574626 if ( ! useStandaloneSourcemapsCommand ) {
575627 return [
576628 sentryCliPath ,
577629 'releases' ,
578630 'files' ,
579- version ,
631+ release ,
580632 'upload-sourcemaps' ,
633+ ...( dist ? [ '--dist' , dist ] : [ ] ) ,
581634 ...uploadArgs ,
582635 ] ;
583636 }
@@ -587,7 +640,8 @@ export function buildSentrySourcemapsUploadArgs(
587640 'sourcemaps' ,
588641 'upload' ,
589642 '--release' ,
590- version ,
643+ release ,
644+ ...( dist ? [ '--dist' , dist ] : [ ] ) ,
591645 ...uploadArgs ,
592646 ] ;
593647}
@@ -607,6 +661,8 @@ export async function uploadSourcemapForSentry(
607661 outputFolder : string ,
608662 sourcemapOutput : string ,
609663 version : string ,
664+ platform = '' ,
665+ sentryOptions : SentryReleaseOptions = { } ,
610666) : Promise < void > {
611667 if ( ! sourcemapOutput ) {
612668 return ;
@@ -626,27 +682,40 @@ export async function uploadSourcemapForSentry(
626682 return ;
627683 }
628684
685+ const { release, dist } = await resolveSentryReleaseAndDist (
686+ platform ,
687+ version ,
688+ sentryOptions ,
689+ ) ;
690+ const { bundlePath, sourcemapPath } = prepareSentryUploadArtifacts (
691+ bundleName ,
692+ outputFolder ,
693+ platform ,
694+ ) ;
695+
629696 assertSuccessfulSyncProcess (
630697 spawnJavaScriptSync (
631- [ sentryCliPath , 'releases' , 'set-commits' , version , '--auto' ] ,
698+ [ sentryCliPath , 'releases' , 'set-commits' , release , '--auto' ] ,
632699 {
633700 stdio : 'inherit' ,
634701 } ,
635702 ) ,
636703 sentryCliPath ,
637704 ) ;
638- console . log ( t ( 'sentryReleaseCreated' , { version } ) ) ;
705+ console . log ( t ( 'sentryReleaseCreated' , { version : release } ) ) ;
639706
640707 console . log ( t ( 'uploadingSourcemap' ) ) ;
641708 assertSuccessfulSyncProcess (
642709 spawnJavaScriptSync (
643- buildSentrySourcemapsUploadArgs (
710+ buildSentrySourcemapsUploadArgs ( {
644711 sentryCliPath,
645- bundleName ,
646- outputFolder ,
647- version ,
648- supportsStandaloneSentrySourcemapsUpload ( sentryCliPath ) ,
649- ) ,
712+ bundlePath,
713+ sourcemapPath,
714+ release,
715+ dist,
716+ useStandaloneSourcemapsCommand :
717+ supportsStandaloneSentrySourcemapsUpload ( sentryCliPath ) ,
718+ } ) ,
650719 {
651720 stdio : 'inherit' ,
652721 } ,
0 commit comments