Skip to content

Commit

Permalink
Revert "chore: bump deps, xo linting"
Browse files Browse the repository at this point in the history
This reverts commit 8b5400b.
  • Loading branch information
titanism committed Aug 15, 2023
1 parent 44c83af commit 6feca3f
Show file tree
Hide file tree
Showing 54 changed files with 250 additions and 304 deletions.
4 changes: 2 additions & 2 deletions ci/remove-deps-4-old-node.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require('node:fs');
const path = require('node:path');
const fs = require('fs');
const path = require('path');
const package = require('../package.json');

const UNSUPPORT_DEPS_4_OLD = new Set([
Expand Down
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,27 @@
"formidable": "^2.1.2",
"methods": "^1.1.2",
"mime": "2.6.0",
"qs": "^6.11.2",
"semver": "^7.5.4"
"qs": "^6.11.0",
"semver": "^7.3.8"
},
"devDependencies": {
"@babel/cli": "^7.22.10",
"@babel/core": "^7.22.10",
"@babel/plugin-transform-runtime": "^7.22.10",
"@babel/preset-env": "^7.22.10",
"@babel/runtime": "^7.22.10",
"@babel/cli": "^7.20.7",
"@babel/core": "^7.20.12",
"@babel/plugin-transform-runtime": "^7.19.6",
"@babel/preset-env": "^7.20.2",
"@babel/runtime": "^7.20.13",
"@commitlint/cli": "17",
"@commitlint/config-conventional": "17",
"Base64": "^1.2.0",
"Base64": "^1.1.0",
"babelify": "^10.0.0",
"basic-auth-connect": "^1.0.0",
"body-parser": "^1.20.2",
"body-parser": "^1.20.1",
"browserify": "^17.0.0",
"cookie-parser": "^1.4.6",
"cross-env": "^7.0.3",
"eslint": "^8.47.0",
"eslint": "^8.32.0",
"eslint-config-xo-lass": "2",
"eslint-plugin-compat": "4.1.4",
"eslint-plugin-compat": "4.0.2",
"eslint-plugin-node": "^11.1.0",
"express": "^4.18.2",
"express-session": "^1.17.3",
Expand All @@ -65,7 +65,7 @@
"should": "^13.2.3",
"should-http": "^0.1.1",
"tinyify": "3.0.0",
"xo": "^0.56.0",
"xo": "^0.53.1",
"zuul": "^3.12.0"
},
"engines": {
Expand Down
10 changes: 4 additions & 6 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ request.getXHR = () => {
* @api private
*/

const trim = ''.trim
? (s) => s.trim()
: (s) => s.replaceAll(/(^\s*|\s*$)/g, '');
const trim = ''.trim ? (s) => s.trim() : (s) => s.replace(/(^\s*|\s*$)/g, '');

/**
* Serialize the given `obj`.
Expand Down Expand Up @@ -312,7 +310,7 @@ function Response(request_) {
this.text =
(this.req.method !== 'HEAD' &&
(this.xhr.responseType === '' || this.xhr.responseType === 'text')) ||
this.xhr.responseType === undefined
typeof this.xhr.responseType === 'undefined'
? this.xhr.responseText
: null;
this.statusText = this.req.xhr.statusText;
Expand Down Expand Up @@ -425,7 +423,7 @@ function Request(method, url) {
if (self.xhr) {
// ie9 doesn't have 'response' property
error.rawResponse =
self.xhr.responseType === undefined
typeof self.xhr.responseType === 'undefined'
? self.xhr.responseText
: self.xhr.response;
// issue #876: return the http status code if the response parsing fails
Expand Down Expand Up @@ -869,7 +867,7 @@ Request.prototype._end = function () {

// IE11 xhr.send(undefined) sends 'undefined' string as POST payload (instead of nothing)
// We need null here if data is undefined
xhr.send(data === undefined ? null : data);
xhr.send(typeof data === 'undefined' ? null : data);
};

request.agent = () => new Agent();
Expand Down
4 changes: 2 additions & 2 deletions src/node/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

// eslint-disable-next-line node/no-deprecated-api
const { parse } = require('node:url');
const { parse } = require('url');
const { CookieJar } = require('cookiejar');
const { CookieAccessInfo } = require('cookiejar');
const methods = require('methods');
Expand Down Expand Up @@ -66,7 +66,7 @@ Agent.prototype = Object.create(AgentBase.prototype);
Agent.prototype._saveCookies = function (res) {
const cookies = res.headers['set-cookie'];
if (cookies) {
const url = parse(res.request?.url || '');
const url = parse(res.request?.url || '')
this.jar.setCookies(cookies, url.hostname, url.pathname);
}
};
Expand Down
37 changes: 13 additions & 24 deletions src/node/http2wrapper.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const Stream = require('node:stream');
const net = require('node:net');
const tls = require('node:tls');
const Stream = require('stream');
const net = require('net');
const tls = require('tls');
// eslint-disable-next-line node/no-deprecated-api
const { parse } = require('node:url');
const process = require('node:process');
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('node: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');

Expand Down Expand Up @@ -70,20 +70,15 @@ class Request extends Stream {

createUnixConnection(authority, options) {
switch (this.protocol) {
case 'http:': {
case 'http:':
return net.connect(options.socketPath);
}

case 'https:': {
case 'https:':
options.ALPNProtocols = ['h2'];
options.servername = this.host;
options.allowHalfOpen = true;
return tls.connect(options.socketPath, options);
}

default: {
default:
throw new Error('Unsupported protocol', this.protocol);
}
}
}

Expand Down Expand Up @@ -134,14 +129,11 @@ class Request extends Stream {
let value = headers[key];
key = key.toLowerCase();
switch (key) {
case HTTP2_HEADER_SET_COOKIE: {
case HTTP2_HEADER_SET_COOKIE:
value = Array.isArray(value) ? value : [value];
break;
}

default: {
default:
break;
}
}

http2Headers[key] = value;
Expand All @@ -157,17 +149,14 @@ class Request extends Stream {
let value = headers[key];
key = key.toLowerCase();
switch (key) {
case HTTP2_HEADER_HOST: {
case HTTP2_HEADER_HOST:
key = HTTP2_HEADER_AUTHORITY;
value = /^http:\/\/|^https:\/\//.test(value)
? parse(value).host
: value;
break;
}

default: {
default:
break;
}
}

http2Headers[key] = value;
Expand Down
20 changes: 11 additions & 9 deletions src/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
*/

// eslint-disable-next-line node/no-deprecated-api
const { parse, format, resolve } = require('node:url');
const Stream = require('node:stream');
const https = require('node:https');
const http = require('node:http');
const fs = require('node:fs');
const zlib = require('node:zlib');
const util = require('node:util');
const { parse, format, resolve } = require('url');
const Stream = require('stream');
const https = require('https');
const http = require('http');
const fs = require('fs');
const zlib = require('zlib');
const util = require('util');
const qs = require('qs');
const mime = require('mime');
let methods = require('methods');
Expand All @@ -19,6 +19,7 @@ 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 { unzip } = require('./unzip');
Expand Down Expand Up @@ -468,6 +469,7 @@ Request.prototype._pipeContinue = function (stream, options) {
res.pipe(stream, options);
res.once('end', () => this.emit('end'));
}

});
return stream;
};
Expand Down Expand Up @@ -717,7 +719,7 @@ Request.prototype.request = function () {
// See https://github.com/ladjs/superagent/issues/1367
if (queryStringBackticks) {
let i = 0;
url.query = url.query.replaceAll('%60', () => queryStringBackticks[i++]);
url.query = url.query.replace(/%60/g, () => queryStringBackticks[i++]);
url.search = `?${url.query}`;
url.path = url.pathname + url.search;
}
Expand All @@ -729,7 +731,7 @@ Request.prototype.request = function () {

// get the socket, path
const unixParts = url.path.match(/^([^/]+)(.+)$/);
options.socketPath = unixParts[1].replaceAll('%2F', '/');
options.socketPath = unixParts[1].replace(/%2F/g, '/');
url.path = unixParts[2];
}

Expand Down
14 changes: 7 additions & 7 deletions src/node/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* Module dependencies.
*/

const util = require('node:util');
const Stream = require('node:stream');
const util = require('util');
const Stream = require('stream');
const ResponseBase = require('../response-base');
const { mixin } = require('../utils');

Expand Down Expand Up @@ -51,11 +51,11 @@ function Response(request) {
// https://github.com/nodejs/node/pull/39520#issuecomment-889697136
Object.defineProperty(Response.prototype, 'body', {
get() {
return this._body === undefined
? this.res.body === undefined
? {}
: this.res.body
: this._body;
return this._body !== undefined
? this._body
: this.res.body !== undefined
? this.res.body
: {};
},
set(value) {
this._body = value;
Expand Down
6 changes: 3 additions & 3 deletions src/node/unzip.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* Module dependencies.
*/

const { StringDecoder } = require('node:string_decoder');
const Stream = require('node:stream');
const zlib = require('node:zlib');
const { StringDecoder } = require('string_decoder');
const Stream = require('stream');
const zlib = require('zlib');

/**
* Buffers response data events and re-emits when they're unzipped.
Expand Down
38 changes: 12 additions & 26 deletions src/request-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,17 @@ RequestBase.prototype.timeout = function (options) {
for (const option in options) {
if (hasOwn(options, option)) {
switch (option) {
case 'deadline': {
case 'deadline':
this._timeout = options.deadline;
break;
}

case 'response': {
case 'response':
this._responseTimeout = options.response;
break;
}

case 'upload': {
case 'upload':
this._uploadTimeout = options.upload;
break;
}

default: {
default:
console.warn('Unknown timeout option', option);
}
}
}
}
Expand Down Expand Up @@ -520,26 +513,20 @@ RequestBase.prototype.abort = function () {

RequestBase.prototype._auth = function (user, pass, options, base64Encoder) {
switch (options.type) {
case 'basic': {
case 'basic':
this.set('Authorization', `Basic ${base64Encoder(`${user}:${pass}`)}`);
break;
}

case 'auto': {
case 'auto':
this.username = user;
this.password = pass;
break;
}

case 'bearer': {
// usage would be .auth(accessToken, { type: 'bearer' })
case 'bearer': // usage would be .auth(accessToken, { type: 'bearer' })
this.set('Authorization', `Bearer ${user}`);
break;
}

default: {
default:
break;
}
}

return this;
Expand Down Expand Up @@ -675,12 +662,11 @@ RequestBase.prototype.send = function (data) {
// merge
if (isObject_ && isObject(this._data)) {
for (const key in data) {
if (typeof data[key] === 'bigint')
throw new Error('Cannot serialize BigInt value to json');
if (typeof data[key] == "bigint") throw new Error("Cannot serialize BigInt value to json");
if (hasOwn(data, key)) this._data[key] = data[key];
}
} else if (typeof data === 'bigint')
throw new Error('Cannot send value of type BigInt');
}
else if (typeof data === 'bigint') throw new Error("Cannot send value of type BigInt");
else if (typeof data === 'string') {
// default to x-www-form-urlencoded
if (!type) this.type('form');
Expand Down Expand Up @@ -734,7 +720,7 @@ RequestBase.prototype.send = function (data) {

RequestBase.prototype.sortQuery = function (sort) {
// _sort default to true but otherwise can be a function or boolean
this._sort = sort === undefined ? true : sort;
this._sort = typeof sort === 'undefined' ? true : sort;
return this;
};

Expand Down
3 changes: 2 additions & 1 deletion test/agent-base.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const assert = require('node:assert');
const assert = require('assert');
const getSetup = require('./support/setup');

const request = require('./support/client');

describe('Agent', () => {
Expand Down
3 changes: 2 additions & 1 deletion test/basic.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const assert = require('node:assert');
const assert = require('assert');
const getSetup = require('./support/setup');

const request = require('./support/client');

describe('request', function () {
Expand Down
2 changes: 1 addition & 1 deletion test/client/request.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('node:assert');
const assert = require('assert');
const request = require('../support/client');

describe('request', function () {
Expand Down
Loading

0 comments on commit 6feca3f

Please sign in to comment.