From d4c2913ec25968e8d99a4a24e589d3e741072369 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 5 Jul 2022 19:46:25 +0200 Subject: [PATCH] Upgrade dependencies --- package.json | 33 +++++++++++++++++---------------- source/core/index.ts | 7 ++++++- source/core/options.ts | 6 +++--- source/index.ts | 2 +- source/types.ts | 8 ++++++++ test/helpers.ts | 3 ++- test/helpers/with-server.ts | 4 ++-- test/hooks.ts | 2 +- test/parse-link-header.ts | 4 ++-- test/post.ts | 4 ++-- test/progress.ts | 4 ++-- test/redirects.ts | 6 +++--- tsconfig.json | 10 ++++++++-- 13 files changed, 57 insertions(+), 36 deletions(-) diff --git a/package.json b/package.json index be4aa078e..448b47395 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "funding": "https://github.com/sindresorhus/got?sponsor=1", "type": "module", "exports": "./dist/source/index.js", + "types": "./dist/source/index.d.ts", "engines": { "node": ">=14.16" }, @@ -44,14 +45,14 @@ "ky" ], "dependencies": { - "@sindresorhus/is": "^4.6.0", + "@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", - "form-data-encoder": "1.7.1", + "form-data-encoder": "^2.0.1", "get-stream": "^6.0.1", "http2-wrapper": "^2.1.10", "lowercase-keys": "^3.0.0", @@ -59,12 +60,12 @@ "responselike": "^2.0.0" }, "devDependencies": { - "@hapi/bourne": "^2.0.0", + "@hapi/bourne": "^3.0.0", "@sindresorhus/tsconfig": "^2.0.0", "@sinonjs/fake-timers": "^9.1.1", "@types/benchmark": "^2.1.1", "@types/express": "^4.17.13", - "@types/node": "^17.0.21", + "@types/node": "^18.0.1", "@types/pem": "^1.9.6", "@types/pify": "^5.0.1", "@types/readable-stream": "^2.3.13", @@ -73,7 +74,7 @@ "@types/sinonjs__fake-timers": "^8.1.1", "@types/tough-cookie": "^4.0.1", "ava": "^3.15.0", - "axios": "^0.26.1", + "axios": "^0.27.2", "benchmark": "^2.1.4", "bluebird": "^3.7.2", "body-parser": "^1.19.2", @@ -90,20 +91,19 @@ "nyc": "^15.1.0", "p-event": "^5.0.1", "pem": "^1.14.6", - "pify": "^5.0.0", - "readable-stream": "^3.6.0", + "pify": "^6.0.0", + "readable-stream": "^4.0.0", "request": "^2.88.2", - "sinon": "^13.0.1", + "sinon": "^14.0.0", "slow-stream": "0.0.4", - "tempy": "^2.0.0", + "tempy": "^3.0.0", "then-busboy": "^5.1.1", "to-readable-stream": "^3.0.0", "tough-cookie": "^4.0.0", - "ts-node": "^10.7.0", - "typescript": "4.6.2", - "xo": "^0.48.0" + "ts-node": "^10.8.2", + "typescript": "^4.7.4", + "xo": "^0.50.0" }, - "types": "dist/source", "sideEffects": false, "ava": { "files": [ @@ -140,9 +140,9 @@ ], "rules": { "@typescript-eslint/no-empty-function": "off", - "node/no-deprecated-api": "off", - "node/prefer-global/url": "off", - "node/prefer-global/url-search-params": "off", + "n/no-deprecated-api": "off", + "n/prefer-global/url": "off", + "n/prefer-global/url-search-params": "off", "@typescript-eslint/no-implicit-any-catch": "off", "unicorn/prefer-node-protocol": "off", "ava/assertion-arguments": "off", @@ -151,6 +151,7 @@ "@typescript-eslint/no-unsafe-assignment": "off", "@typescript-eslint/no-unsafe-call": "off", "@typescript-eslint/await-thenable": "off", + "@typescript-eslint/no-redundant-type-constituents": "off", "no-lone-blocks": "off", "unicorn/no-await-expression-member": "off" } diff --git a/source/core/index.ts b/source/core/index.ts index e521a1a56..ccba907ad 100644 --- a/source/core/index.ts +++ b/source/core/index.ts @@ -10,7 +10,7 @@ import CacheableRequest from 'cacheable-request'; import decompressResponse from 'decompress-response'; import is from '@sindresorhus/is'; import {buffer as getBuffer} from 'get-stream'; -import {FormDataEncoder, isFormDataLike} from 'form-data-encoder'; +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'; @@ -56,6 +56,8 @@ export type GotEventFunction = @example ``` + import got from 'got'; + got.stream('https://github.com') .on('request', request => setTimeout(() => request.destroy(), 50)); ``` @@ -88,6 +90,8 @@ export type GotEventFunction = @example ``` + import got from 'got'; + const response = await got('https://sindresorhus.com') .on('downloadProgress', progress => { // Report download progress @@ -138,6 +142,7 @@ type OptionsType = ConstructorParameters[1]; type DefaultsType = ConstructorParameters[2]; export default class Request extends Duplex implements RequestEvents { + // @ts-expect-error - Ignoring for now. override ['constructor']: typeof Request; _noPipe?: boolean; diff --git a/source/core/options.ts b/source/core/options.ts index 33073636d..fdcabe15f 100644 --- a/source/core/options.ts +++ b/source/core/options.ts @@ -22,7 +22,7 @@ import is, {assert} from '@sindresorhus/is'; import lowercaseKeys from 'lowercase-keys'; import CacheableLookup from 'cacheable-lookup'; import http2wrapper, {ClientHttp2Session} from 'http2-wrapper'; -import {isFormDataLike} from 'form-data-encoder'; +import {isFormData} from 'form-data-encoder'; import type {FormDataLike} from 'form-data-encoder'; import type CacheableRequest from 'cacheable-request'; import type ResponseLike from 'responselike'; @@ -35,7 +35,7 @@ import type {Delays} from './timed-out.js'; type Promisable = T | Promise; -const [major, minor] = process.versions.node.split('.').map(v => Number(v)) as [number, number, number]; +const [major, minor] = process.versions.node.split('.').map(Number) as [number, number, number]; export type DnsLookupIpVersion = undefined | 4 | 6; @@ -1304,7 +1304,7 @@ export default class Options { } set body(value: string | Buffer | Readable | Generator | AsyncGenerator | FormDataLike | undefined) { - assert.any([is.string, is.buffer, is.nodeStream, is.generator, is.asyncGenerator, isFormDataLike, is.undefined], value); + assert.any([is.string, is.buffer, is.nodeStream, is.generator, is.asyncGenerator, isFormData, is.undefined], value); if (is.nodeStream(value)) { assert.truthy(value.readable); diff --git a/source/index.ts b/source/index.ts index cf6d927cd..855a103fd 100644 --- a/source/index.ts +++ b/source/index.ts @@ -19,7 +19,7 @@ export * from './core/response.js'; export type {default as Request} from './core/index.js'; export * from './core/index.js'; export * from './core/errors.js'; -export {Delays} from './core/timed-out.js'; +export type {Delays} from './core/timed-out.js'; export {default as calculateRetryDelay} from './core/calculate-retry-delay.js'; export * from './as-promise/types.js'; export * from './types.js'; diff --git a/source/types.ts b/source/types.ts index 5a865b9b0..81f9957a3 100644 --- a/source/types.ts +++ b/source/types.ts @@ -102,6 +102,8 @@ export interface GotPaginate { @example ``` + import got from 'got'; + const countLimit = 10; const pagination = got.paginate('https://api.github.com/repos/sindresorhus/got/commits', { @@ -125,6 +127,8 @@ export interface GotPaginate { @example ``` + import got from 'got'; + const countLimit = 10; const results = await got.paginate.all('https://api.github.com/repos/sindresorhus/got/commits', { @@ -219,6 +223,8 @@ export interface Got extends Record, GotRequestFu @example ``` + import got from 'got'; + const countLimit = 10; const pagination = got.paginate('https://api.github.com/repos/sindresorhus/got/commits', { @@ -252,6 +258,8 @@ export interface Got extends Record, GotRequestFu @example ``` + import got from 'got'; + const client = got.extend({ prefixUrl: 'https://example.com', headers: { diff --git a/test/helpers.ts b/test/helpers.ts index c852362f5..7f665b642 100644 --- a/test/helpers.ts +++ b/test/helpers.ts @@ -13,7 +13,8 @@ test('works', withServer, async (t, server) => { response.end('not found'); }); - t.is((await got.get(server.url)).body, 'ok'); + const {body} = await got.get(server.url); + t.is(body, 'ok'); const error = await t.throwsAsync(got.get(`${server.url}/404`), {instanceOf: HTTPError}); t.is(error.response.body, 'not found'); diff --git a/test/helpers/with-server.ts b/test/helpers/with-server.ts index 1b3252175..2ab4f06bc 100644 --- a/test/helpers/with-server.ts +++ b/test/helpers/with-server.ts @@ -2,7 +2,7 @@ import http from 'http'; import {promisify} from 'util'; import {ExecutionContext, Macro} from 'ava'; // eslint-disable-line ava/use-test import is from '@sindresorhus/is'; -import tempy from 'tempy'; +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'; @@ -108,7 +108,7 @@ export const withHttpsServer = generateHttpsHook; // TODO: Remove this when `create-test-server` supports custom listen. export const withSocketServer: Macro<[RunTestWithSocket]> = async (t, run) => { - const socketPath = tempy.file({extension: 'socket'}); + const socketPath = temporaryFile({extension: 'socket'}); const server = http.createServer((request, response) => { server.emit(request.url!, request, response); diff --git a/test/hooks.ts b/test/hooks.ts index 2136a9a00..39b41b59c 100644 --- a/test/hooks.ts +++ b/test/hooks.ts @@ -1048,7 +1048,7 @@ test('beforeRequest hook respect `url` option', withServer, async (t, server, go hooks: { beforeRequest: [ options => { - options.url = new URL(server.url + '/changed'); + options.url = new URL(`${server.url}/changed`); }, ], }, diff --git a/test/parse-link-header.ts b/test/parse-link-header.ts index f1cfbb5e0..c137eb075 100644 --- a/test/parse-link-header.ts +++ b/test/parse-link-header.ts @@ -62,7 +62,7 @@ test('works as expected', t => { reference: '/TheBook/chapter2', parameters: { rel: '"previous"', - // eslint-disable-next-line @typescript-eslint/quotes + // eslint-disable-next-line @typescript-eslint/quotes, @typescript-eslint/naming-convention 'title*': `UTF-8'de'letztes%20Kapitel`, }, }, @@ -70,7 +70,7 @@ test('works as expected', t => { reference: '/TheBook/chapter4', parameters: { rel: '"next"', - // eslint-disable-next-line @typescript-eslint/quotes + // eslint-disable-next-line @typescript-eslint/quotes, @typescript-eslint/naming-convention 'title*': `UTF-8'de'n%c3%a4chstes%20Kapitel`, }, }, diff --git a/test/post.ts b/test/post.ts index 0290ebb9d..8a9536cd0 100644 --- a/test/post.ts +++ b/test/post.ts @@ -11,7 +11,7 @@ import {pEvent} from 'p-event'; import {Handler} from 'express'; import {parse, Body, BodyEntryPath, BodyEntryRawValue, isBodyFile} from 'then-busboy'; import {FormData as FormDataNode, Blob, File} from 'formdata-node'; -import {fileFromPath} from 'formdata-node/file-from-path'; +import {fileFromPath} from 'formdata-node/file-from-path'; // eslint-disable-line n/file-extension-in-import import getStream from 'get-stream'; import FormData from 'form-data'; import toReadableStream from 'to-readable-stream'; @@ -346,7 +346,7 @@ test('body - sends files with spec-compliant FormData', withServer, async (t, se const fullPath = path.resolve('test/fixtures/ok'); const blobContent = 'Blob content'; const fileContent = 'File content'; - const anotherFileContent = await fsPromises.readFile(fullPath, 'utf-8'); + const anotherFileContent = await fsPromises.readFile(fullPath, 'utf8'); const expected = { blob: blobContent, file: fileContent, diff --git a/test/progress.ts b/test/progress.ts index 279ae3a22..ffd5ad147 100644 --- a/test/progress.ts +++ b/test/progress.ts @@ -7,7 +7,7 @@ import SlowStream from 'slow-stream'; import toReadableStream from 'to-readable-stream'; import getStream from 'get-stream'; import FormData from 'form-data'; -import tempy from 'tempy'; +import {temporaryFile} from 'tempy'; import is from '@sindresorhus/is'; import test, {ExecutionContext} from 'ava'; import {Handler} from 'express'; @@ -121,7 +121,7 @@ test('upload progress - file', withServer, async (t, server, got) => { test('upload progress - file stream', withServer, async (t, server, got) => { server.post('/', uploadEndpoint); - const path = tempy.file(); + const path = temporaryFile(); fs.writeFileSync(path, file); const {size} = await promisify(fs.stat)(path); diff --git a/test/redirects.ts b/test/redirects.ts index 1b6d4324b..ae2345006 100644 --- a/test/redirects.ts +++ b/test/redirects.ts @@ -63,7 +63,7 @@ test('follows redirect', withServer, async (t, server, got) => { const {body, redirectUrls} = await got('finite'); t.is(body, 'reached'); - t.deepEqual(redirectUrls.map(x => String(x)), [`${server.url}/`]); + t.deepEqual(redirectUrls.map(String), [`${server.url}/`]); }); test('follows 307, 308 redirect', withServer, async (t, server, got) => { @@ -113,7 +113,7 @@ test('throws on endless redirects - default behavior', withServer, async (t, ser const error = await t.throwsAsync(got(''), {message: 'Redirected 10 times. Aborting.'}); - t.deepEqual(error.response.redirectUrls.map(x => String(x)), Array.from({length: 10}).fill(`${server.url}/`)); + t.deepEqual(error.response.redirectUrls.map(String), Array.from({length: 10}).fill(`${server.url}/`)); t.is(error.code, 'ERR_TOO_MANY_REDIRECTS'); }); @@ -127,7 +127,7 @@ test('custom `maxRedirects` option', withServer, async (t, server, got) => { const error = await t.throwsAsync(got('', {maxRedirects: 5}), {message: 'Redirected 5 times. Aborting.'}); - t.deepEqual(error.response.redirectUrls.map(x => String(x)), Array.from({length: 5}).fill(`${server.url}/`)); + t.deepEqual(error.response.redirectUrls.map(String), Array.from({length: 5}).fill(`${server.url}/`)); t.is(error.code, 'ERR_TOO_MANY_REDIRECTS'); }); diff --git a/tsconfig.json b/tsconfig.json index ce1828b7b..64ae06b78 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,11 +7,17 @@ "es2020" ], // TODO: Remove this at some point. - "noPropertyAccessFromIndexSignature": false + "noPropertyAccessFromIndexSignature": false, + "isolatedModules": true }, "include": [ "source", "test", "benchmark" - ] + ], + "ts-node": { + "transpileOnly": true, + "files": true, + "experimentalResolver": true + } }