@@ -86,7 +86,17 @@ export function getReactNativeProjectAppVersion(
86
86
. concat ( xcodeProjectConfig , '".\n' )
87
87
) ;
88
88
const xcodeContents = fs . readFileSync ( xcodeProjectConfig ) . toString ( ) ;
89
- const xcodeVersion = [ ...xcodeContents . matchAll ( / R e l e a s e [ \s \S ] * M A R K E T I N G _ V E R S I O N = ( \d + \. \d + \. \d + ) / gm) ] [ 0 ] [ 1 ] ;
89
+
90
+ const xcodeVersionRegex = / R e l e a s e [ \s \S ] * M A R K E T I N G _ V E R S I O N = ( \d + \. \d + \. \d + ) / gm;
91
+ let xcodeVersion ;
92
+ let match ;
93
+
94
+ while ( ( match = xcodeVersionRegex . exec ( xcodeContents ) ) !== null ) {
95
+ // 这个循环将重复执行,直到没有更多匹配项
96
+ // match[1] 将包含第一个捕获组的值,即版本号
97
+ xcodeVersion = match [ 1 ] ;
98
+ break ; // 因为我们只需要第一个匹配项,所以找到后就可以退出循环
99
+ }
90
100
out . text (
91
101
'Using xcodeProjectConfig version, version "' . concat (
92
102
xcodeVersion ,
@@ -356,7 +366,7 @@ export function runHermesEmitBinaryCommand(
356
366
) : Promise < void > {
357
367
const hermesArgs : string [ ] = [ ] ;
358
368
const envNodeArgs : string = process . env . CODE_PUSH_NODE_ARGS ;
359
-
369
+ out . text ( chalk . cyan ( 'Converting JS bundle to byte code via Hermes, running command:\n' ) ) ;
360
370
if ( typeof envNodeArgs !== 'undefined' ) {
361
371
Array . prototype . push . apply ( hermesArgs , envNodeArgs . trim ( ) . split ( / \s + / ) ) ;
362
372
}
@@ -480,29 +490,41 @@ export function runHermesEmitBinaryCommand(
480
490
} ) ;
481
491
}
482
492
483
- export function getHermesEnabled ( gradleFile ?: string ) : Promise < boolean > {
484
- let buildGradlePath : string = path . join ( 'android' , 'app' ) ;
485
- if ( gradleFile ) {
486
- buildGradlePath = gradleFile ;
487
- }
488
- if ( fs . lstatSync ( buildGradlePath ) . isDirectory ( ) ) {
493
+ export async function getHermesEnabled ( gradleFile ?: string ) : Promise < boolean > {
494
+ let buildGradlePath = gradleFile ?? path . join ( 'android' , 'app' ) ;
495
+
496
+ if ( await fileDoesNotExistOrIsDirectory ( buildGradlePath ) ) {
489
497
buildGradlePath = path . join ( buildGradlePath , 'build.gradle' ) ;
490
498
}
491
499
492
- if ( fileDoesNotExistOrIsDirectory ( buildGradlePath ) ) {
500
+ if ( await fileDoesNotExistOrIsDirectory ( buildGradlePath ) ) {
493
501
throw new Error ( `Unable to find gradle file "${ buildGradlePath } ".` ) ;
494
502
}
495
503
496
- return g2js
497
- . parseFile ( buildGradlePath )
498
- . catch ( ( ) => {
499
- throw new Error (
500
- `Unable to parse the "${ buildGradlePath } " file. Please ensure it is a well-formed Gradle file.` ,
501
- ) ;
502
- } )
503
- . then ( ( buildGradle : any ) => {
504
- return Array . from ( buildGradle [ 'project.ext.react' ] ) . includes ( 'enableHermes: true' ) ;
505
- } ) ;
504
+ let gradlePropertyPath : string = path . join ( 'android' , 'gradle.properties' ) ;
505
+
506
+ if ( await fileDoesNotExistOrIsDirectory ( gradlePropertyPath ) ) {
507
+ throw new Error ( `Unable to find gradle file "${ gradlePropertyPath } ".` ) ;
508
+ }
509
+
510
+ try {
511
+ const buildGradle = await g2js . parseFile ( buildGradlePath ) ;
512
+ const buildProperty = await g2js . parseFile ( gradlePropertyPath ) ;
513
+
514
+ const hermesPropertyEnabled = buildProperty . hermesEnabled ?? false ;
515
+ let hermesBuildEnabled = false ;
516
+
517
+ // 如果buildGradle["project.ext.react"]是一个数组,则继续处理
518
+ if ( Array . isArray ( buildGradle [ "project.ext.react" ] ) ) {
519
+ const reactSettings : string [ ] = buildGradle [ "project.ext.react" ] ;
520
+ hermesBuildEnabled = reactSettings . some ( line => / ^ e n a b l e H e r m e s \s * : \s * t r u e / . test ( line ) ) ;
521
+ }
522
+
523
+ return hermesPropertyEnabled || hermesBuildEnabled ;
524
+ } catch ( error ) {
525
+ // error.message 可能需要根据实际在 try 块中发生的错误进行调整
526
+ throw new Error ( `An error occurred while processing the Gradle files: ${ error . message } ` ) ;
527
+ }
506
528
}
507
529
508
530
export function getiOSHermesEnabled ( podFile : string ) : Promise < boolean > {
0 commit comments