Skip to content

Commit dbab6c3

Browse files
committed
Update dependencies
1 parent 88e623a commit dbab6c3

19 files changed

+140
-104
lines changed

package.json

+14-14
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@
4848
"ky"
4949
],
5050
"dependencies": {
51-
"@sindresorhus/is": "^6.1.0",
51+
"@sindresorhus/is": "^6.3.1",
5252
"@szmarczak/http-timer": "^5.0.1",
5353
"cacheable-lookup": "^7.0.0",
54-
"cacheable-request": "^10.2.14",
54+
"cacheable-request": "^12.0.1",
5555
"decompress-response": "^6.0.0",
5656
"form-data-encoder": "^4.0.2",
5757
"get-stream": "^8.0.1",
@@ -66,48 +66,48 @@
6666
"@sinonjs/fake-timers": "^11.2.2",
6767
"@types/benchmark": "^2.1.5",
6868
"@types/express": "^4.17.21",
69-
"@types/node": "^20.10.0",
69+
"@types/node": "^20.12.12",
7070
"@types/pem": "^1.14.4",
71-
"@types/readable-stream": "^4.0.9",
71+
"@types/readable-stream": "^4.0.14",
7272
"@types/request": "^2.48.12",
7373
"@types/sinon": "^17.0.2",
7474
"@types/sinonjs__fake-timers": "^8.1.5",
7575
"ava": "^5.3.1",
76-
"axios": "^1.6.2",
76+
"axios": "^1.6.8",
7777
"benchmark": "^2.1.4",
7878
"bluebird": "^3.7.2",
7979
"body-parser": "^1.20.2",
8080
"create-cert": "^1.0.6",
8181
"create-test-server": "^3.0.1",
8282
"del-cli": "^5.1.0",
8383
"delay": "^6.0.0",
84-
"express": "^4.18.2",
84+
"express": "^4.19.2",
8585
"form-data": "^4.0.0",
8686
"formdata-node": "^6.0.3",
87-
"nock": "^13.4.0",
87+
"nock": "^13.5.4",
8888
"node-fetch": "^3.3.2",
89-
"np": "^9.0.0",
89+
"np": "^10.0.5",
9090
"nyc": "^15.1.0",
91-
"p-event": "^6.0.0",
91+
"p-event": "^6.0.1",
9292
"pem": "^1.14.8",
9393
"pify": "^6.1.0",
9494
"readable-stream": "^4.4.2",
9595
"request": "^2.88.2",
96-
"sinon": "^17.0.1",
96+
"sinon": "^18.0.0",
9797
"slow-stream": "0.0.4",
9898
"tempy": "^3.1.0",
9999
"then-busboy": "^5.2.1",
100-
"tough-cookie": "^4.1.3",
101-
"tsx": "^4.6.0",
100+
"tough-cookie": "^4.1.4",
101+
"tsx": "^4.10.4",
102102
"type-fest": "^4.8.2",
103-
"typescript": "^5.3.2",
103+
"typescript": "^5.4.5",
104104
"xo": "^0.56.0"
105105
},
106106
"ava": {
107107
"files": [
108108
"test/*"
109109
],
110-
"timeout": "1m",
110+
"timeout": "10m",
111111
"extensions": {
112112
"ts": "module"
113113
},

source/as-promise/index.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import {
77
type RequestError,
88
} from '../core/errors.js';
99
import Request from '../core/index.js';
10-
import {parseBody, isResponseOk, type Response, ParseError} from '../core/response.js';
10+
import {
11+
parseBody,
12+
isResponseOk,
13+
type Response, ParseError,
14+
} from '../core/response.js';
1115
import proxyEvents from '../core/utils/proxy-events.js';
1216
import type Options from '../core/options.js';
1317
import {CancelError, type CancelableRequest} from './types.js';
@@ -168,13 +172,13 @@ export default function asPromise<T>(firstRequest?: Request): CancelableRequest<
168172
makeRequest(0);
169173
}) as CancelableRequest<T>;
170174

