diff --git a/packages/relay-compiler/bin/RelayCompilerMain.js b/packages/relay-compiler/bin/RelayCompilerMain.js index 16d55282e83ce..85775c210319b 100644 --- a/packages/relay-compiler/bin/RelayCompilerMain.js +++ b/packages/relay-compiler/bin/RelayCompilerMain.js @@ -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); @@ -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.'); } diff --git a/packages/relay-compiler/core/GraphQLWatchmanClient.js b/packages/relay-compiler/core/GraphQLWatchmanClient.js index 58d0f640ba208..81a6a16533bf2 100644 --- a/packages/relay-compiler/core/GraphQLWatchmanClient.js +++ b/packages/relay-compiler/core/GraphQLWatchmanClient.js @@ -10,6 +10,7 @@ */ 'use strict'; +const childProcess = require('child_process'); const watchman = require('fb-watchman'); const MAX_ATTEMPT_LIMIT = 5; @@ -24,21 +25,18 @@ class GraphQLWatchmanClient { static isAvailable(): Promise { 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); + }); }); }