@@ -22,18 +22,22 @@ interface IFileLocation {
22
22
23
23
export class LogSourceMapService implements Mobile . ILogSourceMapService {
24
24
private static FILE_PREFIX = "file:///" ;
25
+ private static MEMOIZE_FUNCTION_RANDOM_KEY_FOR_JOIN = "__some_random_value__" ;
25
26
private getProjectData : ( projectDir : string ) => IProjectData ;
26
- private getNSValue : ( projectDir : string , propertyName : string ) => any ;
27
+ private getRuntimeVersion : ( projectDir : string , platform : string ) => string ;
27
28
private cache : IDictionary < sourcemap . SourceMapConsumer > = { } ;
28
29
30
+ private get $platformsDataService ( ) : IPlatformsDataService {
31
+ return this . $injector . resolve < IPlatformsDataService > ( "platformsDataService" ) ;
32
+ }
29
33
constructor (
30
34
private $fs : IFileSystem ,
31
35
private $projectDataService : IProjectDataService ,
32
36
private $injector : IInjector ,
33
37
private $devicePlatformsConstants : Mobile . IDevicePlatformsConstants ,
34
38
private $logger : ILogger ) {
35
39
this . getProjectData = _ . memoize ( this . $projectDataService . getProjectData . bind ( this . $projectDataService ) ) ;
36
- this . getNSValue = _ . memoize ( this . $projectDataService . getNSValue . bind ( this . $projectDataService ) ) ;
40
+ this . getRuntimeVersion = _ . memoize ( this . getRuntimeVersionCore , ( ... args ) => args . join ( LogSourceMapService . MEMOIZE_FUNCTION_RANDOM_KEY_FOR_JOIN ) ) ;
37
41
}
38
42
39
43
public async setSourceMapConsumerForFile ( filePath : string ) : Promise < void > {
@@ -71,11 +75,13 @@ export class LogSourceMapService implements Mobile.ILogSourceMapService {
71
75
const originalLocation = this . getOriginalFileLocation ( platform , parsedLine , projectData ) ;
72
76
73
77
if ( originalLocation && originalLocation . sourceFile ) {
74
- const runtimeData = this . getNSValue ( loggingOptions . projectDir , `tns-${ platform . toLowerCase ( ) } ` ) ;
75
- const runtimeVersion = runtimeData && runtimeData . version ;
78
+ const runtimeVersion = this . getRuntimeVersion ( loggingOptions . projectDir , platform ) ;
76
79
const { sourceFile, line, column } = originalLocation ;
77
80
if ( semver . valid ( runtimeVersion ) && semver . gte ( semver . coerce ( runtimeVersion ) , "6.1.0" ) ) {
78
- outputData += rawLine . replace ( / f i l e : \/ \/ \/ .* ?: \d + : \d + / , `file:///${ sourceFile } :${ line } :${ column } ` ) + '\n' ;
81
+ const lastIndexOfFile = rawLine . lastIndexOf ( LogSourceMapService . FILE_PREFIX ) ;
82
+ const firstPart = rawLine . substr ( 0 , lastIndexOfFile ) ;
83
+
84
+ outputData += firstPart + rawLine . substr ( lastIndexOfFile ) . replace ( / f i l e : \/ \/ \/ .+ ?: \d + : \d + / , `${ LogSourceMapService . FILE_PREFIX } ${ sourceFile } :${ line } :${ column } ` ) + '\n' ;
79
85
} else {
80
86
outputData = `${ outputData } ${ parsedLine . messagePrefix } ${ LogSourceMapService . FILE_PREFIX } ${ sourceFile } :${ line } :${ column } ${ parsedLine . messageSuffix } \n` ;
81
87
}
@@ -87,6 +93,20 @@ export class LogSourceMapService implements Mobile.ILogSourceMapService {
87
93
return outputData ;
88
94
}
89
95
96
+ private getRuntimeVersionCore ( projectDir : string , platform : string ) : string {
97
+ let runtimeVersion : string = null ;
98
+ try {
99
+ const projectData = this . getProjectData ( projectDir ) ;
100
+ const platformData = this . $platformsDataService . getPlatformData ( platform , projectData ) ;
101
+ const runtimeVersionData = this . $projectDataService . getNSValue ( projectData . projectDir , platformData . frameworkPackageName ) ;
102
+ runtimeVersion = runtimeVersionData && runtimeVersionData . version ;
103
+ } catch ( err ) {
104
+ this . $logger . trace ( `Unable to get runtime version for project directory: ${ projectDir } and platform ${ platform } . Error is: ` , err ) ;
105
+ }
106
+
107
+ return runtimeVersion ;
108
+ }
109
+
90
110
private getOriginalFileLocation ( platform : string , parsedLine : IParsedMessage , projectData : IProjectData ) : IFileLocation {
91
111
const fileLocation = path . join ( this . getFilesLocation ( platform , projectData ) , APP_FOLDER_NAME ) ;
92
112
@@ -185,7 +205,7 @@ export class LogSourceMapService implements Mobile.ILogSourceMapService {
185
205
186
206
private getFilesLocation ( platform : string , projectData : IProjectData ) : string {
187
207
try {
188
- const platformsData = this . $injector . resolve ( " platformsDataService" ) . getPlatformData ( platform . toLowerCase ( ) , projectData ) ;
208
+ const platformsData = this . $platformsDataService . getPlatformData ( platform . toLowerCase ( ) , projectData ) ;
189
209
return platformsData . appDestinationDirectoryPath ;
190
210
} catch ( err ) {
191
211
return "" ;
0 commit comments