4
4
5
5
import * as utils from '../webkit/utilities' ;
6
6
import { DebugProtocol } from 'vscode-debugprotocol' ;
7
+ import * as path from 'path' ;
7
8
import { ISetBreakpointsArgs , IDebugTransformer , ILaunchRequestArgs , IAttachRequestArgs , IStackTraceResponseBody } from '../webkit/WebKitAdapterInterfaces' ;
8
9
9
10
interface IPendingBreakpoint {
@@ -21,10 +22,12 @@ export class PathTransformer implements IDebugTransformer {
21
22
private _clientPathToWebkitUrl = new Map < string , string > ( ) ;
22
23
private _webkitUrlToClientPath = new Map < string , string > ( ) ;
23
24
private _pendingBreakpointsByPath = new Map < string , IPendingBreakpoint > ( ) ;
25
+ private inferedDeviceRoot :string = null ;
24
26
25
27
public launch ( args : ILaunchRequestArgs ) : void {
26
28
this . _webRoot = utils . getAppRoot ( args ) ;
27
29
this . _platform = args . platform ;
30
+ this . inferedDeviceRoot = ( this . _platform === 'ios' ) ? 'file://' : this . inferedDeviceRoot ;
28
31
}
29
32
30
33
public attach ( args : IAttachRequestArgs ) : void {
@@ -51,7 +54,28 @@ export class PathTransformer implements IDebugTransformer {
51
54
args . source . path = this . _clientPathToWebkitUrl . get ( url ) ;
52
55
utils . Logger . log ( `Paths.setBP: Resolved ${ url } to ${ args . source . path } ` ) ;
53
56
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 {
55
79
utils . Logger . log ( `Paths.setBP: No target url cached for client path: ${ url } , waiting for target script to be loaded.` ) ;
56
80
args . source . path = url ;
57
81
this . _pendingBreakpointsByPath . set ( args . source . path , { resolve, reject, args } ) ;
@@ -70,6 +94,17 @@ export class PathTransformer implements IDebugTransformer {
70
94
71
95
public scriptParsed ( event : DebugProtocol . Event ) : void {
72
96
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
+
73
108
const clientPath = utils . webkitUrlToClientPath ( this . _webRoot , this . _platform , webkitUrl ) ;
74
109
75
110
if ( ! clientPath ) {
0 commit comments