Skip to content

Commit

Permalink
Upgrade dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Mar 15, 2022
1 parent d95ceea commit 53513ce
Show file tree
Hide file tree
Showing 17 changed files with 110 additions and 109 deletions.
24 changes: 12 additions & 12 deletions benchmark/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,20 @@ const suite = new Benchmark.Suite();
// Benchmarking
suite.add('got - promise', {
defer: true,
fn: async (deferred: {resolve: () => void}) => {
async fn(deferred: {resolve: () => void}) {
await got(url, gotOptions);
deferred.resolve();
},
}).add('got - stream', {
defer: true,
fn: async (deferred: {resolve: () => void}) => {
async fn(deferred: {resolve: () => void}) {
got.stream(url, gotOptions).resume().once('end', () => {
deferred.resolve();
});
},
}).add('got - core', {
defer: true,
fn: async (deferred: {resolve: () => void}) => {
async fn(deferred: {resolve: () => void}) {
const stream = new Request(url, gotOptions);
void stream.flush();
stream.resume().once('end', () => {
Expand All @@ -88,7 +88,7 @@ suite.add('got - promise', {
},
}).add('got - core - normalized options', {
defer: true,
fn: async (deferred: {resolve: () => void}) => {
async fn(deferred: {resolve: () => void}) {
const stream = new Request(undefined, undefined, normalizedGotOptions);
void stream.flush();
stream.resume().once('end', () => {
Expand All @@ -97,7 +97,7 @@ suite.add('got - promise', {
},
}).add('request - callback', {
defer: true,
fn: (deferred: {resolve: () => void}) => {
fn(deferred: {resolve: () => void}) {
request(urlString, requestOptions, (error: Error) => {
if (error) {
throw error;
Expand All @@ -108,7 +108,7 @@ suite.add('got - promise', {
},
}).add('request - stream', {
defer: true,
fn: (deferred: {resolve: () => void}) => {
fn(deferred: {resolve: () => void}) {
const stream = request(urlString, requestOptions);
stream.resume();
stream.once('end', () => {
Expand All @@ -117,15 +117,15 @@ suite.add('got - promise', {
},
}).add('node-fetch - promise', {
defer: true,
fn: async (deferred: {resolve: () => void}) => {
async fn(deferred: {resolve: () => void}) {
const response = await fetch(urlString, fetchOptions);
await response.text();

deferred.resolve();
},
}).add('node-fetch - stream', {
defer: true,
fn: async (deferred: {resolve: () => void}) => {
async fn(deferred: {resolve: () => void}) {
const {body} = await fetch(urlString, fetchOptions);

body!.resume();
Expand All @@ -135,13 +135,13 @@ suite.add('got - promise', {
},
}).add('axios - promise', {
defer: true,
fn: async (deferred: {resolve: () => void}) => {
async fn(deferred: {resolve: () => void}) {
await axios.request(axiosOptions);
deferred.resolve();
},
}).add('axios - stream', {
defer: true,
fn: async (deferred: {resolve: () => void}) => {
async fn(deferred: {resolve: () => void}) {
const result = await axios.request(axiosStreamOptions);
const {data}: any = result;

Expand All @@ -152,7 +152,7 @@ suite.add('got - promise', {
},
}).add('https - stream', {
defer: true,
fn: (deferred: {resolve: () => void}) => {
fn(deferred: {resolve: () => void}) {
https.request(urlString, httpsOptions, response => {
response.resume();
response.once('end', () => {
Expand All @@ -173,7 +173,7 @@ const internalBenchmark = (): void => {

const internalSuite = new Benchmark.Suite();
internalSuite.add('got - normalize options', {
fn: () => {
fn() {
// eslint-disable-next-line no-new
new Options(url, gotOptions);
},
Expand Down
36 changes: 18 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"ky"
],
"dependencies": {
"@sindresorhus/is": "^4.2.0",
"@sindresorhus/is": "^4.6.0",
"@szmarczak/http-timer": "^5.0.1",
"@types/cacheable-request": "^6.0.2",
"@types/responselike": "^1.0.0",
Expand All @@ -53,55 +53,55 @@
"decompress-response": "^6.0.0",
"form-data-encoder": "1.7.1",
"get-stream": "^6.0.1",
"http2-wrapper": "^2.1.9",
"http2-wrapper": "^2.1.10",
"lowercase-keys": "^3.0.0",
"p-cancelable": "^3.0.0",
"responselike": "^2.0.0"
},
"devDependencies": {
"@hapi/bourne": "^2.0.0",
"@sindresorhus/tsconfig": "^2.0.0",
"@sinonjs/fake-timers": "^8.1.0",
"@sinonjs/fake-timers": "^9.1.1",
"@types/benchmark": "^2.1.1",
"@types/express": "^4.17.13",
"@types/node": "^16.11.12",
"@types/node": "^17.0.21",
"@types/pem": "^1.9.6",
"@types/pify": "^5.0.1",
"@types/readable-stream": "^2.3.12",
"@types/request": "^2.48.7",
"@types/sinon": "^10.0.6",
"@types/readable-stream": "^2.3.13",
"@types/request": "^2.48.8",
"@types/sinon": "^10.0.11",
"@types/sinonjs__fake-timers": "^8.1.1",
"@types/tough-cookie": "^4.0.1",
"ava": "^3.15.0",
"axios": "^0.24.0",
"axios": "^0.26.1",
"benchmark": "^2.1.4",
"bluebird": "^3.7.2",
"body-parser": "^1.19.0",
"body-parser": "^1.19.2",
"create-cert": "^1.0.6",
"create-test-server": "^3.0.1",
"del-cli": "^4.0.1",
"delay": "^5.0.0",
"express": "^4.17.1",
"express": "^4.17.3",
"form-data": "^4.0.0",
"formdata-node": "^4.3.1",
"nock": "^13.2.1",
"node-fetch": "^3.1.0",
"formdata-node": "^4.3.2",
"nock": "^13.2.4",
"node-fetch": "^3.2.3",
"np": "^7.6.0",
"nyc": "^15.1.0",
"p-event": "^5.0.1",
"pem": "^1.14.4",
"pem": "^1.14.6",
"pify": "^5.0.0",
"readable-stream": "^3.6.0",
"request": "^2.88.2",
"sinon": "^12.0.1",
"sinon": "^13.0.1",
"slow-stream": "0.0.4",
"tempy": "^2.0.0",
"then-busboy": "^5.1.1",
"to-readable-stream": "^3.0.0",
"tough-cookie": "^4.0.0",
"ts-node": "^10.4.0",
"typescript": "4.5.3",
"xo": "^0.47.0"
"ts-node": "^10.7.0",
"typescript": "4.6.2",
"xo": "^0.48.0"
},
"types": "dist/source",
"sideEffects": false,
Expand Down
15 changes: 8 additions & 7 deletions source/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,9 @@ export default class Request extends Duplex implements RequestEvents<Request> {
}

let data;

while ((data = response.read()) !== null) {
this._downloadedSize += data.length;
this._downloadedSize += data.length; // eslint-disable-line @typescript-eslint/restrict-plus-operands

const progress = this.downloadProgress;

Expand All @@ -462,7 +463,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
}
}

override _write(chunk: unknown, encoding: BufferEncoding | undefined, callback: (error?: Error | null) => void): void {
override _write(chunk: unknown, encoding: BufferEncoding | undefined, callback: (error?: Error | null) => void): void { // eslint-disable-line @typescript-eslint/ban-types
const write = (): void => {
this._writeRequest(chunk, encoding, callback);
};
Expand All @@ -474,7 +475,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
}
}

override _final(callback: (error?: Error | null) => void): void {
override _final(callback: (error?: Error | null) => void): void { // eslint-disable-line @typescript-eslint/ban-types
const endRequest = (): void => {
// We need to check if `this._request` is present,
// because it isn't when we use cache.
Expand All @@ -483,7 +484,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
return;
}

this._request.end((error?: Error | null) => {
this._request.end((error?: Error | null) => { // eslint-disable-line @typescript-eslint/ban-types
// The request has been destroyed before `_final` finished.
// See https://github.com/nodejs/node/issues/39356
if ((this._request as any)._writableState?.errored) {
Expand All @@ -508,7 +509,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
}
}

override _destroy(error: Error | null, callback: (error: Error | null) => void): void {
override _destroy(error: Error | null, callback: (error: Error | null) => void): void { // eslint-disable-line @typescript-eslint/ban-types
this._stopReading = true;
this.flush = async () => {};

Expand Down Expand Up @@ -1186,13 +1187,13 @@ export default class Request extends Duplex implements RequestEvents<Request> {
this.destroy(error);
}

private _writeRequest(chunk: any, encoding: BufferEncoding | undefined, callback: (error?: Error | null) => void): void {
private _writeRequest(chunk: any, encoding: BufferEncoding | undefined, callback: (error?: Error | null) => void): void { // eslint-disable-line @typescript-eslint/ban-types
if (!this._request || this._request.destroyed) {
// Probably the `ClientRequest` instance will throw
return;
}

this._request.write(chunk, encoding!, (error?: Error | null) => {
this._request.write(chunk, encoding!, (error?: Error | null) => { // eslint-disable-line @typescript-eslint/ban-types
if (!error) {
this._uploadedSize += Buffer.byteLength(chunk, encoding);

Expand Down
16 changes: 8 additions & 8 deletions source/core/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ export interface Agents {
export type Headers = Record<string, string | string[] | undefined>;

export interface ToughCookieJar {
getCookieString: ((currentUrl: string, options: Record<string, unknown>, cb: (error: Error | null, cookies: string) => void) => void)
& ((url: string, callback: (error: Error | null, cookieHeader: string) => void) => void);
setCookie: ((cookieOrString: unknown, currentUrl: string, options: Record<string, unknown>, cb: (error: Error | null, cookie: unknown) => void) => void)
& ((rawCookie: string, url: string, callback: (error: Error | null, result: unknown) => void) => void);
getCookieString: ((currentUrl: string, options: Record<string, unknown>, 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<string, unknown>, 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 {
Expand Down Expand Up @@ -621,9 +621,9 @@ export interface PaginationOptions<ElementType, BodyType> {
stackAllItems?: boolean;
}

export type SearchParameters = Record<string, string | number | boolean | null | undefined>;
export type SearchParameters = Record<string, string | number | boolean | null | undefined>; // eslint-disable-line @typescript-eslint/ban-types

function validateSearchParameters(searchParameters: Record<string, unknown>): asserts searchParameters is Record<string, string | number | boolean | null | undefined> {
function validateSearchParameters(searchParameters: Record<string, unknown>): asserts searchParameters is Record<string, string | number | boolean | null | undefined> { // eslint-disable-line @typescript-eslint/ban-types
// eslint-disable-next-line guard-for-in
for (const key in searchParameters) {
const value = searchParameters[key];
Expand Down Expand Up @@ -794,14 +794,14 @@ const defaultInternals: Options['_internals'] = {
responseType: 'text',
url: undefined,
pagination: {
transform: (response: Response) => {
transform(response: Response) {
if (response.request.options.responseType === 'json') {
return response.body;
}

return JSON.parse(response.body as string);
},
paginate: ({response}) => {
paginate({response}) {
const rawLinkHeader = response.headers.link;
if (typeof rawLinkHeader !== 'string' || rawLinkHeader.trim() === '') {
return false;
Expand Down
2 changes: 1 addition & 1 deletion source/core/utils/is-form-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import is from '@sindresorhus/is';

interface FormData extends Readable {
getBoundary: () => string;
getLength: (callback: (error: Error | null, length: number) => void) => void;
getLength: (callback: (error: Error | null, length: number) => void) => void; // eslint-disable-line @typescript-eslint/ban-types
}

export default function isFormData(body: unknown): body is FormData {
Expand Down
4 changes: 2 additions & 2 deletions source/core/utils/url-to-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export interface LegacyUrlOptions {
protocol: string;
hostname: string;
host: string;
hash: string | null;
search: string | null;
hash: string | null; // eslint-disable-line @typescript-eslint/ban-types
search: string | null; // eslint-disable-line @typescript-eslint/ban-types
pathname: string;
href: string;
path: string;
Expand Down
4 changes: 2 additions & 2 deletions test/cancel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ test.serial('does not retry after cancelation', withServerAndFakeTimers, async (

const gotPromise = got('redirect', {
retry: {
calculateDelay: () => {
calculateDelay() {
t.fail('Makes a new try after cancelation');
return 0;
},
Expand All @@ -94,7 +94,7 @@ test.serial('cleans up request timeouts', withServer, async (t, server, got) =>
request: 10,
},
retry: {
calculateDelay: ({computedValue}) => {
calculateDelay({computedValue}) {
process.nextTick(() => {
gotPromise.cancel();
});
Expand Down
20 changes: 10 additions & 10 deletions test/cookies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ test('does not throw on invalid cookies when options.ignoreInvalidCookies is set
test('catches store errors', async t => {
const error = 'Some error';
const cookieJar = new toughCookie.CookieJar({
findCookies: (_, __, ___, callback) => {
findCookies(_, __, ___, callback) {
callback(new Error(error), []);
},
findCookie: () => {},
getAllCookies: () => {},
putCookie: () => {},
removeCookies: () => {},
removeCookie: () => {},
updateCookie: () => {},
findCookie() {},
getAllCookies() {},
putCookie() {},
removeCookies() {},
removeCookie() {},
updateCookie() {},
synchronous: false,
});

Expand Down Expand Up @@ -132,8 +132,8 @@ test('no unhandled errors', async t => {

const options = {
cookieJar: {
setCookie: async (_rawCookie: string, _url: string) => {},
getCookieString: async (_url: string) => {
async setCookie(_rawCookie: string, _url: string) {},
async getCookieString(_url: string) {
throw new Error(message);
},
},
Expand Down Expand Up @@ -183,7 +183,7 @@ test('throws on invalid `options.cookieJar.setCookie`', async t => {
test('throws on invalid `options.cookieJar.getCookieString`', async t => {
await t.throwsAsync(got('https://example.com', {
cookieJar: {
setCookie: async () => {},
async setCookie() {},
// @ts-expect-error Error tests
getCookieString: 123,
},
Expand Down

0 comments on commit 53513ce

Please sign in to comment.