diff --git a/flow-typed/node-abort-controller.js b/flow-typed/node-abort-controller.js deleted file mode 100644 index 34dd940c0d..0000000000 --- a/flow-typed/node-abort-controller.js +++ /dev/null @@ -1,61 +0,0 @@ -/** - * 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 strict-local - * @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; - } -} diff --git a/packages/metro-file-map/package.json b/packages/metro-file-map/package.json index ba1fd7c23b..ab12a59f35 100644 --- a/packages/metro-file-map/package.json +++ b/packages/metro-file-map/package.json @@ -20,7 +20,6 @@ "invariant": "^2.2.4", "jest-worker": "^29.6.3", "micromatch": "^4.0.4", - "node-abort-controller": "^3.1.1", "nullthrows": "^1.1.1", "walker": "^1.0.7" }, diff --git a/packages/metro-file-map/src/Watcher.js b/packages/metro-file-map/src/Watcher.js index 795b169fd2..0c14a03095 100644 --- a/packages/metro-file-map/src/Watcher.js +++ b/packages/metro-file-map/src/Watcher.js @@ -19,7 +19,6 @@ import type { WatchmanClocks, } from './flow-types'; import type {WatcherOptions as WatcherBackendOptions} from './watchers/common'; -import type {AbortSignal} from 'node-abort-controller'; import nodeCrawl from './crawlers/node'; import watchmanCrawl from './crawlers/watchman'; diff --git a/packages/metro-file-map/src/crawlers/__tests__/node-test.js b/packages/metro-file-map/src/crawlers/__tests__/node-test.js index c14e57a75e..c782333467 100644 --- a/packages/metro-file-map/src/crawlers/__tests__/node-test.js +++ b/packages/metro-file-map/src/crawlers/__tests__/node-test.js @@ -9,7 +9,6 @@ */ import TreeFS from '../../lib/TreeFS'; -import {AbortController} from 'node-abort-controller'; jest.useRealTimers(); @@ -404,7 +403,7 @@ describe('node crawler', () => { await expect( nodeCrawl({ console: global.console, - abortSignal: abortSignalWithReason(err), + abortSignal: AbortSignal.abort(err), previousState: {fileSystem: emptyFS}, extensions: ['js', 'json'], ignore: pearMatcher, @@ -446,10 +445,3 @@ describe('node crawler', () => { ).rejects.toThrow(err); }); }); - -function abortSignalWithReason(reason) { - // TODO: use AbortSignal.abort when node-abort-controller supports it - const controller = new AbortController(); - controller.abort(reason); - return controller.signal; -} diff --git a/packages/metro-file-map/src/crawlers/__tests__/watchman-test.js b/packages/metro-file-map/src/crawlers/__tests__/watchman-test.js index a7d4f2de65..b3333d25ec 100644 --- a/packages/metro-file-map/src/crawlers/__tests__/watchman-test.js +++ b/packages/metro-file-map/src/crawlers/__tests__/watchman-test.js @@ -9,7 +9,6 @@ */ import TreeFS from '../../lib/TreeFS'; -import {AbortController} from 'node-abort-controller'; const path = require('path'); @@ -554,7 +553,7 @@ describe('watchman watch', () => { const err = new Error('aborted for test'); await expect( watchmanCrawl({ - abortSignal: abortSignalWithReason(err), + abortSignal: AbortSignal.abort(err), previousState: { clocks: new Map(), files: new Map(), @@ -600,10 +599,3 @@ describe('watchman watch', () => { ).rejects.toThrow(err); }); }); - -function abortSignalWithReason(reason) { - // TODO: use AbortSignal.abort when node-abort-controller supports it - const controller = new AbortController(); - controller.abort(reason); - return controller.signal; -} diff --git a/packages/metro-file-map/src/flow-types.js b/packages/metro-file-map/src/flow-types.js index 37407f73a0..6fa488d09f 100644 --- a/packages/metro-file-map/src/flow-types.js +++ b/packages/metro-file-map/src/flow-types.js @@ -12,7 +12,6 @@ 'use strict'; import type {PerfLogger, PerfLoggerFactory, RootPerfLogger} from 'metro-config'; -import type {AbortSignal} from 'node-abort-controller'; export type {PerfLoggerFactory, PerfLogger}; diff --git a/packages/metro-file-map/src/index.js b/packages/metro-file-map/src/index.js index 46e446b14c..18321fd630 100644 --- a/packages/metro-file-map/src/index.js +++ b/packages/metro-file-map/src/index.js @@ -51,7 +51,6 @@ import EventEmitter from 'events'; import {promises as fsPromises} from 'fs'; import invariant from 'invariant'; import {Worker} from 'jest-worker'; -import {AbortController} from 'node-abort-controller'; import nullthrows from 'nullthrows'; import * as path from 'path'; import {performance} from 'perf_hooks'; diff --git a/packages/metro-file-map/types/flow-types.d.ts b/packages/metro-file-map/types/flow-types.d.ts index 9a71baf7b2..252e31c906 100644 --- a/packages/metro-file-map/types/flow-types.d.ts +++ b/packages/metro-file-map/types/flow-types.d.ts @@ -9,7 +9,6 @@ */ import type {PerfLogger, PerfLoggerFactory, RootPerfLogger} from 'metro-config'; -import type {AbortSignal} from 'node-abort-controller'; export type {PerfLoggerFactory, PerfLogger}; diff --git a/yarn.lock b/yarn.lock index 37bde3e057..692ef7cb4b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4487,11 +4487,6 @@ neo-async@^2.5.0: resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.2.tgz#b4aafb93e3aeb2d8174ca53cf163ab7d7308305f" integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw== -node-abort-controller@^3.1.1: - version "3.1.1" - resolved "https://registry.yarnpkg.com/node-abort-controller/-/node-abort-controller-3.1.1.tgz#a94377e964a9a37ac3976d848cb5c765833b8548" - integrity sha512-AGK2yQKIjRuqnc6VkX2Xj5d+QW8xZ87pa1UK6yA6ouUyuxfHuMP6umE5QK7UmTeOAymo+Zx1Fxiuw9rVx8taHQ== - node-dir@^0.1.17: version "0.1.17" resolved "https://registry.yarnpkg.com/node-dir/-/node-dir-0.1.17.tgz#5f5665d93351335caabef8f1c554516cf5f1e4e5"