From 944caa8ce8151d7b18ab17c4130b18d622c04ebe Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sun, 30 Jul 2023 12:57:24 +0200 Subject: [PATCH] Tweaks Closes #2287 Closes #2286 --- source/as-promise/types.ts | 4 ++-- source/core/index.ts | 6 ++---- source/core/options.ts | 27 +++++++++++---------------- source/index.ts | 2 ++ source/types.ts | 4 ++-- tsconfig.json | 4 ++-- 6 files changed, 21 insertions(+), 26 deletions(-) diff --git a/source/as-promise/types.ts b/source/as-promise/types.ts index 5d6b07d06..ab7aa30dd 100644 --- a/source/as-promise/types.ts +++ b/source/as-promise/types.ts @@ -1,8 +1,8 @@ import type {Buffer} from 'node:buffer'; 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'; +import type Request from '../core/index.js'; // eslint-disable-line import/no-duplicates +import {type RequestEvents} from '../core/index.js'; // eslint-disable-line import/no-duplicates -- It's not allowed to combine these imports. The rule is incorrect. import type {Response} from '../core/response.js'; /** diff --git a/source/core/index.ts b/source/core/index.ts index 3e1f3e210..4ccfaabd2 100644 --- a/source/core/index.ts +++ b/source/core/index.ts @@ -1,10 +1,9 @@ import process from 'node:process'; import {Buffer} from 'node:buffer'; import {Duplex, type Readable} from 'node:stream'; -import http, {ServerResponse} from 'node:http'; -import type {ClientRequest, RequestOptions} from 'node:http'; +import http, {ServerResponse, type ClientRequest, type RequestOptions} from 'node:http'; import type {Socket} from 'node:net'; -import timer from '@szmarczak/http-timer'; +import timer, {type ClientRequestWithTimings, type Timings, type IncomingMessageWithTimings} from '@szmarczak/http-timer'; import CacheableRequest, { CacheError as CacheableCacheError, type StorageAdapter, @@ -15,7 +14,6 @@ import decompressResponse from 'decompress-response'; import is from '@sindresorhus/is'; import getStream from 'get-stream'; import {FormDataEncoder, isFormData as isFormDataLike} from 'form-data-encoder'; -import type {ClientRequestWithTimings, Timings, IncomingMessageWithTimings} from '@szmarczak/http-timer'; import type ResponseLike from 'responselike'; import getBodySize from './utils/get-body-size.js'; import isFormData from './utils/is-form-data.js'; diff --git a/source/core/options.ts b/source/core/options.ts index d33c25d93..b2b761513 100644 --- a/source/core/options.ts +++ b/source/core/options.ts @@ -1,28 +1,23 @@ import process from 'node:process'; import type {Buffer} from 'node:buffer'; -import {promisify, inspect} from 'node:util'; -import {checkServerIdentity} from 'node:tls'; +import {promisify, inspect, type InspectOptions} from 'node:util'; +import {checkServerIdentity, type SecureContextOptions, type DetailedPeerCertificate} from 'node:tls'; // DO NOT use destructuring for `https.request` and `http.request` as it's not compatible with `nock`. -import http from 'node:http'; -import https from 'node:https'; +import https, { + type RequestOptions as HttpsRequestOptions, + type Agent as HttpsAgent, +} from 'node:https'; +import http, { + type Agent as HttpAgent, + type ClientRequest, +} from 'node:http'; import type {Readable} from 'node:stream'; import type {Socket} from 'node:net'; -import type {SecureContextOptions, DetailedPeerCertificate} from 'node:tls'; -import type { - Agent as HttpAgent, - ClientRequest, -} from 'node:http'; -import type { - RequestOptions as HttpsRequestOptions, - Agent as HttpsAgent, -} from 'node:https'; -import type {InspectOptions} from 'node:util'; import is, {assert} from '@sindresorhus/is'; import lowercaseKeys from 'lowercase-keys'; import CacheableLookup from 'cacheable-lookup'; import http2wrapper, {type ClientHttp2Session} from 'http2-wrapper'; -import {isFormData} from 'form-data-encoder'; -import type {FormDataLike} from 'form-data-encoder'; +import {isFormData, type FormDataLike} from 'form-data-encoder'; import type {StorageAdapter} from 'cacheable-request'; import type ResponseLike from 'responselike'; import type {IncomingMessageWithTimings} from '@szmarczak/http-timer'; diff --git a/source/index.ts b/source/index.ts index 817beb427..0edb81512 100644 --- a/source/index.ts +++ b/source/index.ts @@ -11,6 +11,8 @@ const defaults: InstanceDefaults = { const got = create(defaults); export default got; + +// TODO: Remove this in the next major version. export {got}; export {default as Options} from './core/options.js'; diff --git a/source/types.ts b/source/types.ts index 0a47e69d2..88abd9953 100644 --- a/source/types.ts +++ b/source/types.ts @@ -1,8 +1,8 @@ import type {Buffer} from 'node:buffer'; import type {CancelableRequest} from './as-promise/types.js'; import type {Response} from './core/response.js'; -import type Options from './core/options.js'; -import type {PaginationOptions, OptionsInit} from './core/options.js'; +import type Options from './core/options.js'; // eslint-disable-line import/no-duplicates +import {type PaginationOptions, type OptionsInit} from './core/options.js'; // eslint-disable-line import/no-duplicates -- It's not allowed to combine these imports. The rule is incorrect. import type Request from './core/index.js'; // `type-fest` utilities diff --git a/tsconfig.json b/tsconfig.json index cd8c20c10..acf0c5f90 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,9 +2,9 @@ "extends": "@sindresorhus/tsconfig", "compilerOptions": { "outDir": "dist", - "target": "es2020", // Node.js 14 + "target": "es2021", // Node.js 16 "lib": [ - "es2020" + "es2021" ], "noPropertyAccessFromIndexSignature": false, "isolatedModules": true