Skip to content

Commit 9406dae

Browse files
authoredApr 26, 2024··
Merge pull request #1804 from alumni/remove-semver
chore: remove unnecessary semver checks
2 parents e996382 + 86c9bf4 commit 9406dae

File tree

4 files changed

+4
-41
lines changed

4 files changed

+4
-41
lines changed
 

‎package.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
"browser": {
77
"./src/node/index.js": "./src/client.js",
88
"./lib/node/index.js": "./lib/client.js",
9-
"./test/support/server.js": "./test/support/blank.js",
10-
"semver": false
9+
"./test/support/server.js": "./test/support/blank.js"
1110
},
1211
"bugs": {
1312
"url": "https://github.com/ladjs/superagent/issues"
@@ -27,8 +26,7 @@
2726
"formidable": "^3.5.1",
2827
"methods": "^1.1.2",
2928
"mime": "2.6.0",
30-
"qs": "^6.11.0",
31-
"semver": "^7.3.8"
29+
"qs": "^6.11.0"
3230
},
3331
"devDependencies": {
3432
"@babel/cli": "^7.20.7",

‎src/node/http2wrapper.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1+
const http2 = require('http2');
12
const Stream = require('stream');
23
const net = require('net');
34
const tls = require('tls');
45
// eslint-disable-next-line node/no-deprecated-api
56
const { parse } = require('url');
6-
const process = require('process');
7-
const semverGte = require('semver/functions/gte');
8-
9-
let http2;
10-
11-
if (semverGte(process.version, 'v10.10.0')) http2 = require('http2');
12-
else
13-
throw new Error('superagent: this version of Node.js does not support http2');
147

158
const {
169
HTTP2_HEADER_PATH,

‎src/node/index.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,16 @@ const FormData = require('form-data');
1616
const formidable = require('formidable');
1717
const debug = require('debug')('superagent');
1818
const CookieJar = require('cookiejar');
19-
const semverGte = require('semver/functions/gte');
2019
const safeStringify = require('fast-safe-stringify');
2120

2221
const utils = require('../utils');
2322
const RequestBase = require('../request-base');
23+
const http2 = require('./http2wrapper');
2424
const { unzip } = require('./unzip');
2525
const Response = require('./response');
2626

2727
const { mixin, hasOwn } = utils;
2828

29-
let http2;
30-
31-
if (semverGte(process.version, 'v10.10.0')) http2 = require('./http2wrapper');
32-
3329
function request(method, url) {
3430
// callback
3531
if (typeof url === 'function') {

‎src/request-base.js

-24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const semver = require('semver');
2-
31
/**
42
* Module of mixed-in functions shared between node and client code
53
*/
@@ -481,28 +479,6 @@ RequestBase.prototype.abort = function () {
481479
this._aborted = true;
482480
if (this.xhr) this.xhr.abort(); // browser
483481
if (this.req) {
484-
// Node v13 has major differences in `abort()`
485-
// https://github.com/nodejs/node/blob/v12.x/lib/internal/streams/end-of-stream.js
486-
// https://github.com/nodejs/node/blob/v13.x/lib/internal/streams/end-of-stream.js
487-
// https://github.com/nodejs/node/blob/v14.x/lib/internal/streams/end-of-stream.js
488-
// (if you run a diff across these you will see the differences)
489-
//
490-
// References:
491-
// <https://github.com/nodejs/node/issues/31630>
492-
// <https://github.com/ladjs/superagent/pull/1084/commits/dc18679a7c5ccfc6046d882015e5126888973bc8>
493-
//
494-
// Thanks to @shadowgate15 and @niftylettuce
495-
if (
496-
semver.gte(process.version, 'v13.0.0') &&
497-
semver.lt(process.version, 'v14.0.0')
498-
) {
499-
// Note that the reason this doesn't work is because in v13 as compared to v14
500-
// there is no `callback = nop` set in end-of-stream.js above
501-
throw new Error(
502-
'Superagent does not work in v13 properly with abort() due to Node.js core changes'
503-
);
504-
}
505-
506482
this.req.abort(); // node
507483
}
508484

0 commit comments

Comments
 (0)
Please sign in to comment.