Skip to content
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

chore: remove unnecessary semver checks #1804

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 Expand Up @@ -82,7 +75,7 @@
}
}

setNoDelay(bool) {

Check warning on line 78 in src/node/http2wrapper.js

View workflow job for this annotation

GitHub Actions / test (14.x)

'bool' is defined but never used

Check warning on line 78 in src/node/http2wrapper.js

View workflow job for this annotation

GitHub Actions / test (16.x)

'bool' is defined but never used

Check warning on line 78 in src/node/http2wrapper.js

View workflow job for this annotation

GitHub Actions / test (18.x)

'bool' is defined but never used
// We can not use setNoDelay with HTTP/2.
// Node 10 limits http2session.socket methods to ones safe to use with HTTP/2.
// See also https://nodejs.org/api/http2.html#http2_http2session_socket
Expand All @@ -104,7 +97,7 @@

const frame = this.session.request(headers);

frame.once('response', (headers, flags) => {

Check warning on line 100 in src/node/http2wrapper.js

View workflow job for this annotation

GitHub Actions / test (14.x)

'flags' is defined but never used

Check warning on line 100 in src/node/http2wrapper.js

View workflow job for this annotation

GitHub Actions / test (16.x)

'flags' is defined but never used

Check warning on line 100 in src/node/http2wrapper.js

View workflow job for this annotation

GitHub Actions / test (18.x)

'flags' is defined but never used
headers = this.mapToHttpHeader(headers);
frame.headers = headers;
frame.statusCode = headers[HTTP2_HEADER_STATUS];
Expand Down Expand Up @@ -188,7 +181,7 @@
frame.end(data);
}

abort(data) {

Check warning on line 184 in src/node/http2wrapper.js

View workflow job for this annotation

GitHub Actions / test (14.x)

'data' is defined but never used

Check warning on line 184 in src/node/http2wrapper.js

View workflow job for this annotation

GitHub Actions / test (16.x)

'data' is defined but never used

Check warning on line 184 in src/node/http2wrapper.js

View workflow job for this annotation

GitHub Actions / test (18.x)

'data' is defined but never used
const frame = this.getFrame();
frame.close(NGHTTP2_CANCEL);
this.session.destroy();
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
Loading