Skip to content

Commit 092a06b

Browse files
chore: remove gaze dependency
Remove `gaze` dependency, which was used for the Cancellation service - use chokidar instead as we already use it for LiveSync watcher and there's no point of having two different watchers.
1 parent 4753336 commit 092a06b

File tree

5 files changed

+26
-50
lines changed

5 files changed

+26
-50
lines changed

lib/common/declarations.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,8 @@ declare const enum ErrorCodes {
589589
INVALID_ARGUMENT = 128,
590590
RESOURCE_PROBLEM = 129,
591591
KARMA_FAIL = 130,
592-
UNHANDLED_REJECTION_FAILURE = 131
592+
UNHANDLED_REJECTION_FAILURE = 131,
593+
DELETED_KILL_FILE = 132,
593594
}
594595

595596
interface IFutureDispatcher {

lib/common/definitions/watchr.d.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

lib/common/services/cancellation.ts

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,38 @@
1-
const gaze = require("gaze");
1+
import * as choki from "chokidar";
22
import * as path from "path";
33
import * as os from "os";
44

5-
const hostInfo: IHostInfo = $injector.resolve("hostInfo");
6-
75
class CancellationService implements ICancellationService {
8-
private watches: IDictionary<IWatcherInstance> = {};
6+
private watches: IDictionary<choki.FSWatcher> = {};
97

108
constructor(private $fs: IFileSystem,
11-
private $logger: ILogger) {
12-
this.$fs.createDirectory(CancellationService.killSwitchDir);
13-
this.$fs.chmod(CancellationService.killSwitchDir, "0777");
9+
private $logger: ILogger,
10+
private $hostInfo: IHostInfo) {
11+
12+
if (this.$hostInfo.isWindows) {
13+
this.$fs.createDirectory(CancellationService.killSwitchDir);
14+
}
15+
1416
}
1517

1618
public async begin(name: string): Promise<void> {
19+
if (!this.$hostInfo.isWindows) {
20+
return;
21+
}
22+
1723
const triggerFile = CancellationService.makeKillSwitchFileName(name);
1824

1925
if (!this.$fs.exists(triggerFile)) {
2026
this.$fs.writeFile(triggerFile, "");
21-
22-
if (!hostInfo.isWindows) {
23-
this.$fs.chmod(triggerFile, "0777");
24-
}
2527
}
2628

2729
this.$logger.trace("Starting watch on killswitch %s", triggerFile);
2830

29-
const watcherInitialized = new Promise<IWatcherInstance>((resolve, reject) => {
30-
gaze(triggerFile, function (err: any, watcher: any) {
31-
this.on("deleted", (filePath: string) => process.exit());
32-
33-
if (err) {
34-
reject(err);
35-
} else {
36-
resolve(watcher);
37-
}
31+
const watcher = choki.watch(triggerFile, { ignoreInitial: true })
32+
.on("unlink", (filePath: string) => {
33+
this.$logger.info(`Exiting process as the file ${filePath} has been deleted. Probably reinstalling CLI while there's a working instance.`);
34+
process.exit(ErrorCodes.DELETED_KILL_FILE);
3835
});
39-
});
40-
41-
const watcher = await watcherInitialized;
4236

4337
if (watcher) {
4438
this.watches[name] = watcher;
@@ -47,8 +41,10 @@ class CancellationService implements ICancellationService {
4741

4842
public end(name: string): void {
4943
const watcher = this.watches[name];
50-
delete this.watches[name];
51-
watcher.close();
44+
if (watcher) {
45+
delete this.watches[name];
46+
watcher.close();
47+
}
5248
}
5349

5450
public dispose(): void {
@@ -64,22 +60,4 @@ class CancellationService implements ICancellationService {
6460
}
6561
}
6662

67-
class CancellationServiceDummy implements ICancellationService {
68-
dispose(): void {
69-
/* intentionally left blank */
70-
}
71-
72-
async begin(name: string): Promise<void> {
73-
return;
74-
}
75-
76-
end(name: string): void {
77-
/* intentionally left blank */
78-
}
79-
}
80-
81-
if (hostInfo.isWindows) {
82-
$injector.register("cancellation", CancellationService);
83-
} else {
84-
$injector.register("cancellation", CancellationServiceDummy);
85-
}
63+
$injector.register("cancellation", CancellationService);

npm-shrinkwrap.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
"detect-newline": "2.1.0",
4343
"email-validator": "1.0.4",
4444
"esprima": "2.7.0",
45-
"gaze": "1.1.0",
4645
"iconv-lite": "0.4.11",
4746
"inquirer": "6.2.0",
4847
"ios-device-lib": "0.5.1",

0 commit comments

Comments
 (0)