@@ -3,7 +3,7 @@ import { getRNVersion, translateOptions } from './utils';
33import * as fs from 'fs-extra' ;
44import { ZipFile } from 'yazl' ;
55import { open as openZipFile } from 'yauzl' ;
6- import { question , printVersionCommand } from './utils' ;
6+ import { question , checkPlugins } from './utils' ;
77import { checkPlatform } from './app' ;
88import { spawn , spawnSync } from 'node:child_process' ;
99import semverSatisfies from 'semver/functions/satisfies' ;
@@ -86,6 +86,9 @@ async function runReactNativeBundleCommand(
8686 } ) ;
8787 }
8888 }
89+ const bundleParams = await checkPlugins ( ) ;
90+ const minifyOption = bundleParams . minify ;
91+ const isSentry = bundleParams . sentry ;
8992 const bundleCommand = usingExpo
9093 ? 'export:embed'
9194 : platform === 'harmony'
@@ -123,6 +126,8 @@ async function runReactNativeBundleCommand(
123126 '--platform' ,
124127 platform ,
125128 '--reset-cache' ,
129+ '--minify' ,
130+ minifyOption ,
126131 ] ) ;
127132
128133 if ( sourcemapOutput ) {
@@ -190,7 +195,20 @@ async function runReactNativeBundleCommand(
190195 bundleName ,
191196 outputFolder ,
192197 sourcemapOutput ,
198+ ! isSentry ,
193199 ) ;
200+ if ( isSentry ) {
201+ await copyDebugidForSentry (
202+ bundleName ,
203+ outputFolder ,
204+ sourcemapOutput ,
205+ ) ;
206+ await uploadSourcemapForSentry (
207+ bundleName ,
208+ outputFolder ,
209+ sourcemapOutput ,
210+ ) ;
211+ }
194212 }
195213 resolve ( null ) ;
196214 }
@@ -253,6 +271,7 @@ async function compileHermesByteCode(
253271 bundleName ,
254272 outputFolder ,
255273 sourcemapOutput ,
274+ shouldCleanSourcemap ,
256275) {
257276 console . log ( 'Hermes enabled, now compiling to hermes bytecode:\n' ) ;
258277 // >= rn 0.69
@@ -309,9 +328,65 @@ async function compileHermesByteCode(
309328 } ,
310329 ) ;
311330 }
331+ if ( shouldCleanSourcemap ) {
332+ fs . removeSync ( path . join ( outputFolder , `${ bundleName } .txt.map` ) ) ;
333+ }
334+ }
335+
336+ async function copyDebugidForSentry ( bundleName , outputFolder , sourcemapOutput ) {
337+ if ( sourcemapOutput ) {
338+ const copyDebugidPath =
339+ 'node_modules/@sentry/react-native/scripts/copy-debugid.js' ;
340+ if ( ! fs . existsSync ( copyDebugidPath ) ) {
341+ return ;
342+ }
343+ console . log ( 'Copying debugid' ) ;
344+ spawnSync (
345+ 'node' ,
346+ [
347+ copyDebugidPath ,
348+ path . join ( outputFolder , `${ bundleName } .txt.map` ) ,
349+ path . join ( outputFolder , `${ bundleName } .map` ) ,
350+ ] ,
351+ {
352+ stdio : 'ignore' ,
353+ } ,
354+ ) ;
355+ }
312356 fs . removeSync ( path . join ( outputFolder , `${ bundleName } .txt.map` ) ) ;
313357}
314358
359+ async function uploadSourcemapForSentry (
360+ bundleName ,
361+ outputFolder ,
362+ sourcemapOutput ,
363+ ) {
364+ if ( sourcemapOutput ) {
365+ const uploadSourcemapPath =
366+ 'node_modules/@sentry/cli/bin/sentry-cli' ;
367+ if ( ! fs . existsSync ( uploadSourcemapPath ) ) {
368+ return ;
369+ }
370+ console . log ( 'Uploading sourcemap' ) ;
371+ spawnSync (
372+ 'node' ,
373+ [
374+ uploadSourcemapPath ,
375+ 'sourcemaps' ,
376+ 'upload' ,
377+ '--debug-id-reference' ,
378+ '--strip-prefix' ,
379+ path . join ( outputFolder , bundleName ) ,
380+ path . join ( outputFolder , `${ bundleName } .map` ) ,
381+ ] ,
382+ {
383+ stdio : 'ignore' ,
384+ } ,
385+ ) ;
386+ }
387+ fs . removeSync ( path . join ( outputFolder , `${ bundleName } .map` ) ) ;
388+ }
389+
315390async function pack ( dir , output ) {
316391 console . log ( 'Packing' ) ;
317392 fs . ensureDirSync ( path . dirname ( output ) ) ;
@@ -718,12 +793,15 @@ export const commands = {
718793 options . platform || ( await question ( '平台(ios/android/harmony):' ) ) ,
719794 ) ;
720795
721- const { bundleName, entryFile, intermediaDir, output, dev, sourcemap } =
796+ const { bundleName, entryFile, intermediaDir, output, dev } =
722797 translateOptions ( {
723798 ...options ,
724799 platform,
725800 } ) ;
726801
802+ const bundleParams = await checkPlugins ( ) ;
803+ const sourcemap = bundleParams . sourcemap ;
804+
727805 const sourcemapOutput = path . join ( intermediaDir , `${ bundleName } .map` ) ;
728806
729807 const realOutput = output . replace ( / \$ \{ t i m e \} / g, `${ Date . now ( ) } ` ) ;
0 commit comments