Skip to content

Commit 2d32053

Browse files
fix: handle disposing of cleanup-process
Currently the cleanup-process is never disconnected from CLI as in the `commandsService` we set the `shouldDispose` property to false. This breaks short living commands like `tns create`, `tns devices`, etc. Handle the disposing similar to the other long living commands in CLI.
1 parent 2906020 commit 2d32053

File tree

7 files changed

+28
-15
lines changed

7 files changed

+28
-15
lines changed

lib/commands/debug.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,16 @@ export class DebugIOSCommand implements ICommand {
9191
private $sysInfo: ISysInfo,
9292
private $projectData: IProjectData,
9393
$iosDeviceOperations: IIOSDeviceOperations,
94-
$iOSSimulatorLogProvider: Mobile.IiOSSimulatorLogProvider) {
94+
$iOSSimulatorLogProvider: Mobile.IiOSSimulatorLogProvider,
95+
$cleanupService: ICleanupService) {
9596
this.$projectData.initializeProjectData();
9697
// Do not dispose ios-device-lib, so the process will remain alive and the debug application (NativeScript Inspector or Chrome DevTools) will be able to connect to the socket.
9798
// In case we dispose ios-device-lib, the socket will be closed and the code will fail when the debug application tries to read/send data to device socket.
9899
// That's why the `$ tns debug ios --justlaunch` command will not release the terminal.
99100
// In case we do not set it to false, the dispose will be called once the command finishes its execution, which will prevent the debugging.
100101
$iosDeviceOperations.setShouldDispose(false);
101102
$iOSSimulatorLogProvider.setShouldDispose(false);
103+
$cleanupService.setShouldDispose(false);
102104
}
103105

