Skip to content

Commit 463987b

Browse files
committed
Merge pull request #1442 from NativeScript/separate-debugger-ui
Use Debugger UI from a dedicated npm package
2 parents 7c13e2e + e25208d commit 463987b

File tree

2 files changed

+45
-15
lines changed

2 files changed

+45
-15
lines changed

lib/npm-installation-manager.ts

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export class NpmInstallationManager implements INpmInstallationManager {
1818
private packageSpecificDirectories: IStringDictionary = {
1919
"tns-android": constants.PROJECT_FRAMEWORK_FOLDER_NAME,
2020
"tns-ios": constants.PROJECT_FRAMEWORK_FOLDER_NAME,
21+
"tns-ios-inspector": "WebInspectorUI",
2122
"tns-template-hello-world": constants.APP_RESOURCES_FOLDER_NAME,
2223
"tns-template-hello-world-ts": constants.APP_RESOURCES_FOLDER_NAME
2324
};

lib/services/ios-debug-service.ts

+44-15
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22
"use strict";
33

44
import * as iOSDevice from "../common/mobile/ios/device/ios-device";
5-
65
import * as net from "net";
76
import * as path from "path";
87
import * as semver from "semver";
98
import byline = require("byline");
109

11-
let InspectorBackendPort = 18181;
10+
const inspectorBackendPort = 18181;
11+
const inspectorAppName = "NativeScript Inspector.app";
12+
const inspectorZipName = "NativeScript Inspector.zip";
13+
const inspectorNpmPackageName = "tns-ios-inspector";
14+
const inspectorUiDir = "WebInspectorUI/";
15+
const TIMEOUT_SECONDS = 90;
1216

1317
class IOSDebugService implements IDebugService {
14-
private static TIMEOUT_SECONDS = 90;
15-
1618
constructor(
1719
private $platformService: IPlatformService,
1820
private $iOSEmulatorServices: Mobile.IEmulatorPlatformServices,
@@ -91,13 +93,13 @@ class IOSDebugService implements IDebugService {
9193
}
9294
});
9395

94-
this.wireDebuggerClient(() => net.connect(InspectorBackendPort)).wait();
96+
this.wireDebuggerClient(() => net.connect(inspectorBackendPort)).wait();
9597
}).future<void>()();
9698
}
9799

