-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
don’t use watchman when not watching
Summary: Fixes #1644 This PR will update relay-compiler to not use watchman unless watching files. Closes #1966 Reviewed By: asiandrummer Differential Revision: D5522984 Pulled By: leebyron fbshipit-source-id: 5c18f9e03691a542d9c77b9c1858a734ed6b6792
- Loading branch information
1 parent
06ec89b
commit 4f80e02
Showing
9 changed files
with
608 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ const RelayConsoleReporter = require('RelayConsoleReporter'); | |
const RelayFileIRParser = require('RelayFileIRParser'); | ||
const RelayFileWriter = require('RelayFileWriter'); | ||
const RelayIRTransforms = require('RelayIRTransforms'); | ||
const RelayWatchmanClient = require('RelayWatchmanClient'); | ||
|
||
const formatGeneratedModule = require('formatGeneratedModule'); | ||
const fs = require('fs'); | ||
|
@@ -60,6 +61,27 @@ function buildWatchExpression(options: { | |
]; | ||
} | ||
|
||
function getFilepathsFromGlob( | ||
baseDir, | ||
options: { | ||
extensions: Array<string>, | ||
include: Array<string>, | ||
exclude: Array<string>, | ||
}, | ||
): Array<string> { | ||
const {extensions, include, exclude} = options; | ||
const patterns = include.map(inc => `${inc}/*.+(${extensions.join('|')})`); | ||
|
||
// $FlowFixMe | ||
const glob = require('fast-glob'); | ||
return glob.sync(patterns, { | ||
cwd: baseDir, | ||
bashNative: [], | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
robrichard
Author
Contributor
|
||
onlyFiles: true, | ||
ignore: exclude, | ||
}); | ||
} | ||
|
||
/* eslint-disable no-console-disallow */ | ||
|
||
async function run(options: { | ||
|
@@ -69,6 +91,7 @@ async function run(options: { | |
include: Array<string>, | ||
exclude: Array<string>, | ||
verbose: boolean, | ||
watchman: boolean, | ||
watch?: ?boolean, | ||
}) { | ||
const schemaPath = path.resolve(process.cwd(), options.schema); | ||
|
@@ -79,6 +102,9 @@ async function run(options: { | |
if (!fs.existsSync(srcDir)) { | ||
throw new Error(`--source path does not exist: ${srcDir}.`); | ||
} | ||
if (options.watch && !options.watchman) { | ||
throw new Error('Watchman is required to watch for changes.'); | ||
} | ||
if (options.watch && !hasWatchmanRootFile(srcDir)) { | ||
throw new Error( | ||
` | ||
|
@@ -96,13 +122,17 @@ Ensure that one such file exists in ${srcDir} or its parents. | |
|
||
const reporter = new RelayConsoleReporter({verbose: options.verbose}); | ||
|
||
const useWatchman = | ||
options.watchman && (await RelayWatchmanClient.isAvailable()); | ||
|
||
const parserConfigs = { | ||
default: { | ||
baseDir: srcDir, | ||
getFileFilter: RelayFileIRParser.getFileFilter, | ||
getParser: RelayFileIRParser.getParser, | ||
getSchema: () => getSchema(schemaPath), | ||
watchmanExpression: buildWatchExpression(options), | ||
watchmanExpression: useWatchman ? buildWatchExpression(options) : null, | ||
filepaths: useWatchman ? null : getFilepathsFromGlob(srcDir, options), | ||
}, | ||
}; | ||
const writerConfigs = { | ||
|
@@ -234,6 +264,11 @@ const argv = yargs | |
describe: 'More verbose logging', | ||
type: 'boolean', | ||
}, | ||
watchman: { | ||
describe: 'Use watchman when not in watch mode', | ||
type: 'boolean', | ||
default: true, | ||
}, | ||
watch: { | ||
describe: 'If specified, watches files and regenerates on changes', | ||
type: 'boolean', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
What's the reason to not use the default value here? This seems to be causing the issues in #2042
cc @robrichard