Skip to content

chore: remove unnecessary semver checks #1804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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