Skip to content
This repository was archived by the owner on Jul 9, 2021. It is now read-only.

Commit 2e62ccb

Browse files
committed
[changed] added the check for the "relative_root" watchman server capability; also added client disconnection on error
1 parent b4de55c commit 2e62ccb

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

src/watch.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import type {WatchCallback} from './typedef';
44
import {logError, log, consoleStyles} from './logger';
55
import {Client} from 'fb-watchman';
66

7+
/* eslint-disable camelcase */
8+
79
const client = new Client(),
810
ALPHANUMERIC_BASE = 36,
911
{yellow} = consoleStyles;
@@ -31,13 +33,15 @@ const client = new Client(),
3133
export function watch(dir: string, type: string, callback: WatchCallback) {
3234
const subscription = Date.now().toString(ALPHANUMERIC_BASE);
3335

34-
client.capabilityCheck({}, capabilityErr => {
36+
client.capabilityCheck({optional: [], required: ['relative_root']}, capabilityErr => {
3537
if (capabilityErr) {
38+
client.end();
39+
3640
return logError(capabilityErr);
3741
}
3842

3943
client.command(['watch-project', dir], (watchErr, watchResp) => {
40-
const {watch: watcher} = watchResp;
44+
const {watch: watcher, relative_path: relative_root} = watchResp;
4145

4246
if (watchErr) {
4347
return logError(watchErr);
@@ -54,7 +58,8 @@ export function watch(dir: string, type: string, callback: WatchCallback) {
5458

5559
client.command(['subscribe', watcher, subscription, {
5660
expression: ['suffix', type],
57-
since: clockResp.clock
61+
since: clockResp.clock,
62+
relative_root
5863
}], subscribeErr => {
5964
if (subscribeErr) {
6065
logError(subscribeErr);

test/mock.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ export class Client {
104104
capabilityCheck: () => void;
105105
command: () => void;
106106
on: () => void;
107+
end: () => void;
107108
}
108109
Client.prototype.capabilityCheck = noop;
109110
Client.prototype.command = noop;
110111
Client.prototype.on = noop;
112+
Client.prototype.end = noop;

test/watch.spec.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ chai.use(sinonChai);
1010

1111
/* eslint-disable no-unused-expressions */
1212
/* eslint-disable require-jsdoc */
13+
/* eslint-disable camelcase */
1314

1415
const ALPHANUMERIC_BASE = 36,
1516
capabilityErr = new Error('capabilityErr'),
@@ -69,7 +70,7 @@ describe('watch', () => {
6970
});
7071

7172
it('calls capabilityCheck', () => {
72-
expect(Client.prototype.capabilityCheck).calledWith({}, match.func);
73+
expect(Client.prototype.capabilityCheck).calledWith({optional: [], required: ['relative_root']}, match.func);
7374
});
7475

7576
it('prints an error on screen', () => {
@@ -180,7 +181,7 @@ describe('watch', () => {
180181
beforeEach(() => {
181182
stub(Client.prototype, 'command', (command, cb) => {
182183
if ('watch-project' === command[0]) {
183-
cb(null, {watch: 'a watcher instance'});
184+
cb(null, {watch: 'a watcher instance', relative_path: 'relative path'});
184185
} else if ('clock' === command[0]) {
185186
cb(null, {clock: 'clock value'});
186187
} else {
@@ -196,7 +197,7 @@ describe('watch', () => {
196197

197198
it('executes a subscribe command', () => {
198199
expect(Client.prototype.command).calledWith(['subscribe', 'a watcher instance', 'qwerty',
199-
{expression: ['suffix', 'rty'], since: 'clock value'}], match.func);
200+
{expression: ['suffix', 'rty'], since: 'clock value', relative_root: 'relative path'}], match.func);
200201
});
201202

202203
it('prints an error on screen', () => {

0 commit comments

Comments
 (0)