From f078d6026421b5c8222d3cd1595694e2dc31318e Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 20 Nov 2019 23:41:25 +0100 Subject: [PATCH] chore: upgrade to fsevents 2 --- CHANGELOG.md | 1 + packages/jest-haste-map/package.json | 3 +-- .../jest-haste-map/src/lib/FSEventsWatcher.ts | 20 ++++++++++--------- yarn.lock | 11 ++-------- 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 721224415e57..17a271162576 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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-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)) - `[jest-types]` Mark `InitialOptions` as `Partial` ([#8848](https://github.com/facebook/jest/pull/8848)) diff --git a/packages/jest-haste-map/package.json b/packages/jest-haste-map/package.json index 40600caff0e4..a703f8def2cb 100644 --- a/packages/jest-haste-map/package.json +++ b/packages/jest-haste-map/package.json @@ -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" diff --git a/packages/jest-haste-map/src/lib/FSEventsWatcher.ts b/packages/jest-haste-map/src/lib/FSEventsWatcher.ts index b275fd6011cd..08b74ade6338 100644 --- a/packages/jest-haste-map/src/lib/FSEventsWatcher.ts +++ b/packages/jest-haste-map/src/lib/FSEventsWatcher.ts @@ -11,7 +11,6 @@ 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'; @@ -44,7 +43,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; private _tracked: Set; static isSupported() { @@ -104,9 +103,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, @@ -126,11 +127,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) { diff --git a/yarn.lock b/yarn.lock index 37b72d8348b2..5013bde83a18 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1906,13 +1906,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" @@ -6513,7 +6506,7 @@ 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== @@ -6521,7 +6514,7 @@ fsevents@^1.2.3, fsevents@^1.2.7, fsevents@^1.2.9: 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==