Skip to content

Commit

Permalink
feat: replace node-fetch with undici (#3137)
Browse files Browse the repository at this point in the history
swagger-client requires Node.js >=12.20.0 and uses different fetch 
implementation depending on Node.js version:

>=12.20.0 <16.8 - node-fetch@3
>=16.8 <18 - undici
>=18 - native Node.js fetch

Closes #1220
Closes #2736
Closes #2415
Closes #2381
Closes #2187
Closes #2291
  • Loading branch information
char0n authored Sep 12, 2023
1 parent 1f989b1 commit bc7ca17
Show file tree
Hide file tree
Showing 46 changed files with 2,059 additions and 13,559 deletions.
4 changes: 0 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ updates:
prefix: "chore"
include: "scope"
open-pull-requests-limit: 10
ignore:
# cross-fetch and node-fetch must be synced manually
- dependency-name: "cross-fetch"
- dependency-name: "node-fetch"

- package-ecosystem: "github-actions"
target-branch: "master"
Expand Down
20 changes: 12 additions & 8 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

strategy:
matrix:
node-version: [14.x, 16.x, 18.x, 20.x]
node-version: [16.x, 18.x, 20.x]

steps:
- uses: actions/checkout@v4
Expand All @@ -29,6 +29,9 @@ jobs:
with:
path: node_modules
key: node-modules-${{ hashFiles('package-lock.json') }}
- name: Update npm
if: startsWith(matrix.node-version, '14')
run: npm install -g npm@9
- name: Install dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci
Expand All @@ -44,7 +47,7 @@ jobs:
- name: Build swagger-js
run: npm run build
- name: Upload commonjs build artifacts
if: startsWith(matrix.node-version, '14')
if: startsWith(matrix.node-version, '20')
uses: actions/upload-artifact@v3
with:
name: commonjs
Expand All @@ -57,10 +60,11 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Use Node.js 12.20.0
- name: Use Node.js 20
uses: actions/setup-node@v3
with:
node-version: 12.20.0
node-version: 20

- name: Cache Node Modules
id: cache-node-modules
uses: actions/cache@v3
Expand All @@ -77,38 +81,38 @@ jobs:
with:
name: commonjs

- name: Use Node 12.20.0
uses: actions/setup-node@v3
with:
node-version: 12.20.0
- name: Run commonjs build artifacts on Node.js 12.20.0
run: node -p "require('./commonjs')"

- name: Use Node 14.x
uses: actions/setup-node@v3
with:
node-version: 14.x

- name: Run commonjs build artifacts on Node.js 14.x
run: node -p "require('./commonjs')"

- name: Use Node 16.x
uses: actions/setup-node@v3
with:
node-version: 16.x

- name: Run commonjs build artifacts on Node.js 16.x
run: node -p "require('./commonjs')"

- name: Use Node 18.x
uses: actions/setup-node@v3
with:
node-version: 18.x

- name: Run commonjs build artifacts on Node.js 18.x
run: node -p "require('./commonjs')"

- name: Use Node 20.x
uses: actions/setup-node@v3
with:
node-version: 20.x

- name: Run commonjs build artifacts on Node.js 20.x
run: node -p "require('./commonjs')"

21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,25 @@ Swagger Client Version | Release Date | OpenAPI Spec compatibility |

### Runtime

- Node.js `>=`12.20.0
- `swagger-client` works in the latest versions of Chrome, Safari, Firefox, and Edge.
### Node.js

`swagger-client` requires Node.js `>=12.20.0` and uses different `fetch` implementation depending
on Node.js version.

- `>=12.20.0 <16.8` - [node-fetch@3](https://www.npmjs.com/package/node-fetch)
- `>=16.8 <18` - [undici](https://www.npmjs.com/package/undici)
- `>=18` - [native Node.js fetch](https://nodejs.org/dist/latest-v18.x/docs/api/globals.html#fetch)

> NOTE: swagger-client minimum Node.js runtime version aligns with [Node.js Releases](https://nodejs.org/en/about/releases/)
> which means that we can drop support for **EOL** (End Of Life) Node.js versions without doing major version bump.
### Browsers

`swagger-client` works in the latest versions of Chrome, Safari, Firefox, and Edge
and uses [native fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) implementation
provided by each supported browser.



## Security contact

Expand Down
4 changes: 2 additions & 2 deletions config/jest/jest.unit.coverage.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ module.exports = {
collectCoverageFrom: ['src/**/*.js'],
coverageThreshold: {
'./src/': {
branches: 86,
branches: 85,
functions: 91,
lines: 90,
lines: 89,
statements: 89,
},
},
Expand Down
3 changes: 0 additions & 3 deletions config/webpack/browser.config.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import path from 'path';
import { StatsWriterPlugin } from 'webpack-stats-plugin';
import { DuplicatesPlugin } from 'inspectpack/plugin';
import { WebpackBundleSizeAnalyzerPlugin } from 'webpack-bundle-size-analyzer';
import LodashModuleReplacementPlugin from 'lodash-webpack-plugin';
import TerserPlugin from 'terser-webpack-plugin';

const module = {
Expand Down Expand Up @@ -43,7 +42,6 @@ const browser = {
},
module,
plugins: [
new LodashModuleReplacementPlugin(),
new DuplicatesPlugin({
// emit compilation warning or error? (Default: `false`)
emitErrors: false, // https://github.com/FormidableLabs/inspectpack/issues/181
Expand Down Expand Up @@ -85,7 +83,6 @@ const browserMin = {
},
module,
plugins: [
new LodashModuleReplacementPlugin(),
new WebpackBundleSizeAnalyzerPlugin('swagger-client.browser-sizes.txt'),
new StatsWriterPlugin({
filename: path.join('swagger-client.browser-stats.json'),
Expand Down
9 changes: 4 additions & 5 deletions docs/development/setting-up.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
### Prerequisites

- git, any version
- Node.js >=16.16
- NPM >=8.11.0

Generally, we recommend following guidelines from [Node.js Releases](https://nodejs.org/en/about/releases/) to only use `Current`, `Active LTS` or `Maintenance LTS` releases.
- Node.js >=20.3.0
- NPM >=9.6.7

### Setting up

Expand All @@ -16,12 +14,13 @@ If you use [nvm](https://github.com/nvm-sh/nvm), running following command insid
$ nvm use
```

#### Setup teps
#### Setup steps

1. `git clone https://github.com/swagger-api/swagger-js.git`
2. `cd swagger-js`
3. `npm install`
4. `npm run build`
5. `npm run test`

### Testing with Swagger-UI

Expand Down
Loading

0 comments on commit bc7ca17

Please sign in to comment.