171-
promise.on = (event: string, fn: (...args: any[]) => void) => {
172-
emitter.on(event, fn);
175+
promise.on = (event: string, function_: (...arguments_: any[]) => void) => {
176+
emitter.on(event, function_);
173177
return promise;
174178
};
175179

176-
promise.off = (event: string, fn: (...args: any[]) => void) => {
177-
emitter.off(event, fn);
180+
promise.off = (event: string, function_: (...arguments_: any[]) => void) => {
181+
emitter.off(event, function_);
178182
return promise;
179183
};
180184

source/core/calculate-retry-delay.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type {RetryFunction} from './options.js';
22

3-
type Returns<T extends (...args: any) => unknown, V> = (...args: Parameters<T>) => V;
3+
type Returns<T extends (...arguments_: any) => unknown, V> = (...arguments_: Parameters<T>) => V;
44

55
const calculateRetryDelay: Returns<RetryFunction, number> = ({
66
attemptCount,

source/core/index.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1114,9 +1114,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
11141114
}
11151115
}
11161116

1117-
if (!request) {
1118-
request = options.getRequestFunction();
1119-
}
1117+
request ||= options.getRequestFunction();
11201118

11211119
const url = options.url as URL;
11221120

@@ -1130,12 +1128,12 @@ export default class Request extends Duplex implements RequestEvents<Request> {
11301128
}
11311129

11321130
// Cache support
1133-
const fn = options.cache ? this._createCacheableRequest : request;
1131+
const function_ = options.cache ? this._createCacheableRequest : request;
11341132

11351133
try {
11361134
// We can't do `await fn(...)`,
11371135
// because stream `error` event can be emitted before `Promise.resolve()`.
1138-
let requestOrResponse = fn!(url, this._requestOptions);
1136+
let requestOrResponse = function_!(url, this._requestOptions);
11391137

11401138
if (is.promise(requestOrResponse)) {
11411139
requestOrResponse = await requestOrResponse;

source/core/options.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ export type Agents = {
5050
export type Headers = Record<string, string | string[] | undefined>;
5151

5252
export type ToughCookieJar = {
53-
getCookieString: ((currentUrl: string, options: Record<string, unknown>, cb: (error: Error | null, cookies: string) => void) => void) // eslint-disable-line @typescript-eslint/ban-types
53+
getCookieString: ((currentUrl: string, options: Record<string, unknown>, callback: (error: Error | null, cookies: string) => void) => void) // eslint-disable-line @typescript-eslint/ban-types
5454
& ((url: string, callback: (error: Error | null, cookieHeader: string) => void) => void); // eslint-disable-line @typescript-eslint/ban-types
55-
setCookie: ((cookieOrString: unknown, currentUrl: string, options: Record<string, unknown>, cb: (error: Error | null, cookie: unknown) => void) => void) // eslint-disable-line @typescript-eslint/ban-types
55+
setCookie: ((cookieOrString: unknown, currentUrl: string, options: Record<string, unknown>, callback: (error: Error | null, cookie: unknown) => void) => void) // eslint-disable-line @typescript-eslint/ban-types
5656
& ((rawCookie: string, url: string, callback: (error: Error | null, result: unknown) => void) => void); // eslint-disable-line @typescript-eslint/ban-types
5757
};
5858

source/core/utils/proxy-events.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import type {EventEmitter} from 'node:events';
22

3-
type Fn = (...args: unknown[]) => void;
4-
type Fns = Record<string, Fn>;
3+
type AnyFunction = (...arguments_: unknown[]) => void;
4+
type Functions = Record<string, AnyFunction>;
55

66
export default function proxyEvents(from: EventEmitter, to: EventEmitter, events: Readonly<string[]>): () => void {
7-
const eventFunctions: Fns = {};
7+
const eventFunctions: Functions = {};
88

99
for (const event of events) {
10-
const eventFunction = (...args: unknown[]) => {
11-
to.emit(event, ...args);
10+
const eventFunction = (...arguments_: unknown[]) => {
11+
to.emit(event, ...arguments_);
1212
};
1313

1414
eventFunctions[event] = eventFunction;

source/core/utils/unhandle.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ import type {EventEmitter} from 'node:events';
22

33
type Origin = EventEmitter;
44
type Event = string | symbol;
5-
type Fn = (...args: any[]) => void;
5+
type AnyFunction = (...arguments_: any[]) => void;
66

77
type Handler = {
88
origin: Origin;
99
event: Event;
10-
fn: Fn;
10+
fn: AnyFunction;
1111
};
1212

1313
type Unhandler = {
14-
once: (origin: Origin, event: Event, fn: Fn) => void;
14+
once: (origin: Origin, event: Event, function_: AnyFunction) => void;
1515
unhandleAll: () => void;
1616
};
1717

@@ -23,9 +23,9 @@ export default function unhandle(): Unhandler {
2323
const handlers: Handler[] = [];
2424

2525
return {
26-
once(origin: Origin, event: Event, fn: Fn) {
27-
origin.once(event, fn);
28-
handlers.push({origin, event, fn});
26+
once(origin: Origin, event: Event, function_: AnyFunction) {
27+
origin.once(event, function_);
28+
handlers.push({origin, event, fn: function_});
2929
},
3030

3131
unhandleAll() {

source/create.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ const create = (defaults: InstanceDefaults): Got => {
6161
return request;
6262
}
6363

64-
if (!promise) {
65-
promise = asPromise(request);
66-
}
64+
promise ||= asPromise(request);
6765

6866
return promise;
6967
};
@@ -75,9 +73,7 @@ const create = (defaults: InstanceDefaults): Got => {
7573
const result = handler(newOptions, iterateHandlers) as GotReturn;
7674

7775
if (is.promise(result) && !request.options.isStream) {
78-
if (!promise) {
79-
promise = asPromise(request);
80-
}
76+
promise ||= asPromise(request);
8177

8278
if (result !== promise) {
8379
const descriptors = Object.getOwnPropertyDescriptors(promise);

test/create.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,14 @@ test('ability to pass a custom request method', withServer, async (t, server, go
196196

197197
let isCalled = false;
198198

199-
const request: RequestFunction = (...args: [
199+
const request: RequestFunction = (...arguments_: [
200200
string | URL | RequestOptions,
201201
(RequestOptions | ((response: IncomingMessage) => void))?,
202202
((response: IncomingMessage) => void)?,
203203
]) => {
204204
isCalled = true;
205205
// @ts-expect-error Overload error
206-
return httpRequest(...args);
206+
return httpRequest(...arguments_);
207207
};
208208

209209
const instance = got.extend({request});
@@ -217,17 +217,17 @@ test('does not include the `request` option in normalized `http` options', withS
217217

218218
let isCalled = false;
219219

220-
const request: RequestFunction = (...args: [
220+
const request: RequestFunction = (...arguments_: [
221221
string | URL | RequestOptions,
222222
(RequestOptions | ((response: IncomingMessage) => void))?,
223223
((response: IncomingMessage) => void)?,
224224
]) => {
225225
isCalled = true;
226226

227-
t.false(Reflect.has(args[0] as RequestOptions, 'request'));
227+
t.false(Reflect.has(arguments_[0] as RequestOptions, 'request'));
228228

229229
// @ts-expect-error Overload error
230-
return httpRequest(...args);
230+
return httpRequest(...arguments_);
231231
};
232232

233233
const instance = got.extend({request});

test/helpers/create-http-test-server.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@ const createHttpTestServer = async (options: HttpServerOptions = {}): Promise<Ex
2525
if (options.bodyParser !== false) {
2626
server.use(bodyParser.json({limit: '1mb', type: 'application/json', ...options.bodyParser}));
2727
server.use(bodyParser.text({limit: '1mb', type: 'text/plain', ...options.bodyParser}));
28-
server.use(bodyParser.urlencoded({limit: '1mb', type: 'application/x-www-form-urlencoded', extended: true, ...options.bodyParser}));
28+
29+
server.use(bodyParser.urlencoded({
30+
limit: '1mb',
31+
type: 'application/x-www-form-urlencoded',
32+
extended: true,
33+
...options.bodyParser,
34+
}));
35+
2936
server.use(bodyParser.raw({limit: '1mb', type: 'application/octet-stream', ...options.bodyParser}));
3037
}
3138

test/hooks.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import delay from 'delay';
99
import type {Handler} from 'express';
1010
import Responselike from 'responselike';
1111
import type {Constructor} from 'type-fest';
12-
import got, {RequestError, HTTPError, type Response, type OptionsInit} from '../source/index.js';
12+
import got, {
13+
RequestError,
14+
HTTPError,
15+
type Response,
16+
type OptionsInit,
17+
} from '../source/index.js';
1318
import withServer from './helpers/with-server.js';
1419

1520
const errorString = 'oops';

test/https.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ test('https request with `checkServerIdentity` NOT OK', withHttpsServer(), async
119119

120120
// The built-in `openssl` on macOS does not support negative days.
121121
{
122-
const testFn = process.platform === 'darwin' ? test.skip : test;
123-
testFn('https request with expired certificate', withHttpsServer({days: -1}), async (t, _server, got) => {
122+
const testFunction = process.platform === 'darwin' ? test.skip : test;
123+
testFunction('https request with expired certificate', withHttpsServer({days: -1}), async (t, _server, got) => {
124124
await t.throwsAsync(
125125
got({}),
126126
{

test/merge-instances.ts

+40-28
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,24 @@ test('merging two groups of merged instances', withServer, async (t, server) =>
7979
test('hooks are merged', t => {
8080
const getBeforeRequestHooks = (instance: Got): BeforeRequestHook[] => instance.defaults.options.hooks.beforeRequest;
8181

82-
const instanceA = got.extend({hooks: {
83-
beforeRequest: [
84-
options => {
85-
options.headers.dog = 'woof';
86-
},
87-
],
88-
}});
89-
const instanceB = got.extend({hooks: {
90-
beforeRequest: [
91-
options => {
92-
options.headers.cat = 'meow';
93-
},
94-
],
95-
}});
82+
const instanceA = got.extend({
83+
hooks: {
84+
beforeRequest: [
85+
options => {
86+
options.headers.dog = 'woof';
87+
},
88+
],
89+
},
90+
});
91+
const instanceB = got.extend({
92+
hooks: {
93+
beforeRequest: [
94+
options => {
95+
options.headers.cat = 'meow';
96+
},
97+
],
98+
},
99+
});
96100

97101
const merged = instanceA.extend(instanceB);
98102
t.deepEqual(getBeforeRequestHooks(merged), [...getBeforeRequestHooks(instanceA), ...getBeforeRequestHooks(instanceB)]);
@@ -118,13 +122,17 @@ test('URL is not polluted', withServer, async (t, server, got) => {
118122
});
119123

120124
test('merging instances with HTTPS options', t => {
121-
const instanceA = got.extend({https: {
122-
rejectUnauthorized: true,
123-
certificate: 'FIRST',
124-
}});
125-
const instanceB = got.extend({https: {
126-
certificate: 'SECOND',
127-
}});
125+
const instanceA = got.extend({
126+
https: {
127+
rejectUnauthorized: true,
128+
certificate: 'FIRST',
129+
},
130+
});
131+
const instanceB = got.extend({
132+
https: {
133+
certificate: 'SECOND',
134+
},
135+
});
128136

129137
const merged = instanceA.extend(instanceB);
130138

@@ -133,13 +141,17 @@ test('merging instances with HTTPS options', t => {
133141
});
134142

135143
test('merging instances with HTTPS options undefined', t => {
136-
const instanceA = got.extend({https: {
137-
rejectUnauthorized: true,
138-
certificate: 'FIRST',
139-
}});
140-
const instanceB = got.extend({https: {
141-
certificate: undefined,
142-
}});
144+
const instanceA = got.extend({
145+
https: {
146+
rejectUnauthorized: true,
147+
certificate: 'FIRST',
148+
},
149+
});
150+
const instanceB = got.extend({
151+
https: {
152+
certificate: undefined,
153+
},
154+
});
143155

144156
const merged = instanceA.extend(instanceB);
145157

0 commit comments

Comments
 (0)