Skip to content

Commit 88111db

Browse files
Upgrade node-fetch to v3
1 parent 694dcf1 commit 88111db

File tree

8 files changed

+169
-75
lines changed

8 files changed

+169
-75
lines changed

.eslintrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@
5555
"ecmaVersion": 2015,
5656
"sourceType": "module"
5757
}
58+
},
59+
{
60+
"files": ["src/platform/getFetch/node.js"],
61+
"parserOptions": {
62+
"ecmaVersion": 2020,
63+
"sourceType": "module"
64+
}
5865
}
5966
],
6067

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
11.8.0 (October XX, 2025)
22
- Updated @splitsoftware/splitio-commons package to version 2.8.0, which updates the SDK’s initial synchronization in Node.js (server-side) to use the `startup.requestTimeoutBeforeReady` and `startup.retriesOnFailureBeforeReady` options to control the timeout and retry behavior of segment requests.
3+
- Updated node-fetch to version 3.3.2, which fixes some issues with the Fetch API implementation.
34

45
11.7.1 (October 8, 2025)
56
- Bugfix - Updated @splitsoftware/splitio-commons package to version 2.7.1, which fixes the `debug` option to support log levels when the `logger` option is used.

package-lock.json

Lines changed: 125 additions & 59 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@splitsoftware/splitio",
3-
"version": "11.7.2-rc.0",
3+
"version": "11.7.2-rc.1",
44
"description": "Split SDK",
55
"files": [
66
"README.md",
@@ -42,7 +42,7 @@
4242
"bloom-filters": "^3.0.4",
4343
"ioredis": "^4.28.0",
4444
"js-yaml": "^3.13.1",
45-
"node-fetch": "^2.7.0",
45+
"node-fetch": "^3.3.2",
4646
"tslib": "^2.3.1",
4747
"unfetch": "^4.2.0"
4848
},
@@ -102,7 +102,7 @@
102102
"test-node": "npm run test-node-unit && npm run test-node-e2e",
103103
"test-node-unit": "cross-env NODE_ENV=test tape -r ./ts-node.register \"src/*/**/__tests__/**/!(browser).spec.js\" | tap-min",
104104
"test-node-e2e": "npm run test-node-e2e-online && npm run test-node-e2e-offline && npm run test-node-e2e-destroy && npm run test-node-e2e-errorCatching && npm run test-node-e2e-push && npm run test-node-e2e-redis",
105-
"test-node-e2e-online": "cross-env NODE_ENV=test tape -r ./ts-node.register src/__tests__/online/node.spec.js",
105+
"test-node-e2e-online": "cross-env NODE_ENV=test tape -r ./ts-node.register src/__tests__/online/node.spec.js | tap-min",
106106
"test-node-e2e-offline": "cross-env NODE_ENV=test tape -r ./ts-node.register src/__tests__/offline/node.spec.js | tap-min",
107107
"test-node-e2e-destroy": "cross-env NODE_ENV=test tape -r ./ts-node.register src/__tests__/destroy/node.spec.js | tap-min",
108108
"test-node-e2e-errorCatching": "cross-env NODE_ENV=test tape -r ./ts-node.register src/__tests__/errorCatching/node.spec.js | tap-min",

scripts/build_cjs_replace_imports.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# replace splitio-commons imports to use CommonJS
44
replace '@splitsoftware/splitio-commons/src' '@splitsoftware/splitio-commons/cjs' ./cjs -r
55

6+
replace "__importStar\(require\('node-fetch'\)\)" "import('node-fetch')" ./cjs/platform/getFetch/node.js
7+
68
if [ $? -eq 0 ]
79
then
810
exit 0
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import tape from 'tape-catch';
22
import { getFetch } from '../node';
33

4-
tape('getFetch returns node-fetch module in Node', assert => {
5-
assert.equal(getFetch(), require('node-fetch'));
4+
5+
tape('getFetch returns node-fetch module in Node', async assert => {
6+
// @TODO: not working as expected. Both are `fetch` but different function instances?
7+
// const nodeFetch = await eval("import('node-fetch')");
8+
// assert.equal(getFetch(), nodeFetch.default);
9+
10+
assert.equal(getFetch().name, 'nodeFetch');
611

712
assert.end();
813
});

src/platform/getFetch/node.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
1-
let nodeFetch;
1+
let __setFetchCalled = false;
2+
let nodeFetchImport;
23

3-
try {
4-
nodeFetch = require('node-fetch');
4+
let nodeFetch = (url, options) => {
5+
try {
6+
if (!nodeFetchImport) {
7+
// lazy import, recommended for other runtimes than Node.js
8+
nodeFetchImport = import('node-fetch').then(({ default: fetch }) => {
9+
if (!__setFetchCalled) nodeFetch = fetch;
10+
}).catch(() => {
11+
if (!__setFetchCalled) nodeFetch = typeof fetch === 'function' ? fetch : undefined;
12+
});
13+
}
514

6-
// Handle node-fetch issue https://github.com/node-fetch/node-fetch/issues/1037
7-
if (typeof nodeFetch !== 'function') nodeFetch = nodeFetch.default;
8-
9-
} catch (error) {
10-
// Try to access global fetch if `node-fetch` package couldn't be imported (e.g., not in a Node environment)
11-
nodeFetch = typeof fetch === 'function' ? fetch : undefined;
12-
}
15+
return nodeFetchImport.then(() => {
16+
if (!nodeFetch) throw new Error('Fetch API not available');
17+
return nodeFetch(url, options);
18+
});
19+
} catch (error) {
20+
if (!__setFetchCalled) nodeFetch = typeof fetch === 'function' ? fetch : undefined;
21+
if (!nodeFetch) throw new Error('Fetch API not available');
22+
return nodeFetch(url, options);
23+
}
24+
};
1325

1426
// This function is only exposed for testing purposes.
1527
export function __setFetch(fetch) {
28+
__setFetchCalled = true;
1629
nodeFetch = fetch;
1730
}
1831

src/settings/defaults/version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const packageVersion = '11.7.2-rc.0';
1+
export const packageVersion = '11.7.2-rc.1';

0 commit comments

Comments
 (0)