Skip to content

Commit

Permalink
Added method to get an iterator for all files in HasteFS (#7010)
Browse files Browse the repository at this point in the history
* Added method to get an iterator for all files in HasteFS

* Used hasteFS.getFileIterator() in jest-resolve-dependencies

* Update changelog
  • Loading branch information
rubennorte authored Sep 20, 2018
1 parent ab06a7b commit ee751bf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
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> {
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

0 comments on commit ee751bf

Please sign in to comment.