Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak jest-haste-map watchman initial query to make it faster #6689

Merged
merged 4 commits into from
Jul 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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