Skip to content

Commit

Permalink
feat: CommonJS and ES Modules compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
mindhells committed Oct 14, 2021
1 parent 050db8a commit 03f9603
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 13 deletions.
3 changes: 0 additions & 3 deletions README.md
Expand Up @@ -10,9 +10,6 @@ Axios plugin that intercepts failed requests and retries them whenever possible.
npm install axios-retry
```

### Note
Not working with `axios 0.19.0`. For details see the [bug](https://github.com/axios/axios/issues/2203). [`axios 0.19.1`](https://github.com/axios/axios/releases/tag/0.19.1) has fixed this bug.

## Usage

```js
Expand Down
12 changes: 12 additions & 0 deletions babel.config.cjs.json
@@ -0,0 +1,12 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": "defaults",
"modules": "commonjs"
}
]
],
"plugins": ["@babel/plugin-transform-runtime"]
}
5 changes: 4 additions & 1 deletion babel.config.json
Expand Up @@ -3,7 +3,10 @@
[
"@babel/preset-env",
{
"targets": "defaults"
"targets": {
"esmodules": true
},
"modules": false
}
]
]
Expand Down
11 changes: 11 additions & 0 deletions fixup
@@ -0,0 +1,11 @@
cat >lib/cjs/package.json <<!EOF
{
"type": "commonjs"
}
!EOF

cat >lib/esm/package.json <<!EOF
{
"type": "module"
}
!EOF
2 changes: 1 addition & 1 deletion index.js
@@ -1 +1 @@
module.exports = require('./lib/index').default;
module.exports = require('./lib/cjs/index').default;
28 changes: 25 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 15 additions & 5 deletions package.json
Expand Up @@ -4,20 +4,18 @@
"author": "Rubén Norte <ruben.norte@softonic.com>",
"description": "Axios plugin that intercepts failed requests and retries them whenever posible.",
"license": "Apache-2.0",
"main": "index.js",
"homepage": "https://github.com/softonic/axios-retry",
"files": [
"es",
"lib",
"index.js",
"index.d.ts"
],
"scripts": {
"lint": "eslint es/**/*.mjs spec/**/*.spec.mjs",
"pretest": "npm run lint",
"test": "NODE_OPTIONS=--es-module-specifier-resolution=node jasmine",
"prebuild": "npm run test",
"build": "rm -rf lib && babel es -d lib --source-maps",
"build": "rm -rf lib && babel es -d lib/esm --source-maps && babel es -d lib/cjs --config-file ./babel.config.cjs.json --source-maps && ./fixup",
"prerelease": "npm run build",
"release": "npm version -m \"New version: %s\"",
"postrelease": "npm run push && npm publish",
Expand All @@ -32,14 +30,15 @@
"*.js": "eslint --cache --fix"
},
"dependencies": {
"is-retry-allowed": "^3.0.0"
"is-retry-allowed": "^2.2.0"
},
"peerDependencies": {
"axios": ">=0.21.2"
},
"devDependencies": {
"@babel/cli": "^7.15.7",
"@babel/core": "^7.15.5",
"@babel/plugin-transform-runtime": "^7.15.8",
"@babel/preset-env": "^7.15.6",
"axios": "^0.21.2",
"eslint": "^7.32.0",
Expand All @@ -61,5 +60,16 @@
"bugs": {
"url": "https://github.com/softonic/axios-retry/issues"
},
"typings": "./index.d.ts"
"typings": "./index.d.ts",
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"

This comment has been minimized.

Copy link
@dko-slapdash

dko-slapdash Oct 15, 2021

This change makes the library not working in Node 15. So basically, all the projects which are on Node 15 started failing.

This comment has been minimized.

Copy link
@mindhells

mindhells Oct 15, 2021

Author Member

This applies to axios-retry versions >=3.2.1
So, projects with NodeJS versions not matching that criteria shouldn't update or install versions greater than 3.2.0.
As odd numbered versions of NodeJS are meant to experiment (became EOL after 6 months), you can always fork this repo for that.

},
"main": "lib/cjs/index.js",
"module": "lib/esm/index.js",
"exports": {
".": {
"import": "./lib/esm/index.js",
"require": "./index.js"
}
}
}

0 comments on commit 03f9603

Please sign in to comment.