From 86c9bf4f365e202ccbda6927fc974646ab16be34 Mon Sep 17 00:00:00 2001 From: Lucian Mocanu Date: Thu, 25 Apr 2024 23:19:06 +0200 Subject: [PATCH] chore: remove unnecessary semver checks --- package.json | 6 ++---- src/node/http2wrapper.js | 9 +-------- src/node/index.js | 6 +----- src/request-base.js | 24 ------------------------ 4 files changed, 4 insertions(+), 41 deletions(-) diff --git a/package.json b/package.json index c4f41bc9..9643ee2d 100644 --- a/package.json +++ b/package.json @@ -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" @@ -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", diff --git a/src/node/http2wrapper.js b/src/node/http2wrapper.js index 4141692c..83878a28 100644 --- a/src/node/http2wrapper.js +++ b/src/node/http2wrapper.js @@ -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, diff --git a/src/node/index.js b/src/node/index.js index 8edecaac..75217c8b 100644 --- a/src/node/index.js +++ b/src/node/index.js @@ -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') { diff --git a/src/request-base.js b/src/request-base.js index a2649979..c69262e3 100644 --- a/src/request-base.js +++ b/src/request-base.js @@ -1,5 +1,3 @@ -const semver = require('semver'); - /** * Module of mixed-in functions shared between node and client code */ @@ -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: - // - // - // - // 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 }