diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bf8563bc7..3bcb98a23 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,7 +14,6 @@ jobs: node-version: - 18 - 16 - - 14 os: # Ubuntu fails and I don't have time to look into it. PR welcome. # - ubuntu-latest diff --git a/documentation/2-options.md b/documentation/2-options.md index f54a90c90..cde04e1a8 100644 --- a/documentation/2-options.md +++ b/documentation/2-options.md @@ -215,8 +215,6 @@ await got('https://httpbin.org/anything'); You can abort the `request` using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController). -*Requires Node.js 16 or later.* - ```js import got from 'got'; diff --git a/documentation/tips.md b/documentation/tips.md index 1058e4188..20ab3a005 100644 --- a/documentation/tips.md +++ b/documentation/tips.md @@ -176,8 +176,8 @@ If you're using proxies, you may run into connection issues.\ One way out is to disable proxies when retrying. The solution for the Stream API looks like this: ```js -import https from 'https'; -import fs from 'fs'; +import https from 'node:https'; +import fs from 'node:fs'; import got from 'got'; class MyAgent extends https.Agent { diff --git a/package.json b/package.json index b8e662931..50c711859 100644 --- a/package.json +++ b/package.json @@ -138,7 +138,6 @@ "@typescript-eslint/no-empty-function": "off", "n/no-deprecated-api": "off", "@typescript-eslint/no-implicit-any-catch": "off", - "unicorn/prefer-node-protocol": "off", "ava/assertion-arguments": "off", "@typescript-eslint/no-unsafe-member-access": "off", "@typescript-eslint/no-unsafe-return": "off", diff --git a/readme.md b/readme.md index b7b2eecf7..89c15cc72 100644 --- a/readme.md +++ b/readme.md @@ -94,7 +94,7 @@ npm install got **Warning:** This package is native [ESM](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) and no longer provides a CommonJS export. If your project uses CommonJS, you will have to [convert to ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) or use the [dynamic `import()`](https://v8.dev/features/dynamic-import) function. Please don't open issues for questions regarding CommonJS / ESM. -**Got v11 (the previous major version) is no longer maintained and we will not accept any backport requests.** +**Got v11 is no longer maintained and we will not accept any backport requests.** ## Take a peek diff --git a/source/core/index.ts b/source/core/index.ts index dca359e29..3e1f3e210 100644 --- a/source/core/index.ts +++ b/source/core/index.ts @@ -276,8 +276,9 @@ export default class Request extends Duplex implements RequestEvents { abort(); } else { this.options.signal.addEventListener('abort', abort); + this._removeListeners = () => { - this.options.signal.removeEventListener('abort', abort); + this.options.signal?.removeEventListener('abort', abort); }; } } diff --git a/source/core/options.ts b/source/core/options.ts index 0ec270330..d33c25d93 100644 --- a/source/core/options.ts +++ b/source/core/options.ts @@ -1499,8 +1499,6 @@ export default class Options { /** You can abort the `request` using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController). - *Requires Node.js 16 or later.* - @example ``` import got from 'got'; @@ -1516,13 +1514,11 @@ export default class Options { }, 100); ``` */ - // TODO: Replace `any` with `AbortSignal` when targeting Node 16. - get signal(): any | undefined { + get signal(): AbortSignal | undefined { return this._internals.signal; } - // TODO: Replace `any` with `AbortSignal` when targeting Node 16. - set signal(value: any | undefined) { + set signal(value: AbortSignal | undefined) { assert.object(value); this._internals.signal = value; diff --git a/test/abort.ts b/test/abort.ts index 890f87899..e9d151400 100644 --- a/test/abort.ts +++ b/test/abort.ts @@ -1,7 +1,7 @@ -import process from 'process'; -import {EventEmitter} from 'events'; -import {Readable as ReadableStream} from 'stream'; -import {pipeline as streamPipeline} from 'stream/promises'; +import process from 'node:process'; +import {EventEmitter} from 'node:events'; +import {Readable as ReadableStream} from 'node:stream'; +import {pipeline as streamPipeline} from 'node:stream/promises'; import test from 'ava'; import delay from 'delay'; import {pEvent} from 'p-event'; diff --git a/test/agent.ts b/test/agent.ts index 87fbf4f55..402ec4b8d 100644 --- a/test/agent.ts +++ b/test/agent.ts @@ -1,5 +1,5 @@ -import {Agent as HttpAgent} from 'http'; -import {Agent as HttpsAgent} from 'https'; +import {Agent as HttpAgent} from 'node:http'; +import {Agent as HttpsAgent} from 'node:https'; import test from 'ava'; import sinon from 'sinon'; import type {Constructor} from 'type-fest'; diff --git a/test/arguments.ts b/test/arguments.ts index 6088caad1..2bee4bb8f 100644 --- a/test/arguments.ts +++ b/test/arguments.ts @@ -1,4 +1,4 @@ -import {parse} from 'url'; +import {parse} from 'node:url'; import test from 'ava'; import type {Handler} from 'express'; import {pEvent} from 'p-event'; diff --git a/test/cache.ts b/test/cache.ts index e023fef92..ba423ccab 100644 --- a/test/cache.ts +++ b/test/cache.ts @@ -1,9 +1,9 @@ -import {Buffer} from 'buffer'; -import {promisify} from 'util'; -import {Readable as ReadableStream} from 'stream'; -import {Agent} from 'http'; -import {gzip} from 'zlib'; -import process from 'process'; +import {Buffer} from 'node:buffer'; +import {promisify} from 'node:util'; +import {Readable as ReadableStream} from 'node:stream'; +import {Agent} from 'node:http'; +import {gzip} from 'node:zlib'; +import process from 'node:process'; import test from 'ava'; import {pEvent} from 'p-event'; import getStream from 'get-stream'; @@ -561,7 +561,8 @@ test.failing('revalidated compressed responses are retrieved from cache', withSe }); }); -test.failing('revalidated uncompressed responses from github are retrieved from cache', async t => { +// eslint-disable-next-line ava/no-skip-test -- Unreliable +test.skip('revalidated uncompressed responses from github are retrieved from cache', async t => { const client = got.extend({ cache: new Map(), cacheOptions: {shared: false}, @@ -590,7 +591,8 @@ test.failing('revalidated uncompressed responses from github are retrieved from }); }); -test.failing('revalidated compressed responses from github are retrieved from cache', async t => { +// eslint-disable-next-line ava/no-skip-test -- Unreliable +test.skip('revalidated compressed responses from github are retrieved from cache', async t => { const client = got.extend({ cache: new Map(), cacheOptions: {shared: false}, diff --git a/test/cancel.ts b/test/cancel.ts index dcaf95b0a..5cca579f3 100644 --- a/test/cancel.ts +++ b/test/cancel.ts @@ -1,7 +1,7 @@ -import process from 'process'; -import {EventEmitter} from 'events'; -import {Readable as ReadableStream} from 'stream'; -import {pipeline as streamPipeline} from 'stream/promises'; +import process from 'node:process'; +import {EventEmitter} from 'node:events'; +import {Readable as ReadableStream} from 'node:stream'; +import {pipeline as streamPipeline} from 'node:stream/promises'; import test from 'ava'; import delay from 'delay'; import {pEvent} from 'p-event'; diff --git a/test/cookies.ts b/test/cookies.ts index e46aa9963..e12009c39 100644 --- a/test/cookies.ts +++ b/test/cookies.ts @@ -1,4 +1,4 @@ -import net from 'net'; +import net from 'node:net'; import test from 'ava'; import toughCookie from 'tough-cookie'; import delay from 'delay'; diff --git a/test/create.ts b/test/create.ts index 934321266..8cd2186c1 100644 --- a/test/create.ts +++ b/test/create.ts @@ -3,7 +3,7 @@ import { request as httpRequest, type IncomingMessage, type RequestOptions, -} from 'http'; +} from 'node:http'; import test from 'ava'; import is from '@sindresorhus/is'; import type {Handler} from 'express'; diff --git a/test/encoding.ts b/test/encoding.ts index 8e6b1d68e..ba8c60983 100644 --- a/test/encoding.ts +++ b/test/encoding.ts @@ -1,4 +1,4 @@ -import {Buffer} from 'buffer'; +import {Buffer} from 'node:buffer'; import test from 'ava'; import withServer from './helpers/with-server.js'; diff --git a/test/error.ts b/test/error.ts index 28db17fb6..ef4adc1fb 100644 --- a/test/error.ts +++ b/test/error.ts @@ -1,9 +1,9 @@ -import {Buffer} from 'buffer'; -import {promisify} from 'util'; -import net from 'net'; -import http from 'http'; -import stream from 'stream'; -import {pipeline as streamPipeline} from 'stream/promises'; +import {Buffer} from 'node:buffer'; +import {promisify} from 'node:util'; +import net from 'node:net'; +import http from 'node:http'; +import stream from 'node:stream'; +import {pipeline as streamPipeline} from 'node:stream/promises'; import test from 'ava'; import getStream from 'get-stream'; import is from '@sindresorhus/is'; diff --git a/test/gzip.ts b/test/gzip.ts index 2f597eb3f..29bc0b42e 100644 --- a/test/gzip.ts +++ b/test/gzip.ts @@ -1,6 +1,6 @@ -import {Buffer} from 'buffer'; -import {promisify} from 'util'; -import zlib from 'zlib'; +import {Buffer} from 'node:buffer'; +import {promisify} from 'node:util'; +import zlib from 'node:zlib'; import test from 'ava'; import getStream from 'get-stream'; import {ReadError, type HTTPError} from '../source/index.js'; diff --git a/test/headers.ts b/test/headers.ts index 0f70de4dc..43e30fec3 100644 --- a/test/headers.ts +++ b/test/headers.ts @@ -1,7 +1,7 @@ -import process from 'process'; -import {Buffer} from 'buffer'; -import fs from 'fs'; -import path from 'path'; +import process from 'node:process'; +import {Buffer} from 'node:buffer'; +import fs from 'node:fs'; +import path from 'node:path'; import test from 'ava'; import type {Handler} from 'express'; import FormData from 'form-data'; diff --git a/test/helpers/create-http-test-server.ts b/test/helpers/create-http-test-server.ts index 139114eb4..149a6dffc 100644 --- a/test/helpers/create-http-test-server.ts +++ b/test/helpers/create-http-test-server.ts @@ -1,5 +1,5 @@ -import http from 'http'; -import type net from 'net'; +import http from 'node:http'; +import type net from 'node:net'; import express, {type Express, type NextFunction} from 'express'; import pify from 'pify'; import bodyParser from 'body-parser'; diff --git a/test/helpers/create-https-test-server.ts b/test/helpers/create-https-test-server.ts index 3ea6a66b2..54f2554cf 100644 --- a/test/helpers/create-https-test-server.ts +++ b/test/helpers/create-https-test-server.ts @@ -1,7 +1,7 @@ -import type {Buffer} from 'buffer'; -import https from 'https'; -import type net from 'net'; -import type {SecureContextOptions} from 'tls'; +import type {Buffer} from 'node:buffer'; +import https from 'node:https'; +import type net from 'node:net'; +import type {SecureContextOptions} from 'node:tls'; import express from 'express'; import pify from 'pify'; import pem from 'pem'; diff --git a/test/helpers/slow-data-stream.ts b/test/helpers/slow-data-stream.ts index 6bc1da1f4..58ae28525 100644 --- a/test/helpers/slow-data-stream.ts +++ b/test/helpers/slow-data-stream.ts @@ -1,4 +1,4 @@ -import {Readable} from 'stream'; +import {Readable} from 'node:stream'; import type {Clock} from '@sinonjs/fake-timers'; import delay from 'delay'; diff --git a/test/helpers/types.ts b/test/helpers/types.ts index 18e4c9f7e..d89029978 100644 --- a/test/helpers/types.ts +++ b/test/helpers/types.ts @@ -1,4 +1,4 @@ -import type {Server} from 'http'; +import type {Server} from 'node:http'; // @ts-expect-error Fails to locate ../types/create-test-server/index.d.ts import type {TestServer} from 'create-test-server'; diff --git a/test/helpers/with-server.ts b/test/helpers/with-server.ts index 816f26926..04eb907b6 100644 --- a/test/helpers/with-server.ts +++ b/test/helpers/with-server.ts @@ -1,5 +1,5 @@ -import http from 'http'; -import {promisify} from 'util'; +import http from 'node:http'; +import {promisify} from 'node:util'; import type {ExecutionContext, Macro} from 'ava'; import is from '@sindresorhus/is'; import {temporaryFile} from 'tempy'; diff --git a/test/hooks.ts b/test/hooks.ts index c649bd8d0..53ff50e60 100644 --- a/test/hooks.ts +++ b/test/hooks.ts @@ -1,5 +1,5 @@ -import {Buffer} from 'buffer'; -import {Agent as HttpAgent} from 'http'; +import {Buffer} from 'node:buffer'; +import {Agent as HttpAgent} from 'node:http'; import test from 'ava'; import nock from 'nock'; import getStream from 'get-stream'; diff --git a/test/http.ts b/test/http.ts index 26c8c5850..39d763c30 100644 --- a/test/http.ts +++ b/test/http.ts @@ -1,8 +1,8 @@ -import process from 'process'; -import {Buffer} from 'buffer'; -import {STATUS_CODES, Agent} from 'http'; -import os from 'os'; -import {isIPv4, isIPv6, isIP} from 'net'; +import process from 'node:process'; +import {Buffer} from 'node:buffer'; +import {STATUS_CODES, Agent} from 'node:http'; +import os from 'node:os'; +import {isIPv4, isIPv6, isIP} from 'node:net'; import test from 'ava'; import type {Handler} from 'express'; import nock from 'nock'; diff --git a/test/https.ts b/test/https.ts index 62bff49e6..01497dcc7 100644 --- a/test/https.ts +++ b/test/https.ts @@ -1,5 +1,5 @@ -import process from 'process'; -import tls, {type DetailedPeerCertificate} from 'tls'; +import process from 'node:process'; +import tls, {type DetailedPeerCertificate} from 'node:tls'; import test from 'ava'; import {pEvent} from 'p-event'; import pify from 'pify'; diff --git a/test/pagination.ts b/test/pagination.ts index 0b9849b82..b035a5816 100644 --- a/test/pagination.ts +++ b/test/pagination.ts @@ -1,4 +1,4 @@ -import {Buffer} from 'buffer'; +import {Buffer} from 'node:buffer'; import test from 'ava'; import delay from 'delay'; import getStream from 'get-stream'; diff --git a/test/post.ts b/test/post.ts index 53d757438..8a559cac8 100644 --- a/test/post.ts +++ b/test/post.ts @@ -1,10 +1,10 @@ -import process from 'process'; -import {Buffer} from 'buffer'; -import stream from 'stream'; -import {pipeline as streamPipeline} from 'stream/promises'; -import fs from 'fs'; -import fsPromises from 'fs/promises'; -import path from 'path'; +import process from 'node:process'; +import {Buffer} from 'node:buffer'; +import stream from 'node:stream'; +import {pipeline as streamPipeline} from 'node:stream/promises'; +import fs from 'node:fs'; +import fsPromises from 'node:fs/promises'; +import path from 'node:path'; import test from 'ava'; import delay from 'delay'; import {pEvent} from 'p-event'; diff --git a/test/progress.ts b/test/progress.ts index c71068e58..d3b7fdb7c 100644 --- a/test/progress.ts +++ b/test/progress.ts @@ -1,9 +1,9 @@ -import process from 'process'; -import {Buffer} from 'buffer'; -import {promisify} from 'util'; -import stream from 'stream'; +import process from 'node:process'; +import {Buffer} from 'node:buffer'; +import {promisify} from 'node:util'; +import stream from 'node:stream'; import {pipeline as streamPipeline} from 'node:stream/promises'; -import fs from 'fs'; +import fs from 'node:fs'; // @ts-expect-error Fails to find slow-stream/index.d.ts import SlowStream from 'slow-stream'; import getStream from 'get-stream'; diff --git a/test/promise.ts b/test/promise.ts index 7f3906070..d3527cf3f 100644 --- a/test/promise.ts +++ b/test/promise.ts @@ -1,6 +1,6 @@ -import {Buffer} from 'buffer'; -import {ReadStream} from 'fs'; -import {ClientRequest, IncomingMessage} from 'http'; +import {Buffer} from 'node:buffer'; +import {ReadStream} from 'node:fs'; +import {ClientRequest, IncomingMessage} from 'node:http'; import test from 'ava'; import {type Response, CancelError} from '../source/index.js'; import withServer from './helpers/with-server.js'; diff --git a/test/redirects.ts b/test/redirects.ts index 2665a4b30..e920bd269 100644 --- a/test/redirects.ts +++ b/test/redirects.ts @@ -1,4 +1,4 @@ -import {Buffer} from 'buffer'; +import {Buffer} from 'node:buffer'; import test from 'ava'; import type {Handler} from 'express'; import nock from 'nock'; diff --git a/test/response-parse.ts b/test/response-parse.ts index 5cb7a699b..da88222b1 100644 --- a/test/response-parse.ts +++ b/test/response-parse.ts @@ -1,4 +1,4 @@ -import {Buffer} from 'buffer'; +import {Buffer} from 'node:buffer'; import test from 'ava'; import type {Handler} from 'express'; import getStream from 'get-stream'; diff --git a/test/retry.ts b/test/retry.ts index 890789b6b..9f47b8c00 100644 --- a/test/retry.ts +++ b/test/retry.ts @@ -1,8 +1,8 @@ -import process from 'process'; -import {EventEmitter} from 'events'; -import {PassThrough as PassThroughStream} from 'stream'; -import type {Socket} from 'net'; -import http from 'http'; +import process from 'node:process'; +import {EventEmitter} from 'node:events'; +import {PassThrough as PassThroughStream} from 'node:stream'; +import type {Socket} from 'node:net'; +import http from 'node:http'; import test from 'ava'; import is from '@sindresorhus/is'; import type {Handler} from 'express'; diff --git a/test/stream.ts b/test/stream.ts index a7e704506..425636689 100644 --- a/test/stream.ts +++ b/test/stream.ts @@ -1,9 +1,9 @@ -import process from 'process'; -import {Buffer} from 'buffer'; -import fs from 'fs'; -import {Agent as HttpAgent} from 'http'; -import stream, {Readable as ReadableStream, Writable} from 'stream'; -import {pipeline as streamPipeline} from 'stream/promises'; +import process from 'node:process'; +import {Buffer} from 'node:buffer'; +import fs from 'node:fs'; +import {Agent as HttpAgent} from 'node:http'; +import stream, {Readable as ReadableStream, Writable} from 'node:stream'; +import {pipeline as streamPipeline} from 'node:stream/promises'; import {Readable as Readable2} from 'readable-stream'; import test from 'ava'; import type {Handler} from 'express'; diff --git a/test/timeout.ts b/test/timeout.ts index 0b3b390a0..0c8c9adcf 100644 --- a/test/timeout.ts +++ b/test/timeout.ts @@ -1,9 +1,9 @@ -import process from 'process'; -import {EventEmitter} from 'events'; -import stream, {PassThrough as PassThroughStream} from 'stream'; -import {pipeline as streamPipeline} from 'stream/promises'; -import http from 'http'; -import net from 'net'; +import process from 'node:process'; +import {EventEmitter} from 'node:events'; +import stream, {PassThrough as PassThroughStream} from 'node:stream'; +import {pipeline as streamPipeline} from 'node:stream/promises'; +import http from 'node:http'; +import net from 'node:net'; import getStream from 'get-stream'; import test from 'ava'; import delay from 'delay'; diff --git a/test/types/create-test-server/index.d.ts b/test/types/create-test-server/index.d.ts index c5c358195..40aafa13c 100644 --- a/test/types/create-test-server/index.d.ts +++ b/test/types/create-test-server/index.d.ts @@ -1,4 +1,4 @@ -import type {Buffer} from 'buffer'; +import type {Buffer} from 'node:buffer'; declare module 'create-test-server' { import type {Express} from 'express'; diff --git a/test/types/slow-stream/index.d.ts b/test/types/slow-stream/index.d.ts index 7b56e1e1b..d87d348fc 100644 --- a/test/types/slow-stream/index.d.ts +++ b/test/types/slow-stream/index.d.ts @@ -1,4 +1,4 @@ -import {PassThrough} from 'stream'; +import {PassThrough} from 'node:stream'; declare module 'slow-stream' { export = PassThrough; diff --git a/test/unix-socket.ts b/test/unix-socket.ts index 72b52fdc1..e9216ff5c 100644 --- a/test/unix-socket.ts +++ b/test/unix-socket.ts @@ -1,5 +1,5 @@ -import process from 'process'; -import {format} from 'util'; +import process from 'node:process'; +import {format} from 'node:util'; import test from 'ava'; import type {Handler} from 'express'; import baseGot from '../source/index.js'; diff --git a/test/url-to-options.ts b/test/url-to-options.ts index 8337e3930..c55346abe 100644 --- a/test/url-to-options.ts +++ b/test/url-to-options.ts @@ -1,4 +1,4 @@ -import {parse as urlParse} from 'url'; +import {parse as urlParse} from 'node:url'; import test from 'ava'; import urlToOptions from '../source/core/utils/url-to-options.js';