diff --git a/lib/definitions/debug.d.ts b/lib/definitions/debug.d.ts index 5afa583073..6254473cbf 100644 --- a/lib/definitions/debug.d.ts +++ b/lib/definitions/debug.d.ts @@ -1,7 +1,7 @@ /** * Describes information for starting debug process. */ -interface IDebugData extends Mobile.IDeviceIdentifier { +interface IDebugData extends Mobile.IDeviceIdentifier, IProjectDir { /** * Application identifier of the app that it will be debugged. */ @@ -16,11 +16,6 @@ interface IDebugData extends Mobile.IDeviceIdentifier { * The name of the application, for example `MyProject`. */ projectName?: string; - - /** - * Path to project. - */ - projectDir?: string; } /** diff --git a/lib/definitions/ios-debugger-port-service.d.ts b/lib/definitions/ios-debugger-port-service.d.ts index 326df11e75..a81391e8fd 100644 --- a/lib/definitions/ios-debugger-port-service.d.ts +++ b/lib/definitions/ios-debugger-port-service.d.ts @@ -1,4 +1,4 @@ -interface IIOSDebuggerPortInputData { +interface IIOSDebuggerPortInputData extends IProjectDir { deviceId: string; appId: string; } @@ -21,8 +21,10 @@ interface IIOSDebuggerPortService { /** * Attaches on DEBUGGER_PORT_FOUND event and STARTING_IOS_APPLICATION events * In case when DEBUGGER_PORT_FOUND event is emitted, stores the port and clears the timeout if such. - * In case when STARTING_IOS_APPLICATION event is emiited, sets the port to null and add timeout for 5000 miliseconds which checks if port is null and prints a warning. - * @param {Mobile.IDevice} device - Describes the device which logs should be parsed. + * In case when STARTING_IOS_APPLICATION event is emitted, sets the port to null and add timeout for 5000 miliseconds which checks if port is null and prints a warning. + * @param {Mobile.IDevice} device - Describes the device which logs should be parsed. + * @param {IProjectDir} data - Object that has a projectDir property. + * @returns {void} */ - attachToDebuggerPortFoundEvent(device: Mobile.IDevice): void; + attachToDebuggerPortFoundEvent(device: Mobile.IDevice, data: IProjectDir): void; } \ No newline at end of file diff --git a/lib/definitions/ios-log-parser-service.d.ts b/lib/definitions/ios-log-parser-service.d.ts index 1a46f0011f..72b86615be 100644 --- a/lib/definitions/ios-log-parser-service.d.ts +++ b/lib/definitions/ios-log-parser-service.d.ts @@ -3,5 +3,5 @@ interface IIOSLogParserService extends NodeJS.EventEmitter { * Starts looking for debugger port. Attaches on device logs and processes them. In case when port is found, DEBUGGER_PORT_FOUND event is emitted. * @param {Mobile.IDevice} device - Describes the device which logs will be processed. */ - startParsingLog(device: Mobile.IDevice): void; + startParsingLog(device: Mobile.IDevice, data: IProjectName): void; } diff --git a/lib/definitions/project.d.ts b/lib/definitions/project.d.ts index 93ba8cc14a..9f101446af 100644 --- a/lib/definitions/project.d.ts +++ b/lib/definitions/project.d.ts @@ -1,13 +1,11 @@ interface IProjectName { - projectName: string; -} - -interface IProjectSettingsBase extends IProjectName { /** * Name of the newly created application. */ projectName: string; +} +interface IProjectSettingsBase extends IProjectName { /** * Defines whether the `npm install` command should be executed with `--ignore-scripts` option. * When it is passed, all scripts (postinstall for example) will not be executed. diff --git a/lib/services/ios-debug-service.ts b/lib/services/ios-debug-service.ts index 553110e94a..7295caa9ac 100644 --- a/lib/services/ios-debug-service.ts +++ b/lib/services/ios-debug-service.ts @@ -143,7 +143,7 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS private async emulatorStart(debugData: IDebugData, debugOptions: IDebugOptions): Promise { const device = await this.$devicesService.getDevice(debugData.deviceIdentifier); - this.$iOSDebuggerPortService.attachToDebuggerPortFoundEvent(device); + this.$iOSDebuggerPortService.attachToDebuggerPortFoundEvent(device, debugData); const result = await this.wireDebuggerClient(debugData, debugOptions); const attachRequestMessage = this.$iOSNotification.getAttachRequest(debugData.applicationIdentifier, debugData.deviceIdentifier); @@ -192,7 +192,7 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS } private async deviceStartCore(device: Mobile.IiOSDevice, debugData: IDebugData, debugOptions: IDebugOptions): Promise { - this.$iOSDebuggerPortService.attachToDebuggerPortFoundEvent(device); + this.$iOSDebuggerPortService.attachToDebuggerPortFoundEvent(device, debugData); await this.$iOSSocketRequestExecutor.executeAttachRequest(device, AWAIT_NOTIFICATION_TIMEOUT_SECONDS, debugData.applicationIdentifier); return this.wireDebuggerClient(debugData, debugOptions, device); } @@ -231,7 +231,7 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS private getSocketFactory(debugData: IDebugData, device?: Mobile.IiOSDevice): () => Promise { const factory = async () => { - const port = await this.$iOSDebuggerPortService.getPort({ deviceId: debugData.deviceIdentifier, appId: debugData.applicationIdentifier }); + const port = await this.$iOSDebuggerPortService.getPort({ projectDir: debugData.projectDir, deviceId: debugData.deviceIdentifier, appId: debugData.applicationIdentifier }); if (!port) { this.$errors.fail("NativeScript debugger was not able to get inspector socket port."); } diff --git a/lib/services/ios-debugger-port-service.ts b/lib/services/ios-debugger-port-service.ts index 64c4dc830f..f7f2ebc19c 100644 --- a/lib/services/ios-debugger-port-service.ts +++ b/lib/services/ios-debugger-port-service.ts @@ -10,12 +10,12 @@ export class IOSDebuggerPortService implements IIOSDebuggerPortService { constructor(private $iOSLogParserService: IIOSLogParserService, private $iOSProjectService: IPlatformProjectService, private $iOSNotification: IiOSNotification, - private $logger: ILogger, - private $projectData: IProjectData) { } + private $projectDataService: IProjectDataService, + private $logger: ILogger) { } public getPort(data: IIOSDebuggerPortInputData): Promise { return new Promise((resolve, reject) => { - if (!this.canStartLookingForDebuggerPort()) { + if (!this.canStartLookingForDebuggerPort(data)) { resolve(IOSDebuggerPortService.DEFAULT_PORT); return; } @@ -36,19 +36,21 @@ export class IOSDebuggerPortService implements IIOSDebuggerPortService { }); } - public attachToDebuggerPortFoundEvent(device: Mobile.IDevice): void { - if (!this.canStartLookingForDebuggerPort()) { + public attachToDebuggerPortFoundEvent(device: Mobile.IDevice, data: IProjectDir): void { + const projectData = this.$projectDataService.getProjectData(data && data.projectDir); + if (!this.canStartLookingForDebuggerPort(projectData)) { return; } this.attachToDebuggerPortFoundEventCore(); this.attachToAttachRequestEvent(device); - this.$iOSLogParserService.startParsingLog(device); + this.$iOSLogParserService.startParsingLog(device, projectData); } - private canStartLookingForDebuggerPort(): boolean { - const frameworkVersion = this.$iOSProjectService.getFrameworkVersion(this.$projectData); + private canStartLookingForDebuggerPort(data: IProjectDir): boolean { + const projectData = this.$projectDataService.getProjectData(data && data.projectDir); + const frameworkVersion = this.$iOSProjectService.getFrameworkVersion(projectData); return semver.gt(frameworkVersion, IOSDebuggerPortService.MIN_REQUIRED_FRAMEWORK_VERSION); } diff --git a/lib/services/ios-log-parser-service.ts b/lib/services/ios-log-parser-service.ts index efd9d75fec..dad99d6904 100644 --- a/lib/services/ios-log-parser-service.ts +++ b/lib/services/ios-log-parser-service.ts @@ -9,13 +9,12 @@ export class IOSLogParserService extends EventEmitter implements IIOSLogParserSe constructor(private $deviceLogProvider: Mobile.IDeviceLogProvider, private $iosDeviceOperations: IIOSDeviceOperations, private $iOSSimulatorLogProvider: Mobile.IiOSSimulatorLogProvider, - private $logger: ILogger, - private $projectData: IProjectData) { + private $logger: ILogger) { super(); } - public startParsingLog(device: Mobile.IDevice): void { - this.$deviceLogProvider.setProjectNameForDevice(device.deviceInfo.identifier, this.$projectData.projectName); + public startParsingLog(device: Mobile.IDevice, data: IProjectName): void { + this.$deviceLogProvider.setProjectNameForDevice(device.deviceInfo.identifier, data.projectName); if (!this.startedDeviceLogInstances[device.deviceInfo.identifier]) { this.startParsingLogCore(device); diff --git a/lib/services/livesync/android-livesync-service.ts b/lib/services/livesync/android-livesync-service.ts index d9416643c5..759683c444 100644 --- a/lib/services/livesync/android-livesync-service.ts +++ b/lib/services/livesync/android-livesync-service.ts @@ -13,8 +13,8 @@ export class AndroidLiveSyncService extends PlatformLiveSyncServiceBase implemen super($fs, $logger, $platformsData, $projectFilesManager, $devicePathProvider, $projectFilesProvider); } - protected _getDeviceLiveSyncService(device: Mobile.IDevice): INativeScriptDeviceLiveSyncService { - const service = this.$injector.resolve(AndroidDeviceLiveSyncService, { _device: device }); + protected _getDeviceLiveSyncService(device: Mobile.IDevice, data: IProjectDir): INativeScriptDeviceLiveSyncService { + const service = this.$injector.resolve(AndroidDeviceLiveSyncService, { _device: device, data }); return service; } } diff --git a/lib/services/livesync/ios-device-livesync-service.ts b/lib/services/livesync/ios-device-livesync-service.ts index 80a4698c5a..562fbb935d 100644 --- a/lib/services/livesync/ios-device-livesync-service.ts +++ b/lib/services/livesync/ios-device-livesync-service.ts @@ -10,6 +10,7 @@ export class IOSDeviceLiveSyncService extends DeviceLiveSyncServiceBase implemen private device: Mobile.IiOSDevice; constructor(_device: Mobile.IiOSDevice, + data: IProjectDir, private $iOSSocketRequestExecutor: IiOSSocketRequestExecutor, private $iOSNotification: IiOSNotification, private $iOSEmulatorServices: Mobile.IiOSSimulatorService, @@ -19,25 +20,25 @@ export class IOSDeviceLiveSyncService extends DeviceLiveSyncServiceBase implemen private $processService: IProcessService, protected $platformsData: IPlatformsData) { super($platformsData); - this.$iOSDebuggerPortService.attachToDebuggerPortFoundEvent(_device); + this.$iOSDebuggerPortService.attachToDebuggerPortFoundEvent(_device, data); this.device = _device; } - private async setupSocketIfNeeded(appId: string): Promise { + private async setupSocketIfNeeded(projectData: IProjectData): Promise { if (this.socket) { return true; } if (this.device.isEmulator) { - await this.$iOSEmulatorServices.postDarwinNotification(this.$iOSNotification.getAttachRequest(appId, this.device.deviceInfo.identifier), this.device.deviceInfo.identifier); - const port = await this.$iOSDebuggerPortService.getPort({ deviceId: this.device.deviceInfo.identifier, appId }); + await this.$iOSEmulatorServices.postDarwinNotification(this.$iOSNotification.getAttachRequest(projectData.projectId, this.device.deviceInfo.identifier), this.device.deviceInfo.identifier); + const port = await this.$iOSDebuggerPortService.getPort({ projectDir: projectData.projectDir, deviceId: this.device.deviceInfo.identifier, appId: projectData.projectId }); this.socket = await this.$iOSEmulatorServices.connectToPort({ port }); if (!this.socket) { return false; } } else { - await this.$iOSSocketRequestExecutor.executeAttachRequest(this.device, constants.AWAIT_NOTIFICATION_TIMEOUT_SECONDS, appId); - const port = await this.$iOSDebuggerPortService.getPort({ deviceId: this.device.deviceInfo.identifier, appId }); + await this.$iOSSocketRequestExecutor.executeAttachRequest(this.device, constants.AWAIT_NOTIFICATION_TIMEOUT_SECONDS, projectData.projectId); + const port = await this.$iOSDebuggerPortService.getPort({ projectDir: projectData.projectDir, deviceId: this.device.deviceInfo.identifier, appId: projectData.projectId }); this.socket = await this.device.connectToPort(port); } @@ -70,7 +71,7 @@ export class IOSDeviceLiveSyncService extends DeviceLiveSyncServiceBase implemen return; } - if (await this.setupSocketIfNeeded(projectData.projectId)) { + if (await this.setupSocketIfNeeded(projectData)) { await this.liveEdit(scriptFiles); await this.reloadPage(deviceAppData, otherFiles); } else { diff --git a/lib/services/livesync/ios-livesync-service.ts b/lib/services/livesync/ios-livesync-service.ts index 31f66b768f..1970de3531 100644 --- a/lib/services/livesync/ios-livesync-service.ts +++ b/lib/services/livesync/ios-livesync-service.ts @@ -25,7 +25,7 @@ export class IOSLiveSyncService extends PlatformLiveSyncServiceBase implements I return super.fullSync(syncInfo); } - this.$iOSDebuggerPortService.attachToDebuggerPortFoundEvent(device); + this.$iOSDebuggerPortService.attachToDebuggerPortFoundEvent(device, syncInfo.projectData); const projectData = syncInfo.projectData; const platformData = this.$platformsData.getPlatformData(device.deviceInfo.platform, projectData); @@ -70,8 +70,8 @@ export class IOSLiveSyncService extends PlatformLiveSyncServiceBase implements I } } - protected _getDeviceLiveSyncService(device: Mobile.IDevice): INativeScriptDeviceLiveSyncService { - const service = this.$injector.resolve(IOSDeviceLiveSyncService, { _device: device }); + protected _getDeviceLiveSyncService(device: Mobile.IDevice, data: IProjectDir): INativeScriptDeviceLiveSyncService { + const service = this.$injector.resolve(IOSDeviceLiveSyncService, { _device: device, data }); return service; } } diff --git a/lib/services/livesync/platform-livesync-service-base.ts b/lib/services/livesync/platform-livesync-service-base.ts index ce27af8453..df1a2f8bdd 100644 --- a/lib/services/livesync/platform-livesync-service-base.ts +++ b/lib/services/livesync/platform-livesync-service-base.ts @@ -12,20 +12,20 @@ export abstract class PlatformLiveSyncServiceBase { private $devicePathProvider: IDevicePathProvider, private $projectFilesProvider: IProjectFilesProvider) { } - public getDeviceLiveSyncService(device: Mobile.IDevice, applicationIdentifier: string): INativeScriptDeviceLiveSyncService { - const key = device.deviceInfo.identifier + applicationIdentifier; + public getDeviceLiveSyncService(device: Mobile.IDevice, projectData: IProjectData): INativeScriptDeviceLiveSyncService { + const key = device.deviceInfo.identifier + projectData.projectId; if (!this._deviceLiveSyncServicesCache[key]) { - this._deviceLiveSyncServicesCache[key] = this._getDeviceLiveSyncService(device); + this._deviceLiveSyncServicesCache[key] = this._getDeviceLiveSyncService(device, projectData); } return this._deviceLiveSyncServicesCache[key]; } - protected abstract _getDeviceLiveSyncService(device: Mobile.IDevice): INativeScriptDeviceLiveSyncService; + protected abstract _getDeviceLiveSyncService(device: Mobile.IDevice, data: IProjectDir): INativeScriptDeviceLiveSyncService; public async refreshApplication(projectData: IProjectData, liveSyncInfo: ILiveSyncResultInfo): Promise { if (liveSyncInfo.isFullSync || liveSyncInfo.modifiedFilesData.length) { - const deviceLiveSyncService = this.getDeviceLiveSyncService(liveSyncInfo.deviceAppData.device, projectData.projectId); + const deviceLiveSyncService = this.getDeviceLiveSyncService(liveSyncInfo.deviceAppData.device, projectData); this.$logger.info("Refreshing application..."); await deviceLiveSyncService.refreshApplication(projectData, liveSyncInfo); } @@ -34,7 +34,7 @@ export abstract class PlatformLiveSyncServiceBase { public async fullSync(syncInfo: IFullSyncInfo): Promise { const projectData = syncInfo.projectData; const device = syncInfo.device; - const deviceLiveSyncService = this.getDeviceLiveSyncService(device, syncInfo.projectData.projectId); + const deviceLiveSyncService = this.getDeviceLiveSyncService(device, syncInfo.projectData); const platformData = this.$platformsData.getPlatformData(device.deviceInfo.platform, projectData); const deviceAppData = await this.getAppData(syncInfo); @@ -93,7 +93,7 @@ export abstract class PlatformLiveSyncServiceBase { const localToDevicePaths = await this.$projectFilesManager.createLocalToDevicePaths(deviceAppData, projectFilesPath, mappedFiles, []); modifiedLocalToDevicePaths.push(...localToDevicePaths); - const deviceLiveSyncService = this.getDeviceLiveSyncService(device, projectData.projectId); + const deviceLiveSyncService = this.getDeviceLiveSyncService(device, projectData); await deviceLiveSyncService.removeFiles(deviceAppData, localToDevicePaths); } diff --git a/test/services/ios-debugger-port-service.ts b/test/services/ios-debugger-port-service.ts index a1a8cd2950..72b0e502b4 100644 --- a/test/services/ios-debugger-port-service.ts +++ b/test/services/ios-debugger-port-service.ts @@ -47,9 +47,11 @@ function createTestInjector() { injector.register("processService", { attachToProcessExitSignals: () => ({}) }); - injector.register("projectData", { - projectName: "test", - projectId: appId + injector.register("projectDataService", { + getProjectData: (projectDir: string) => ({ + projectName: "test", + projectId: appId + }) }); injector.register("iOSNotification", DeviceApplicationManagerMock); @@ -140,9 +142,13 @@ describe("iOSDebuggerPortService", () => { } ]; + const mockProjectDirObj = { + projectDir: "/Users/username/projectdir" + }; + _.each(testCases, testCase => { it(testCase.name, async () => { - iOSDebuggerPortService.attachToDebuggerPortFoundEvent(device); + iOSDebuggerPortService.attachToDebuggerPortFoundEvent(device, mockProjectDirObj); if (testCase.emitStartingIOSApplicationEvent) { emitStartingIOSApplicationEvent(); } @@ -150,13 +156,13 @@ describe("iOSDebuggerPortService", () => { emitDeviceLog(getDebuggerPortMessage(testCase.emittedPort)); } - const promise = iOSDebuggerPortService.getPort({ deviceId: deviceId, appId: appId }); + const promise = iOSDebuggerPortService.getPort({ deviceId: deviceId, appId: appId, projectDir: mockProjectDirObj.projectDir }); clock.tick(10000); const port = await promise; assert.deepEqual(port, testCase.emittedPort); }); it(`${testCase.name} for multiline debugger port message.`, async () => { - iOSDebuggerPortService.attachToDebuggerPortFoundEvent(device); + iOSDebuggerPortService.attachToDebuggerPortFoundEvent(device, mockProjectDirObj); if (testCase.emitStartingIOSApplicationEvent) { emitStartingIOSApplicationEvent(); } @@ -164,7 +170,7 @@ describe("iOSDebuggerPortService", () => { emitDeviceLog(getMultilineDebuggerPortMessage(testCase.emittedPort)); } - const promise = iOSDebuggerPortService.getPort({ deviceId: deviceId, appId: appId }); + const promise = iOSDebuggerPortService.getPort({ deviceId: deviceId, appId: appId, projectDir: mockProjectDirObj.projectDir }); clock.tick(10000); const port = await promise; assert.deepEqual(port, testCase.emittedPort); diff --git a/test/services/ios-log-parser-service.ts b/test/services/ios-log-parser-service.ts index 937f0c9470..df124a8bc8 100644 --- a/test/services/ios-log-parser-service.ts +++ b/test/services/ios-log-parser-service.ts @@ -35,9 +35,11 @@ function createTestInjector() { injector.register("processService", { attachToProcessExitSignals: () => ({}) }); - injector.register("projectData", { - projectName: "test", - projectId: appId + injector.register("projectDataService", { + getProjectData: (projectDir: string) => ({ + projectName: "test", + projectId: appId + }) }); return injector; @@ -77,12 +79,16 @@ describe("iOSLogParserService", () => { }); } + const mockProjectNameObj: IProjectName = { + projectName: "projectName" + }; + describe("startLookingForDebuggerPort", () => { it(`should emit ${DEBUGGER_PORT_FOUND_EVENT_NAME} event`, async () => { const emittedMessagesCount = 1; const promise = attachOnDebuggerFoundEvent(emittedMessagesCount); - iOSLogParserService.startParsingLog(device); + iOSLogParserService.startParsingLog(device, mockProjectNameObj); emitDeviceLog("test message"); emitDeviceLog(getDebuggerPortMessage(18181)); @@ -95,7 +101,7 @@ describe("iOSLogParserService", () => { const emittedMessagesCount = 5; const promise = attachOnDebuggerFoundEvent(emittedMessagesCount); - iOSLogParserService.startParsingLog(device); + iOSLogParserService.startParsingLog(device, mockProjectNameObj); emitDeviceLog(getDebuggerPortMessage(18181)); emitDeviceLog(getDebuggerPortMessage(18181)); emitDeviceLog(getDebuggerPortMessage(18181)); @@ -115,7 +121,7 @@ describe("iOSLogParserService", () => { const emittedMessagesCount = 5; const promise = attachOnDebuggerFoundEvent(emittedMessagesCount); - iOSLogParserService.startParsingLog(device); + iOSLogParserService.startParsingLog(device, mockProjectNameObj); emitDeviceLog(getDebuggerPortMessage(45898)); emitDeviceLog(getDebuggerPortMessage(1809)); emitDeviceLog(getDebuggerPortMessage(65072)); @@ -136,7 +142,7 @@ describe("iOSLogParserService", () => { iOSLogParserService.on(DEBUGGER_PORT_FOUND_EVENT_NAME, (data: IIOSDebuggerPortData) => isDebuggedPortFound = true); - iOSLogParserService.startParsingLog(device); + iOSLogParserService.startParsingLog(device, mockProjectNameObj); emitDeviceLog("some test message"); emitDeviceLog("another test message");