From 0f9bec8662d2dbd638da0c85ff32cbc78fd4d6dd Mon Sep 17 00:00:00 2001 From: fatme Date: Mon, 17 Sep 2018 09:01:59 +0300 Subject: [PATCH] chore: stop webpack compiler when ctrl+c is pressed while executing `tns preview --bundle` command --- lib/common | 2 +- lib/definitions/livesync.d.ts | 1 + lib/services/livesync/livesync-service.ts | 16 ++++++++-------- test/services/livesync-service.ts | 3 ++- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/common b/lib/common index c78d5bdf7b..0a906cdc0c 160000 --- a/lib/common +++ b/lib/common @@ -1 +1 @@ -Subproject commit c78d5bdf7ba550fe19812e39f08e3690834149d5 +Subproject commit 0a906cdc0ca944811229636db1715c429f0de9c6 diff --git a/lib/definitions/livesync.d.ts b/lib/definitions/livesync.d.ts index b160c6034b..e1bcd70ae1 100644 --- a/lib/definitions/livesync.d.ts +++ b/lib/definitions/livesync.d.ts @@ -66,6 +66,7 @@ interface ILiveSyncProcessInfo { isStopped: boolean; deviceDescriptors: ILiveSyncDeviceInfo[]; currentSyncAction: Promise; + syncToPreviewApp: boolean; } interface IOptionalOutputPath { diff --git a/lib/services/livesync/livesync-service.ts b/lib/services/livesync/livesync-service.ts index a7328c8c9d..63a83bcb77 100644 --- a/lib/services/livesync/livesync-service.ts +++ b/lib/services/livesync/livesync-service.ts @@ -79,6 +79,10 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi liveSyncProcessInfo.deviceDescriptors = []; + if (liveSyncProcessInfo.syncToPreviewApp) { + await this.$previewAppLiveSyncService.stopLiveSync(); + } + // Kill typescript watcher const projectData = this.$projectDataService.getProjectData(projectDir); await this.$hooksService.executeAfterHooks('watch', { @@ -350,6 +354,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi this.liveSyncProcessesInfo[projectDir].actionsChain = this.liveSyncProcessesInfo[projectDir].actionsChain || Promise.resolve(); this.liveSyncProcessesInfo[projectDir].currentSyncAction = this.liveSyncProcessesInfo[projectDir].actionsChain; this.liveSyncProcessesInfo[projectDir].isStopped = false; + this.liveSyncProcessesInfo[projectDir].syncToPreviewApp = liveSyncData.syncToPreviewApp; const currentDeviceDescriptors = this.getLiveSyncDeviceDescriptors(projectDir); this.liveSyncProcessesInfo[projectDir].deviceDescriptors = _.uniqBy(currentDeviceDescriptors.concat(deviceDescriptors), deviceDescriptorPrimaryKey); @@ -744,13 +749,6 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi this.liveSyncProcessesInfo[liveSyncData.projectDir].timer = timeoutTimer; this.$processService.attachToProcessExitSignals(this, () => { - if (liveSyncData.syncToPreviewApp) { - // Do not await here, we are in process exit's handler. - /* tslint:disable:no-floating-promises */ - this.$previewAppLiveSyncService.stopLiveSync(); - /* tslint:enable:no-floating-promises */ - } - _.keys(this.liveSyncProcessesInfo).forEach(projectDir => { // Do not await here, we are in process exit's handler. /* tslint:disable:no-floating-promises */ @@ -768,7 +766,9 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi for (const projectDir in this.liveSyncProcessesInfo) { try { - await this.stopLiveSync(projectDir, [device.deviceInfo.identifier]); + if (_.find(this.liveSyncProcessesInfo[projectDir].deviceDescriptors, d => d.identifier === device.deviceInfo.identifier)) { + await this.stopLiveSync(projectDir, [device.deviceInfo.identifier]); + } } catch (err) { this.$logger.warn(`Unable to stop LiveSync operation for ${device.deviceInfo.identifier}.`, err); } diff --git a/test/services/livesync-service.ts b/test/services/livesync-service.ts index 5ce618c523..d4ac93bc7f 100644 --- a/test/services/livesync-service.ts +++ b/test/services/livesync-service.ts @@ -105,7 +105,8 @@ describe("liveSyncService", () => { }, patterns: ["pattern"] }, - deviceDescriptors: [] + deviceDescriptors: [], + syncToPreviewApp: false }); const getDeviceDescriptor = (identifier: string): ILiveSyncDeviceInfo => ({