104106
public execute(args: string[]): Promise<void> {

lib/commands/preview.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ export class PreviewCommand implements ICommand {
1313
private $projectData: IProjectData,
1414
private $options: IOptions,
1515
private $previewAppLogProvider: IPreviewAppLogProvider,
16-
private $previewQrCodeService: IPreviewQrCodeService) {
17-
this.$analyticsService.setShouldDispose(this.$options.justlaunch || !this.$options.watch);
16+
private $previewQrCodeService: IPreviewQrCodeService,
17+
$cleanupService: ICleanupService) {
18+
this.$analyticsService.setShouldDispose(false);
19+
$cleanupService.setShouldDispose(false);
1820
}
1921

2022
public async execute(): Promise<void> {

lib/commands/test.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ abstract class TestCommandBase {
1010
protected abstract $options: IOptions;
1111
protected abstract $platformEnvironmentRequirements: IPlatformEnvironmentRequirements;
1212
protected abstract $errors: IErrors;
13+
protected abstract $cleanupService: ICleanupService;
1314

1415
async execute(args: string[]): Promise<void> {
1516
await this.$testExecutionService.startKarmaServer(this.platform, this.$projectData, this.projectFilesConfig);
@@ -18,6 +19,7 @@ abstract class TestCommandBase {
1819
async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
1920
this.$projectData.initializeProjectData();
2021
this.$analyticsService.setShouldDispose(this.$options.justlaunch || !this.$options.watch);
22+
this.$cleanupService.setShouldDispose(this.$options.justlaunch || !this.$options.watch);
2123
this.projectFilesConfig = helpers.getProjectFilesConfig({ isReleaseBuild: this.$options.release });
2224

2325
const output = await this.$platformEnvironmentRequirements.checkEnvironmentRequirements({
@@ -51,7 +53,8 @@ class TestAndroidCommand extends TestCommandBase implements ICommand {
5153
protected $analyticsService: IAnalyticsService,
5254
protected $options: IOptions,
5355
protected $platformEnvironmentRequirements: IPlatformEnvironmentRequirements,
54-
protected $errors: IErrors) {
56+
protected $errors: IErrors,
57+
protected $cleanupService: ICleanupService) {
5558
super();
5659
}
5760

@@ -65,7 +68,8 @@ class TestIosCommand extends TestCommandBase implements ICommand {
6568
protected $analyticsService: IAnalyticsService,
6669
protected $options: IOptions,
6770
protected $platformEnvironmentRequirements: IPlatformEnvironmentRequirements,
68-
protected $errors: IErrors) {
71+
protected $errors: IErrors,
72+
protected $cleanupService: ICleanupService) {
6973
super();
7074
}
7175

lib/common/commands/device/device-log-stream.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ export class OpenDeviceLogStreamCommand implements ICommand {
77
private $options: IOptions,
88
private $deviceLogProvider: Mobile.IDeviceLogProvider,
99
private $loggingLevels: Mobile.ILoggingLevels,
10-
$iOSSimulatorLogProvider: Mobile.IiOSSimulatorLogProvider) {
10+
$iOSSimulatorLogProvider: Mobile.IiOSSimulatorLogProvider,
11+
$cleanupService: ICleanupService) {
1112
$iOSSimulatorLogProvider.setShouldDispose(false);
13+
$cleanupService.setShouldDispose(false);
1214
}
1315

1416
allowedParameters: ICommandParameter[] = [];

lib/common/services/commands-service.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ export class CommandsService implements ICommandsService {
2828
private $helpService: IHelpService,
2929
private $extensibilityService: IExtensibilityService,
3030
private $optionsTracker: IOptionsTracker,
31-
private $projectDataService: IProjectDataService,
32-
private $cleanupService: ICleanupService) {
31+
private $projectDataService: IProjectDataService) {
3332
let projectData = null;
3433
try {
3534
projectData = this.$projectDataService.getProjectData();
@@ -38,7 +37,6 @@ export class CommandsService implements ICommandsService {
3837
}
3938

4039
this.$options.setupOptions(projectData);
41-
this.$cleanupService.setShouldDispose(this.$options.justlaunch || !this.$options.watch);
4240
}
4341

4442
public allCommands(opts: { includeDevCommands: boolean }): string[] {

lib/helpers/livesync-command-helper.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
1515
private $bundleValidatorHelper: IBundleValidatorHelper,
1616
private $errors: IErrors,
1717
private $iOSSimulatorLogProvider: Mobile.IiOSSimulatorLogProvider,
18-
private $logger: ILogger) {
19-
this.$analyticsService.setShouldDispose(this.$options.justlaunch || !this.$options.watch);
18+
private $logger: ILogger,
19+
private $cleanupService: ICleanupService) {
2020
}
2121

2222
public getPlatformsForOperation(platform: string): string[] {
@@ -59,9 +59,14 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
5959

6060
const workingWithiOSDevices = !platform || this.$mobileHelper.isiOSPlatform(platform);
6161
const shouldKeepProcessAlive = this.$options.watch || !this.$options.justlaunch;
62-
if (workingWithiOSDevices && shouldKeepProcessAlive) {
63-
this.$iosDeviceOperations.setShouldDispose(false);
64-
this.$iOSSimulatorLogProvider.setShouldDispose(false);
62+
if (shouldKeepProcessAlive) {
63+
this.$analyticsService.setShouldDispose(false);
64+
this.$cleanupService.setShouldDispose(false);
65+
66+
if (workingWithiOSDevices) {
67+
this.$iosDeviceOperations.setShouldDispose(false);
68+
this.$iOSSimulatorLogProvider.setShouldDispose(false);
69+
}
6570
}
6671

6772
if (this.$options.release) {

lib/services/cleanup-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class CleanupService implements ICleanupService {
1313
this.pathToCleanupLogFile = $options.cleanupLogFile;
1414
}
1515

16-
public shouldDispose = false;
16+
public shouldDispose = true;
1717

1818
public async addCleanupCommand(commandInfo: ISpawnCommandInfo): Promise<void> {
1919
const cleanupProcess = await this.getCleanupProcess();

0 commit comments

Comments
 (0)