From 9f06060a3d35a1aafe8bd7a6b3c708409f1c2ece Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 30 Aug 2022 01:56:33 +0700 Subject: [PATCH] Upgrade dependencies --- .github/workflows/main.yml | 6 +-- benchmark/index.ts | 2 +- benchmark/server.ts | 2 +- package.json | 13 +++--- source/as-promise/index.ts | 8 ++-- source/as-promise/types.ts | 4 +- source/core/index.ts | 22 ++++++---- source/core/options.ts | 53 ++++++++++++------------ source/core/response.ts | 8 ++-- source/core/timed-out.ts | 11 ++--- source/core/utils/get-body-size.ts | 2 +- source/core/utils/is-form-data.ts | 6 +-- source/core/utils/is-unix-socket-url.ts | 2 +- source/core/utils/options-to-url.ts | 4 +- source/core/utils/proxy-events.ts | 2 +- source/core/utils/unhandle.ts | 10 ++--- source/core/utils/url-to-options.ts | 6 +-- source/create.ts | 8 ++-- source/index.ts | 2 +- source/types.ts | 20 ++++----- test/abort.ts | 11 +++-- test/agent.ts | 2 +- test/arguments.ts | 4 +- test/cache.ts | 4 +- test/cancel.ts | 6 +-- test/create.ts | 19 +++++---- test/error.ts | 2 +- test/gzip.ts | 2 +- test/headers.ts | 4 +- test/helpers/create-http-test-server.ts | 8 ++-- test/helpers/create-https-test-server.ts | 8 ++-- test/helpers/invalid-url.ts | 4 +- test/helpers/slow-data-stream.ts | 2 +- test/helpers/types.ts | 12 +++--- test/helpers/with-server.ts | 16 ++++--- test/hooks.ts | 20 +++++---- test/http.ts | 4 +- test/https.ts | 2 +- test/merge-instances.ts | 4 +- test/pagination.ts | 16 +++---- test/post.ts | 4 +- test/progress.ts | 6 +-- test/promise.ts | 2 +- test/redirects.ts | 2 +- test/response-parse.ts | 2 +- test/retry.ts | 6 +-- test/stream.ts | 2 +- test/timeout.ts | 8 ++-- test/types/create-test-server/index.d.ts | 6 +-- test/types/slow-stream/index.d.ts | 2 +- test/unix-socket.ts | 2 +- 51 files changed, 203 insertions(+), 180 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 76d555e11..c28f3354c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,13 +18,13 @@ jobs: - macos-latest - windows-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} - run: npm install - run: npm test - # - uses: codecov/codecov-action@v2 + # - uses: codecov/codecov-action@v3 # if: matrix.os == 'ubuntu-latest' && matrix.node-version == 16 # with: # fail_ci_if_error: true diff --git a/benchmark/index.ts b/benchmark/index.ts index d97e0f355..5c0a58e90 100644 --- a/benchmark/index.ts +++ b/benchmark/index.ts @@ -6,7 +6,7 @@ import fetch from 'node-fetch'; import request from 'request'; import got from '../source/index.js'; import Request from '../source/core/index.js'; -import Options, {OptionsInit} from '../source/core/options.js'; +import Options, {type OptionsInit} from '../source/core/options.js'; // Configuration const httpsAgent = new https.Agent({ diff --git a/benchmark/server.ts b/benchmark/server.ts index fa1eb0caf..5b11a1bd8 100644 --- a/benchmark/server.ts +++ b/benchmark/server.ts @@ -1,4 +1,4 @@ -import {AddressInfo} from 'node:net'; +import type {AddressInfo} from 'node:net'; import https from 'node:https'; // @ts-expect-error No types import createCert from 'create-cert'; diff --git a/package.json b/package.json index dbfbfd9b1..e3b47b9fc 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,6 @@ "@sindresorhus/is": "^5.2.0", "@szmarczak/http-timer": "^5.0.1", "@types/cacheable-request": "^6.0.2", - "@types/responselike": "^1.0.0", "cacheable-lookup": "^6.0.4", "cacheable-request": "^7.0.2", "decompress-response": "^6.0.0", @@ -57,15 +56,15 @@ "http2-wrapper": "^2.1.10", "lowercase-keys": "^3.0.0", "p-cancelable": "^3.0.0", - "responselike": "^2.0.0" + "responselike": "^3.0.0" }, "devDependencies": { "@hapi/bourne": "^3.0.0", "@sindresorhus/tsconfig": "^2.0.0", "@sinonjs/fake-timers": "^9.1.1", - "@types/benchmark": "^2.1.1", + "@types/benchmark": "^2.1.2", "@types/express": "^4.17.13", - "@types/node": "^18.0.1", + "@types/node": "^18.7.13", "@types/pem": "^1.9.6", "@types/pify": "^5.0.1", "@types/readable-stream": "^2.3.13", @@ -80,7 +79,7 @@ "body-parser": "^1.19.2", "create-cert": "^1.0.6", "create-test-server": "^3.0.1", - "del-cli": "^4.0.1", + "del-cli": "^5.0.0", "delay": "^5.0.0", "express": "^4.17.3", "form-data": "^4.0.0", @@ -101,8 +100,8 @@ "to-readable-stream": "^3.0.0", "tough-cookie": "4.0.0", "ts-node": "^10.8.2", - "typescript": "^4.7.4", - "xo": "^0.50.0" + "typescript": "~4.8.2", + "xo": "^0.52.2" }, "sideEffects": false, "ava": { diff --git a/source/as-promise/index.ts b/source/as-promise/index.ts index 5e7bd2bb4..eee8903da 100644 --- a/source/as-promise/index.ts +++ b/source/as-promise/index.ts @@ -2,17 +2,15 @@ import {EventEmitter} from 'node:events'; import is from '@sindresorhus/is'; import PCancelable from 'p-cancelable'; import { - RequestError, HTTPError, RetryError, + type RequestError, } from '../core/errors.js'; import Request from '../core/index.js'; -import {parseBody, isResponseOk} from '../core/response.js'; +import {parseBody, isResponseOk, type Response} from '../core/response.js'; import proxyEvents from '../core/utils/proxy-events.js'; import type Options from '../core/options.js'; -import type {Response} from '../core/response.js'; -import {CancelError} from './types.js'; -import type {CancelableRequest} from './types.js'; +import {CancelError, type CancelableRequest} from './types.js'; const proxiedRequestEvents = [ 'request', diff --git a/source/as-promise/types.ts b/source/as-promise/types.ts index 261cf3fa2..5d6b07d06 100644 --- a/source/as-promise/types.ts +++ b/source/as-promise/types.ts @@ -1,5 +1,5 @@ import type {Buffer} from 'node:buffer'; -import PCancelable from 'p-cancelable'; +import type PCancelable from 'p-cancelable'; import {RequestError} from '../core/errors.js'; import type Request from '../core/index.js'; import type {RequestEvents} from '../core/index.js'; @@ -25,6 +25,8 @@ export class CancelError extends RequestError { } } +// TODO: Make this a `type`. +// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- TS cannot handle this being a `type` for some reason. export interface CancelableRequest extends PCancelable, RequestEvents> { /** A shortcut method that gives a Promise returning a JSON object. diff --git a/source/core/index.ts b/source/core/index.ts index 079d349ac..edb12467d 100644 --- a/source/core/index.ts +++ b/source/core/index.ts @@ -1,6 +1,6 @@ import process from 'node:process'; import {Buffer} from 'node:buffer'; -import {Duplex, Readable} from 'node:stream'; +import {Duplex, type Readable} from 'node:stream'; import {URL, URLSearchParams} from 'node:url'; import http, {ServerResponse} from 'node:http'; import type {ClientRequest, RequestOptions} from 'node:http'; @@ -20,8 +20,14 @@ import timedOut, {TimeoutError as TimedOutTimeoutError} from './timed-out.js'; import urlToOptions from './utils/url-to-options.js'; import WeakableMap from './utils/weakable-map.js'; import calculateRetryDelay from './calculate-retry-delay.js'; -import Options, {OptionsError, OptionsInit} from './options.js'; -import {isResponseOk, Response} from './response.js'; +import Options, { + type PromiseCookieJar, + type NativeRequestOptions, + type RetryOptions, + type OptionsError, + type OptionsInit, +} from './options.js'; +import {isResponseOk, type PlainResponse, type Response} from './response.js'; import isClientRequest from './utils/is-client-request.js'; import isUnixSocketURL from './utils/is-unix-socket-url.js'; import { @@ -34,16 +40,14 @@ import { CacheError, AbortError, } from './errors.js'; -import type {PlainResponse} from './response.js'; -import type {PromiseCookieJar, NativeRequestOptions, RetryOptions} from './options.js'; type Error = NodeJS.ErrnoException; -export interface Progress { +export type Progress = { percent: number; transferred: number; total?: number; -} +}; const supportsBrotli = is.string(process.versions.brotli); @@ -114,11 +118,11 @@ export type GotEventFunction = */ & ((name: 'retry', listener: (retryCount: number, error: RequestError) => void) => T); -export interface RequestEvents { +export type RequestEvents = { on: GotEventFunction; once: GotEventFunction; off: GotEventFunction; -} +}; export type CacheableRequestFunction = ( options: string | URL | NativeRequestOptions, diff --git a/source/core/options.ts b/source/core/options.ts index 110e763e7..f5bff81d9 100644 --- a/source/core/options.ts +++ b/source/core/options.ts @@ -1,5 +1,5 @@ import process from 'node:process'; -import {Buffer} from 'node:buffer'; +import type {Buffer} from 'node:buffer'; import {promisify, inspect} from 'node:util'; import {URL, URLSearchParams} from 'node:url'; import {checkServerIdentity} from 'node:tls'; @@ -21,7 +21,7 @@ import type {InspectOptions} from 'node:util'; import is, {assert} from '@sindresorhus/is'; import lowercaseKeys from 'lowercase-keys'; import CacheableLookup from 'cacheable-lookup'; -import http2wrapper, {ClientHttp2Session} from 'http2-wrapper'; +import http2wrapper, {type ClientHttp2Session} from 'http2-wrapper'; import {isFormData} from 'form-data-encoder'; import type {FormDataLike} from 'form-data-encoder'; import type CacheableRequest from 'cacheable-request'; @@ -47,25 +47,25 @@ type AcceptableResponse = IncomingMessageWithTimings | ResponseLike; type AcceptableRequestResult = Promisable | undefined; export type RequestFunction = (url: URL, options: NativeRequestOptions, callback?: (response: AcceptableResponse) => void) => AcceptableRequestResult; -export interface Agents { +export type Agents = { http?: HttpAgent | false; https?: HttpsAgent | false; http2?: unknown | false; -} +}; export type Headers = Record; -export interface ToughCookieJar { +export type ToughCookieJar = { getCookieString: ((currentUrl: string, options: Record, cb: (error: Error | null, cookies: string) => void) => void) // eslint-disable-line @typescript-eslint/ban-types & ((url: string, callback: (error: Error | null, cookieHeader: string) => void) => void); // eslint-disable-line @typescript-eslint/ban-types setCookie: ((cookieOrString: unknown, currentUrl: string, options: Record, cb: (error: Error | null, cookie: unknown) => void) => void) // eslint-disable-line @typescript-eslint/ban-types & ((rawCookie: string, url: string, callback: (error: Error | null, result: unknown) => void) => void); // eslint-disable-line @typescript-eslint/ban-types -} +}; -export interface PromiseCookieJar { +export type PromiseCookieJar = { getCookieString: (url: string) => Promise; setCookie: (rawCookie: string, url: string) => Promise; -} +}; export type InitHook = (init: OptionsInit, self: Options) => void; export type BeforeRequestHook = (options: Options) => Promisable; @@ -77,7 +77,7 @@ export type AfterResponseHook = (response: Response unknown; export type StringifyJsonFunction = (object: unknown) => string; @@ -376,13 +376,13 @@ export type Method = | 'options' | 'trace'; -export interface RetryObject { +export type RetryObject = { attemptCount: number; retryOptions: RetryOptions; error: RequestError; computedValue: number; retryAfter?: number; -} +}; export type RetryFunction = (retryObject: RetryObject) => Promisable; @@ -408,7 +408,7 @@ __Note:__ Got does not retry on `POST` by default. __Note:__ If `maxRetryAfter` is set to `undefined`, it will use `options.timeout`. __Note:__ If [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) header is greater than `maxRetryAfter`, it will cancel the request. */ -export interface RetryOptions { +export type RetryOptions = { limit: number; methods: Method[]; statusCodes: number[]; @@ -417,17 +417,17 @@ export interface RetryOptions { backoffLimit: number; noise: number; maxRetryAfter?: number; -} +}; export type CreateConnectionFunction = (options: NativeRequestOptions, oncreate: (error: NodeJS.ErrnoException, socket: Socket) => void) => Socket; export type CheckServerIdentityFunction = (hostname: string, certificate: DetailedPeerCertificate) => NodeJS.ErrnoException | void; -export interface CacheOptions { +export type CacheOptions = { shared?: boolean; cacheHeuristic?: number; immutableMinTimeToLive?: number; ignoreCargoCult?: boolean; -} +}; type PfxObject = { buffer: string | Buffer; @@ -436,7 +436,7 @@ type PfxObject = { type PfxType = string | Buffer | Array | undefined; -export interface HttpsOptions { +export type HttpsOptions = { alpnProtocols?: string[]; // From `http.RequestOptions` and `tls.CommonConnectionOptions` @@ -497,24 +497,24 @@ export interface HttpsOptions { dhparam?: SecureContextOptions['dhparam']; ecdhCurve?: SecureContextOptions['ecdhCurve']; certificateRevocationLists?: SecureContextOptions['crl']; -} +}; -export interface PaginateData { +export type PaginateData = { response: Response; currentItems: ElementType[]; allItems: ElementType[]; -} +}; -export interface FilterData { +export type FilterData = { item: ElementType; currentItems: ElementType[]; allItems: ElementType[]; -} +}; /** All options accepted by `got.paginate()`. */ -export interface PaginationOptions { +export type PaginationOptions = { /** A function that transform [`Response`](#response) into an array of items. This is where you should do the parsing. @@ -619,7 +619,7 @@ export interface PaginationOptions { @default false */ stackAllItems?: boolean; -} +}; export type SearchParameters = Record; // eslint-disable-line @typescript-eslint/ban-types @@ -1142,6 +1142,7 @@ export default class Options { throw new TypeError(`Unexpected agent option: ${key}`); } + // @ts-expect-error - No idea why `value[key]` doesn't work here. assert.any([is.object, is.undefined], value[key]); } @@ -1210,6 +1211,7 @@ export default class Options { throw new Error(`Unexpected timeout option: ${key}`); } + // @ts-expect-error - No idea why `value[key]` doesn't work here. assert.any([is.number, is.undefined], value[key]); } @@ -1732,8 +1734,7 @@ export default class Options { } const typedKnownHookEvent = knownHookEvent as keyof Hooks; - const typedValue = value as Hooks; - const hooks = typedValue[typedKnownHookEvent]; + const hooks = value[typedKnownHookEvent]; assert.any([is.array, is.undefined], hooks); diff --git a/source/core/response.ts b/source/core/response.ts index 6fee258b0..256789aee 100644 --- a/source/core/response.ts +++ b/source/core/response.ts @@ -5,7 +5,7 @@ import {RequestError} from './errors.js'; import type {ParseJsonFunction, ResponseType} from './options.js'; import type Request from './index.js'; -export interface PlainResponse extends IncomingMessageWithTimings { +export type PlainResponse = { /** The original request URL. */ @@ -98,10 +98,10 @@ export interface PlainResponse extends IncomingMessageWithTimings { __Note__: Got throws automatically when `response.ok` is `false` and `throwHttpErrors` is `true`. */ ok: boolean; -} +} & IncomingMessageWithTimings; // For Promise support -export interface Response extends PlainResponse { +export type Response = { /** The result of the request. */ @@ -111,7 +111,7 @@ export interface Response extends PlainResponse { The raw result of the request. */ rawBody: Buffer; -} +} & PlainResponse; export const isResponseOk = (response: PlainResponse): boolean => { const {statusCode} = response; diff --git a/source/core/timed-out.ts b/source/core/timed-out.ts index 7d19ac731..77f175647 100644 --- a/source/core/timed-out.ts +++ b/source/core/timed-out.ts @@ -1,17 +1,17 @@ import net from 'node:net'; -import {ClientRequest, IncomingMessage} from 'node:http'; +import type {ClientRequest, IncomingMessage} from 'node:http'; import unhandler from './utils/unhandle.js'; const reentry: unique symbol = Symbol('reentry'); const noop = (): void => {}; -interface TimedOutOptions { +type TimedOutOptions = { host?: string; hostname?: string; protocol?: string; -} +}; -export interface Delays { +export type Delays = { lookup?: number; socket?: number; connect?: number; @@ -20,7 +20,7 @@ export interface Delays { response?: number; read?: number; request?: number; -} +}; export type ErrorCode = | 'ETIMEDOUT' @@ -186,6 +186,7 @@ export default function timedOut(request: ClientRequest, delays: Delays, options } declare module 'http' { + // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- This has to be an `interface` to be able to be merged. interface ClientRequest { [reentry]: boolean; } diff --git a/source/core/utils/get-body-size.ts b/source/core/utils/get-body-size.ts index bf032449a..02edd0f04 100644 --- a/source/core/utils/get-body-size.ts +++ b/source/core/utils/get-body-size.ts @@ -1,6 +1,6 @@ import {Buffer} from 'node:buffer'; import {promisify} from 'node:util'; -import {ClientRequestArgs} from 'node:http'; +import type {ClientRequestArgs} from 'node:http'; import is from '@sindresorhus/is'; import isFormData from './is-form-data.js'; diff --git a/source/core/utils/is-form-data.ts b/source/core/utils/is-form-data.ts index 81335ee50..8de3c73d8 100644 --- a/source/core/utils/is-form-data.ts +++ b/source/core/utils/is-form-data.ts @@ -1,10 +1,10 @@ -import {Readable} from 'node:stream'; +import type {Readable} from 'node:stream'; import is from '@sindresorhus/is'; -interface FormData extends Readable { +type FormData = { getBoundary: () => string; getLength: (callback: (error: Error | null, length: number) => void) => void; // eslint-disable-line @typescript-eslint/ban-types -} +} & Readable; export default function isFormData(body: unknown): body is FormData { return is.nodeStream(body) && is.function_((body as FormData).getBoundary); diff --git a/source/core/utils/is-unix-socket-url.ts b/source/core/utils/is-unix-socket-url.ts index af1dc3d09..e96188bcd 100644 --- a/source/core/utils/is-unix-socket-url.ts +++ b/source/core/utils/is-unix-socket-url.ts @@ -1,4 +1,4 @@ -import {URL} from 'url'; +import type {URL} from 'url'; // eslint-disable-next-line @typescript-eslint/naming-convention export default function isUnixSocketURL(url: URL) { diff --git a/source/core/utils/options-to-url.ts b/source/core/utils/options-to-url.ts index c56969c62..b5edd0421 100644 --- a/source/core/utils/options-to-url.ts +++ b/source/core/utils/options-to-url.ts @@ -2,7 +2,7 @@ import {URL} from 'node:url'; // eslint-disable-next-line @typescript-eslint/naming-convention -export interface URLOptions { +export type URLOptions = { href?: string; protocol?: string; host?: string; @@ -12,7 +12,7 @@ export interface URLOptions { search?: string; searchParams?: unknown; path?: string; -} +}; const keys: Array> = [ 'protocol', diff --git a/source/core/utils/proxy-events.ts b/source/core/utils/proxy-events.ts index ae6ac644e..ad185eaf8 100644 --- a/source/core/utils/proxy-events.ts +++ b/source/core/utils/proxy-events.ts @@ -1,4 +1,4 @@ -import {EventEmitter} from 'node:events'; +import type {EventEmitter} from 'node:events'; type Fn = (...args: unknown[]) => void; type Fns = Record; diff --git a/source/core/utils/unhandle.ts b/source/core/utils/unhandle.ts index 29a3fb2cb..9837444fa 100644 --- a/source/core/utils/unhandle.ts +++ b/source/core/utils/unhandle.ts @@ -1,19 +1,19 @@ -import {EventEmitter} from 'node:events'; +import type {EventEmitter} from 'node:events'; type Origin = EventEmitter; type Event = string | symbol; type Fn = (...args: any[]) => void; -interface Handler { +type Handler = { origin: Origin; event: Event; fn: Fn; -} +}; -interface Unhandler { +type Unhandler = { once: (origin: Origin, event: Event, fn: Fn) => void; unhandleAll: () => void; -} +}; // When attaching listeners, it's very easy to forget about them. // Especially if you do error handling and set timeouts. diff --git a/source/core/utils/url-to-options.ts b/source/core/utils/url-to-options.ts index f880fb33c..13d2168e2 100644 --- a/source/core/utils/url-to-options.ts +++ b/source/core/utils/url-to-options.ts @@ -1,9 +1,9 @@ -import {URL, UrlWithStringQuery} from 'node:url'; +import type {URL, UrlWithStringQuery} from 'node:url'; import is from '@sindresorhus/is'; // TODO: Deprecate legacy URL at some point -export interface LegacyUrlOptions { +export type LegacyUrlOptions = { protocol: string; hostname: string; host: string; @@ -14,7 +14,7 @@ export interface LegacyUrlOptions { path: string; port?: number; auth?: string; -} +}; export default function urlToOptions(url: URL | UrlWithStringQuery): LegacyUrlOptions { // Cast to URL diff --git a/source/create.ts b/source/create.ts index 376fda30f..c40337bab 100644 --- a/source/create.ts +++ b/source/create.ts @@ -1,7 +1,7 @@ -import {URL} from 'node:url'; +import type {URL} from 'node:url'; import is, {assert} from '@sindresorhus/is'; import asPromise from './as-promise/index.js'; -import { +import type { GotReturn, ExtendOptions, Got, @@ -14,8 +14,8 @@ import { StreamOptions, } from './types.js'; import Request from './core/index.js'; -import {Response} from './core/response.js'; -import Options, {OptionsInit} from './core/options.js'; +import type {Response} from './core/response.js'; +import Options, {type OptionsInit} from './core/options.js'; import type {CancelableRequest} from './as-promise/types.js'; // The `delay` package weighs 10KB (!) diff --git a/source/index.ts b/source/index.ts index 855a103fd..817beb427 100644 --- a/source/index.ts +++ b/source/index.ts @@ -1,5 +1,5 @@ import create from './create.js'; -import {InstanceDefaults} from './types.js'; +import type {InstanceDefaults} from './types.js'; import Options from './core/options.js'; const defaults: InstanceDefaults = { diff --git a/source/types.ts b/source/types.ts index 81f9957a3..9c34a4335 100644 --- a/source/types.ts +++ b/source/types.ts @@ -13,7 +13,7 @@ type Merge = Except(options: Options, next: (opt /** The options available for `got.extend()`. */ -export interface ExtendOptions extends OptionsInit { +export type ExtendOptions = { /** An array of functions. You execute them directly by calling `got()`. They are some sort of "global hooks" - these functions are called first. @@ -68,7 +68,7 @@ export interface ExtendOptions extends OptionsInit { @default false */ mutableDefaults?: boolean; -} +} & OptionsInit; export type OptionsOfTextResponseBody = Merge; // eslint-disable-next-line @typescript-eslint/naming-convention @@ -84,7 +84,7 @@ export type OptionsWithPagination = Merge(url: string | URL, options?: OptionsWithPagination) => Promise) & ((options?: OptionsWithPagination) => Promise); -} +}; -export interface GotRequestFunction { +export type GotRequestFunction = { // `asPromise` usage (url: string | URL, options?: OptionsOfTextResponseBody): CancelableRequest>; (url: string | URL, options?: OptionsOfJSONResponseBody): CancelableRequest>; @@ -176,7 +176,7 @@ export interface GotRequestFunction { // Internal usage (url: undefined, options: undefined, defaults: Options): CancelableRequest | Request; -} +}; /** All available HTTP request methods provided by Got. @@ -202,7 +202,7 @@ export type GotStream = GotStreamFunction & Record /** An instance of `got`. */ -export interface Got extends Record, GotRequestFunction { +export type Got = { /** Sets `options.isStream` to `true`. @@ -276,4 +276,4 @@ export interface Got extends Record, GotRequestFu ``` */ extend: (...instancesOrOptions: Array) => Got; -} +} & Record & GotRequestFunction; diff --git a/test/abort.ts b/test/abort.ts index fea2c1c67..92d81f448 100644 --- a/test/abort.ts +++ b/test/abort.ts @@ -4,13 +4,14 @@ import stream, {Readable as ReadableStream} from 'stream'; import test from 'ava'; import delay from 'delay'; import {pEvent} from 'p-event'; -import {Handler} from 'express'; +import type {Handler} from 'express'; import got from '../source/index.js'; import slowDataStream from './helpers/slow-data-stream.js'; -import {GlobalClock} from './helpers/types.js'; -import {ExtendedHttpTestServer} from './helpers/create-http-test-server.js'; +import type {GlobalClock} from './helpers/types.js'; +import type {ExtendedHttpTestServer} from './helpers/create-http-test-server.js'; import withServer, {withServerAndFakeTimers} from './helpers/with-server.js'; +// eslint-disable-next-line no-negated-condition if (globalThis.AbortController !== undefined) { const prepareServer = (server: ExtendedHttpTestServer, clock: GlobalClock): {emitter: EventEmitter; promise: Promise} => { const emitter = new EventEmitter(); @@ -284,4 +285,8 @@ if (globalThis.AbortController !== undefined) { message: 'This operation was aborted.', }); }); +} else { + test('x', t => { + t.pass(); + }); } diff --git a/test/agent.ts b/test/agent.ts index a8087d959..66a023a41 100644 --- a/test/agent.ts +++ b/test/agent.ts @@ -1,6 +1,6 @@ import {Agent as HttpAgent} from 'http'; import {Agent as HttpsAgent} from 'https'; -import test, {Constructor} from 'ava'; +import test, {type Constructor} from 'ava'; import sinon from 'sinon'; import withServer, {withHttpsServer} from './helpers/with-server.js'; diff --git a/test/arguments.ts b/test/arguments.ts index 73d2776de..5de4fb54f 100644 --- a/test/arguments.ts +++ b/test/arguments.ts @@ -1,8 +1,8 @@ import {parse, URL, URLSearchParams} from 'url'; import test from 'ava'; -import {Handler} from 'express'; +import type {Handler} from 'express'; import {pEvent} from 'p-event'; -import got, {Options, RequestError, StrictOptions} from '../source/index.js'; +import got, {Options, RequestError, type StrictOptions} from '../source/index.js'; import withServer, {withBodyParsingServer} from './helpers/with-server.js'; import invalidUrl from './helpers/invalid-url.js'; diff --git a/test/cache.ts b/test/cache.ts index 70e7d38a5..a6059cbf9 100644 --- a/test/cache.ts +++ b/test/cache.ts @@ -5,11 +5,11 @@ import {gzip} from 'zlib'; import test from 'ava'; import {pEvent} from 'p-event'; import getStream from 'get-stream'; -import {Handler} from 'express'; +import type {Handler} from 'express'; import nock from 'nock'; import CacheableLookup from 'cacheable-lookup'; import delay from 'delay'; -import got, {CacheError, Response} from '../source/index.js'; +import got, {CacheError, type Response} from '../source/index.js'; import withServer from './helpers/with-server.js'; const cacheEndpoint: Handler = (_request, response) => { diff --git a/test/cancel.ts b/test/cancel.ts index c41ac0861..deeb514d8 100644 --- a/test/cancel.ts +++ b/test/cancel.ts @@ -5,11 +5,11 @@ import test from 'ava'; import delay from 'delay'; import {pEvent} from 'p-event'; import getStream from 'get-stream'; -import {Handler} from 'express'; +import type {Handler} from 'express'; import got, {CancelError, TimeoutError, RequestError} from '../source/index.js'; import slowDataStream from './helpers/slow-data-stream.js'; -import {GlobalClock} from './helpers/types.js'; -import {ExtendedHttpTestServer} from './helpers/create-http-test-server.js'; +import type {GlobalClock} from './helpers/types.js'; +import type {ExtendedHttpTestServer} from './helpers/create-http-test-server.js'; import withServer, {withServerAndFakeTimers} from './helpers/with-server.js'; const prepareServer = (server: ExtendedHttpTestServer, clock: GlobalClock): {emitter: EventEmitter; promise: Promise} => { diff --git a/test/create.ts b/test/create.ts index 4e3d00eb3..1b1df29a0 100644 --- a/test/create.ts +++ b/test/create.ts @@ -1,16 +1,21 @@ -import {Agent as HttpAgent, IncomingMessage, request as httpRequest, RequestOptions} from 'http'; +import { + Agent as HttpAgent, + request as httpRequest, + type IncomingMessage, + type RequestOptions, +} from 'http'; import {URL} from 'url'; import test from 'ava'; import is from '@sindresorhus/is'; -import {Handler} from 'express'; +import type {Handler} from 'express'; import delay from 'delay'; import got, { - BeforeRequestHook, - Headers, - Hooks, Options, - OptionsInit, - RequestFunction, + type BeforeRequestHook, + type Headers, + type Hooks, + type OptionsInit, + type RequestFunction, } from '../source/index.js'; import withServer from './helpers/with-server.js'; diff --git a/test/error.ts b/test/error.ts index e50c658d0..643b9e27f 100644 --- a/test/error.ts +++ b/test/error.ts @@ -8,7 +8,7 @@ import test from 'ava'; import getStream from 'get-stream'; import is from '@sindresorhus/is'; import got, {RequestError, HTTPError, TimeoutError} from '../source/index.js'; -import Request from '../source/core/index.js'; +import type Request from '../source/core/index.js'; import withServer from './helpers/with-server.js'; import invalidUrl from './helpers/invalid-url.js'; diff --git a/test/gzip.ts b/test/gzip.ts index e67014ceb..2d230aaa0 100644 --- a/test/gzip.ts +++ b/test/gzip.ts @@ -3,7 +3,7 @@ import {promisify} from 'util'; import zlib from 'zlib'; import test from 'ava'; import getStream from 'get-stream'; -import {HTTPError, ReadError} from '../source/index.js'; +import {ReadError, type HTTPError} from '../source/index.js'; import withServer from './helpers/with-server.js'; const testContent = 'Compressible response content.\n'; diff --git a/test/headers.ts b/test/headers.ts index 45a583ddb..0f70de4dc 100644 --- a/test/headers.ts +++ b/test/headers.ts @@ -3,11 +3,11 @@ import {Buffer} from 'buffer'; import fs from 'fs'; import path from 'path'; import test from 'ava'; -import {Handler} from 'express'; +import type {Handler} from 'express'; import FormData from 'form-data'; import {FormDataEncoder} from 'form-data-encoder'; import {FormData as FormDataNode} from 'formdata-node'; -import got, {Headers} from '../source/index.js'; +import got, {type Headers} from '../source/index.js'; import withServer from './helpers/with-server.js'; const supportsBrotli = typeof (process.versions as any).brotli === 'string'; diff --git a/test/helpers/create-http-test-server.ts b/test/helpers/create-http-test-server.ts index 2007175c9..139114eb4 100644 --- a/test/helpers/create-http-test-server.ts +++ b/test/helpers/create-http-test-server.ts @@ -1,6 +1,6 @@ import http from 'http'; -import net from 'net'; -import express, {Express, NextFunction} from 'express'; +import type net from 'net'; +import express, {type Express, type NextFunction} from 'express'; import pify from 'pify'; import bodyParser from 'body-parser'; @@ -8,13 +8,13 @@ export type HttpServerOptions = { bodyParser?: NextFunction | false; }; -export interface ExtendedHttpTestServer extends Express { +export type ExtendedHttpTestServer = { http: http.Server; url: string; port: number; hostname: string; close: () => Promise; -} +} & Express; const createHttpTestServer = async (options: HttpServerOptions = {}): Promise => { const server = express() as ExtendedHttpTestServer; diff --git a/test/helpers/create-https-test-server.ts b/test/helpers/create-https-test-server.ts index 1fa52c786..05b5c3565 100644 --- a/test/helpers/create-https-test-server.ts +++ b/test/helpers/create-https-test-server.ts @@ -1,6 +1,6 @@ -import {Buffer} from 'buffer'; +import type {Buffer} from 'buffer'; import https from 'https'; -import net from 'net'; +import type net from 'net'; import type {SecureContextOptions} from 'tls'; import express from 'express'; import pify from 'pify'; @@ -15,14 +15,14 @@ export type HttpsServerOptions = { maxVersion?: SecureContextOptions['maxVersion']; }; -export interface ExtendedHttpsTestServer extends express.Express { +export type ExtendedHttpsTestServer = { https: https.Server; caKey: Buffer; caCert: Buffer; url: string; port: number; close: () => Promise; -} +} & express.Express; const createHttpsTestServer = async (options: HttpsServerOptions = {}): Promise => { const createCsr = pify(pem.createCSR); diff --git a/test/helpers/invalid-url.ts b/test/helpers/invalid-url.ts index 38483474d..0500f358f 100644 --- a/test/helpers/invalid-url.ts +++ b/test/helpers/invalid-url.ts @@ -1,5 +1,5 @@ -// eslint-disable-next-line ava/use-test -import {ExecutionContext} from 'ava'; + +import type {ExecutionContext} from 'ava'; export default function invalidUrl(t: ExecutionContext, error: TypeError & NodeJS.ErrnoException, url: string) { t.is(error.code, 'ERR_INVALID_URL'); diff --git a/test/helpers/slow-data-stream.ts b/test/helpers/slow-data-stream.ts index c09bbc026..6bc1da1f4 100644 --- a/test/helpers/slow-data-stream.ts +++ b/test/helpers/slow-data-stream.ts @@ -1,5 +1,5 @@ import {Readable} from 'stream'; -import {Clock} from '@sinonjs/fake-timers'; +import type {Clock} from '@sinonjs/fake-timers'; import delay from 'delay'; export default function slowDataStream(clock?: Clock): Readable { diff --git a/test/helpers/types.ts b/test/helpers/types.ts index 510c04210..18e4c9f7e 100644 --- a/test/helpers/types.ts +++ b/test/helpers/types.ts @@ -1,15 +1,15 @@ -import {Server} from 'http'; +import type {Server} from 'http'; // @ts-expect-error Fails to locate ../types/create-test-server/index.d.ts -import {TestServer} from 'create-test-server'; +import type {TestServer} from 'create-test-server'; -export interface ExtendedHttpServer extends Server { +export type ExtendedHttpServer = { socketPath: string; -} +} & Server; -export interface ExtendedTestServer extends TestServer { +export type ExtendedTestServer = { hostname: string; sslHostname: string; -} +} & TestServer; // https://github.com/sinonjs/fake-timers/pull/386 export type InstalledClock = any; diff --git a/test/helpers/with-server.ts b/test/helpers/with-server.ts index 2ab4f06bc..da47b715a 100644 --- a/test/helpers/with-server.ts +++ b/test/helpers/with-server.ts @@ -1,13 +1,19 @@ import http from 'http'; import {promisify} from 'util'; -import {ExecutionContext, Macro} from 'ava'; // eslint-disable-line ava/use-test +import type {ExecutionContext, Macro} from 'ava'; import is from '@sindresorhus/is'; import {temporaryFile} from 'tempy'; import FakeTimers from '@sinonjs/fake-timers'; -import got, {Got, ExtendOptions} from '../../source/index.js'; -import createHttpsTestServer, {ExtendedHttpsTestServer, HttpsServerOptions} from './create-https-test-server.js'; -import createHttpTestServer, {ExtendedHttpTestServer, HttpServerOptions} from './create-http-test-server.js'; -import {ExtendedHttpServer, GlobalClock, InstalledClock} from './types.js'; +import got, {type Got, type ExtendOptions} from '../../source/index.js'; +import createHttpsTestServer, { + type ExtendedHttpsTestServer, + type HttpsServerOptions, +} from './create-https-test-server.js'; +import createHttpTestServer, { + type ExtendedHttpTestServer, + type HttpServerOptions, +} from './create-http-test-server.js'; +import type {ExtendedHttpServer, GlobalClock, InstalledClock} from './types.js'; export type RunTestWithServer = (t: ExecutionContext, server: ExtendedHttpTestServer, got: Got, clock: GlobalClock) => Promise | void; export type RunTestWithHttpsServer = (t: ExecutionContext, server: ExtendedHttpsTestServer, got: Got, fakeTimer?: GlobalClock) => Promise | void; diff --git a/test/hooks.ts b/test/hooks.ts index 39b41b59c..fab442a11 100644 --- a/test/hooks.ts +++ b/test/hooks.ts @@ -1,15 +1,15 @@ import {Buffer} from 'buffer'; import {URL} from 'url'; import {Agent as HttpAgent} from 'http'; -import test, {Constructor} from 'ava'; +import test, {type Constructor} from 'ava'; import nock from 'nock'; import getStream from 'get-stream'; import FormData from 'form-data'; import sinon from 'sinon'; import delay from 'delay'; -import {Handler} from 'express'; +import type {Handler} from 'express'; import Responselike from 'responselike'; -import got, {RequestError, HTTPError, Response, OptionsInit} from '../source/index.js'; +import got, {RequestError, HTTPError, type Response, type OptionsInit} from '../source/index.js'; import withServer from './helpers/with-server.js'; const errorString = 'oops'; @@ -368,12 +368,14 @@ test('returning HTTP response from a beforeRequest hook', withServer, async (t, const {statusCode, headers, body} = await got({ hooks: { beforeRequest: [ - () => new Responselike( - 200, - {foo: 'bar'}, - Buffer.from('Hi!'), - '', - ), + () => new Responselike({ + statusCode: 200, + headers: { + foo: 'bar', + }, + body: Buffer.from('Hi!'), + url: '', + }), ], }, }); diff --git a/test/http.ts b/test/http.ts index 662129461..e2a3ee045 100644 --- a/test/http.ts +++ b/test/http.ts @@ -4,11 +4,11 @@ import {STATUS_CODES, Agent} from 'http'; import os from 'os'; import {isIPv4, isIPv6, isIP} from 'net'; import test from 'ava'; -import {Handler} from 'express'; +import type {Handler} from 'express'; import nock from 'nock'; import getStream from 'get-stream'; import {pEvent} from 'p-event'; -import got, {HTTPError, ReadError, RequestError} from '../source/index.js'; +import got, {HTTPError, RequestError, type ReadError} from '../source/index.js'; import withServer from './helpers/with-server.js'; // eslint-disable-next-line @typescript-eslint/naming-convention diff --git a/test/https.ts b/test/https.ts index 999b86400..e1b80ec75 100644 --- a/test/https.ts +++ b/test/https.ts @@ -1,5 +1,5 @@ import process from 'process'; -import tls, {DetailedPeerCertificate} from 'tls'; +import tls, {type DetailedPeerCertificate} from 'tls'; import test from 'ava'; import {pEvent} from 'p-event'; import pify from 'pify'; diff --git a/test/merge-instances.ts b/test/merge-instances.ts index abd01b8b3..b3aefebb8 100644 --- a/test/merge-instances.ts +++ b/test/merge-instances.ts @@ -1,6 +1,6 @@ import test from 'ava'; -import {Handler} from 'express'; -import got, {BeforeRequestHook, Got, Headers} from '../source/index.js'; +import type {Handler} from 'express'; +import got, {type BeforeRequestHook, type Got, type Headers} from '../source/index.js'; import withServer from './helpers/with-server.js'; const echoHeaders: Handler = (request, response) => { diff --git a/test/pagination.ts b/test/pagination.ts index 2eae5f4b5..ec511f922 100644 --- a/test/pagination.ts +++ b/test/pagination.ts @@ -3,9 +3,9 @@ import {URL} from 'url'; import test from 'ava'; import delay from 'delay'; import getStream from 'get-stream'; -import got, {Response} from '../source/index.js'; +import got, {type Response} from '../source/index.js'; import withServer, {withBodyParsingServer} from './helpers/with-server.js'; -import {ExtendedHttpTestServer} from './helpers/create-http-test-server.js'; +import type {ExtendedHttpTestServer} from './helpers/create-http-test-server.js'; const thrower = (): any => { throw new Error('This should not be called'); @@ -557,10 +557,10 @@ test('next url in json response', withServer, async (t, server, got) => { })); }); - interface Page { + type Page = { currentUrl: string; next?: string; - } + }; const all = await got.paginate.all('', { searchParams: { @@ -604,10 +604,10 @@ test('pagination using searchParams', withServer, async (t, server, got) => { })); }); - interface Page { + type Page = { currentUrl: string; next?: string; - } + }; const all = await got.paginate.all('', { searchParams: { @@ -654,10 +654,10 @@ test('pagination using extended searchParams', withServer, async (t, server, got })); }); - interface Page { + type Page = { currentUrl: string; next?: string; - } + }; const client = got.extend({ searchParams: { diff --git a/test/post.ts b/test/post.ts index 8a9536cd0..a19614c52 100644 --- a/test/post.ts +++ b/test/post.ts @@ -8,8 +8,8 @@ import path from 'path'; import test from 'ava'; import delay from 'delay'; import {pEvent} from 'p-event'; -import {Handler} from 'express'; -import {parse, Body, BodyEntryPath, BodyEntryRawValue, isBodyFile} from 'then-busboy'; +import type {Handler} from 'express'; +import {parse, Body, isBodyFile, type BodyEntryPath, type BodyEntryRawValue} from 'then-busboy'; import {FormData as FormDataNode, Blob, File} from 'formdata-node'; import {fileFromPath} from 'formdata-node/file-from-path'; // eslint-disable-line n/file-extension-in-import import getStream from 'get-stream'; diff --git a/test/progress.ts b/test/progress.ts index 26924f15b..51dd51990 100644 --- a/test/progress.ts +++ b/test/progress.ts @@ -9,9 +9,9 @@ import getStream from 'get-stream'; import FormData from 'form-data'; import {temporaryFile} from 'tempy'; import is from '@sindresorhus/is'; -import test, {ExecutionContext} from 'ava'; -import {Handler} from 'express'; -import {Progress} from '../source/index.js'; +import test, {type ExecutionContext} from 'ava'; +import type {Handler} from 'express'; +import type {Progress} from '../source/index.js'; import withServer from './helpers/with-server.js'; const checkEvents = (t: ExecutionContext, events: Progress[], bodySize?: number) => { diff --git a/test/promise.ts b/test/promise.ts index 6de528333..7f3906070 100644 --- a/test/promise.ts +++ b/test/promise.ts @@ -2,7 +2,7 @@ import {Buffer} from 'buffer'; import {ReadStream} from 'fs'; import {ClientRequest, IncomingMessage} from 'http'; import test from 'ava'; -import {Response, CancelError} from '../source/index.js'; +import {type Response, CancelError} from '../source/index.js'; import withServer from './helpers/with-server.js'; test('emits request event as promise', withServer, async (t, server, got) => { diff --git a/test/redirects.ts b/test/redirects.ts index 12841768f..76f8f2436 100644 --- a/test/redirects.ts +++ b/test/redirects.ts @@ -1,6 +1,6 @@ import {Buffer} from 'buffer'; import test from 'ava'; -import {Handler} from 'express'; +import type {Handler} from 'express'; import nock from 'nock'; import got, {MaxRedirectsError, RequestError} from '../source/index.js'; import withServer, {withHttpsServer} from './helpers/with-server.js'; diff --git a/test/response-parse.ts b/test/response-parse.ts index cb4985bff..eca4aa551 100644 --- a/test/response-parse.ts +++ b/test/response-parse.ts @@ -1,6 +1,6 @@ import {Buffer} from 'buffer'; import test from 'ava'; -import {Handler} from 'express'; +import type {Handler} from 'express'; import getStream from 'get-stream'; import {HTTPError, ParseError} from '../source/index.js'; import withServer from './helpers/with-server.js'; diff --git a/test/retry.ts b/test/retry.ts index f6ca2368f..1ced25c4e 100644 --- a/test/retry.ts +++ b/test/retry.ts @@ -1,15 +1,15 @@ import process from 'process'; import {EventEmitter} from 'events'; import {PassThrough as PassThroughStream} from 'stream'; -import {Socket} from 'net'; +import type {Socket} from 'net'; import http from 'http'; import test from 'ava'; import is from '@sindresorhus/is'; -import {Handler} from 'express'; +import type {Handler} from 'express'; import getStream from 'get-stream'; import {pEvent} from 'p-event'; import got, {HTTPError, TimeoutError} from '../source/index.js'; -import Request from '../source/core/index.js'; +import type Request from '../source/core/index.js'; import withServer from './helpers/with-server.js'; const retryAfterOn413 = 2; diff --git a/test/stream.ts b/test/stream.ts index f4ff396b1..c00bbaa15 100644 --- a/test/stream.ts +++ b/test/stream.ts @@ -6,7 +6,7 @@ import {Agent as HttpAgent} from 'http'; import stream, {Readable as ReadableStream, Writable} from 'stream'; import {Readable as Readable2} from 'readable-stream'; import test from 'ava'; -import {Handler} from 'express'; +import type {Handler} from 'express'; import toReadableStream from 'to-readable-stream'; import getStream from 'get-stream'; import {pEvent} from 'p-event'; diff --git a/test/timeout.ts b/test/timeout.ts index 3e53395e1..26206c43f 100644 --- a/test/timeout.ts +++ b/test/timeout.ts @@ -7,13 +7,13 @@ import net from 'net'; import getStream from 'get-stream'; import test from 'ava'; import delay from 'delay'; -import CacheableLookup from 'cacheable-lookup'; -import {Handler} from 'express'; +import type CacheableLookup from 'cacheable-lookup'; +import type {Handler} from 'express'; import {pEvent} from 'p-event'; -import got, {RequestError, TimeoutError} from '../source/index.js'; +import got, {type RequestError, TimeoutError} from '../source/index.js'; import timedOut from '../source/core/timed-out.js'; import slowDataStream from './helpers/slow-data-stream.js'; -import {GlobalClock} from './helpers/types.js'; +import type {GlobalClock} from './helpers/types.js'; import withServer, {withServerAndFakeTimers, withHttpsServer} from './helpers/with-server.js'; const pStreamPipeline = promisify(stream.pipeline); diff --git a/test/types/create-test-server/index.d.ts b/test/types/create-test-server/index.d.ts index 365df962b..c5c358195 100644 --- a/test/types/create-test-server/index.d.ts +++ b/test/types/create-test-server/index.d.ts @@ -1,14 +1,14 @@ import type {Buffer} from 'buffer'; declare module 'create-test-server' { - import {Express} from 'express'; + import type {Express} from 'express'; function createTestServer(options: unknown): Promise; export = createTestServer; namespace createTestServer { - export interface TestServer extends Express { + export type TestServer = { caCert: string | Buffer | Array; port: number; url: string; @@ -16,6 +16,6 @@ declare module 'create-test-server' { sslUrl: string; close: () => Promise; - } + } & Express; } } diff --git a/test/types/slow-stream/index.d.ts b/test/types/slow-stream/index.d.ts index e9eb986ed..7b56e1e1b 100644 --- a/test/types/slow-stream/index.d.ts +++ b/test/types/slow-stream/index.d.ts @@ -1,4 +1,4 @@ -import type {PassThrough} from 'stream'; +import {PassThrough} from 'stream'; declare module 'slow-stream' { export = PassThrough; diff --git a/test/unix-socket.ts b/test/unix-socket.ts index 4523ec76f..8ff7c4ea4 100644 --- a/test/unix-socket.ts +++ b/test/unix-socket.ts @@ -1,7 +1,7 @@ import process from 'process'; import {format} from 'util'; import test from 'ava'; -import {Handler} from 'express'; +import type {Handler} from 'express'; import got from '../source/index.js'; import {withSocketServer} from './helpers/with-server.js';