From d87aa73d3fafbdc013b03b7629a41decda6da98a Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Sun, 12 Apr 2020 14:47:38 -0700 Subject: [PATCH] build!: drop support for node.js 8.x (#159) BREAKING CHANGE: dropping support for Node.js 8.x --- .eslintrc.yml | 15 -------------- .prettierrc | 8 -------- package.json | 8 +++++--- src/agents.ts | 1 + src/index.ts | 16 ++++++++------- test/agents.ts | 8 ++++---- test/index.ts | 54 ++++++++++++++++++-------------------------------- tsconfig.json | 7 ++----- tslint.json | 3 --- 9 files changed, 40 insertions(+), 80 deletions(-) delete mode 100644 .eslintrc.yml delete mode 100644 .prettierrc delete mode 100644 tslint.json diff --git a/.eslintrc.yml b/.eslintrc.yml deleted file mode 100644 index 73eeec2..0000000 --- a/.eslintrc.yml +++ /dev/null @@ -1,15 +0,0 @@ ---- -extends: - - 'eslint:recommended' - - 'plugin:node/recommended' - - prettier -plugins: - - node - - prettier -rules: - prettier/prettier: error - block-scoped-var: error - eqeqeq: error - no-warning-comments: warn - no-var: error - prefer-const: error diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index df6eac0..0000000 --- a/.prettierrc +++ /dev/null @@ -1,8 +0,0 @@ ---- -bracketSpacing: false -printWidth: 80 -semi: true -singleQuote: true -tabWidth: 2 -trailingComma: es5 -useTabs: false diff --git a/package.json b/package.json index 8aabee1..eed3f3d 100644 --- a/package.json +++ b/package.json @@ -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 .", @@ -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", @@ -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": [ diff --git a/src/agents.ts b/src/agents.ts index cfce7a9..a1d21ea 100644 --- a/src/agents.ts +++ b/src/agents.ts @@ -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 './'; diff --git a/src/index.ts b/src/index.ts index a419769..62a41cb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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[]; @@ -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 { statusCode: number; headers: Headers; @@ -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 { (err: Error | null, response: Response, body?: T): void; } @@ -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; } @@ -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; @@ -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) { diff --git a/test/agents.ts b/test/agents.ts index 250b57c..19eff45 100644 --- a/test/agents.ts +++ b/test/agents.ts @@ -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', () => { @@ -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); @@ -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); diff --git a/test/index.ts b/test/index.ts index bb3dfa8..bad2f46 100644 --- a/test/index.ts +++ b/test/index.ts @@ -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', () => { @@ -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 => { @@ -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) => { @@ -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']); @@ -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(); @@ -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(); @@ -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(); @@ -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); @@ -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); @@ -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); @@ -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(); }); }); @@ -241,6 +223,7 @@ describe('teeny', () => { teenyRequest({uri}) .on('error', done) .on('data', () => { + scope.done(); done(); }); }); @@ -261,6 +244,7 @@ describe('teeny', () => { responseStream.body._readableState.pipesCount ?? responseStream.body._readableState.pipes?.length; assert.strictEqual(numPipes, 1); + scope.done(); done(); }); }); diff --git a/tsconfig.json b/tsconfig.json index 997a62d..26f33cd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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" ] } diff --git a/tslint.json b/tslint.json deleted file mode 100644 index 617dc97..0000000 --- a/tslint.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "gts/tslint.json" -}