Skip to content

Commit

Permalink
What if Watchman CLI is missing... (#2643)
Browse files Browse the repository at this point in the history
Summary:
Here is an updated version of the `GraphQLWatchmanClient.isAvailable`. (as a fix for #2617)

Now, it's also checking if the `watchman` CLI is available.

Test plan (Tested with `relay-examples:relay-publish-test`  (relayjs/relay-examples#89)

First of all, I've removed watchman from my machine.
Then,
  - Build the compiler
  - Install updated dependencies relay-examples (yarn)
  - Run the compiler (yarn build)

Compiled without errors.
Pull Request resolved: #2643

Reviewed By: kassens

Differential Revision: D14240611

Pulled By: alunyov

fbshipit-source-id: 551a9338158debe7db8748676a6dccf0dfd479b0
  • Loading branch information
alunyov authored and facebook-github-bot committed Feb 28, 2019
1 parent fae6903 commit 2958b97
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
3 changes: 1 addition & 2 deletions packages/relay-compiler/bin/RelayCompilerMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ Ensure that one such file exists in ${srcDir} or its parents.
verbose: options.verbose,
quiet: options.quiet,
});

const useWatchman = options.watchman && (await WatchmanClient.isAvailable());

const schema = getSchema(schemaPath);
Expand Down Expand Up @@ -270,7 +269,7 @@ Ensure that one such file exists in ${srcDir} or its parents.
// TODO: allow passing in a flag or detect?
sourceControl: null,
});
if (!options.validate && !options.watch && options.watchman) {
if (!options.validate && !options.watch && useWatchman) {
// eslint-disable-next-line no-console
console.log('HINT: pass --watch to keep watching for changes.');
}
Expand Down
24 changes: 11 additions & 13 deletions packages/relay-compiler/core/GraphQLWatchmanClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
'use strict';

const childProcess = require('child_process');
const watchman = require('fb-watchman');

const MAX_ATTEMPT_LIMIT = 5;
Expand All @@ -24,21 +25,18 @@ class GraphQLWatchmanClient {

static isAvailable(): Promise<boolean> {
return new Promise(resolve => {
const client = new GraphQLWatchmanClient(MAX_ATTEMPT_LIMIT);
client.on('error', () => {
// This command not only will verify that watchman CLI is available
// More than that `watchman version` is a command that runs on the server.
// And it can tell us that watchman is up and running
// Also `watchman version` check ``relative_root`` capability
// under the covers
const proc = childProcess.spawn('watchman', ['version']);
proc.on('error', () => {
resolve(false);
client.end();
});
client.hasCapability('relative_root').then(
hasRelativeRoot => {
resolve(hasRelativeRoot);
client.end();
},
() => {
resolve(false);
client.end();
},
);
proc.on('close', code => {
resolve(code === 0);
});
});
}

Expand Down

0 comments on commit 2958b97

Please sign in to comment.