Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed May 27, 2023
1 parent 852c312 commit 81447e9
Show file tree
Hide file tree
Showing 39 changed files with 103 additions and 108 deletions.
1 change: 0 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions documentation/2-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
4 changes: 2 additions & 2 deletions documentation/tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion source/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,9 @@ export default class Request extends Duplex implements RequestEvents<Request> {
abort();
} else {
this.options.signal.addEventListener('abort', abort);

this._removeListeners = () => {
this.options.signal.removeEventListener('abort', abort);
this.options.signal?.removeEventListener('abort', abort);
};
}
}
Expand Down
8 changes: 2 additions & 6 deletions source/core/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions test/abort.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
4 changes: 2 additions & 2 deletions test/agent.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion test/arguments.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
18 changes: 10 additions & 8 deletions test/cache.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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},
Expand Down
8 changes: 4 additions & 4 deletions test/cancel.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion test/cookies.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion test/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion test/encoding.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Buffer} from 'buffer';
import {Buffer} from 'node:buffer';
import test from 'ava';
import withServer from './helpers/with-server.js';

Expand Down
12 changes: 6 additions & 6 deletions test/error.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
6 changes: 3 additions & 3 deletions test/gzip.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
8 changes: 4 additions & 4 deletions test/headers.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/create-http-test-server.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
8 changes: 4 additions & 4 deletions test/helpers/create-https-test-server.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/slow-data-stream.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Readable} from 'stream';
import {Readable} from 'node:stream';
import type {Clock} from '@sinonjs/fake-timers';
import delay from 'delay';

Expand Down
2 changes: 1 addition & 1 deletion test/helpers/types.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
4 changes: 2 additions & 2 deletions test/helpers/with-server.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
4 changes: 2 additions & 2 deletions test/hooks.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
10 changes: 5 additions & 5 deletions test/http.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
4 changes: 2 additions & 2 deletions test/https.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion test/pagination.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
14 changes: 7 additions & 7 deletions test/post.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
10 changes: 5 additions & 5 deletions test/progress.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
6 changes: 3 additions & 3 deletions test/promise.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion test/redirects.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion test/response-parse.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
10 changes: 5 additions & 5 deletions test/retry.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
12 changes: 6 additions & 6 deletions test/stream.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
12 changes: 6 additions & 6 deletions test/timeout.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion test/types/create-test-server/index.d.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Loading

0 comments on commit 81447e9

Please sign in to comment.