Skip to content

Commit b67c459

Browse files
committed
Remove getAppRoot and getBrowserPath from utilities
1 parent 82ec3b3 commit b67c459

File tree

4 files changed

+12
-44
lines changed

4 files changed

+12
-44
lines changed

src/debug-adapter/adapter/pathTransformer.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@ interface IPendingBreakpoint {
1717
* Converts a local path from Code to a path on the target.
1818
*/
1919
export class PathTransformer implements DebugProtocol.IDebugTransformer {
20-
private _webRoot: string;
20+
private _appRoot: string;
2121
private _platform: string;
2222
private _clientPathToWebkitUrl = new Map<string, string>();
2323
private _webkitUrlToClientPath = new Map<string, string>();
2424
private _pendingBreakpointsByPath = new Map<string, IPendingBreakpoint>();
2525
private inferedDeviceRoot :string = null;
2626

2727
public launch(args: DebugProtocol.ILaunchRequestArgs): void {
28-
this._webRoot = utils.getAppRoot(args);
28+
this._appRoot = args.appRoot;
2929
this._platform = args.platform;
3030
this.inferedDeviceRoot = (this._platform === 'ios') ? 'file://' : this.inferedDeviceRoot;
3131
}
3232

3333
public attach(args: DebugProtocol.IAttachRequestArgs): void {
34-
this._webRoot = utils.getAppRoot(args);
34+
this._appRoot = args.appRoot;
3535
this._platform = args.platform;
3636
}
3737

@@ -56,7 +56,7 @@ export class PathTransformer implements DebugProtocol.IDebugTransformer {
5656
resolve();
5757
}
5858
else if (this.inferedDeviceRoot) {
59-
let inferedUrl = url.replace(this._webRoot, this.inferedDeviceRoot).replace(/\\/g, "/");
59+
let inferedUrl = url.replace(this._appRoot, this.inferedDeviceRoot).replace(/\\/g, "/");
6060

6161
//change device path if {N} core module or {N} module
6262
if (inferedUrl.indexOf("/node_modules/tns-core-modules/") != -1)
@@ -96,7 +96,7 @@ export class PathTransformer implements DebugProtocol.IDebugTransformer {
9696
const webkitUrl: string = event.body.scriptUrl;
9797
if (!this.inferedDeviceRoot && this._platform === "android")
9898
{
99-
this.inferedDeviceRoot = utils.inferDeviceRoot(this._webRoot, this._platform, webkitUrl);
99+
this.inferedDeviceRoot = utils.inferDeviceRoot(this._appRoot, this._platform, webkitUrl);
100100
Logger.log("\n\n\n ***Inferred device root: " + this.inferedDeviceRoot + "\n\n\n");
101101

102102
if (this.inferedDeviceRoot.indexOf("/data/user/0/") != -1)
@@ -105,12 +105,12 @@ export class PathTransformer implements DebugProtocol.IDebugTransformer {
105105
}
106106
}
107107

108-
const clientPath = utils.webkitUrlToClientPath(this._webRoot, this._platform, webkitUrl);
108+
const clientPath = utils.webkitUrlToClientPath(this._appRoot, this._platform, webkitUrl);
109109

110110
if (!clientPath) {
111-
Logger.log(`Paths.scriptParsed: could not resolve ${webkitUrl} to a file in the workspace. webRoot: ${this._webRoot}`);
111+
Logger.log(`Paths.scriptParsed: could not resolve ${webkitUrl} to a file in the workspace. webRoot: ${this._appRoot}`);
112112
} else {
113-
Logger.log(`Paths.scriptParsed: resolved ${webkitUrl} to ${clientPath}. webRoot: ${this._webRoot}`);
113+
Logger.log(`Paths.scriptParsed: resolved ${webkitUrl} to ${clientPath}. webRoot: ${this._appRoot}`);
114114
this._clientPathToWebkitUrl.set(clientPath, webkitUrl);
115115
this._webkitUrlToClientPath.set(webkitUrl, clientPath);
116116

@@ -132,7 +132,7 @@ export class PathTransformer implements DebugProtocol.IDebugTransformer {
132132
if (frame.source && frame.source.path) {
133133
const clientPath = this._webkitUrlToClientPath.has(frame.source.path) ?
134134
this._webkitUrlToClientPath.get(frame.source.path) :
135-
utils.webkitUrlToClientPath(this._webRoot, this._platform, frame.source.path);
135+
utils.webkitUrlToClientPath(this._appRoot, this._platform, frame.source.path);
136136
// Incoming stackFrames have sourceReference and path set. If the path was resolved to a file in the workspace,
137137
// clear the sourceReference since it's not needed.
138138
if (clientPath) {

src/debug-adapter/adapter/sourceMaps/sourceMapTransformer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class SourceMapTransformer implements DebugProtocol.IDebugTransformer {
3838

3939
private init(args: DebugProtocol.ILaunchRequestArgs | DebugProtocol.IAttachRequestArgs): void {
4040
if (args.sourceMaps) {
41-
this._webRoot = utils.getAppRoot(args);
41+
this._webRoot = args.appRoot;
4242
this._sourceMaps = new SourceMaps(this._webRoot);
4343
this._requestSeqToSetBreakpointsArgs = new Map<number, DebugProtocol.ISetBreakpointsArgs>();
4444
this._allRuntimeScriptPaths = new Set<string>();

src/debug-adapter/utilities.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,6 @@ import * as os from 'os';
99
import * as fs from 'fs';
1010
import * as url from 'url';
1111
import * as path from 'path';
12-
import {DebugProtocol} from 'vscode-debugprotocol';
13-
14-
const DEFAULT_CHROME_PATH = {
15-
OSX: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
16-
WIN: 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
17-
WINx86: 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
18-
LINUX: '/usr/bin/google-chrome'
19-
};
20-
21-
export function getBrowserPath(): string {
22-
const platform = getPlatform();
23-
if (platform === Platform.OSX) {
24-
return existsSync(DEFAULT_CHROME_PATH.OSX) ? DEFAULT_CHROME_PATH.OSX : null;
25-
} else if (platform === Platform.Windows) {
26-
if (existsSync(DEFAULT_CHROME_PATH.WINx86)) {
27-
return DEFAULT_CHROME_PATH.WINx86;
28-
} else if (existsSync(DEFAULT_CHROME_PATH.WIN)) {
29-
return DEFAULT_CHROME_PATH.WIN;
30-
} else {
31-
return null;
32-
}
33-
} else {
34-
return existsSync(DEFAULT_CHROME_PATH.LINUX) ? DEFAULT_CHROME_PATH.LINUX : null;
35-
}
36-
}
3712

3813
export const enum Platform {
3914
Windows, OSX, Linux
@@ -364,13 +339,6 @@ export function errP(msg: any): Promise<any> {
364339
return Promise.reject(e);
365340
}
366341

367-
/**
368-
* Calculates the appRoot from a launch/attach request. The appRoot is the root directory of the NativeScript app.
369-
*/
370-
export function getAppRoot(args: DebugProtocol.ILaunchRequestArgs | DebugProtocol.IAttachRequestArgs): string {
371-
return (args.appRoot && path.isAbsolute(args.appRoot)) ? args.appRoot : '';
372-
}
373-
374342
/**
375343
* Helper function to GET the contents of a url
376344
*/

src/debug-adapter/webKitDebugAdapter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {
122122
}
123123

124124
private _attach(args: DebugProtocol.IAttachRequestArgs | DebugProtocol.ILaunchRequestArgs) {
125-
ExtensionClient.setAppRoot(utils.getAppRoot(args));
125+
ExtensionClient.setAppRoot(args.appRoot);
126126
let analyticsRequest = (args.request == "launch" && !(args as DebugProtocol.ILaunchRequestArgs).rebuild) ? "sync" : args.request;
127127
ExtensionClient.getInstance().analyticsLaunchDebugger({ request: analyticsRequest, platform: args.platform });
128128
this.configureLoggingForRequest(args.request, args);
129-
this.appRoot = utils.getAppRoot(args);
129+
this.appRoot = args.appRoot;
130130
this.platform = args.platform;
131131

132132
return ((args.platform == 'ios') ? this._attachIos(args) : this._attachAndroid(args))

0 commit comments

Comments
 (0)