Skip to content

Commit

Permalink
Remove unnecessary node-abort-controller polyfill
Browse files Browse the repository at this point in the history
Summary:
The builtin `AbortController`/`AbortSignal` is now sufficient in Metro's minimum Node.js version (18.18) that we don't need this polyfill.

In particular:
 - `AbortSignal.abort(reason)`: https://nodejs.org/api/globals.html#static-method-abortsignalabortreason
 - `AbortSignal.throwIfAborted()`: https://nodejs.org/api/globals.html#abortsignalthrowifaborted

Have both been supported since Node 17.3.0. At the time we introduced `node-abort-controller`, Metro's minimum was Node 16.0.

Changelog: Internal

Reviewed By: huntie

Differential Revision: D67829632

fbshipit-source-id: 994f7f52203671704a503db43359f504f36dd326
  • Loading branch information
robhogan authored and facebook-github-bot committed Jan 6, 2025
1 parent b7b3cf4 commit d631f45
Show file tree
Hide file tree
Showing 9 changed files with 2 additions and 89 deletions.
61 changes: 0 additions & 61 deletions flow-typed/node-abort-controller.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/metro-file-map/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
1 change: 0 additions & 1 deletion packages/metro-file-map/src/Watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
10 changes: 1 addition & 9 deletions packages/metro-file-map/src/crawlers/__tests__/node-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/

import TreeFS from '../../lib/TreeFS';
import {AbortController} from 'node-abort-controller';

jest.useRealTimers();

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
10 changes: 1 addition & 9 deletions packages/metro-file-map/src/crawlers/__tests__/watchman-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/

import TreeFS from '../../lib/TreeFS';
import {AbortController} from 'node-abort-controller';

const path = require('path');

Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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;
}
1 change: 0 additions & 1 deletion packages/metro-file-map/src/flow-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
1 change: 0 additions & 1 deletion packages/metro-file-map/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
1 change: 0 additions & 1 deletion packages/metro-file-map/types/flow-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/

import type {PerfLogger, PerfLoggerFactory, RootPerfLogger} from 'metro-config';
import type {AbortSignal} from 'node-abort-controller';

export type {PerfLoggerFactory, PerfLogger};

Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit d631f45

Please sign in to comment.