98100
private emulatorStart(): IFuture<void> {
99101
return (() => {
100-
this.wireDebuggerClient(() => net.connect(InspectorBackendPort)).wait();
102+
this.wireDebuggerClient(() => net.connect(inspectorBackendPort)).wait();
101103

102104
let attachRequestMessage = this.$iOSNotification.attachRequest;
103105

@@ -120,11 +122,11 @@ class IOSDebugService implements IDebugService {
120122

121123
private debugBrkCore(device: Mobile.IiOSDevice): IFuture<void> {
122124
return (() => {
123-
let timeout = this.$utils.getMilliSecondsTimeout(IOSDebugService.TIMEOUT_SECONDS);
125+
let timeout = this.$utils.getMilliSecondsTimeout(TIMEOUT_SECONDS);
124126
let readyForAttachTimeout = this.getReadyForAttachTimeout(timeout);
125127

126128
this.$iOSSocketRequestExecutor.executeLaunchRequest(device, timeout, readyForAttachTimeout).wait();
127-
this.wireDebuggerClient(() => device.connectToPort(InspectorBackendPort)).wait();
129+
this.wireDebuggerClient(() => device.connectToPort(inspectorBackendPort)).wait();
128130
}).future<void>()();
129131
}
130132

@@ -139,7 +141,7 @@ class IOSDebugService implements IDebugService {
139141
return (() => {
140142
let timeout = this.getReadyForAttachTimeout();
141143
this.$iOSSocketRequestExecutor.executeAttachRequest(device, timeout).wait();
142-
this.wireDebuggerClient(() => device.connectToPort(InspectorBackendPort)).wait();
144+
this.wireDebuggerClient(() => device.connectToPort(inspectorBackendPort)).wait();
143145
}).future<void>()();
144146
}
145147

@@ -164,15 +166,24 @@ class IOSDebugService implements IDebugService {
164166
return (() => {
165167
let frameworkVersion = this.getProjectFrameworkVersion().wait();
166168
let inspectorPath = this.getInspectorPath(frameworkVersion).wait();
167-
let inspectorSourceLocation = path.join(inspectorPath, "Safari/Main.html");
169+
let inspectorSourceLocation: string;
168170
let cmd: string = null;
169171

170-
if(semver.lt(frameworkVersion, "1.2.0")) {
172+
if (semver.lt(frameworkVersion, "1.2.0")) {
171173
cmd = `open -a Safari "${inspectorSourceLocation}"`;
172174
} else {
173-
let inspectorApplicationPath = path.join(inspectorPath, "NativeScript Inspector.app");
175+
let inspectorApplicationDir: string;
176+
if (semver.lt(frameworkVersion, "1.6.0")) {
177+
inspectorApplicationDir = inspectorPath;
178+
inspectorSourceLocation = path.join(inspectorPath, "Safari/Main.html");
179+
} else {
180+
inspectorApplicationDir = path.join(inspectorPath, "..");
181+
inspectorSourceLocation = path.join(inspectorPath, "Main.html");
182+
}
183+
184+
let inspectorApplicationPath = path.join(inspectorApplicationDir, inspectorAppName);
174185
if(!this.$fs.exists(inspectorApplicationPath).wait()) {
175-
this.$fs.unzip(path.join(inspectorPath, "NativeScript Inspector.zip"), inspectorPath).wait();
186+
this.$fs.unzip(path.join(inspectorApplicationDir, inspectorZipName), inspectorApplicationDir).wait();
176187
}
177188
cmd = `open -a '${inspectorApplicationPath}' --args '${inspectorSourceLocation}' '${this.$projectData.projectName}' '${fileDescriptor}'`;
178189
}
@@ -190,6 +201,24 @@ class IOSDebugService implements IDebugService {
190201
}
191202

192203
private getInspectorPath(frameworkVersion: string): IFuture<string> {
204+
return (() => {
205+
if (semver.lt(frameworkVersion, "1.6.0")) {
206+
return this.getInspectorPathFromDebuggerPackage(frameworkVersion).wait();
207+
} else {
208+
return this.getInspectorPathFromTnsIosPackage(frameworkVersion).wait();
209+
}
210+
}).future<string>()();
211+
}
212+
213+
private getInspectorPathFromDebuggerPackage(frameworkVersion: string): IFuture<string> {
214+
return (() => {
215+
let inspectorPackage = this.$npmInstallationManager.install(inspectorNpmPackageName).wait();
216+
let inspectorPath = path.join(inspectorPackage, inspectorUiDir);
217+
return inspectorPath;
218+
}).future<string>()();
219+
}
220+
221+
private getInspectorPathFromTnsIosPackage(frameworkVersion: string): IFuture<string> {
193222
return (() => {
194223
let tnsIosPackage = "";
195224
if (this.$options.frameworkPath) {
@@ -201,13 +230,13 @@ class IOSDebugService implements IDebugService {
201230
let platformData = this.$platformsData.getPlatformData(this.platform);
202231
tnsIosPackage = this.$npmInstallationManager.install(platformData.frameworkPackageName, { version: frameworkVersion }).wait();
203232
}
204-
let inspectorPath = path.join(tnsIosPackage, "WebInspectorUI/");
233+
let inspectorPath = path.join(tnsIosPackage, inspectorUiDir);
205234
return inspectorPath;
206235
}).future<string>()();
207236
}
208237

209238
private getReadyForAttachTimeout(timeoutInMilliseconds?: number): number {
210-
let timeout = timeoutInMilliseconds || this.$utils.getMilliSecondsTimeout(IOSDebugService.TIMEOUT_SECONDS);
239+
let timeout = timeoutInMilliseconds || this.$utils.getMilliSecondsTimeout(TIMEOUT_SECONDS);
211240
let readyForAttachTimeout = timeout / 10 ;
212241
let defaultReadyForAttachTimeout = 5000;
213242
return readyForAttachTimeout > defaultReadyForAttachTimeout ? readyForAttachTimeout : defaultReadyForAttachTimeout;

0 commit comments

Comments
 (0)