-
Notifications
You must be signed in to change notification settings - Fork 625
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
metro-file-map: Consistently abort crawl on end() calls
Summary: Changelog: * **[Fix]**: `metro-file-map`: consistently abort crawl when `end()` is called. Ensures that `metro-file-map`'s `build()` method rejects (and terminates early if possible) if `end()` is called either *before* or *during* the `build()` call. Previously this was handled inconsistently. Also switches to a different, more complete `AbortController` polyfill (which is internal and not exposed via the API). Our minimum Node version doesn't support some of the newer methods used here - otherwise we could have used the built-in `AbortController`. NOTE: We can probably do more to bail out of the Node crawler early, similarly to how we shut down the Watchman client immediately on `end()`. Here I'm just setting up the correct API expectations + tests so we can transparently improve the behaviour later. Reviewed By: robhogan Differential Revision: D44104748 fbshipit-source-id: 65c9b897c0f74e421a8d82d16e89d9cb3e48ec9b
- Loading branch information
1 parent
de19bbd
commit 51877a8
Showing
10 changed files
with
223 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
* @format | ||
*/ | ||
|
||
// Translated manually from TS: https://github.com/southpolesteve/node-abort-controller/blob/10e0cea66a069d9319f948d055621e1d37aea5db/index.d.ts | ||
|
||
// `AbortSignal`,`AbortController` are defined here to prevent a dependency on the `dom` library which disagrees with node runtime. | ||
// The definition for `AbortSignal` is taken from @types/node-fetch (https://github.com/DefinitelyTyped/DefinitelyTyped) for | ||
// maximal compatibility with node-fetch. | ||
// Original node-fetch definitions are under MIT License. | ||
|
||
declare module 'node-abort-controller' { | ||
declare export class AbortSignal { | ||
aborted: boolean; | ||
reason?: any; | ||
|
||
addEventListener: ( | ||
type: 'abort', | ||
listener: (this: AbortSignal, event: any) => any, | ||
options?: | ||
| boolean | ||
| { | ||
capture?: boolean, | ||
once?: boolean, | ||
passive?: boolean, | ||
}, | ||
) => void; | ||
|
||
removeEventListener: ( | ||
type: 'abort', | ||
listener: (this: AbortSignal, event: any) => any, | ||
options?: | ||
| boolean | ||
| { | ||
capture?: boolean, | ||
}, | ||
) => void; | ||
|
||
dispatchEvent: (event: any) => boolean; | ||
|
||
onabort: null | ((this: AbortSignal, event: any) => void); | ||
|
||
throwIfAborted(): void; | ||
|
||
static abort(reason?: any): AbortSignal; | ||
|
||
static timeout(time: number): AbortSignal; | ||
} | ||
|
||
declare export class AbortController { | ||
signal: AbortSignal; | ||
|
||
abort(reason?: any): void; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.