Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build!: drop support for node.js 8.x #159

Merged
merged 1 commit into from Apr 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 0 additions & 15 deletions .eslintrc.yml

This file was deleted.

8 changes: 0 additions & 8 deletions .prettierrc

This file was deleted.

8 changes: 5 additions & 3 deletions package.json
Expand Up @@ -4,6 +4,9 @@
"description": "Like request, but smaller.",
"main": "./build/src/index.js",
"types": "./build/src/index.d.ts",
"engines": {
"node": ">=10"
},
"scripts": {
"test": "c8 mocha build/test",
"compile": "tsc -p .",
Expand All @@ -12,7 +15,6 @@
"clean": "gts clean",
"fix": "gts fix",
"prepare": "npm run compile",
"posttest": "npm run lint",
"docs": "compodoc src/",
"predocs-test": "npm run docs",
"docs-test": "linkinator docs",
Expand Down Expand Up @@ -49,12 +51,12 @@
"@types/uuid": "^7.0.0",
"c8": "^7.0.0",
"codecov": "^3.1.0",
"gts": "^1.0.0",
"gts": "^2.0.0",
"linkinator": "^2.0.0",
"mocha": "^7.0.0",
"nock": "^12.0.0",
"sinon": "^9.0.0",
"typescript": "~3.8.2"
"typescript": "^3.8.3"
},
"nyc": {
"exclude": [
Expand Down
1 change: 1 addition & 0 deletions src/agents.ts
Expand Up @@ -16,6 +16,7 @@

import {Agent as HTTPAgent} from 'http';
import {Agent as HTTPSAgent} from 'https';
// eslint-disable-next-line node/no-deprecated-api
import {parse} from 'url';
import {Options} from './';

Expand Down
16 changes: 9 additions & 7 deletions src/index.ts
Expand Up @@ -20,18 +20,19 @@ import fetch, * as f from 'node-fetch';
import {PassThrough, Readable} from 'stream';
import * as uuid from 'uuid';
import {getAgent} from './agents';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const streamEvents = require('stream-events');

export interface CoreOptions {
method?: string;
timeout?: number;
gzip?: boolean;
// tslint:disable-next-line no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
json?: any;
headers?: Headers;
body?: string | {};
useQuerystring?: boolean;
// tslint:disable-next-line no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
qs?: any;
proxy?: string;
multipart?: RequestPart[];
Expand All @@ -55,7 +56,7 @@ export interface Request extends PassThrough {
href?: string;
}

// tslint:disable-next-line no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export interface Response<T = any> {
statusCode: number;
headers: Headers;
Expand All @@ -68,7 +69,7 @@ export interface RequestPart {
body: string | Readable;
}

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

interface Headers {
// tslint:disable-next-line no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[index: string]: any;
}

Expand Down Expand Up @@ -109,12 +110,13 @@ function requestToFetchOptions(reqOpts: Options) {
}
}

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

let uri = ((reqOpts as OptionsWithUri).uri ||
(reqOpts as OptionsWithUrl).url) as string;
if (reqOpts.useQuerystring === true || typeof reqOpts.qs === 'object') {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const qs = require('querystring');
const params = qs.stringify(reqOpts.qs);
uri = uri + '?' + params;
Expand Down Expand Up @@ -245,7 +247,7 @@ function teenyRequest(
if (callback === undefined) {
// Stream mode
const requestStream = streamEvents(new PassThrough());
// tslint:disable-next-line no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let responseStream: any;
requestStream.once('reading', () => {
if (responseStream) {
Expand Down
8 changes: 4 additions & 4 deletions test/agents.ts
Expand Up @@ -21,9 +21,9 @@ import * as https from 'https';
import * as sinon from 'sinon';
import {getAgent, pool} from '../src/agents';

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

describe('agents', () => {
Expand Down Expand Up @@ -66,7 +66,7 @@ describe('agents', () => {
const agent = getAgent(uri, options);
assert(agent instanceof HttpProxyAgent);

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

// tslint:disable-next-line:no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const {proxy: proxyActual}: any = agent!;
assert.strictEqual(proxyActual.protocol, proxyExpected.protocol);
assert.strictEqual(proxyActual.hostname, proxyExpected.hostname);
Expand Down
54 changes: 19 additions & 35 deletions test/index.ts
Expand Up @@ -22,18 +22,16 @@ import * as sinon from 'sinon';
import {teenyRequest} from '../src';
import {pool} from '../src/agents';

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

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

function mockJson() {
return nock(uri)
.get('/')
.reply(200, {hello: '🌍'});
return nock(uri).get('/').reply(200, {hello: '🌍'});
}

describe('teeny', () => {
Expand Down Expand Up @@ -70,9 +68,7 @@ describe('teeny', () => {
it('response event emits object compatible with request module', done => {
const reqHeaders = {fruit: 'banana'};
const resHeaders = {veggies: 'carrots'};
const scope = nock(uri)
.get('/')
.reply(202, 'ok', resHeaders);
const scope = nock(uri).get('/').reply(202, 'ok', resHeaders);
const reqStream = teenyRequest({uri, headers: reqHeaders});
reqStream
.on('response', res => {
Expand All @@ -91,9 +87,7 @@ describe('teeny', () => {

it('should include the request in the response', done => {
const path = '/?dessert=pie';
const scope = nock(uri)
.get(path)
.reply(202);
const scope = nock(uri).get(path).reply(202);
const headers = {dinner: 'tacos'};
const url = `${uri}${path}`;
teenyRequest({url, headers}, (error, response) => {
Expand Down Expand Up @@ -121,9 +115,7 @@ describe('teeny', () => {
it('should include headers in the response', done => {
const headers = {dinner: 'tacos'};
const body = {hello: '🌍'};
const scope = nock(uri)
.get('/')
.reply(200, body, headers);
const scope = nock(uri).get('/').reply(200, body, headers);
teenyRequest({uri}, (err, res) => {
assert.ifError(err);
assert.strictEqual(headers['dinner'], res.headers['dinner']);
Expand All @@ -133,12 +125,10 @@ describe('teeny', () => {
});

it('should accept the forever option', done => {
const scope = nock(uri)
.get('/')
.reply(200);
const scope = nock(uri).get('/').reply(200);
teenyRequest({uri, forever: true}, (err, res) => {
assert.ifError(err);
// tslint:disable-next-line no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
assert.strictEqual((res.request.agent as any).keepAlive, true);
scope.done();
done();
Expand All @@ -150,11 +140,9 @@ describe('teeny', () => {
'Accept-Encoding': 'gzip,deflate',
};

const scope = nock(uri, {reqheaders})
.get('/')
.reply(200);
const scope = nock(uri, {reqheaders}).get('/').reply(200);

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

const scope = nock(uri, {badheaders})
.get('/')
.reply(200);
const scope = nock(uri, {badheaders}).get('/').reply(200);

teenyRequest({uri, gzip: false}, (err, res) => {
teenyRequest({uri, gzip: false}, err => {
assert.ifError(err);
scope.done();
done();
Expand All @@ -180,9 +166,7 @@ describe('teeny', () => {
it(`should respect ${v} environment variable for proxy config`, done => {
sandbox.stub(process, 'env').value({[v]: 'https://fake.proxy'});
const expectedBody = {hello: '🌎'};
const scope = nock(uri)
.get('/')
.reply(200, expectedBody);
const scope = nock(uri).get('/').reply(200, expectedBody);
teenyRequest({uri}, (err, res, body) => {
scope.done();
assert.ifError(err);
Expand All @@ -196,9 +180,7 @@ describe('teeny', () => {
it('should create http proxy if upstream scheme is http', done => {
sandbox.stub(process, 'env').value({http_proxy: 'https://fake.proxy'});
const expectedBody = {hello: '🌎'};
const scope = nock('http://example.com')
.get('/')
.reply(200, expectedBody);
const scope = nock('http://example.com').get('/').reply(200, expectedBody);
teenyRequest({uri: 'http://example.com'}, (err, res, body) => {
scope.done();
assert.ifError(err);
Expand All @@ -210,9 +192,7 @@ describe('teeny', () => {

it('should use proxy if set in request options', done => {
const expectedBody = {hello: '🌎'};
const scope = nock(uri)
.get('/')
.reply(200, expectedBody);
const scope = nock(uri).get('/').reply(200, expectedBody);
teenyRequest({uri, proxy: 'https://fake.proxy'}, (err, res, body) => {
scope.done();
assert.ifError(err);
Expand All @@ -226,12 +206,14 @@ describe('teeny', () => {
it('should not throw exception when piped through pumpify', () => {
const scope = mockJson();
teenyRequest({uri}).pipe(new PassThrough());
scope.done();
});

it('should emit response event when called without callback', done => {
const scope = mockJson();
teenyRequest({uri}).on('response', res => {
assert.ok(res);
scope.done();
return done();
});
});
Expand All @@ -241,6 +223,7 @@ describe('teeny', () => {
teenyRequest({uri})
.on('error', done)
.on('data', () => {
scope.done();
done();
});
});
Expand All @@ -261,6 +244,7 @@ describe('teeny', () => {
responseStream.body._readableState.pipesCount ??
responseStream.body._readableState.pipes?.length;
assert.strictEqual(numPipes, 1);
scope.done();
done();
});
});
Expand Down
7 changes: 2 additions & 5 deletions tsconfig.json
Expand Up @@ -2,13 +2,10 @@
"extends": "./node_modules/gts/tsconfig-google.json",
"compilerOptions": {
"rootDir": ".",
"outDir": "build",
"target": "es5",
"outDir": "build"
},
"include": [
"src/*.ts",
"src/**/*.ts",
"test/*.ts",
"test/**/*.ts"
"test/*.ts"
]
}
3 changes: 0 additions & 3 deletions tslint.json

This file was deleted.