Skip to content

Commit d12952b

Browse files
committed
Merge pull request #30 from NativeScript/support-preliminary-brakepoints
Support preliminary brakepoints
2 parents eb41c59 + eba6ed0 commit d12952b

File tree

5 files changed

+381
-75
lines changed

5 files changed

+381
-75
lines changed

adapter/pathTransformer.ts

+36-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import * as utils from '../webkit/utilities';
66
import {DebugProtocol} from 'vscode-debugprotocol';
7+
import * as path from 'path';
78
import {ISetBreakpointsArgs, IDebugTransformer, ILaunchRequestArgs, IAttachRequestArgs, IStackTraceResponseBody} from '../webkit/WebKitAdapterInterfaces';
89

910
interface 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) {

adapter/sourceMaps/sourceMapTransformer.ts

+33-21
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class SourceMapTransformer implements IDebugTransformer {
5656
*/
5757
public setBreakpoints(args: ISetBreakpointsArgs, requestSeq: number): Promise<void> {
5858
return new Promise<void>((resolve, reject) => {
59-
if (this._sourceMaps && args.source.path) {
59+
if (this._sourceMaps && args.source.path && path.extname(args.source.path) !== ".js") {
6060
const argsPath = args.source.path;
6161
const mappedPath = this._sourceMaps.MapPathFromSource(argsPath);
6262
if (mappedPath) {
@@ -189,26 +189,8 @@ export class SourceMapTransformer implements IDebugTransformer {
189189

190190
let sourceMapUrlValue = event.body.sourceMapURL;
191191

192-
if (!event.body.sourceMapURL) {
193-
194-
let fileContents = fs.readFileSync(event.body.scriptUrl, 'utf8');
195-
196-
var baseRegex = "\\s*[@#]\\s*sourceMappingURL\\s*=\\s*([^\\s]*)";
197-
198-
// Matches /* ... */ comments
199-
var blockCommentRegex = new RegExp("/\\*" + baseRegex + "\\s*\\*/");
200-
201-
// Matches // .... comments
202-
var commentRegex = new RegExp("//" + baseRegex + "($|\n|\r\n?)");
203-
204-
let match = fileContents.match(commentRegex);
205-
if (!match) {
206-
match = fileContents.match(blockCommentRegex);
207-
}
208-
209-
if (match) {
210-
sourceMapUrlValue = match[1];
211-
}
192+
if (!sourceMapUrlValue) {
193+
sourceMapUrlValue = this._sourceMaps.FindSourceMapUrlInFile(event.body.scriptUrl);
212194
}
213195

214196
if (!sourceMapUrlValue || sourceMapUrlValue === "") {
@@ -226,6 +208,36 @@ export class SourceMapTransformer implements IDebugTransformer {
226208
}
227209
}
228210

211+
// private getSourceMappingFile(filePathOrSourceMapValue: string): string {
212+
213+
// let result = filePathOrSourceMapValue;
214+
215+
// if (!fs.existsSync(filePathOrSourceMapValue)) {
216+
// return result;
217+
// }
218+
219+
// let fileContents = fs.readFileSync(filePathOrSourceMapValue, 'utf8');
220+
221+
// var baseRegex = "\\s*[@#]\\s*sourceMappingURL\\s*=\\s*([^\\s]*)";
222+
223+
// // Matches /* ... */ comments
224+
// var blockCommentRegex = new RegExp("/\\*" + baseRegex + "\\s*\\*/");
225+
226+
// // Matches // .... comments
227+
// var commentRegex = new RegExp("//" + baseRegex + "($|\n|\r\n?)");
228+
229+
// let match = fileContents.match(commentRegex);
230+
// if (!match) {
231+
// match = fileContents.match(blockCommentRegex);
232+
// }
233+
234+
// if (match) {
235+
// result = match[1];
236+
// }
237+
238+
// return result;
239+
// }
240+
229241
private resolvePendingBreakpoints(sourcePath: string): void {
230242
// If there's a setBreakpoints request waiting on this script, go through setBreakpoints again
231243
if (this._pendingBreakpointsByPath.has(sourcePath)) {

0 commit comments

Comments
 (0)