1
1
import { cache } from "../common/decorators" ;
2
- import { HmrConstants } from "../common/constants" ;
2
+ import { HmrConstants , IOS_APP_CRASH_LOG_REG_EXP } from "../common/constants" ;
3
3
4
4
export class HmrStatusService implements IHmrStatusService {
5
5
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 {
11
11
12
12
constructor ( private $logParserService : ILogParserService ,
13
13
private $processService : IProcessService ,
14
+ private $devicePlatformsConstants : Mobile . IDevicePlatformsConstants ,
14
15
private $logger : ILogger ) {
15
- this . $processService . attachToProcessExitSignals ( this , this . dispose ) ;
16
- }
16
+ this . $processService . attachToProcessExitSignals ( this , this . dispose ) ;
17
+ }
17
18
18
19
public getHmrStatus ( deviceId : string , operationHash : string ) : Promise < number > {
19
20
return new Promise ( ( resolve , reject ) => {
@@ -33,13 +34,32 @@ export class HmrStatusService implements IHmrStatusService {
33
34
} ) ;
34
35
}
35
36
37
+ public watchHmrStatus ( deviceId : string , operationHash : string ) : void {
38
+ this . setData ( deviceId , operationHash ) ;
39
+ }
40
+
36
41
@cache ( )
37
42
public attachToHmrStatusEvent ( ) : void {
38
43
this . $logParserService . addParseRule ( {
39
44
regex : HmrStatusService . HMR_STATUS_LOG_REGEX ,
40
45
handler : this . handleHmrStatusFound . bind ( this ) ,
41
46
name : "hmrStatus"
42
47
} ) ;
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
+ }
43
63
}
44
64
45
65
private handleHmrStatusFound ( matches : RegExpMatchArray , deviceId : string ) : void {
@@ -65,7 +85,7 @@ export class HmrStatusService implements IHmrStatusService {
65
85
this . $logger . trace ( "Found hmr status." , { status, hash } ) ;
66
86
67
87
if ( status ) {
68
- this . setData ( status , hash , deviceId ) ;
88
+ this . setData ( deviceId , hash , status ) ;
69
89
}
70
90
}
71
91
@@ -77,7 +97,7 @@ export class HmrStatusService implements IHmrStatusService {
77
97
return null ;
78
98
}
79
99
80
- private setData ( status : Number , operationHash : string , deviceId : string ) : void {
100
+ private setData ( deviceId : string , operationHash : string , status ?: Number ) : void {
81
101
const key = `${ deviceId } ${ operationHash } ` ;
82
102
83
103
if ( ! this . hashOperationStatuses [ key ] ) {
0 commit comments