From 316a35c75b23b4dbc5e5dfff44b49ee6ca6488a0 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 20 Nov 2019 23:41:25 +0100 Subject: [PATCH 1/2] 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 ad040187169b..48c5a075b80c 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-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)) 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 53fa6b52b96a..b33b221d0fd8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -6529,7 +6522,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== @@ -6537,7 +6530,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== From eca03a93107b8cb9d589b510fc06211d113813f4 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 20 Nov 2019 23:53:17 +0100 Subject: [PATCH 2/2] ignore type which might be missing on linux --- packages/jest-haste-map/src/lib/FSEventsWatcher.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/jest-haste-map/src/lib/FSEventsWatcher.ts b/packages/jest-haste-map/src/lib/FSEventsWatcher.ts index 08b74ade6338..8034fde92163 100644 --- a/packages/jest-haste-map/src/lib/FSEventsWatcher.ts +++ b/packages/jest-haste-map/src/lib/FSEventsWatcher.ts @@ -14,6 +14,7 @@ import micromatch = require('micromatch'); // @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');