Skip to content

Commit d4e2d84

Browse files
authored
chore: upgrade to fsevents 2 (#9215)
1 parent ee66670 commit d4e2d84

File tree

4 files changed

+16
-20
lines changed

4 files changed

+16
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
- `[jest-cli]` [**BREAKING**] Remove re-exports from `@jest/core` ([#8874](https://github.com/facebook/jest/pull/8874))
7777
- `[jest-diff]` Remove the need to export `splitLines0` function ([#9151](https://github.com/facebook/jest/pull/9151))
7878
- `[jest-environment-jsdom]` [**BREAKING**] Upgrade JSDOM from v11 to v15 ([#8851](https://github.com/facebook/jest/pull/8851))
79+
- `[jest-haste-map]` Upgrade to `fsevents@2` ([#9215](https://github.com/facebook/jest/pull/9215))
7980
- `[jest-reporters]` [**BREAKING**] Upgrade Istanbul dependencies, which are used for code coverage ([#9192](https://github.com/facebook/jest/pull/9192))
8081
- `[jest-util]` [**BREAKING**] Remove deprecated exports ([#8863](https://github.com/facebook/jest/pull/8863))
8182
- `[jest-validate]` [**BREAKING**] Use ESM exports ([#8874](https://github.com/facebook/jest/pull/8874))

packages/jest-haste-map/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@
2525
"devDependencies": {
2626
"@types/anymatch": "^1.3.1",
2727
"@types/fb-watchman": "^2.0.0",
28-
"@types/fsevents": "^1.1.0",
2928
"@types/graceful-fs": "^4.1.2",
3029
"@types/invariant": "^2.2.29",
3130
"@types/micromatch": "^3.1.0",
3231
"@types/sane": "^2.0.0"
3332
},
3433
"optionalDependencies": {
35-
"fsevents": "^1.2.9"
34+
"fsevents": "^2.1.2"
3635
},
3736
"engines": {
3837
"node": ">= 8"

packages/jest-haste-map/src/lib/FSEventsWatcher.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import * as path from 'path';
1111
import {EventEmitter} from 'events';
1212
import anymatch, {Matcher} from 'anymatch';
1313
import micromatch = require('micromatch');
14-
import {Watcher} from 'fsevents';
1514
// @ts-ignore no types
1615
import walker from 'walker';
1716

17+
// @ts-ignore: this is for CI which runs linux and might not have this
1818
let fsevents: typeof import('fsevents') | null = null;
1919
try {
2020
fsevents = require('fsevents');
@@ -44,7 +44,7 @@ class FSEventsWatcher extends EventEmitter {
4444
public readonly dot: boolean;
4545
public readonly hasIgnore: boolean;
4646
public readonly doIgnore: (path: string) => boolean;
47-
public readonly watcher: Watcher;
47+
public readonly fsEventsWatchStopper: () => Promise<void>;
4848
private _tracked: Set<string>;
4949

5050
static isSupported() {
@@ -104,9 +104,11 @@ class FSEventsWatcher extends EventEmitter {
104104
this.doIgnore = opts.ignored ? anymatch(opts.ignored) : () => false;
105105

106106
this.root = path.resolve(dir);
107-
this.watcher = fsevents(this.root);
107+
this.fsEventsWatchStopper = fsevents.watch(
108+
this.root,
109+
this.handleEvent.bind(this),
110+
);
108111

109-
this.watcher.start().on('change', this.handleEvent.bind(this));
110112
this._tracked = new Set();
111113
FSEventsWatcher.recReaddir(
112114
this.root,
@@ -126,11 +128,12 @@ class FSEventsWatcher extends EventEmitter {
126128
* End watching.
127129
*/
128130
close(callback?: () => void) {
129-
this.watcher.stop();
130-
this.removeAllListeners();
131-
if (typeof callback === 'function') {
132-
process.nextTick(callback.bind(null, null, true));
133-
}
131+
this.fsEventsWatchStopper().then(() => {
132+
this.removeAllListeners();
133+
if (typeof callback === 'function') {
134+
process.nextTick(callback.bind(null, null, true));
135+
}
136+
});
134137
}
135138

136139
private isFileIncluded(relativePath: string) {

yarn.lock

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,13 +1921,6 @@
19211921
dependencies:
19221922
"@types/events" "*"
19231923

1924-
"@types/fsevents@^1.1.0":
1925-
version "1.1.2"
1926-
resolved "https://registry.yarnpkg.com/@types/fsevents/-/fsevents-1.1.2.tgz#31f5fcd1abc9a4c9431c03ca60bcac82ba2d05a4"
1927-
integrity sha512-obkdv2Yf8rnWYG2WSE5y2ZANP34HMNLAHORgB1m3AiOEA6y8kLJrJDvnTDaZxRDH0iH8mwBYKp18IeOMTYn51Q==
1928-
dependencies:
1929-
"@types/node" "*"
1930-
19311924
"@types/glob@*", "@types/glob@^7.1.1":
19321925
version "7.1.1"
19331926
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.1.tgz#aa59a1c6e3fbc421e07ccd31a944c30eba521575"
@@ -6529,15 +6522,15 @@ fs.realpath@^1.0.0:
65296522
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
65306523
integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8=
65316524

6532-
fsevents@^1.2.3, fsevents@^1.2.7, fsevents@^1.2.9:
6525+
fsevents@^1.2.3, fsevents@^1.2.7:
65336526
version "1.2.9"
65346527
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-1.2.9.tgz#3f5ed66583ccd6f400b5a00db6f7e861363e388f"
65356528
integrity sha512-oeyj2H3EjjonWcFjD5NvZNE9Rqe4UW+nQBU2HNeKw0koVLEFIhtyETyAakeAM3de7Z/SW5kcA+fZUait9EApnw==
65366529
dependencies:
65376530
nan "^2.12.1"
65386531
node-pre-gyp "^0.12.0"
65396532

6540-
fsevents@~2.1.1:
6533+
fsevents@^2.1.2, fsevents@~2.1.1:
65416534
version "2.1.2"
65426535
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.1.2.tgz#4c0a1fb34bc68e543b4b82a9ec392bfbda840805"
65436536
integrity sha512-R4wDiBwZ0KzpgOWetKDug1FZcYhqYnUYKtfZYt4mD5SBz76q0KR4Q9o7GIPamsVPGmW3EYPPJ0dOOjvx32ldZA==

0 commit comments

Comments
 (0)