Skip to content

Commit

Permalink
Tweak jest-haste-map watchman initial query to make it faster (#6689)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafeca authored and mjesun committed Jul 13, 2018
1 parent 7eaeb03 commit 8b8f5bc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

- `[jest-cli]` Watch plugins now have access to a broader range of global configuration options in their `updateConfigAndRun` callbacks, so they can provide a wider set of extra features ([#6473](https://github.com/facebook/jest/pull/6473))

## Fixes

- `[jest-haste-map]` Optimize watchman crawler by using `glob` on initial query ([#6689](https://github.com/facebook/jest/pull/6689))

## 23.4.0

### Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ describe('watchman watch', () => {

expect(query[2].fields).toEqual(['name', 'exists', 'mtime_ms']);

expect(query[2].suffix).toEqual(['js', 'json']);
expect(query[2].glob).toEqual([
'fruits/**/*.js',
'fruits/**/*.json',
'vegetables/**/*.js',
'vegetables/**/*.json',
]);

expect(data.clocks).toEqual({
[ROOT_MOCK]: 'c:fake-clock:1',
Expand Down Expand Up @@ -412,7 +417,7 @@ describe('watchman watch', () => {

expect(query[2].fields).toEqual(['name', 'exists', 'mtime_ms']);

expect(query[2].suffix).toEqual(['js', 'json']);
expect(query[2].glob).toEqual(['**/*.js', '**/*.json']);

expect(data.clocks).toEqual({
[ROOT_MOCK]: 'c:fake-clock:1',
Expand Down
16 changes: 14 additions & 2 deletions packages/jest-haste-map/src/crawlers/watchman.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,30 @@ module.exports = async function watchmanCrawl(
Array.from(rootProjectDirMappings).map(
async ([root, directoryFilters]) => {
const expression = Array.from(defaultWatchExpression);
const glob = [];

if (directoryFilters.length > 0) {
expression.push([
'anyof',
...directoryFilters.map(dir => ['dirname', dir]),
]);

for (const directory of directoryFilters) {
for (const extension of extensions) {
glob.push(`${directory}/**/*.${extension}`);
}
}
} else {
for (const extension of extensions) {
glob.push(`**/*.${extension}`);
}
}

const query = clocks[root]
? // Use the `since` generator if we have a clock available
{expression, fields, since: clocks[root]}
: // Otherwise use the `suffix` generator
{expression, fields, suffix: extensions};
: // Otherwise use the `glob` filter
{expression, fields, glob};

const response = await cmd('query', root, query);

Expand Down

0 comments on commit 8b8f5bc

Please sign in to comment.