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

Added method to get an iterator for all files in HasteFS #7010

Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Features

- `[pretty-format]` Option to not escape strings in diff messages ([#5661](https://github.com/facebook/jest/pull/5661))
- `[jest-haste-map]` Add `getFileIterator` to `HasteFS` for faster file iteration ([#7010](https://github.com/facebook/jest/pull/7010)).

### Fixes

Expand Down
4 changes: 4 additions & 0 deletions packages/jest-haste-map/src/haste_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export default class HasteFS {
return Array.from(this._files.keys());
}

getFileIterator(): Iterator<string> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rafeca you'll be able to use this in Metro. It should be way faster if you just want to iterate over the files.

return this._files.keys();
}

matchFiles(pattern: RegExp | string): Array<Path> {
if (!(pattern instanceof RegExp)) {
pattern = new RegExp(pattern);
Expand Down
11 changes: 7 additions & 4 deletions packages/jest-resolve-dependencies/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,13 @@ class DependencyResolver {
}
}
}
const modules = this._hasteFS.getAllFiles().map(file => ({
dependencies: this.resolve(file, options),
file,
}));
const modules = [];
for (const file of this._hasteFS.getFileIterator()) {
modules.push({
dependencies: this.resolve(file, options),
file,
});
}
return Array.from(collectModules(relatedPaths, modules, changed));
}
}
Expand Down