Skip to content

Commit

Permalink
chore: remove unnecessary semver checks
Browse files Browse the repository at this point in the history
  • Loading branch information
alumni committed Apr 25, 2024
1 parent e996382 commit 86c9bf4
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 41 deletions.
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"browser": {
"./src/node/index.js": "./src/client.js",
"./lib/node/index.js": "./lib/client.js",
"./test/support/server.js": "./test/support/blank.js",
"semver": false
"./test/support/server.js": "./test/support/blank.js"
},
"bugs": {
"url": "https://github.com/ladjs/superagent/issues"
Expand All @@ -27,8 +26,7 @@
"formidable": "^3.5.1",
"methods": "^1.1.2",
"mime": "2.6.0",
"qs": "^6.11.0",
"semver": "^7.3.8"
"qs": "^6.11.0"
},
"devDependencies": {
"@babel/cli": "^7.20.7",
Expand Down
9 changes: 1 addition & 8 deletions src/node/http2wrapper.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
const http2 = require('http2');
const Stream = require('stream');
const net = require('net');
const tls = require('tls');
// eslint-disable-next-line node/no-deprecated-api
const { parse } = require('url');
const process = require('process');
const semverGte = require('semver/functions/gte');

let http2;

if (semverGte(process.version, 'v10.10.0')) http2 = require('http2');
else
throw new Error('superagent: this version of Node.js does not support http2');

const {
HTTP2_HEADER_PATH,
Expand Down
6 changes: 1 addition & 5 deletions src/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,16 @@ const FormData = require('form-data');
const formidable = require('formidable');
const debug = require('debug')('superagent');
const CookieJar = require('cookiejar');
const semverGte = require('semver/functions/gte');
const safeStringify = require('fast-safe-stringify');

const utils = require('../utils');
const RequestBase = require('../request-base');
const http2 = require('./http2wrapper');
const { unzip } = require('./unzip');
const Response = require('./response');

const { mixin, hasOwn } = utils;

let http2;

if (semverGte(process.version, 'v10.10.0')) http2 = require('./http2wrapper');

function request(method, url) {
// callback
if (typeof url === 'function') {
Expand Down
24 changes: 0 additions & 24 deletions src/request-base.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const semver = require('semver');

/**
* Module of mixed-in functions shared between node and client code
*/
Expand Down Expand Up @@ -481,28 +479,6 @@ RequestBase.prototype.abort = function () {
this._aborted = true;
if (this.xhr) this.xhr.abort(); // browser
if (this.req) {
// Node v13 has major differences in `abort()`
// https://github.com/nodejs/node/blob/v12.x/lib/internal/streams/end-of-stream.js
// https://github.com/nodejs/node/blob/v13.x/lib/internal/streams/end-of-stream.js
// https://github.com/nodejs/node/blob/v14.x/lib/internal/streams/end-of-stream.js
// (if you run a diff across these you will see the differences)
//
// References:
// <https://github.com/nodejs/node/issues/31630>
// <https://github.com/ladjs/superagent/pull/1084/commits/dc18679a7c5ccfc6046d882015e5126888973bc8>
//
// Thanks to @shadowgate15 and @niftylettuce
if (
semver.gte(process.version, 'v13.0.0') &&
semver.lt(process.version, 'v14.0.0')
) {
// Note that the reason this doesn't work is because in v13 as compared to v14
// there is no `callback = nop` set in end-of-stream.js above
throw new Error(
'Superagent does not work in v13 properly with abort() due to Node.js core changes'
);
}

this.req.abort(); // node
}

Expand Down

0 comments on commit 86c9bf4

Please sign in to comment.