From ef74217113cf611af420564421d844858d70701b Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Wed, 4 May 2022 09:45:23 -0700 Subject: [PATCH] feat!: support the latest versions of node.js (#188) BREAKING CHANGE: This release drops support for node.js 12 and 14. It also drops support for the browser specific compilation, as the entire toolchain was deprecated. I am open to this being re-added if someone wants to take it on :) --- .babelrc | 19 ------------- .github/workflows/ci.yaml | 8 +++--- .prettierrc.js | 17 ----------- .prettierrc.json | 6 ++++ package.json | 46 ++++++++++++------------------ test/index.ts | 60 +++++++++++++++++++++++---------------- tsconfig.json | 3 +- 7 files changed, 66 insertions(+), 93 deletions(-) delete mode 100644 .babelrc delete mode 100644 .prettierrc.js create mode 100644 .prettierrc.json diff --git a/.babelrc b/.babelrc deleted file mode 100644 index b2477fa..0000000 --- a/.babelrc +++ /dev/null @@ -1,19 +0,0 @@ -{ - "presets": [ - [ - "@babel/preset-env", - { - "useBuiltIns": "entry", - "modules": false - } - ] - ], - "plugins": [ - ["transform-es2015-modules-umd", { - "globals": { - "axios": "axios" - } - }] - ], - "moduleId": "rax" -} \ No newline at end of file diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 75197c3..58d88de 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node: [10, 12, 14, 16] + node: [14, 16, 18] steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 @@ -33,7 +33,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: - node-version: 14 + node-version: 18 - run: npm install - run: npm run lint license_check: @@ -42,7 +42,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: - node-version: 14 + node-version: 18 - run: npm install - run: npm run license-check release: @@ -53,7 +53,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: - node-version: 14 + node-version: 18 - run: npm install - run: npm run compile - run: npx semantic-release diff --git a/.prettierrc.js b/.prettierrc.js deleted file mode 100644 index d1b9510..0000000 --- a/.prettierrc.js +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2020 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -module.exports = { - ...require('gts/.prettierrc.json') -} diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..993c327 --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,6 @@ +{ + "bracketSpacing": false, + "singleQuote": true, + "trailingComma": "es5", + "arrowParens": "avoid" +} diff --git a/package.json b/package.json index 3a38121..6ad6ff3 100644 --- a/package.json +++ b/package.json @@ -2,13 +2,11 @@ "name": "retry-axios", "version": "0.0.0", "description": "Retry HTTP requests with Axios.", - "source": "src/index.ts", - "main": "dist/index.js", - "module": "dist/index.module.js", - "unpkg": "dist/index.umd.js", - "types": "dist/src/index.d.ts", + "exports": "./build/src/index.js", + "type": "module", + "types": "./build/src/index.d.ts", "engines": { - "node": ">=10.7.0" + "node": ">=14" }, "repository": { "type": "git", @@ -18,11 +16,8 @@ "lint": "gts check", "clean": "gts clean", "fix": "gts fix", - "compile": "tsc --target ES5 --module CommonJS", - "build-web": "microbundle", - "umd": "rm -rf umd && babel build/src -d umd --source-maps", + "compile": "tsc -p .", "test": "c8 mocha build/test", - "prepare": "npm run build-web", "pretest": "npm run compile", "license-check": "jsgl --local ." }, @@ -38,31 +33,26 @@ "axios": "*" }, "devDependencies": { - "@babel/cli": "^7.4.4", - "@babel/preset-env": "^7.4.5", - "@types/mocha": "^9.0.0", - "@types/sinon": "^10.0.0", - "@types/node": "^16.0.0", + "@types/mocha": "^9.1.1", + "@types/sinon": "^10.0.11", + "@types/node": "^17.0.31", "axios": "^0.26.0", - "babel-plugin-transform-es2015-modules-umd": "^6.24.1", - "c8": "^7.0.0", - "gts": "^3.0.0", - "js-green-licenses": "^3.0.0", - "microbundle": "^0.11.0", - "mocha": "^9.0.0", - "nock": "^13.0.0", - "semantic-release": "^18.0.0", - "sinon": "^13.0.0", - "typescript": "~4.3.0" + "c8": "^7.11.2", + "gts": "^3.1.0", + "js-green-licenses": "^3.0.1", + "mocha": "^10.0.0", + "nock": "^13.2.4", + "semantic-release": "^19.0.2", + "sinon": "^13.0.2", + "typescript": "~4.6.4" }, "files": [ - "dist" + "build/src" ], "c8": { "exclude": [ "build/test", "dist" ] - }, - "browserslist": "> 1%, last 2 versions, Firefox ESR" + } } diff --git a/test/index.ts b/test/index.ts index e852960..f7e523a 100644 --- a/test/index.ts +++ b/test/index.ts @@ -1,10 +1,10 @@ -import * as assert from 'assert'; -import axios, {AxiosRequestConfig} from 'axios'; -import * as nock from 'nock'; -import * as sinon from 'sinon'; +import assert from 'assert'; +import axios, {AxiosError, AxiosRequestConfig} from 'axios'; +import nock from 'nock'; +import sinon from 'sinon'; import {describe, it, afterEach} from 'mocha'; -import * as rax from '../src'; -import {RaxConfig} from '../src'; +import * as rax from '../src/index.js'; +import {RaxConfig} from '../src/index.js'; const url = 'http://test.local'; @@ -25,7 +25,8 @@ describe('retry-axios', () => { interceptorId = rax.attach(); try { await axios(url); - } catch (e) { + } catch (ex) { + const e = ex as AxiosError; scope.done(); const config = rax.getConfig(e); assert.strictEqual(config!.currentRetryAttempt, 3, 'currentRetryAttempt'); @@ -73,7 +74,8 @@ describe('retry-axios', () => { interceptorId = rax.attach(); try { await axios.post(url); - } catch (e) { + } catch (ex) { + const e = ex as AxiosError; const config = rax.getConfig(e); assert.strictEqual(config!.currentRetryAttempt, 0); scope.done(); @@ -101,7 +103,8 @@ describe('retry-axios', () => { const cfg: rax.RaxConfig = {url, raxConfig: {retry: 1}}; try { await axios(cfg); - } catch (e) { + } catch (ex) { + const e = ex as AxiosError; assert.strictEqual(rax.getConfig(e)!.currentRetryAttempt, 1); scope.done(); return; @@ -114,13 +117,13 @@ describe('retry-axios', () => { const scopes = [ nock(url) .get('/') - .reply((_, __) => { + .reply(() => { requesttimes.push(process.hrtime.bigint()); return [500, 'foo']; }), nock(url) .get('/') - .reply((_, __) => { + .reply(() => { requesttimes.push(process.hrtime.bigint()); return [200, 'bar']; }), @@ -154,13 +157,13 @@ describe('retry-axios', () => { const scopes = [ nock(url) .get('/') - .reply((_, __) => { + .reply(() => { requesttimes.push(process.hrtime.bigint()); return [500, 'foo']; }), nock(url) .get('/') - .reply((_, __) => { + .reply(() => { requesttimes.push(process.hrtime.bigint()); return [200, 'bar']; }), @@ -194,13 +197,13 @@ describe('retry-axios', () => { const scopes = [ nock(url) .get('/') - .reply((_, __) => { + .reply(() => { requesttimes.push(process.hrtime.bigint()); return [500, 'foo']; }), nock(url) .get('/') - .reply((_, __) => { + .reply(() => { requesttimes.push(process.hrtime.bigint()); return [200, 'bar']; }), @@ -246,7 +249,8 @@ describe('retry-axios', () => { assert.notStrictEqual(ax, axios); try { await axios({url}); - } catch (e) { + } catch (ex) { + const e = ex as AxiosError; assert.strictEqual(undefined, rax.getConfig(e)); scope.done(); return; @@ -278,7 +282,8 @@ describe('retry-axios', () => { interceptorId = rax.attach(); try { await axios.get(url); - } catch (e) { + } catch (ex) { + const e = ex as AxiosError; const cfg = rax.getConfig(e); assert.strictEqual(cfg!.currentRetryAttempt, 0); scope.done(); @@ -293,7 +298,8 @@ describe('retry-axios', () => { try { const cfg: rax.RaxConfig = {url, raxConfig: {retry: 0}}; await axios(cfg); - } catch (e) { + } catch (ex) { + const e = ex as AxiosError; const cfg = rax.getConfig(e); assert.strictEqual(0, cfg!.currentRetryAttempt); scope.done(); @@ -311,7 +317,8 @@ describe('retry-axios', () => { }; try { await axios(config); - } catch (e) { + } catch (ex) { + const e = ex as AxiosError; const cfg = rax.getConfig(e); assert.strictEqual(cfg!.backoffType, 'exponential'); scope.isDone(); @@ -381,7 +388,8 @@ describe('retry-axios', () => { }; try { await axios(config); - } catch (e) { + } catch (ex) { + const e = ex as AxiosError; const cfg = rax.getConfig(e); assert.strictEqual(cfg!.currentRetryAttempt, 0); scope.done(); @@ -418,7 +426,8 @@ describe('retry-axios', () => { const config = {url, raxConfig: {noResponseRetries: 0}}; try { await axios(config); - } catch (e) { + } catch (ex) { + const e = ex as AxiosError; const cfg = rax.getConfig(e); assert.strictEqual(cfg!.currentRetryAttempt, 0); scope.isDone(); @@ -477,7 +486,8 @@ describe('retry-axios', () => { }; try { await axios(config); - } catch (e) { + } catch (ex) { + const e = ex as AxiosError; const cfg = rax.getConfig(e); assert.strictEqual(cfg!.retryDelay, 0); scope.isDone(); @@ -495,7 +505,8 @@ describe('retry-axios', () => { }; try { await axios(config); - } catch (e) { + } catch (ex) { + const e = ex as AxiosError; const cfg = rax.getConfig(e); assert.strictEqual(cfg!.retry, 0); scope.isDone(); @@ -513,7 +524,8 @@ describe('retry-axios', () => { }; try { await axios(config); - } catch (e) { + } catch (ex) { + const e = ex as AxiosError; const cfg = rax.getConfig(e); assert.strictEqual(cfg!.noResponseRetries, 0); scope.isDone(); diff --git a/tsconfig.json b/tsconfig.json index 9cc5849..347ac39 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,8 @@ "rootDir": ".", "outDir": "build", "moduleResolution": "node", - "module": "ES2015" + "module": "ES2022", + "esModuleInterop": true }, "include": [ "src/*.ts",