From f65c9efd2f343dcabc72d0fb235228aea31719f1 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 20 Oct 2020 19:00:05 +0200 Subject: [PATCH] Upgrade dependencies --- package.json | 12 ++++++------ source/core/index.ts | 26 +++++++++++--------------- source/core/utils/proxy-events.ts | 2 +- source/core/utils/url-to-options.ts | 2 +- test/create.ts | 8 ++++---- test/retry.ts | 6 +++--- test/timeout.ts | 2 +- 7 files changed, 27 insertions(+), 31 deletions(-) diff --git a/package.json b/package.json index 5e76e27ae..fe8f6ccc0 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", @@ -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, @@ -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" diff --git a/source/core/index.ts b/source/core/index.ts index 8b8b0966e..7c43f4fcd 100644 --- a/source/core/index.ts +++ b/source/core/index.ts @@ -66,9 +66,9 @@ export interface Agents { export const withoutBody: ReadonlySet = 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, 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, cb: (err: Error | null, cookie: unknown) => void) => void) & ((rawCookie: string, url: string, callback: (error: Error | null, result: unknown) => void) => void); } @@ -250,7 +250,7 @@ export type RequestFunction = (url: URL, options: RequestOptions, callback?: (re export type Headers = Record; type CacheableRequestFunction = ( - opts: string | URL | RequestOptions, + options: string | URL | RequestOptions, cb?: (response: ServerResponse | ResponseLike) => void ) => CacheableRequest.Emitter; @@ -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; /** JSON body. If the `Content-Type` header is not set, it will be set to `application/json`. @@ -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; /** 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). @@ -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 | URLSearchParams; /** An instance of [`CacheableLookup`](https://github.com/szmarczak/cacheable-lookup) used for making DNS lookups. @@ -1805,7 +1805,7 @@ export default class Request extends Duplex implements RequestEvents { 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], @@ -2206,11 +2206,7 @@ export default class Request extends Duplex implements RequestEvents { // 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); }); @@ -2652,7 +2648,7 @@ export default class Request extends Duplex implements RequestEvents { // 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()!(); } @@ -2729,7 +2725,7 @@ export default class Request extends Duplex implements RequestEvents { The remote IP address. */ get ip(): string | undefined { - return this[kRequest]?.socket.remoteAddress; + return this.socket?.remoteAddress; } /** @@ -2740,7 +2736,7 @@ export default class Request extends Duplex implements RequestEvents { } get socket(): Socket | undefined { - return this[kRequest]?.socket; + return this[kRequest]?.socket ?? undefined; } /** diff --git a/source/core/utils/proxy-events.ts b/source/core/utils/proxy-events.ts index bd78b4a64..b231e5360 100644 --- a/source/core/utils/proxy-events.ts +++ b/source/core/utils/proxy-events.ts @@ -1,7 +1,7 @@ import {EventEmitter} from 'events'; type Fn = (...args: unknown[]) => void; -type Fns = {[key: string]: Fn}; +type Fns = Record; export default function (from: EventEmitter, to: EventEmitter, events: string[]): () => void { const fns: Fns = {}; diff --git a/source/core/utils/url-to-options.ts b/source/core/utils/url-to-options.ts index 3b0ab107a..06342f58b 100644 --- a/source/core/utils/url-to-options.ts +++ b/source/core/utils/url-to-options.ts @@ -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); } diff --git a/test/create.ts b/test/create.ts index 5f7ffc68b..4b767ac95 100644 --- a/test/create.ts +++ b/test/create.ts @@ -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 @@ -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; diff --git a/test/retry.ts b/test/retry.ts index 580a92705..4647cc7a4 100644 --- a/test/retry.ts +++ b/test/retry.ts @@ -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 @@ -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); diff --git a/test/timeout.ts b/test/timeout.ts index d06041a00..fc1cebdeb 100644 --- a/test/timeout.ts +++ b/test/timeout.ts @@ -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;