Skip to content

Commit 3933a0f

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

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
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

+12-8
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
5151
const liveSyncProcessInfo = this.liveSyncProcessesInfo[projectDir];
5252

5353
if (liveSyncProcessInfo) {
54+
const projectData = this.$projectDataService.getProjectData(projectDir);
55+
56+
if (liveSyncProcessInfo.syncToPreviewApp) {
57+
await this.$hooksService.executeAfterHooks('watch', {
58+
hookArgs: {
59+
projectData
60+
}
61+
});
62+
await this.$previewAppLiveSyncService.stopLiveSync();
63+
}
64+
5465
// In case we are coming from error during livesync, the current action is the one that erred (but we are still executing it),
5566
// so we cannot await it as this will cause infinite loop.
5667
const shouldAwaitPendingOperation = !stopOptions || stopOptions.shouldAwaitAllActions;
@@ -80,7 +91,6 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
8091
liveSyncProcessInfo.deviceDescriptors = [];
8192

8293
// Kill typescript watcher
83-
const projectData = this.$projectDataService.getProjectData(projectDir);
8494
await this.$hooksService.executeAfterHooks('watch', {
8595
hookArgs: {
8696
projectData
@@ -350,6 +360,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
350360
this.liveSyncProcessesInfo[projectDir].actionsChain = this.liveSyncProcessesInfo[projectDir].actionsChain || Promise.resolve();
351361
this.liveSyncProcessesInfo[projectDir].currentSyncAction = this.liveSyncProcessesInfo[projectDir].actionsChain;
352362
this.liveSyncProcessesInfo[projectDir].isStopped = false;
363+
this.liveSyncProcessesInfo[projectDir].syncToPreviewApp = liveSyncData.syncToPreviewApp;
353364

354365
const currentDeviceDescriptors = this.getLiveSyncDeviceDescriptors(projectDir);
355366
this.liveSyncProcessesInfo[projectDir].deviceDescriptors = _.uniqBy(currentDeviceDescriptors.concat(deviceDescriptors), deviceDescriptorPrimaryKey);
@@ -744,13 +755,6 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
744755
this.liveSyncProcessesInfo[liveSyncData.projectDir].timer = timeoutTimer;
745756

746757
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-
754758
_.keys(this.liveSyncProcessesInfo).forEach(projectDir => {
755759
// Do not await here, we are in process exit's handler.
756760
/* tslint:disable:no-floating-promises */

0 commit comments

Comments
 (0)