Skip to content

Commit

Permalink
Upgrade dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Oct 20, 2020
1 parent 7acd380 commit f65c9ef
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 31 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"ky"
],
"dependencies": {
"@sindresorhus/is": "^3.1.1",
"@sindresorhus/is": "^4.0.0",
"@szmarczak/http-timer": "^4.0.5",
"@types/cacheable-request": "^6.0.1",
"@types/responselike": "^1.0.0",
Expand All @@ -61,7 +61,7 @@
"@sinonjs/fake-timers": "^6.0.1",
"@types/benchmark": "^1.0.33",
"@types/express": "^4.17.7",
"@types/node": "^14.6.0",
"@types/node": "^14.14.0",
"@types/node-fetch": "^2.5.7",
"@types/pem": "^1.9.5",
"@types/pify": "^3.0.2",
Expand All @@ -87,11 +87,11 @@
"pify": "^5.0.0",
"sinon": "^9.0.3",
"slow-stream": "0.0.4",
"tempy": "^0.6.0",
"tempy": "^1.0.0",
"to-readable-stream": "^2.1.0",
"tough-cookie": "^4.0.0",
"typescript": "^4.0.2",
"xo": "^0.33.0"
"typescript": "4.0.3",
"xo": "^0.34.1"
},
"types": "dist/source",
"sideEffects": false,
Expand Down Expand Up @@ -123,7 +123,7 @@
"node/prefer-global/url": "off",
"node/prefer-global/url-search-params": "off",
"import/no-anonymous-default-export": "off",
"@typescript-eslint/no-invalid-void-type": "off"
"@typescript-eslint/no-implicit-any-catch": "off"
}
},
"runkitExampleFilename": "./documentation/examples/runkit-example.js"
Expand Down
26 changes: 11 additions & 15 deletions source/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ export interface Agents {
export const withoutBody: ReadonlySet<string> = new Set(['GET', 'HEAD']);

export interface ToughCookieJar {
getCookieString: ((currentUrl: string, options: {[key: string]: unknown}, cb: (err: Error | null, cookies: string) => void) => void)
getCookieString: ((currentUrl: string, options: Record<string, unknown>, cb: (err: Error | null, cookies: string) => void) => void)
& ((url: string, callback: (error: Error | null, cookieHeader: string) => void) => void);
setCookie: ((cookieOrString: unknown, currentUrl: string, options: {[key: string]: unknown}, cb: (err: Error | null, cookie: unknown) => void) => void)
setCookie: ((cookieOrString: unknown, currentUrl: string, options: Record<string, unknown>, cb: (err: Error | null, cookie: unknown) => void) => void)
& ((rawCookie: string, url: string, callback: (error: Error | null, result: unknown) => void) => void);
}

Expand Down Expand Up @@ -250,7 +250,7 @@ export type RequestFunction = (url: URL, options: RequestOptions, callback?: (re
export type Headers = Record<string, string | string[] | undefined>;

type CacheableRequestFunction = (
opts: string | URL | RequestOptions,
options: string | URL | RequestOptions,
cb?: (response: ServerResponse | ResponseLike) => void
) => CacheableRequest.Emitter;

Expand Down Expand Up @@ -436,7 +436,7 @@ interface PlainOptions extends URLOptions {
__Note #2__: This option is not enumerable and will not be merged with the instance defaults.
*/
form?: {[key: string]: any};
form?: Record<string, any>;

/**
JSON body. If the `Content-Type` header is not set, it will be set to `application/json`.
Expand All @@ -445,7 +445,7 @@ interface PlainOptions extends URLOptions {
__Note #2__: This option is not enumerable and will not be merged with the instance defaults.
*/
json?: {[key: string]: any};
json?: Record<string, any>;

/**
The URL to request, as a string, a [`https.request` options object](https://nodejs.org/api/https.html#https_https_request_options_callback), or a [WHATWG `URL`](https://nodejs.org/api/url.html#url_class_url).
Expand Down Expand Up @@ -500,7 +500,7 @@ interface PlainOptions extends URLOptions {
//=> 'key=a&key=b'
```
*/
searchParams?: string | {[key: string]: string | number | boolean | null | undefined} | URLSearchParams;
searchParams?: string | Record<string, string | number | boolean | null | undefined> | URLSearchParams;

/**
An instance of [`CacheableLookup`](https://github.com/szmarczak/cacheable-lookup) used for making DNS lookups.
Expand Down Expand Up @@ -1805,7 +1805,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
for (const event of knownHookEvents) {
const defaultHooks = defaults.hooks[event];

if (defaultHooks.length !== 0) {
if (defaultHooks.length > 0) {
// See https://github.com/microsoft/TypeScript/issues/31445#issuecomment-576929044
(options.hooks as any)[event] = [
...defaults.hooks[event],
Expand Down Expand Up @@ -2206,11 +2206,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
// Node.js <= 12.18.2 mistakenly emits the response `end` first.
(request as ClientRequest & {res: IncomingMessage | undefined}).res?.removeAllListeners('end');

if (error instanceof TimedOutTimeoutError) {
error = new TimeoutError(error, this.timings!, this);
} else {
error = new RequestError(error.message, error, this);
}
error = error instanceof TimedOutTimeoutError ? new TimeoutError(error, this.timings!, this) : new RequestError(error.message, error, this);

this._beforeError(error as RequestError);
});
Expand Down Expand Up @@ -2652,7 +2648,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
// TODO: What happens if it's from cache? Then this[kRequest] won't be defined.

this[kRequest]!.write(chunk, encoding!, (error?: Error | null) => {
if (!error && this._progressCallbacks.length !== 0) {
if (!error && this._progressCallbacks.length > 0) {
this._progressCallbacks.shift()!();
}

Expand Down Expand Up @@ -2729,7 +2725,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
The remote IP address.
*/
get ip(): string | undefined {
return this[kRequest]?.socket.remoteAddress;
return this.socket?.remoteAddress;
}

/**
Expand All @@ -2740,7 +2736,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
}

get socket(): Socket | undefined {
return this[kRequest]?.socket;
return this[kRequest]?.socket ?? undefined;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion source/core/utils/proxy-events.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {EventEmitter} from 'events';

type Fn = (...args: unknown[]) => void;
type Fns = {[key: string]: Fn};
type Fns = Record<string, Fn>;

export default function (from: EventEmitter, to: EventEmitter, events: string[]): () => void {
const fns: Fns = {};
Expand Down
2 changes: 1 addition & 1 deletion source/core/utils/url-to-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default (url: URL | UrlWithStringQuery): LegacyUrlOptions => {
path: `${url.pathname || ''}${url.search || ''}`
};

if (is.string(url.port) && url.port.length !== 0) {
if (is.string(url.port) && url.port.length > 0) {
options.port = Number(url.port);
}

Expand Down
8 changes: 4 additions & 4 deletions test/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ test('ability to pass a custom request method', withServer, async (t, server, go

const request: RequestFunction = (...args: [
string | URL | RequestOptions,
(RequestOptions | ((res: IncomingMessage) => void))?,
((res: IncomingMessage) => void)?
(RequestOptions | ((response: IncomingMessage) => void))?,
((response: IncomingMessage) => void)?
]) => {
isCalled = true;
// @ts-expect-error Overload error
Expand All @@ -214,8 +214,8 @@ test('does not include the `request` option in normalized `http` options', withS

const request: RequestFunction = (...args: [
string | URL | RequestOptions,
(RequestOptions | ((res: IncomingMessage) => void))?,
((res: IncomingMessage) => void)?
(RequestOptions | ((response: IncomingMessage) => void))?,
((response: IncomingMessage) => void)?
]) => {
isCalled = true;

Expand Down
6 changes: 3 additions & 3 deletions test/retry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ test('works on timeout', withServer, async (t, server, got) => {
},
request: (...args: [
string | URL | http.RequestOptions,
(http.RequestOptions | ((res: http.IncomingMessage) => void))?,
((res: http.IncomingMessage) => void)?
(http.RequestOptions | ((response: http.IncomingMessage) => void))?,
((response: http.IncomingMessage) => void)?
]) => {
if (knocks === 1) {
// @ts-expect-error Overload error
Expand Down Expand Up @@ -413,7 +413,7 @@ test('does not destroy the socket on HTTP error', withServer, async (t, server,
http: agent
}
}).on('request', request => {
sockets.push(request.socket);
sockets.push(request.socket!);
});

t.is(sockets.length, 2);
Expand Down
2 changes: 1 addition & 1 deletion test/timeout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ test.serial('no unhandled timeout errors', withServer, async (t, _server, got) =
const result = http.request(...args);

result.once('socket', () => {
result.socket.destroy();
result.socket?.destroy();
});

return result;
Expand Down

0 comments on commit f65c9ef

Please sign in to comment.