Skip to content

Commit 349afc3

Browse files
authored
fix: only check for watchman existence once per process (#14826)
1 parent bfbb45c commit 349afc3

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
### Performance
5151

5252
- `[*]` [**BREAKING**] Bundle all of Jest's modules into `index.js` ([#12348](https://github.com/jestjs/jest/pull/12348), [#14550](https://github.com/jestjs/jest/pull/14550) & [#14661](https://github.com/jestjs/jest/pull/14661))
53+
- `[*]` [jest-haste-map] Only spawn one process to check for `watchman` installation ([#14826](https://github.com/jestjs/jest/pull/14826))
5354

5455
### Chore & Maintenance
5556

packages/jest-core/src/getChangedFilesPromise.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,10 @@ export default function getChangedFilesPromise(
1818
configs: Array<Config.ProjectConfig>,
1919
): ChangedFilesPromise | undefined {
2020
if (globalConfig.onlyChanged) {
21-
const allRootsForAllProjects = configs.reduce<Array<string>>(
22-
(roots, config) => {
23-
if (config.roots) {
24-
roots.push(...config.roots);
25-
}
26-
return roots;
27-
},
28-
[],
21+
const allRootsForAllProjects = new Set(
22+
configs.flatMap(config => config.roots || []),
2923
);
30-
return getChangedFilesForRoots(allRootsForAllProjects, {
24+
return getChangedFilesForRoots([...allRootsForAllProjects], {
3125
changedSince: globalConfig.changedSince,
3226
lastCommit: globalConfig.lastCommit,
3327
withAncestor: globalConfig.changedFilesWithAncestor,

packages/jest-haste-map/src/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ type Watcher = {
113113

114114
type HasteWorker = typeof import('./worker');
115115

116+
let isWatchmanInstalledPromise: Promise<boolean> | undefined;
117+
116118
export const ModuleMap = HasteModuleMap as {
117119
create: (rootPath: string) => IModuleMap;
118120
};
@@ -216,7 +218,6 @@ class HasteMap extends EventEmitter implements IHasteMap {
216218
private _cachePath = '';
217219
private _changeInterval?: ReturnType<typeof setInterval>;
218220
private readonly _console: Console;
219-
private _isWatchmanInstalledPromise: Promise<boolean> | null = null;
220221
private readonly _options: InternalOptions;
221222
private _watchers: Array<Watcher> = [];
222223
private _worker: JestWorkerFarm<HasteWorker> | HasteWorker | null = null;
@@ -1108,10 +1109,10 @@ class HasteMap extends EventEmitter implements IHasteMap {
11081109
if (!this._options.useWatchman) {
11091110
return false;
11101111
}
1111-
if (!this._isWatchmanInstalledPromise) {
1112-
this._isWatchmanInstalledPromise = isWatchmanInstalled();
1112+
if (!isWatchmanInstalledPromise) {
1113+
isWatchmanInstalledPromise = isWatchmanInstalled();
11131114
}
1114-
return this._isWatchmanInstalledPromise;
1115+
return isWatchmanInstalledPromise;
11151116
}
11161117

11171118
private _createEmptyMap(): InternalHasteMap {

0 commit comments

Comments
 (0)