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

Commit

Permalink
[changed] added the check for the "relative_root" watchman server cap…
Browse files Browse the repository at this point in the history
…ability; also added client disconnection on error
  • Loading branch information
thealjey committed Feb 11, 2017
1 parent b4de55c commit 2e62ccb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import type {WatchCallback} from './typedef';
import {logError, log, consoleStyles} from './logger';
import {Client} from 'fb-watchman';

/* eslint-disable camelcase */

const client = new Client(),
ALPHANUMERIC_BASE = 36,
{yellow} = consoleStyles;
Expand Down Expand Up @@ -31,13 +33,15 @@ const client = new Client(),
export function watch(dir: string, type: string, callback: WatchCallback) {
const subscription = Date.now().toString(ALPHANUMERIC_BASE);

client.capabilityCheck({}, capabilityErr => {
client.capabilityCheck({optional: [], required: ['relative_root']}, capabilityErr => {
if (capabilityErr) {
client.end();

return logError(capabilityErr);
}

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

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

client.command(['subscribe', watcher, subscription, {
expression: ['suffix', type],
since: clockResp.clock
since: clockResp.clock,
relative_root
}], subscribeErr => {
if (subscribeErr) {
logError(subscribeErr);
Expand Down
2 changes: 2 additions & 0 deletions test/mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ export class Client {
capabilityCheck: () => void;
command: () => void;
on: () => void;
end: () => void;
}
Client.prototype.capabilityCheck = noop;
Client.prototype.command = noop;
Client.prototype.on = noop;
Client.prototype.end = noop;
7 changes: 4 additions & 3 deletions test/watch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ chai.use(sinonChai);

/* eslint-disable no-unused-expressions */
/* eslint-disable require-jsdoc */
/* eslint-disable camelcase */

const ALPHANUMERIC_BASE = 36,
capabilityErr = new Error('capabilityErr'),
Expand Down Expand Up @@ -69,7 +70,7 @@ describe('watch', () => {
});

it('calls capabilityCheck', () => {
expect(Client.prototype.capabilityCheck).calledWith({}, match.func);
expect(Client.prototype.capabilityCheck).calledWith({optional: [], required: ['relative_root']}, match.func);
});

it('prints an error on screen', () => {
Expand Down Expand Up @@ -180,7 +181,7 @@ describe('watch', () => {
beforeEach(() => {
stub(Client.prototype, 'command', (command, cb) => {
if ('watch-project' === command[0]) {
cb(null, {watch: 'a watcher instance'});
cb(null, {watch: 'a watcher instance', relative_path: 'relative path'});
} else if ('clock' === command[0]) {
cb(null, {clock: 'clock value'});
} else {
Expand All @@ -196,7 +197,7 @@ describe('watch', () => {

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

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

0 comments on commit 2e62ccb

Please sign in to comment.