44
55import * as utils from '../webkit/utilities' ;
66import { DebugProtocol } from 'vscode-debugprotocol' ;
7+ import * as path from 'path' ;
78import { ISetBreakpointsArgs , IDebugTransformer , ILaunchRequestArgs , IAttachRequestArgs , IStackTraceResponseBody } from '../webkit/WebKitAdapterInterfaces' ;
89
910interface IPendingBreakpoint {
@@ -21,10 +22,12 @@ export class PathTransformer implements IDebugTransformer {
2122 private _clientPathToWebkitUrl = new Map < string , string > ( ) ;
2223 private _webkitUrlToClientPath = new Map < string , string > ( ) ;
2324 private _pendingBreakpointsByPath = new Map < string , IPendingBreakpoint > ( ) ;
25+ private inferedDeviceRoot :string = null ;
2426
2527 public launch ( args : ILaunchRequestArgs ) : void {
2628 this . _webRoot = utils . getAppRoot ( args ) ;
2729 this . _platform = args . platform ;
30+ this . inferedDeviceRoot = ( this . _platform === 'ios' ) ? 'file://' : this . inferedDeviceRoot ;
2831 }
2932
3033 public attach ( args : IAttachRequestArgs ) : void {
@@ -51,7 +54,28 @@ export class PathTransformer implements IDebugTransformer {
5154 args . source . path = this . _clientPathToWebkitUrl . get ( url ) ;
5255 utils . Logger . log ( `Paths.setBP: Resolved ${ url } to ${ args . source . path } ` ) ;
5356 resolve ( ) ;
54- } else {
57+ }
58+ else if ( this . inferedDeviceRoot ) {
59+ let inferedUrl = url . replace ( this . _webRoot , this . inferedDeviceRoot ) . replace ( / \\ / g, "/" ) ;
60+
61+ //change device path if {N} core module or {N} module
62+ if ( inferedUrl . indexOf ( "/node_modules/tns-core-modules/" ) != - 1 )
63+ {
64+ inferedUrl = inferedUrl . replace ( "/node_modules/tns-core-modules/" , "/app/tns_modules/" ) ;
65+ }
66+ else if ( inferedUrl . indexOf ( "/node_modules/" ) != - 1 )
67+ {
68+ inferedUrl = inferedUrl . replace ( "/node_modules/" , "/app/tns_modules/" ) ;
69+ }
70+
71+ //change platform specific paths
72+ inferedUrl = inferedUrl . replace ( `.${ this . _platform } .` , '.' ) ;
73+
74+ args . source . path = inferedUrl ;
75+ utils . Logger . log ( `Paths.setBP: Resolved (by infering) ${ url } to ${ args . source . path } ` ) ;
76+ resolve ( ) ;
77+ }
78+ else {
5579 utils . Logger . log ( `Paths.setBP: No target url cached for client path: ${ url } , waiting for target script to be loaded.` ) ;
5680 args . source . path = url ;
5781 this . _pendingBreakpointsByPath . set ( args . source . path , { resolve, reject, args } ) ;
@@ -70,6 +94,17 @@ export class PathTransformer implements IDebugTransformer {
7094
7195 public scriptParsed ( event : DebugProtocol . Event ) : void {
7296 const webkitUrl : string = event . body . scriptUrl ;
97+ if ( ! this . inferedDeviceRoot && this . _platform === "android" )
98+ {
99+ this . inferedDeviceRoot = utils . inferDeviceRoot ( this . _webRoot , this . _platform , webkitUrl ) ;
100+ utils . Logger . log ( "\n\n\n ***Inferred device root: " + this . inferedDeviceRoot + "\n\n\n" ) ;
101+
102+ if ( this . inferedDeviceRoot . indexOf ( "/data/user/0/" ) != - 1 )
103+ {
104+ this . inferedDeviceRoot = this . inferedDeviceRoot . replace ( "/data/user/0/" , "/data/data/" ) ;
105+ }
106+ }
107+
73108 const clientPath = utils . webkitUrlToClientPath ( this . _webRoot , this . _platform , webkitUrl ) ;
74109
75110 if ( ! clientPath ) {
0 commit comments