Skip to content

Commit 96d2619

Browse files
authored
fix: use AbortController in backward compatible way for Node.js >=12.20.0 (#3141)
1 parent 93dcd76 commit 96d2619

11 files changed

+34
-32
lines changed

config/jest/jest.unit.coverage.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = {
99
branches: 84,
1010
functions: 91,
1111
lines: 89,
12-
statements: 89,
12+
statements: 88,
1313
},
1414
},
1515
};

package-lock.json

+6-20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
"./es/helpers/btoa.node.js": "./es/helpers/btoa.browser.js",
99
"./src/helpers/fetch-polyfill.node.js": "./src/helpers/fetch-polyfill.browser.js",
1010
"./es/helpers/fetch-polyfill.node.js": "./es/helpers/fetch-polyfill.browser.js",
11-
"./lib/helpers/fetch-polyfill.node.js": "./lib/helpers/fetch-polyfill.browser.js"
11+
"./lib/helpers/fetch-polyfill.node.js": "./lib/helpers/fetch-polyfill.browser.js",
12+
"./src/helpers/abortcontroller-polyfill.node.js": "./src/helpers/abortcontroller-polyfill.browser.js",
13+
"./es/helpers/abortcontroller-polyfill.node.js": "./es/helpers/abortcontroller-polyfill.browser.js",
14+
"./lib/helpers/abortcontroller-polyfill.node.js": "./lib/helpers/abortcontroller-polyfill.browser.js"
1215
},
1316
"main": "lib/commonjs.js",
1417
"module": "es/index.js",
@@ -110,13 +113,13 @@
110113
"@swagger-api/apidom-json-pointer": ">=0.76.2 <1.0.0",
111114
"@swagger-api/apidom-ns-openapi-3-1": ">=0.76.2 <1.0.0",
112115
"@swagger-api/apidom-reference": ">=0.76.2 <1.0.0",
113-
"abort-controller": "^3.0.0",
114116
"cookie": "~0.5.0",
115117
"deepmerge": "~4.3.0",
116118
"fast-json-patch": "^3.0.0-1",
117119
"is-plain-object": "^5.0.0",
118120
"js-yaml": "^4.1.0",
119121
"node-fetch-commonjs": "^3.3.1",
122+
"node-abort-controller": "^3.1.1",
120123
"qs": "^6.10.2",
121124
"traverse": "~0.6.6",
122125
"undici": "^5.24.0"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { AbortController, AbortSignal } from './abortcontroller-ponyfill.browser.js';
2+
3+
if (typeof globalThis.AbortController === 'undefined') {
4+
globalThis.AbortController = AbortController;
5+
}
6+
if (typeof globalThis.AbortSignal === 'undefined') {
7+
globalThis.AbortSignal = AbortSignal;
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { AbortController, AbortSignal } from './abortcontroller-ponyfill.node.js';
2+
3+
if (typeof globalThis.AbortController === 'undefined') {
4+
globalThis.AbortController = AbortController;
5+
}
6+
if (typeof globalThis.AbortSignal === 'undefined') {
7+
globalThis.AbortSignal = AbortSignal;
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// we're targeting browsers that already support fetch API
2+
const { AbortController, AbortSignal } = globalThis;
3+
4+
export { AbortController, AbortSignal };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { AbortController, AbortSignal } from 'node-abort-controller';

src/resolver/apidom/reference/resolve/resolvers/http-swagger-client/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import AbortController from 'abort-controller';
21
import { ResolverError, HttpResolver } from '@swagger-api/apidom-reference/configuration/empty';
32

43
import '../../../../../../helpers/fetch-polyfill.node.js';
4+
import '../../../../../../helpers/abortcontroller-polyfill.node.js';
55
import Http from '../../../../../../http/index.js';
66

77
const HttpResolverSwaggerClient = HttpResolver.compose({

test/execute/main.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import AbortController from 'abort-controller';
2-
31
import { execute, buildRequest, self as stubs } from '../../src/execute/index.js';
42
// eslint-disable-next-line camelcase
53
import normalize from '../../src/resolver/strategies/generic/normalize.js';

test/interfaces.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import AbortController from 'abort-controller';
2-
31
import {
42
mapTagOperations,
53
makeApisTagOperationsOperationExecute,

test/jest.setup.js

-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import process from 'node:process';
22
import http from 'node:http';
33
import path from 'node:path';
44
import fs from 'node:fs';
5-
import AbortController from 'abort-controller';
65

76
import {
87
fetch,
@@ -23,9 +22,6 @@ globalThis.FormData = FormData;
2322
globalThis.File = File;
2423
globalThis.Blob = Blob;
2524

26-
// provide AbortController for older Node.js versions
27-
globalThis.AbortController = AbortController;
28-
2925
// helpers for reading local files
3026
globalThis.loadFile = (uri) => fs.readFileSync(uri).toString();
3127
globalThis.loadJsonFile = (uri) => JSON.parse(globalThis.loadFile(uri));

0 commit comments

Comments
 (0)