Skip to content

Commit 7ab62ce

Browse files
Fix debug command
- `tns debug ios` prints message that you have to open `null` url in Chrome - when you do not pass `--chrome` to this command, it will use NativeScript inspector, so hide the incorrect message. - debugData is constructed too early in the command - in case the application has not been built before calling `tns debug ...`, construction of debugData will fail as CLI will not be able to find the latest built package. In order to fix this make the `pathToAppPackage` not mandatory (we do not need it for debug commands when `--start` is passed) and populate it after successful deploy of the application. This way it will have correct value. Delete most of the DebugDataService as most of the methods are not needed with these changes. - remove the check if `--chrome` is passed in order to print the url when `tns debug android` is used. The check was incorrect (it should check the value of `options.client`), but in fact we do not need it - the idea of the check was to suppress starting of Node Inspector, however we do not start it anymore no matter of the passed flags. So remove the incorrect check.
1 parent 88825da commit 7ab62ce

File tree

6 files changed

+40
-55
lines changed

6 files changed

+40
-55
lines changed

lib/commands/debug.ts

+21-12
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ export abstract class DebugPlatformCommand implements ICommand {
66
constructor(private debugService: IPlatformDebugService,
77
private $devicesService: Mobile.IDevicesService,
88
private $injector: IInjector,
9-
private $logger: ILogger,
109
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
1110
private $config: IConfiguration,
1211
private $usbLiveSyncService: ILiveSyncService,
1312
private $debugDataService: IDebugDataService,
1413
protected $platformService: IPlatformService,
1514
protected $projectData: IProjectData,
1615
protected $options: IOptions,
17-
protected $platformsData: IPlatformsData) {
16+
protected $platformsData: IPlatformsData,
17+
protected $logger: ILogger) {
1818
this.$projectData.initializeProjectData();
1919
}
2020

@@ -31,9 +31,7 @@ export abstract class DebugPlatformCommand implements ICommand {
3131
teamId: this.$options.teamId
3232
};
3333

34-
const buildConfig: IBuildConfig = _.merge({ buildForDevice: this.$options.forDevice }, deployOptions);
35-
36-
const debugData = this.$debugDataService.createDebugData(this.debugService, this.$options, buildConfig);
34+
let debugData = this.$debugDataService.createDebugData(this.$projectData, this.$options);
3735

3836
await this.$platformService.trackProjectType(this.$projectData);
3937

@@ -57,6 +55,9 @@ export abstract class DebugPlatformCommand implements ICommand {
5755

5856
await deviceAppData.device.applicationManager.stopApplication(applicationId);
5957

58+
const buildConfig: IBuildConfig = _.merge({ buildForDevice: this.$options.forDevice }, deployOptions);
59+
debugData.pathToAppPackage = this.$platformService.lastOutputPath(this.debugService.platform, buildConfig, projectData);
60+
6061
this.printDebugInformation(await this.debugService.debug(debugData, debugOptions));
6162
};
6263

@@ -80,18 +81,18 @@ export abstract class DebugPlatformCommand implements ICommand {
8081
return true;
8182
}
8283

83-
private printDebugInformation(information: string[]): void {
84+
protected printDebugInformation(information: string[]): void {
8485
_.each(information, i => {
8586
this.$logger.info(`To start debugging, open the following URL in Chrome:${EOL}${i}${EOL}`.cyan);
8687
});
8788
}
8889
}
8990

9091
export class DebugIOSCommand extends DebugPlatformCommand {
91-
constructor($iOSDebugService: IPlatformDebugService,
92+
constructor(protected $logger: ILogger,
93+
$iOSDebugService: IPlatformDebugService,
9294
$devicesService: Mobile.IDevicesService,
9395
$injector: IInjector,
94-
$logger: ILogger,
9596
$devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
9697
$config: IConfiguration,
9798
$usbLiveSyncService: ILiveSyncService,
@@ -101,22 +102,30 @@ export class DebugIOSCommand extends DebugPlatformCommand {
101102
$projectData: IProjectData,
102103
$platformsData: IPlatformsData,
103104
$iosDeviceOperations: IIOSDeviceOperations) {
104-
super($iOSDebugService, $devicesService, $injector, $logger, $devicePlatformsConstants, $config, $usbLiveSyncService, $debugDataService, $platformService, $projectData, $options, $platformsData);
105+
super($iOSDebugService, $devicesService, $injector, $devicePlatformsConstants, $config, $usbLiveSyncService, $debugDataService, $platformService, $projectData, $options, $platformsData, $logger);
105106
$iosDeviceOperations.setShouldDispose(this.$options.justlaunch);
106107
}
107108

108109
public async canExecute(args: string[]): Promise<boolean> {
109110
return await super.canExecute(args) && await this.$platformService.validateOptions(this.$options.provision, this.$projectData, this.$platformsData.availablePlatforms.iOS);
110111
}
112+
113+
protected printDebugInformation(information: string[]): void {
114+
if (this.$options.chrome) {
115+
_.each(information, i => {
116+
this.$logger.info(`To start debugging, open the following URL in Chrome:${EOL}${i}${EOL}`.cyan);
117+
});
118+
}
119+
}
111120
}
112121

113122
$injector.registerCommand("debug|ios", DebugIOSCommand);
114123

115124
export class DebugAndroidCommand extends DebugPlatformCommand {
116-
constructor($androidDebugService: IPlatformDebugService,
125+
constructor($logger: ILogger,
126+
$androidDebugService: IPlatformDebugService,
117127
$devicesService: Mobile.IDevicesService,
118128
$injector: IInjector,
119-
$logger: ILogger,
120129
$devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
121130
$config: IConfiguration,
122131
$usbLiveSyncService: ILiveSyncService,
@@ -125,7 +134,7 @@ export class DebugAndroidCommand extends DebugPlatformCommand {
125134
$options: IOptions,
126135
$projectData: IProjectData,
127136
$platformsData: IPlatformsData) {
128-
super($androidDebugService, $devicesService, $injector, $logger, $devicePlatformsConstants, $config, $usbLiveSyncService, $debugDataService, $platformService, $projectData, $options, $platformsData);
137+
super($androidDebugService, $devicesService, $injector, $devicePlatformsConstants, $config, $usbLiveSyncService, $debugDataService, $platformService, $projectData, $options, $platformsData, $logger);
129138
}
130139

131140
public async canExecute(args: string[]): Promise<boolean> {

lib/definitions/debug.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
interface IDebugData {
22
deviceIdentifier: string;
33
applicationIdentifier: string;
4-
pathToAppPackage: string;
4+
pathToAppPackage?: string;
55
projectName?: string;
66
projectDir?: string;
77
}
@@ -17,7 +17,7 @@ interface IDebugOptions {
1717
}
1818

1919
interface IDebugDataService {
20-
createDebugData(debugService: IPlatformDebugService, options: IOptions, buildConfig: IBuildConfig): IDebugData;
20+
createDebugData(projectData: IProjectData, options: IOptions): IDebugData;
2121
}
2222

2323
interface IDebugService extends NodeJS.EventEmitter {

lib/device-sockets/ios/socket-proxy-factory.ts

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export class SocketProxyFactory extends EventEmitter implements ISocketProxyFact
5050
backendSocket.destroy();
5151
}
5252
});
53+
5354
backendSocket.on("close", () => {
5455
console.log("backend socket closed");
5556
if (!(<any>frontendSocket).destroyed) {

lib/services/android-debug-service.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,8 @@ class AndroidDebugService extends DebugServiceBase implements IPlatformDebugServ
128128
let startDebuggerCommand = ["am", "broadcast", "-a", `\"${packageName}-debug\"`, "--ez", "enable", "true"];
129129
await this.device.adb.executeShellCommand(startDebuggerCommand);
130130

131-
if (debugOptions.chrome) {
132-
let port = await this.getForwardedLocalDebugPortForPackageName(deviceId, packageName);
133-
return `chrome-devtools://devtools/bundled/inspector.html?experiments=true&ws=localhost:${port}`;
134-
}
131+
let port = await this.getForwardedLocalDebugPortForPackageName(deviceId, packageName);
132+
return `chrome-devtools://devtools/bundled/inspector.html?experiments=true&ws=localhost:${port}`;
135133
}
136134

137135
private detachDebugger(packageName: string): Promise<void> {

lib/services/debug-data-service.ts

+4-33
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,12 @@
11
export class DebugDataService implements IDebugDataService {
2-
constructor(private $projectData: IProjectData,
3-
private $platformService: IPlatformService,
4-
private $platformsData: IPlatformsData,
5-
private $mobileHelper: Mobile.IMobileHelper) { }
6-
7-
public createDebugData(debugService: IPlatformDebugService, options: IOptions, buildConfig: IBuildConfig): IDebugData {
8-
this.$projectData.initializeProjectData(options.path);
2+
public createDebugData(projectData: IProjectData, options: IOptions): IDebugData {
93
return {
10-
applicationIdentifier: this.$projectData.projectId,
11-
projectDir: this.$projectData.projectDir,
4+
applicationIdentifier: projectData.projectId,
5+
projectDir: projectData.projectDir,
126
deviceIdentifier: options.device,
13-
pathToAppPackage: this.getPathToAppPackage(debugService, options, buildConfig),
14-
projectName: this.$projectData.projectName
7+
projectName: projectData.projectName
158
};
169
}
17-
18-
private getPathToAppPackage(debugService: IPlatformDebugService, options: IOptions, buildConfig: IBuildConfig): string {
19-
if (this.$mobileHelper.isAndroidPlatform(debugService.platform)) {
20-
if (!options.start && !options.emulator) {
21-
const platformData = this.getPlatformData(debugService);
22-
23-
return this.$platformService.getLatestApplicationPackageForDevice(platformData, buildConfig).packageName;
24-
}
25-
} else if (this.$mobileHelper.isiOSPlatform(debugService.platform)) {
26-
if (options.emulator) {
27-
const platformData = this.getPlatformData(debugService);
28-
29-
return this.$platformService.getLatestApplicationPackageForEmulator(platformData, buildConfig).packageName;
30-
}
31-
}
32-
33-
return null;
34-
}
35-
36-
private getPlatformData(debugService: IPlatformDebugService): IPlatformData {
37-
return this.$platformsData.getPlatformData(debugService.platform, this.$projectData);
38-
}
3910
}
4011

4112
$injector.register("debugDataService", DebugDataService);

lib/services/test-execution-service.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,9 @@ class TestExecutionService implements ITestExecutionService {
7474
await this.$usbLiveSyncService.liveSync(platform, projectData);
7575

7676
if (this.$options.debugBrk) {
77-
const buildConfig: IBuildConfig = _.merge({ buildForDevice: this.$options.forDevice }, deployOptions);
7877
this.$logger.info('Starting debugger...');
7978
let debugService: IPlatformDebugService = this.$injector.resolve(`${platform}DebugService`);
80-
const debugData: IDebugData = this.$debugDataService.createDebugData(debugService, this.$options, buildConfig);
79+
const debugData = this.getDebugData(platform, projectData, deployOptions);
8180
await debugService.debugStart(debugData, this.$options);
8281
}
8382
resolve();
@@ -143,8 +142,7 @@ class TestExecutionService implements ITestExecutionService {
143142

144143
if (this.$options.debugBrk) {
145144
const debugService = this.getDebugService(platform);
146-
const buildConfig: IBuildConfig = _.merge({ buildForDevice: this.$options.forDevice }, deployOptions);
147-
const debugData = this.$debugDataService.createDebugData(debugService, this.$options, buildConfig);
145+
const debugData = this.getDebugData(platform, projectData, deployOptions);
148146
await debugService.debug(debugData, this.$options);
149147
} else {
150148
await this.$platformService.deployPlatform(platform, appFilesUpdaterOptions, deployOptions, projectData, { provision: this.$options.provision, sdk: this.$options.sdk });
@@ -247,5 +245,13 @@ class TestExecutionService implements ITestExecutionService {
247245

248246
return karmaConfig;
249247
}
248+
249+
private getDebugData(platform: string, projectData: IProjectData, deployOptions: IDeployPlatformOptions): IDebugData {
250+
const buildConfig: IBuildConfig = _.merge({ buildForDevice: this.$options.forDevice }, deployOptions);
251+
let debugData = this.$debugDataService.createDebugData(projectData, this.$options);
252+
debugData.pathToAppPackage = this.$platformService.lastOutputPath(platform, buildConfig, projectData);
253+
254+
return debugData;
255+
}
250256
}
251257
$injector.register('testExecutionService', TestExecutionService);

0 commit comments

Comments
 (0)