Skip to content

Commit d87aa73

Browse files
build!: drop support for node.js 8.x (#159)
BREAKING CHANGE: dropping support for Node.js 8.x
1 parent f95d552 commit d87aa73

9 files changed

+40
-80
lines changed

.eslintrc.yml

-15
This file was deleted.

.prettierrc

-8
This file was deleted.

package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
"description": "Like request, but smaller.",
55
"main": "./build/src/index.js",
66
"types": "./build/src/index.d.ts",
7+
"engines": {
8+
"node": ">=10"
9+
},
710
"scripts": {
811
"test": "c8 mocha build/test",
912
"compile": "tsc -p .",
@@ -12,7 +15,6 @@
1215
"clean": "gts clean",
1316
"fix": "gts fix",
1417
"prepare": "npm run compile",
15-
"posttest": "npm run lint",
1618
"docs": "compodoc src/",
1719
"predocs-test": "npm run docs",
1820
"docs-test": "linkinator docs",
@@ -49,12 +51,12 @@
4951
"@types/uuid": "^7.0.0",
5052
"c8": "^7.0.0",
5153
"codecov": "^3.1.0",
52-
"gts": "^1.0.0",
54+
"gts": "^2.0.0",
5355
"linkinator": "^2.0.0",
5456
"mocha": "^7.0.0",
5557
"nock": "^12.0.0",
5658
"sinon": "^9.0.0",
57-
"typescript": "~3.8.2"
59+
"typescript": "^3.8.3"
5860
},
5961
"nyc": {
6062
"exclude": [

src/agents.ts

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import {Agent as HTTPAgent} from 'http';
1818
import {Agent as HTTPSAgent} from 'https';
19+
// eslint-disable-next-line node/no-deprecated-api
1920
import {parse} from 'url';
2021
import {Options} from './';
2122

src/index.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,19 @@ import fetch, * as f from 'node-fetch';
2020
import {PassThrough, Readable} from 'stream';
2121
import * as uuid from 'uuid';
2222
import {getAgent} from './agents';
23+
// eslint-disable-next-line @typescript-eslint/no-var-requires
2324
const streamEvents = require('stream-events');
2425

2526
export interface CoreOptions {
2627
method?: string;
2728
timeout?: number;
2829
gzip?: boolean;
29-
// tslint:disable-next-line no-any
30+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3031
json?: any;
3132
headers?: Headers;
3233
body?: string | {};
3334
useQuerystring?: boolean;
34-
// tslint:disable-next-line no-any
35+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3536
qs?: any;
3637
proxy?: string;
3738
multipart?: RequestPart[];
@@ -55,7 +56,7 @@ export interface Request extends PassThrough {
5556
href?: string;
5657
}
5758

58-
// tslint:disable-next-line no-any
59+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5960
export interface Response<T = any> {
6061
statusCode: number;
6162
headers: Headers;
@@ -68,7 +69,7 @@ export interface RequestPart {
6869
body: string | Readable;
6970
}
7071

71-
// tslint:disable-next-line no-any
72+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7273
export interface RequestCallback<T = any> {
7374
(err: Error | null, response: Response, body?: T): void;
7475
}
@@ -78,7 +79,7 @@ export class RequestError extends Error {
7879
}
7980

8081
interface Headers {
81-
// tslint:disable-next-line no-any
82+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8283
[index: string]: any;
8384
}
8485

@@ -109,12 +110,13 @@ function requestToFetchOptions(reqOpts: Options) {
109110
}
110111
}
111112

112-
// tslint:disable-next-line no-any
113+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
113114
options.headers = reqOpts.headers as any;
114115

115116
let uri = ((reqOpts as OptionsWithUri).uri ||
116117
(reqOpts as OptionsWithUrl).url) as string;
117118
if (reqOpts.useQuerystring === true || typeof reqOpts.qs === 'object') {
119+
// eslint-disable-next-line @typescript-eslint/no-var-requires
118120
const qs = require('querystring');
119121
const params = qs.stringify(reqOpts.qs);
120122
uri = uri + '?' + params;
@@ -245,7 +247,7 @@ function teenyRequest(
245247
if (callback === undefined) {
246248
// Stream mode
247249
const requestStream = streamEvents(new PassThrough());
248-
// tslint:disable-next-line no-any
250+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
249251
let responseStream: any;
250252
requestStream.once('reading', () => {
251253
if (responseStream) {

test/agents.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import * as https from 'https';
2121
import * as sinon from 'sinon';
2222
import {getAgent, pool} from '../src/agents';
2323

24-
// tslint:disable-next-line variable-name
24+
// eslint-disable-next-line @typescript-eslint/no-var-requires
2525
const HttpProxyAgent = require('http-proxy-agent');
26-
// tslint:disable-next-line variable-name
26+
// eslint-disable-next-line @typescript-eslint/no-var-requires
2727
const HttpsProxyAgent = require('https-proxy-agent');
2828

2929
describe('agents', () => {
@@ -66,7 +66,7 @@ describe('agents', () => {
6666
const agent = getAgent(uri, options);
6767
assert(agent instanceof HttpProxyAgent);
6868

69-
// tslint:disable-next-line:no-any
69+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7070
const {proxy: proxyActual}: any = agent!;
7171
assert.strictEqual(proxyActual.protocol, proxyExpected.protocol);
7272
assert.strictEqual(proxyActual.hostname, proxyExpected.hostname);
@@ -97,7 +97,7 @@ describe('agents', () => {
9797
const agent = getAgent(uri, options);
9898
assert(agent instanceof HttpsProxyAgent);
9999

100-
// tslint:disable-next-line:no-any
100+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
101101
const {proxy: proxyActual}: any = agent!;
102102
assert.strictEqual(proxyActual.protocol, proxyExpected.protocol);
103103
assert.strictEqual(proxyActual.hostname, proxyExpected.hostname);

test/index.ts

+19-35
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,16 @@ import * as sinon from 'sinon';
2222
import {teenyRequest} from '../src';
2323
import {pool} from '../src/agents';
2424

25-
// tslint:disable-next-line variable-name
25+
// eslint-disable-next-line @typescript-eslint/no-var-requires
2626
const HttpProxyAgent = require('http-proxy-agent');
27-
// tslint:disable-next-line variable-name
27+
// eslint-disable-next-line @typescript-eslint/no-var-requires
2828
const HttpsProxyAgent = require('https-proxy-agent');
2929

3030
nock.disableNetConnect();
3131
const uri = 'https://example.com';
3232

3333
function mockJson() {
34-
return nock(uri)
35-
.get('/')
36-
.reply(200, {hello: '🌍'});
34+
return nock(uri).get('/').reply(200, {hello: '🌍'});
3735
}
3836

3937
describe('teeny', () => {
@@ -70,9 +68,7 @@ describe('teeny', () => {
7068
it('response event emits object compatible with request module', done => {
7169
const reqHeaders = {fruit: 'banana'};
7270
const resHeaders = {veggies: 'carrots'};
73-
const scope = nock(uri)
74-
.get('/')
75-
.reply(202, 'ok', resHeaders);
71+
const scope = nock(uri).get('/').reply(202, 'ok', resHeaders);
7672
const reqStream = teenyRequest({uri, headers: reqHeaders});
7773
reqStream
7874
.on('response', res => {
@@ -91,9 +87,7 @@ describe('teeny', () => {
9187

9288
it('should include the request in the response', done => {
9389
const path = '/?dessert=pie';
94-
const scope = nock(uri)
95-
.get(path)
96-
.reply(202);
90+
const scope = nock(uri).get(path).reply(202);
9791
const headers = {dinner: 'tacos'};
9892
const url = `${uri}${path}`;
9993
teenyRequest({url, headers}, (error, response) => {
@@ -121,9 +115,7 @@ describe('teeny', () => {
121115
it('should include headers in the response', done => {
122116
const headers = {dinner: 'tacos'};
123117
const body = {hello: '🌍'};
124-
const scope = nock(uri)
125-
.get('/')
126-
.reply(200, body, headers);
118+
const scope = nock(uri).get('/').reply(200, body, headers);
127119
teenyRequest({uri}, (err, res) => {
128120
assert.ifError(err);
129121
assert.strictEqual(headers['dinner'], res.headers['dinner']);
@@ -133,12 +125,10 @@ describe('teeny', () => {
133125
});
134126

135127
it('should accept the forever option', done => {
136-
const scope = nock(uri)
137-
.get('/')
138-
.reply(200);
128+
const scope = nock(uri).get('/').reply(200);
139129
teenyRequest({uri, forever: true}, (err, res) => {
140130
assert.ifError(err);
141-
// tslint:disable-next-line no-any
131+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
142132
assert.strictEqual((res.request.agent as any).keepAlive, true);
143133
scope.done();
144134
done();
@@ -150,11 +140,9 @@ describe('teeny', () => {
150140
'Accept-Encoding': 'gzip,deflate',
151141
};
152142

153-
const scope = nock(uri, {reqheaders})
154-
.get('/')
155-
.reply(200);
143+
const scope = nock(uri, {reqheaders}).get('/').reply(200);
156144

157-
teenyRequest({uri, gzip: true}, (err, res) => {
145+
teenyRequest({uri, gzip: true}, err => {
158146
assert.ifError(err);
159147
scope.done();
160148
done();
@@ -164,11 +152,9 @@ describe('teeny', () => {
164152
it('should allow setting compress/gzip to false', done => {
165153
const badheaders = ['Accept-Encoding'];
166154

167-
const scope = nock(uri, {badheaders})
168-
.get('/')
169-
.reply(200);
155+
const scope = nock(uri, {badheaders}).get('/').reply(200);
170156

171-
teenyRequest({uri, gzip: false}, (err, res) => {
157+
teenyRequest({uri, gzip: false}, err => {
172158
assert.ifError(err);
173159
scope.done();
174160
done();
@@ -180,9 +166,7 @@ describe('teeny', () => {
180166
it(`should respect ${v} environment variable for proxy config`, done => {
181167
sandbox.stub(process, 'env').value({[v]: 'https://fake.proxy'});
182168
const expectedBody = {hello: '🌎'};
183-
const scope = nock(uri)
184-
.get('/')
185-
.reply(200, expectedBody);
169+
const scope = nock(uri).get('/').reply(200, expectedBody);
186170
teenyRequest({uri}, (err, res, body) => {
187171
scope.done();
188172
assert.ifError(err);
@@ -196,9 +180,7 @@ describe('teeny', () => {
196180
it('should create http proxy if upstream scheme is http', done => {
197181
sandbox.stub(process, 'env').value({http_proxy: 'https://fake.proxy'});
198182
const expectedBody = {hello: '🌎'};
199-
const scope = nock('http://example.com')
200-
.get('/')
201-
.reply(200, expectedBody);
183+
const scope = nock('http://example.com').get('/').reply(200, expectedBody);
202184
teenyRequest({uri: 'http://example.com'}, (err, res, body) => {
203185
scope.done();
204186
assert.ifError(err);
@@ -210,9 +192,7 @@ describe('teeny', () => {
210192

211193
it('should use proxy if set in request options', done => {
212194
const expectedBody = {hello: '🌎'};
213-
const scope = nock(uri)
214-
.get('/')
215-
.reply(200, expectedBody);
195+
const scope = nock(uri).get('/').reply(200, expectedBody);
216196
teenyRequest({uri, proxy: 'https://fake.proxy'}, (err, res, body) => {
217197
scope.done();
218198
assert.ifError(err);
@@ -226,12 +206,14 @@ describe('teeny', () => {
226206
it('should not throw exception when piped through pumpify', () => {
227207
const scope = mockJson();
228208
teenyRequest({uri}).pipe(new PassThrough());
209+
scope.done();
229210
});
230211

231212
it('should emit response event when called without callback', done => {
232213
const scope = mockJson();
233214
teenyRequest({uri}).on('response', res => {
234215
assert.ok(res);
216+
scope.done();
235217
return done();
236218
});
237219
});
@@ -241,6 +223,7 @@ describe('teeny', () => {
241223
teenyRequest({uri})
242224
.on('error', done)
243225
.on('data', () => {
226+
scope.done();
244227
done();
245228
});
246229
});
@@ -261,6 +244,7 @@ describe('teeny', () => {
261244
responseStream.body._readableState.pipesCount ??
262245
responseStream.body._readableState.pipes?.length;
263246
assert.strictEqual(numPipes, 1);
247+
scope.done();
264248
done();
265249
});
266250
});

tsconfig.json

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22
"extends": "./node_modules/gts/tsconfig-google.json",
33
"compilerOptions": {
44
"rootDir": ".",
5-
"outDir": "build",
6-
"target": "es5",
5+
"outDir": "build"
76
},
87
"include": [
98
"src/*.ts",
10-
"src/**/*.ts",
11-
"test/*.ts",
12-
"test/**/*.ts"
9+
"test/*.ts"
1310
]
1411
}

tslint.json

-3
This file was deleted.

0 commit comments

Comments
 (0)