@@ -22,18 +22,22 @@ interface IFileLocation {
2222
2323export class LogSourceMapService implements Mobile . ILogSourceMapService {
2424 private static FILE_PREFIX = "file:///" ;
25+ private static MEMOIZE_FUNCTION_RANDOM_KEY_FOR_JOIN = "__some_random_value__" ;
2526 private getProjectData : ( projectDir : string ) => IProjectData ;
26- private getNSValue : ( projectDir : string , propertyName : string ) => any ;
27+ private getRuntimeVersion : ( projectDir : string , platform : string ) => string ;
2728 private cache : IDictionary < sourcemap . SourceMapConsumer > = { } ;
2829
30+ private get $platformsDataService ( ) : IPlatformsDataService {
31+ return this . $injector . resolve < IPlatformsDataService > ( "platformsDataService" ) ;
32+ }
2933 constructor (
3034 private $fs : IFileSystem ,
3135 private $projectDataService : IProjectDataService ,
3236 private $injector : IInjector ,
3337 private $devicePlatformsConstants : Mobile . IDevicePlatformsConstants ,
3438 private $logger : ILogger ) {
3539 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 ) ) ;
3741 }
3842
3943 public async setSourceMapConsumerForFile ( filePath : string ) : Promise < void > {
@@ -71,11 +75,13 @@ export class LogSourceMapService implements Mobile.ILogSourceMapService {
7175 const originalLocation = this . getOriginalFileLocation ( platform , parsedLine , projectData ) ;
7276
7377 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 ) ;
7679 const { sourceFile, line, column } = originalLocation ;
7780 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' ;
7985 } else {
8086 outputData = `${ outputData } ${ parsedLine . messagePrefix } ${ LogSourceMapService . FILE_PREFIX } ${ sourceFile } :${ line } :${ column } ${ parsedLine . messageSuffix } \n` ;
8187 }
@@ -87,6 +93,20 @@ export class LogSourceMapService implements Mobile.ILogSourceMapService {
8793 return outputData ;
8894 }
8995
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+
90110 private getOriginalFileLocation ( platform : string , parsedLine : IParsedMessage , projectData : IProjectData ) : IFileLocation {
91111 const fileLocation = path . join ( this . getFilesLocation ( platform , projectData ) , APP_FOLDER_NAME ) ;
92112
@@ -185,7 +205,7 @@ export class LogSourceMapService implements Mobile.ILogSourceMapService {
185205
186206 private getFilesLocation ( platform : string , projectData : IProjectData ) : string {
187207 try {
188- const platformsData = this . $injector . resolve ( " platformsDataService" ) . getPlatformData ( platform . toLowerCase ( ) , projectData ) ;
208+ const platformsData = this . $platformsDataService . getPlatformData ( platform . toLowerCase ( ) , projectData ) ;
189209 return platformsData . appDestinationDirectoryPath ;
190210 } catch ( err ) {
191211 return "" ;
0 commit comments