Skip to content

Commit 0f9bec8

Browse files
committed
chore: stop webpack compiler when ctrl+c is pressed while executing tns preview --bundle command
1 parent 76ff072 commit 0f9bec8

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

lib/common

lib/definitions/livesync.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ interface ILiveSyncProcessInfo {
6666
isStopped: boolean;
6767
deviceDescriptors: ILiveSyncDeviceInfo[];
6868
currentSyncAction: Promise<any>;
69+
syncToPreviewApp: boolean;
6970
}
7071

7172
interface IOptionalOutputPath {

lib/services/livesync/livesync-service.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
7979

8080
liveSyncProcessInfo.deviceDescriptors = [];
8181

82+
if (liveSyncProcessInfo.syncToPreviewApp) {
83+
await this.$previewAppLiveSyncService.stopLiveSync();
84+
}
85+
8286
// Kill typescript watcher
8387
const projectData = this.$projectDataService.getProjectData(projectDir);
8488
await this.$hooksService.executeAfterHooks('watch', {
@@ -350,6 +354,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
350354
this.liveSyncProcessesInfo[projectDir].actionsChain = this.liveSyncProcessesInfo[projectDir].actionsChain || Promise.resolve();
351355
this.liveSyncProcessesInfo[projectDir].currentSyncAction = this.liveSyncProcessesInfo[projectDir].actionsChain;
352356
this.liveSyncProcessesInfo[projectDir].isStopped = false;
357+
this.liveSyncProcessesInfo[projectDir].syncToPreviewApp = liveSyncData.syncToPreviewApp;
353358

354359
const currentDeviceDescriptors = this.getLiveSyncDeviceDescriptors(projectDir);
355360
this.liveSyncProcessesInfo[projectDir].deviceDescriptors = _.uniqBy(currentDeviceDescriptors.concat(deviceDescriptors), deviceDescriptorPrimaryKey);
@@ -744,13 +749,6 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
744749
this.liveSyncProcessesInfo[liveSyncData.projectDir].timer = timeoutTimer;
745750

746751
this.$processService.attachToProcessExitSignals(this, () => {
747-
if (liveSyncData.syncToPreviewApp) {
748-
// Do not await here, we are in process exit's handler.
749-
/* tslint:disable:no-floating-promises */
750-
this.$previewAppLiveSyncService.stopLiveSync();
751-
/* tslint:enable:no-floating-promises */
752-
}
753-
754752
_.keys(this.liveSyncProcessesInfo).forEach(projectDir => {
755753
// Do not await here, we are in process exit's handler.
756754
/* tslint:disable:no-floating-promises */
@@ -768,7 +766,9 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
768766

769767
for (const projectDir in this.liveSyncProcessesInfo) {
770768
try {
771-
await this.stopLiveSync(projectDir, [device.deviceInfo.identifier]);
769+
if (_.find(this.liveSyncProcessesInfo[projectDir].deviceDescriptors, d => d.identifier === device.deviceInfo.identifier)) {
770+
await this.stopLiveSync(projectDir, [device.deviceInfo.identifier]);
771+
}
772772
} catch (err) {
773773
this.$logger.warn(`Unable to stop LiveSync operation for ${device.deviceInfo.identifier}.`, err);
774774
}

test/services/livesync-service.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ describe("liveSyncService", () => {
105105
},
106106
patterns: ["pattern"]
107107
},
108-
deviceDescriptors: []
108+
deviceDescriptors: [],
109+
syncToPreviewApp: false
109110
});
110111

111112
const getDeviceDescriptor = (identifier: string): ILiveSyncDeviceInfo => ({

0 commit comments

Comments
 (0)