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

chore: upgrade to fsevents 2 #9215

Merged
merged 2 commits into from
Nov 20, 2019
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 @@ -76,6 +76,7 @@
- `[jest-cli]` [**BREAKING**] Remove re-exports from `@jest/core` ([#8874](https://github.com/facebook/jest/pull/8874))
- `[jest-diff]` Remove the need to export `splitLines0` function ([#9151](https://github.com/facebook/jest/pull/9151))
- `[jest-environment-jsdom]` [**BREAKING**] Upgrade JSDOM from v11 to v15 ([#8851](https://github.com/facebook/jest/pull/8851))
- `[jest-haste-map]` Upgrade to `fsevents@2` ([#9215](https://github.com/facebook/jest/pull/9215))
- `[jest-reporters]` [**BREAKING**] Upgrade Istanbul dependencies, which are used for code coverage ([#9192](https://github.com/facebook/jest/pull/9192))
- `[jest-util]` [**BREAKING**] Remove deprecated exports ([#8863](https://github.com/facebook/jest/pull/8863))
- `[jest-validate]` [**BREAKING**] Use ESM exports ([#8874](https://github.com/facebook/jest/pull/8874))
Expand Down
3 changes: 1 addition & 2 deletions packages/jest-haste-map/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@
"devDependencies": {
"@types/anymatch": "^1.3.1",
"@types/fb-watchman": "^2.0.0",
"@types/fsevents": "^1.1.0",
"@types/graceful-fs": "^4.1.2",
"@types/invariant": "^2.2.29",
"@types/micromatch": "^3.1.0",
"@types/sane": "^2.0.0"
},
"optionalDependencies": {
"fsevents": "^1.2.9"
"fsevents": "^2.1.2"
},
"engines": {
"node": ">= 8"
Expand Down
21 changes: 12 additions & 9 deletions packages/jest-haste-map/src/lib/FSEventsWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import * as path from 'path';
import {EventEmitter} from 'events';
import anymatch, {Matcher} from 'anymatch';
import micromatch = require('micromatch');
import {Watcher} from 'fsevents';
// @ts-ignore no types
import walker from 'walker';

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

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

this.root = path.resolve(dir);
this.watcher = fsevents(this.root);
this.fsEventsWatchStopper = fsevents.watch(
this.root,
this.handleEvent.bind(this),
);

this.watcher.start().on('change', this.handleEvent.bind(this));
this._tracked = new Set();
FSEventsWatcher.recReaddir(
this.root,
Expand All @@ -126,11 +128,12 @@ class FSEventsWatcher extends EventEmitter {
* End watching.
*/
close(callback?: () => void) {
this.watcher.stop();
this.removeAllListeners();
if (typeof callback === 'function') {
process.nextTick(callback.bind(null, null, true));
}
this.fsEventsWatchStopper().then(() => {
this.removeAllListeners();
if (typeof callback === 'function') {
process.nextTick(callback.bind(null, null, true));
}
});
}

private isFileIncluded(relativePath: string) {
Expand Down
11 changes: 2 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1921,13 +1921,6 @@
dependencies:
"@types/events" "*"

"@types/fsevents@^1.1.0":
version "1.1.2"
resolved "https://registry.yarnpkg.com/@types/fsevents/-/fsevents-1.1.2.tgz#31f5fcd1abc9a4c9431c03ca60bcac82ba2d05a4"
integrity sha512-obkdv2Yf8rnWYG2WSE5y2ZANP34HMNLAHORgB1m3AiOEA6y8kLJrJDvnTDaZxRDH0iH8mwBYKp18IeOMTYn51Q==
dependencies:
"@types/node" "*"

"@types/glob@*", "@types/glob@^7.1.1":
version "7.1.1"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.1.tgz#aa59a1c6e3fbc421e07ccd31a944c30eba521575"
Expand Down Expand Up @@ -6529,15 +6522,15 @@ fs.realpath@^1.0.0:
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8=

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

fsevents@~2.1.1:
fsevents@^2.1.2, fsevents@~2.1.1:
version "2.1.2"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.1.2.tgz#4c0a1fb34bc68e543b4b82a9ec392bfbda840805"
integrity sha512-R4wDiBwZ0KzpgOWetKDug1FZcYhqYnUYKtfZYt4mD5SBz76q0KR4Q9o7GIPamsVPGmW3EYPPJ0dOOjvx32ldZA==
Expand Down