@@ -3,7 +3,7 @@ import { getRNVersion, translateOptions } from './utils';
3
3
import * as fs from 'fs-extra' ;
4
4
import { ZipFile } from 'yazl' ;
5
5
import { open as openZipFile } from 'yauzl' ;
6
- import { question , printVersionCommand } from './utils' ;
6
+ import { question , checkPlugins } from './utils' ;
7
7
import { checkPlatform } from './app' ;
8
8
import { spawn , spawnSync } from 'node:child_process' ;
9
9
import semverSatisfies from 'semver/functions/satisfies' ;
@@ -86,6 +86,9 @@ async function runReactNativeBundleCommand(
86
86
} ) ;
87
87
}
88
88
}
89
+ const bundleParams = await checkPlugins ( ) ;
90
+ const minifyOption = bundleParams . minify ;
91
+ const isSentry = bundleParams . sentry ;
89
92
const bundleCommand = usingExpo
90
93
? 'export:embed'
91
94
: platform === 'harmony'
@@ -123,6 +126,8 @@ async function runReactNativeBundleCommand(
123
126
'--platform' ,
124
127
platform ,
125
128
'--reset-cache' ,
129
+ '--minify' ,
130
+ minifyOption ,
126
131
] ) ;
127
132
128
133
if ( sourcemapOutput ) {
@@ -190,6 +195,7 @@ async function runReactNativeBundleCommand(
190
195
bundleName ,
191
196
outputFolder ,
192
197
sourcemapOutput ,
198
+ ! isSentry ,
193
199
) ;
194
200
}
195
201
resolve ( null ) ;
@@ -253,6 +259,7 @@ async function compileHermesByteCode(
253
259
bundleName ,
254
260
outputFolder ,
255
261
sourcemapOutput ,
262
+ shouldCleanSourcemap ,
256
263
) {
257
264
console . log ( 'Hermes enabled, now compiling to hermes bytecode:\n' ) ;
258
265
// >= rn 0.69
@@ -309,9 +316,98 @@ async function compileHermesByteCode(
309
316
} ,
310
317
) ;
311
318
}
319
+ if ( shouldCleanSourcemap ) {
320
+ fs . removeSync ( path . join ( outputFolder , `${ bundleName } .txt.map` ) ) ;
321
+ }
322
+ }
323
+
324
+ async function copyDebugidForSentry ( bundleName , outputFolder , sourcemapOutput ) {
325
+ if ( sourcemapOutput ) {
326
+ let copyDebugidPath ;
327
+ try {
328
+ copyDebugidPath = require . resolve (
329
+ '@sentry/react-native/scripts/copy-debugid.js' ,
330
+ {
331
+ paths : [ process . cwd ( ) ] ,
332
+ } ,
333
+ ) ;
334
+ } catch ( error ) {
335
+ console . error (
336
+ '无法找到 Sentry copy-debugid.js 脚本文件,请确保已正确安装 @sentry/react-native' ,
337
+ ) ;
338
+ return ;
339
+ }
340
+
341
+ if ( ! fs . existsSync ( copyDebugidPath ) ) {
342
+ return ;
343
+ }
344
+ console . log ( 'Copying debugid' ) ;
345
+ spawnSync (
346
+ 'node' ,
347
+ [
348
+ copyDebugidPath ,
349
+ path . join ( outputFolder , `${ bundleName } .txt.map` ) ,
350
+ path . join ( outputFolder , `${ bundleName } .map` ) ,
351
+ ] ,
352
+ {
353
+ stdio : 'ignore' ,
354
+ } ,
355
+ ) ;
356
+ }
312
357
fs . removeSync ( path . join ( outputFolder , `${ bundleName } .txt.map` ) ) ;
313
358
}
314
359
360
+ async function uploadSourcemapForSentry (
361
+ bundleName ,
362
+ outputFolder ,
363
+ sourcemapOutput ,
364
+ version ,
365
+ ) {
366
+ if ( sourcemapOutput ) {
367
+ let sentryCliPath ;
368
+ try {
369
+ sentryCliPath = require . resolve ( '@sentry/cli/bin/sentry-cli' , {
370
+ paths : [ process . cwd ( ) ] ,
371
+ } ) ;
372
+ } catch ( error ) {
373
+ console . error ( '无法找到 Sentry CLI 工具,请确保已正确安装 @sentry/cli' ) ;
374
+ return ;
375
+ }
376
+
377
+ if ( ! fs . existsSync ( sentryCliPath ) ) {
378
+ return ;
379
+ }
380
+
381
+ spawnSync (
382
+ 'node' ,
383
+ [ sentryCliPath , 'releases' , 'set-commits' , version , '--auto' ] ,
384
+ {
385
+ stdio : 'inherit' ,
386
+ } ,
387
+ ) ;
388
+ console . log ( `Sentry release created for version: ${ version } ` ) ;
389
+
390
+ console . log ( 'Uploading sourcemap' ) ;
391
+ spawnSync (
392
+ 'node' ,
393
+ [
394
+ sentryCliPath ,
395
+ 'releases' ,
396
+ 'files' ,
397
+ version ,
398
+ 'upload-sourcemaps' ,
399
+ '--strip-prefix' ,
400
+ path . join ( process . cwd ( ) , outputFolder ) ,
401
+ path . join ( outputFolder , bundleName ) ,
402
+ path . join ( outputFolder , `${ bundleName } .map` ) ,
403
+ ] ,
404
+ {
405
+ stdio : 'inherit' ,
406
+ } ,
407
+ ) ;
408
+ }
409
+ }
410
+
315
411
async function pack ( dir , output ) {
316
412
console . log ( 'Packing' ) ;
317
413
fs . ensureDirSync ( path . dirname ( output ) ) ;
@@ -718,12 +814,16 @@ export const commands = {
718
814
options . platform || ( await question ( '平台(ios/android/harmony):' ) ) ,
719
815
) ;
720
816
721
- const { bundleName, entryFile, intermediaDir, output, dev, sourcemap } =
817
+ const { bundleName, entryFile, intermediaDir, output, dev } =
722
818
translateOptions ( {
723
819
...options ,
724
820
platform,
725
821
} ) ;
726
822
823
+ const bundleParams = await checkPlugins ( ) ;
824
+ const sourcemap = bundleParams . sourcemap ;
825
+ const isSentry = bundleParams . sentry ;
826
+
727
827
const sourcemapOutput = path . join ( intermediaDir , `${ bundleName } .map` ) ;
728
828
729
829
const realOutput = output . replace ( / \$ \{ t i m e \} / g, `${ Date . now ( ) } ` ) ;
@@ -749,12 +849,21 @@ export const commands = {
749
849
750
850
const v = await question ( '是否现在上传此热更包?(Y/N)' ) ;
751
851
if ( v . toLowerCase ( ) === 'y' ) {
752
- await this . publish ( {
852
+ const versionName = await this . publish ( {
753
853
args : [ realOutput ] ,
754
854
options : {
755
855
platform,
756
856
} ,
757
857
} ) ;
858
+ if ( isSentry ) {
859
+ await copyDebugidForSentry ( bundleName , intermediaDir , sourcemapOutput ) ;
860
+ await uploadSourcemapForSentry (
861
+ bundleName ,
862
+ intermediaDir ,
863
+ sourcemapOutput ,
864
+ versionName ,
865
+ ) ;
866
+ }
758
867
}
759
868
} ,
760
869
0 commit comments