Skip to content

Commit bc7ca17

Browse files
authored
feat: replace node-fetch with undici (#3137)
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
1 parent 1f989b1 commit bc7ca17

File tree

46 files changed

+2059
-13559
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2059
-13559
lines changed

.github/dependabot.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ updates:
99
prefix: "chore"
1010
include: "scope"
1111
open-pull-requests-limit: 10
12-
ignore:
13-
# cross-fetch and node-fetch must be synced manually
14-
- dependency-name: "cross-fetch"
15-
- dependency-name: "node-fetch"
1612

1713
- package-ecosystem: "github-actions"
1814
target-branch: "master"

.github/workflows/nodejs.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515

1616
strategy:
1717
matrix:
18-
node-version: [14.x, 16.x, 18.x, 20.x]
18+
node-version: [16.x, 18.x, 20.x]
1919

2020
steps:
2121
- uses: actions/checkout@v4
@@ -29,6 +29,9 @@ jobs:
2929
with:
3030
path: node_modules
3131
key: node-modules-${{ hashFiles('package-lock.json') }}
32+
- name: Update npm
33+
if: startsWith(matrix.node-version, '14')
34+
run: npm install -g npm@9
3235
- name: Install dependencies
3336
if: steps.cache-node-modules.outputs.cache-hit != 'true'
3437
run: npm ci
@@ -44,7 +47,7 @@ jobs:
4447
- name: Build swagger-js
4548
run: npm run build
4649
- name: Upload commonjs build artifacts
47-
if: startsWith(matrix.node-version, '14')
50+
if: startsWith(matrix.node-version, '20')
4851
uses: actions/upload-artifact@v3
4952
with:
5053
name: commonjs
@@ -57,10 +60,11 @@ jobs:
5760

5861
steps:
5962
- uses: actions/checkout@v4
60-
- name: Use Node.js 12.20.0
63+
- name: Use Node.js 20
6164
uses: actions/setup-node@v3
6265
with:
63-
node-version: 12.20.0
66+
node-version: 20
67+
6468
- name: Cache Node Modules
6569
id: cache-node-modules
6670
uses: actions/cache@v3
@@ -77,38 +81,38 @@ jobs:
7781
with:
7882
name: commonjs
7983

84+
- name: Use Node 12.20.0
85+
uses: actions/setup-node@v3
86+
with:
87+
node-version: 12.20.0
8088
- name: Run commonjs build artifacts on Node.js 12.20.0
8189
run: node -p "require('./commonjs')"
8290

8391
- name: Use Node 14.x
8492
uses: actions/setup-node@v3
8593
with:
8694
node-version: 14.x
87-
8895
- name: Run commonjs build artifacts on Node.js 14.x
8996
run: node -p "require('./commonjs')"
9097

9198
- name: Use Node 16.x
9299
uses: actions/setup-node@v3
93100
with:
94101
node-version: 16.x
95-
96102
- name: Run commonjs build artifacts on Node.js 16.x
97103
run: node -p "require('./commonjs')"
98104

99105
- name: Use Node 18.x
100106
uses: actions/setup-node@v3
101107
with:
102108
node-version: 18.x
103-
104109
- name: Run commonjs build artifacts on Node.js 18.x
105110
run: node -p "require('./commonjs')"
106111

107112
- name: Use Node 20.x
108113
uses: actions/setup-node@v3
109114
with:
110115
node-version: 20.x
111-
112116
- name: Run commonjs build artifacts on Node.js 20.x
113117
run: node -p "require('./commonjs')"
114118

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,25 @@ Swagger Client Version | Release Date | OpenAPI Spec compatibility |
5252

5353
### Runtime
5454

55-
- Node.js `>=`12.20.0
56-
- `swagger-client` works in the latest versions of Chrome, Safari, Firefox, and Edge.
55+
### Node.js
56+
57+
`swagger-client` requires Node.js `>=12.20.0` and uses different `fetch` implementation depending
58+
on Node.js version.
59+
60+
- `>=12.20.0 <16.8` - [node-fetch@3](https://www.npmjs.com/package/node-fetch)
61+
- `>=16.8 <18` - [undici](https://www.npmjs.com/package/undici)
62+
- `>=18` - [native Node.js fetch](https://nodejs.org/dist/latest-v18.x/docs/api/globals.html#fetch)
63+
64+
> NOTE: swagger-client minimum Node.js runtime version aligns with [Node.js Releases](https://nodejs.org/en/about/releases/)
65+
> which means that we can drop support for **EOL** (End Of Life) Node.js versions without doing major version bump.
66+
67+
### Browsers
68+
69+
`swagger-client` works in the latest versions of Chrome, Safari, Firefox, and Edge
70+
and uses [native fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) implementation
71+
provided by each supported browser.
72+
73+
5774

5875
## Security contact
5976

config/jest/jest.unit.coverage.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ module.exports = {
66
collectCoverageFrom: ['src/**/*.js'],
77
coverageThreshold: {
88
'./src/': {
9-
branches: 86,
9+
branches: 85,
1010
functions: 91,
11-
lines: 90,
11+
lines: 89,
1212
statements: 89,
1313
},
1414
},

config/webpack/browser.config.babel.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import path from 'path';
22
import { StatsWriterPlugin } from 'webpack-stats-plugin';
33
import { DuplicatesPlugin } from 'inspectpack/plugin';
44
import { WebpackBundleSizeAnalyzerPlugin } from 'webpack-bundle-size-analyzer';
5-
import LodashModuleReplacementPlugin from 'lodash-webpack-plugin';
65
import TerserPlugin from 'terser-webpack-plugin';
76

87
const module = {
@@ -43,7 +42,6 @@ const browser = {
4342
},
4443
module,
4544
plugins: [
46-
new LodashModuleReplacementPlugin(),
4745
new DuplicatesPlugin({
4846
// emit compilation warning or error? (Default: `false`)
4947
emitErrors: false, // https://github.com/FormidableLabs/inspectpack/issues/181
@@ -85,7 +83,6 @@ const browserMin = {
8583
},
8684
module,
8785
plugins: [
88-
new LodashModuleReplacementPlugin(),
8986
new WebpackBundleSizeAnalyzerPlugin('swagger-client.browser-sizes.txt'),
9087
new StatsWriterPlugin({
9188
filename: path.join('swagger-client.browser-stats.json'),

docs/development/setting-up.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
### Prerequisites
44

55
- git, any version
6-
- Node.js >=16.16
7-
- NPM >=8.11.0
8-
9-
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.
6+
- Node.js >=20.3.0
7+
- NPM >=9.6.7
108

119
### Setting up
1210

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

19-
#### Setup teps
17+
#### Setup steps
2018

2119
1. `git clone https://github.com/swagger-api/swagger-js.git`
2220
2. `cd swagger-js`
2321
3. `npm install`
2422
4. `npm run build`
23+
5. `npm run test`
2524

2625
### Testing with Swagger-UI
2726

0 commit comments

Comments
 (0)