Skip to content

Commit 2135c65

Browse files
committed
fix: fix pr comments
1 parent d12300e commit 2135c65

File tree

17 files changed

+56
-137
lines changed

17 files changed

+56
-137
lines changed

lib/common/bootstrap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,4 @@ $injector.require("qr", "./services/qr");
122122
$injector.require("printPluginsService", "./services/plugins/print-plugins-service");
123123
$injector.require("npmPluginsService", "./services/plugins/npm-plugins-service");
124124

125-
$injector.require("lockfile", "./services/lockfile");
125+
$injector.require(["lockfile", "lockService"], "./services/lock-service");

lib/common/mobile/ios/device/ios-device.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class IOSDevice extends IOSDeviceBase {
1717
protected $errors: IErrors,
1818
private $injector: IInjector,
1919
protected $iOSDebuggerPortService: IIOSDebuggerPortService,
20-
protected $lockfile: ILockFile,
20+
protected $lockService: ILockService,
2121
private $iOSSocketRequestExecutor: IiOSSocketRequestExecutor,
2222
protected $processService: IProcessService,
2323
private $deviceLogProvider: Mobile.IDeviceLogProvider,

lib/common/mobile/ios/ios-device-base.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export abstract class IOSDeviceBase implements Mobile.IiOSDevice {
55
protected abstract $errors: IErrors;
66
protected abstract $iOSDebuggerPortService: IIOSDebuggerPortService;
77
protected abstract $processService: IProcessService;
8-
protected abstract $lockfile: ILockFile;
8+
protected abstract $lockService: ILockService;
99
abstract deviceInfo: Mobile.IDeviceInfo;
1010
abstract applicationManager: Mobile.IDeviceApplicationManager;
1111
abstract fileSystem: Mobile.IDeviceFileSystem;
@@ -25,7 +25,7 @@ export abstract class IOSDeviceBase implements Mobile.IiOSDevice {
2525
}
2626

2727
public async getSocket(appId: string): Promise<net.Socket> {
28-
return this.$lockfile.executeActionWithLock(async () => {
28+
return this.$lockService.executeActionWithLock(async () => {
2929
if (this.cachedSockets[appId]) {
3030
return this.cachedSockets[appId];
3131
}

lib/common/mobile/ios/simulator/ios-simulator-device.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class IOSSimulator extends IOSDeviceBase implements Mobile.IiOSDevice {
1414
constructor(private simulator: Mobile.IiSimDevice,
1515
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
1616
protected $errors: IErrors,
17-
protected $lockfile: ILockFile,
17+
protected $lockService: ILockService,
1818
private $injector: IInjector,
1919
protected $iOSDebuggerPortService: IIOSDebuggerPortService,
2020
private $iOSSimResolver: Mobile.IiOSSimResolver,

lib/common/services/lockfile.ts renamed to lib/common/services/lock-service.ts

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as lockfile from "lockfile";
22
import * as path from "path";
33
import { cache } from "../decorators";
44

5-
export class LockFile implements ILockFile {
5+
export class LockService implements ILockService {
66
private currentlyLockedFiles: string[] = [];
77

88
@cache()
@@ -14,10 +14,10 @@ export class LockFile implements ILockFile {
1414
return path.join(this.$settingsService.getProfileDir(), relativeLockFilePath);
1515
}
1616

17-
private get defaultLockParams(): ILockFileOptions {
17+
private get defaultLockParams(): ILockOptions {
1818
// We'll retry 100 times and time between retries is 100ms, i.e. full wait in case we are unable to get lock will be 10 seconds.
1919
// In case lock is older than the `stale` value, consider it stale and try to get a new lock.
20-
const lockParams: ILockFileOptions = {
20+
const lockParams: ILockOptions = {
2121
retryWait: 100,
2222
retries: 100,
2323
stale: 30 * 1000,
@@ -37,8 +37,19 @@ export class LockFile implements ILockFile {
3737
});
3838
}
3939

40-
public lock(lockFilePath?: string, lockFileOpts?: ILockFileOptions): Promise<string> {
41-
const { filePath, fileOpts } = this.getLockFileSettings(lockFilePath, lockFileOpts);
40+
public async executeActionWithLock<T>(action: () => Promise<T>, lockFilePath?: string, lockOpts?: ILockOptions): Promise<T> {
41+
const resolvedLockFilePath = await this.lock(lockFilePath, lockOpts);
42+
43+
try {
44+
const result = await action();
45+
return result;
46+
} finally {
47+
this.unlock(resolvedLockFilePath);
48+
}
49+
}
50+
51+
private lock(lockFilePath?: string, lockOpts?: ILockOptions): Promise<string> {
52+
const { filePath, fileOpts } = this.getLockFileSettings(lockFilePath, lockOpts);
4253
this.currentlyLockedFiles.push(filePath);
4354

4455
// Prevent ENOENT error when the dir, where lock should be created, does not exist.
@@ -51,30 +62,13 @@ export class LockFile implements ILockFile {
5162
});
5263
}
5364

54-
public async executeActionWithLock<T>(action: () => Promise<T>, lockFilePath?: string, lockFileOpts?: ILockFileOptions): Promise<T> {
55-
const resolvedLockFilePath = await this.lock(lockFilePath, lockFileOpts);
56-
57-
try {
58-
const result = await action();
59-
return result;
60-
} finally {
61-
this.unlock(resolvedLockFilePath);
62-
}
63-
}
64-
65-
public unlock(lockFilePath?: string): void {
65+
private unlock(lockFilePath?: string): void {
6666
const { filePath } = this.getLockFileSettings(lockFilePath);
6767
_.remove(this.currentlyLockedFiles, e => e === lockFilePath);
6868
lockfile.unlockSync(filePath);
6969
}
7070

71-
public check(lockFilePath?: string, lockFileOpts?: ILockFileOptions): boolean {
72-
const { filePath, fileOpts } = this.getLockFileSettings(lockFilePath, lockFileOpts);
73-
74-
return lockfile.checkSync(filePath, fileOpts);
75-
}
76-
77-
private getLockFileSettings(filePath?: string, fileOpts?: ILockFileOptions): { filePath: string, fileOpts: ILockFileOptions } {
71+
private getLockFileSettings(filePath?: string, fileOpts?: ILockOptions): { filePath: string, fileOpts: ILockOptions } {
7872
if (filePath && !path.isAbsolute(filePath)) {
7973
filePath = this.getAbsoluteLockFilePath(filePath);
8074
}
@@ -89,4 +83,6 @@ export class LockFile implements ILockFile {
8983
}
9084
}
9185

92-
$injector.register("lockfile", LockFile);
86+
$injector.register("lockService", LockService);
87+
// backwards compatibility
88+
$injector.register("lockfile", LockService);

lib/common/services/user-settings-service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class UserSettingsServiceBase implements IUserSettingsService {
1010

1111
constructor(userSettingsFilePath: string,
1212
protected $fs: IFileSystem,
13-
protected $lockfile: ILockFile,
13+
protected $lockService: ILockService,
1414
private $logger: ILogger) {
1515
this.userSettingsFilePath = userSettingsFilePath;
1616
}
@@ -21,7 +21,7 @@ export class UserSettingsServiceBase implements IUserSettingsService {
2121
return this.userSettingsData ? this.userSettingsData[settingName] : null;
2222
};
2323

24-
return this.$lockfile.executeActionWithLock<T>(action, this.lockFilePath);
24+
return this.$lockService.executeActionWithLock<T>(action, this.lockFilePath);
2525
}
2626

2727
public async saveSetting<T>(key: string, value: T): Promise<void> {
@@ -39,7 +39,7 @@ export class UserSettingsServiceBase implements IUserSettingsService {
3939
await this.saveSettings();
4040
};
4141

42-
return this.$lockfile.executeActionWithLock<void>(action, this.lockFilePath);
42+
return this.$lockService.executeActionWithLock<void>(action, this.lockFilePath);
4343
}
4444

4545
public saveSettings(data?: any): Promise<void> {
@@ -56,7 +56,7 @@ export class UserSettingsServiceBase implements IUserSettingsService {
5656
this.$fs.writeJson(this.userSettingsFilePath, this.userSettingsData);
5757
};
5858

59-
return this.$lockfile.executeActionWithLock<void>(action, this.lockFilePath);
59+
return this.$lockService.executeActionWithLock<void>(action, this.lockFilePath);
6060
}
6161

6262
// TODO: Remove Promise, reason: writeFile - blocked as other implementation of the interface has async operation.

lib/common/test/unit-tests/mobile/ios-simulator-discovery.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Yok } from "../../../yok";
44
import { assert } from "chai";
55
import { DeviceDiscoveryEventNames, CONNECTED_STATUS } from "../../../constants";
66
import { DevicePlatformsConstants } from "../../../mobile/device-platforms-constants";
7-
import { ErrorsStub, CommonLoggerStub, HooksServiceStub, LockFileStub } from "../stubs";
7+
import { ErrorsStub, CommonLoggerStub, HooksServiceStub, LockServiceStub } from "../stubs";
88
import { FileSystemStub } from "../../../../../test/stubs";
99

1010
let currentlyRunningSimulators: Mobile.IiSimDevice[];
@@ -16,7 +16,7 @@ function createTestInjector(): IInjector {
1616
injector.register("injector", injector);
1717
injector.register("errors", ErrorsStub);
1818
injector.register("iOSDebuggerPortService", {});
19-
injector.register("lockfile", LockFileStub);
19+
injector.register("lockService", LockServiceStub);
2020
injector.register("iOSSimResolver", {
2121
iOSSim: {
2222
getRunningSimulators: async () => currentlyRunningSimulators

lib/common/test/unit-tests/stubs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import * as util from "util";
44
import { EventEmitter } from "events";
55

6-
export class LockFileStub implements ILockFile {
7-
public async executeActionWithLock<T>(action: () => Promise<T>, lockFilePath?: string, lockFileOpts?: ILockFileOptions): Promise<T> {
6+
export class LockServiceStub implements ILockService {
7+
public async executeActionWithLock<T>(action: () => Promise<T>, lockFilePath?: string, lockOpts?: ILockOptions): Promise<T> {
88
const result = await action();
99
return result;
1010
}

lib/declarations.d.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -745,17 +745,11 @@ interface IAppDebugSocketProxyFactory extends NodeJS.EventEmitter {
745745
}
746746

747747
interface IiOSNotification extends NodeJS.EventEmitter {
748-
getWaitForDebug(projectId: string): string;
749748
getAttachRequest(projectId: string, deviceId: string): string;
750-
getAppLaunching(projectId: string): string;
751749
getReadyForAttach(projectId: string): string;
752-
getAttachAvailabilityQuery(projectId: string): string;
753-
getAlreadyConnected(projectId: string): string;
754-
getAttachAvailable(projectId: string): string;
755750
}
756751

757752
interface IiOSSocketRequestExecutor {
758-
executeLaunchRequest(device: Mobile.IiOSDevice, timeout: number, readyForAttachTimeout: number, projectId: string, debugOptions: IDebugOptions): Promise<void>;
759753
executeAttachRequest(device: Mobile.IiOSDevice, timeout: number, projectId: string): Promise<void>;
760754
}
761755

lib/definitions/debug.d.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,6 @@ interface IDebugOptions {
9696
* The sdk version of the emulator.
9797
*/
9898
sdk?: string;
99-
/**
100-
* Defines if the handshake(AppLaunching notification) between CLI and runtime should be executed. The handshake is not needed when CLI retries to attach to the debugger.
101-
*/
102-
skipHandshake?: boolean;
10399
/**
104100
* Forces the debugger attach event to be emitted.
105101
*/

0 commit comments

Comments
 (0)