11import { cache } from "../common/decorators" ;
2- import { HmrConstants } from "../common/constants" ;
2+ import { HmrConstants , IOS_APP_CRASH_LOG_REG_EXP } from "../common/constants" ;
33
44export class HmrStatusService implements IHmrStatusService {
55 public static HMR_STATUS_LOG_REGEX = / ( [ a - z A - Z ] * ) h m r h a s h ( [ a - z 0 - 9 ] * ) \. / ;
@@ -11,9 +11,10 @@ export class HmrStatusService implements IHmrStatusService {
1111
1212 constructor ( private $logParserService : ILogParserService ,
1313 private $processService : IProcessService ,
14+ private $devicePlatformsConstants : Mobile . IDevicePlatformsConstants ,
1415 private $logger : ILogger ) {
15- this . $processService . attachToProcessExitSignals ( this , this . dispose ) ;
16- }
16+ this . $processService . attachToProcessExitSignals ( this , this . dispose ) ;
17+ }
1718
1819 public getHmrStatus ( deviceId : string , operationHash : string ) : Promise < number > {
1920 return new Promise ( ( resolve , reject ) => {
@@ -33,13 +34,32 @@ export class HmrStatusService implements IHmrStatusService {
3334 } ) ;
3435 }
3536
37+ public watchHmrStatus ( deviceId : string , operationHash : string ) : void {
38+ this . setData ( deviceId , operationHash ) ;
39+ }
40+
3641 @cache ( )
3742 public attachToHmrStatusEvent ( ) : void {
3843 this . $logParserService . addParseRule ( {
3944 regex : HmrStatusService . HMR_STATUS_LOG_REGEX ,
4045 handler : this . handleHmrStatusFound . bind ( this ) ,
4146 name : "hmrStatus"
4247 } ) ;
48+ this . $logParserService . addParseRule ( {
49+ regex : IOS_APP_CRASH_LOG_REG_EXP ,
50+ handler : this . handleAppCrash . bind ( this ) ,
51+ name : "appCrashHmr" ,
52+ platform : this . $devicePlatformsConstants . iOS . toLowerCase ( )
53+ } ) ;
54+ }
55+
56+ private handleAppCrash ( matches : RegExpMatchArray , deviceId : string ) : void {
57+ for ( const operationId in this . hashOperationStatuses ) {
58+ const operation = this . hashOperationStatuses [ operationId ] ;
59+ if ( operationId . startsWith ( deviceId ) && ! operation . status ) {
60+ operation . status = HmrConstants . HMR_ERROR_STATUS ;
61+ }
62+ }
4363 }
4464
4565 private handleHmrStatusFound ( matches : RegExpMatchArray , deviceId : string ) : void {
@@ -65,7 +85,7 @@ export class HmrStatusService implements IHmrStatusService {
6585 this . $logger . trace ( "Found hmr status." , { status, hash } ) ;
6686
6787 if ( status ) {
68- this . setData ( status , hash , deviceId ) ;
88+ this . setData ( deviceId , hash , status ) ;
6989 }
7090 }
7191
@@ -77,7 +97,7 @@ export class HmrStatusService implements IHmrStatusService {
7797 return null ;
7898 }
7999
80- private setData ( status : Number , operationHash : string , deviceId : string ) : void {
100+ private setData ( deviceId : string , operationHash : string , status ?: Number ) : void {
81101 const key = `${ deviceId } ${ operationHash } ` ;
82102
83103 if ( ! this . hashOperationStatuses [ key ] ) {
0 commit comments