Skip to content

Commit 853fcf1

Browse files
moved fetch to dynamic import
1 parent 3cfbe2d commit 853fcf1

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"devDependencies": {
2222
"@ef-carbon/fetch": "^2.1.3",
2323
"@types/node": "^10.12.18",
24+
"@types/node-fetch": "^2.1.4",
2425
"ava": "^1.0.1",
2526
"cross-env": "^5.2.0",
2627
"node-fetch": "^2.3.0",

src/fetch.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import FetchOptions from './lib/FetchOptions';
2+
3+
const callFetch = (url: string, options: Partial<FetchOptions>) => {
4+
//@ts-ignore
5+
if (typeof fetch === 'undefined') {
6+
return import('node-fetch').then(fetch => {
7+
//@ts-ignore
8+
return fetch(url, options);
9+
});
10+
}
11+
12+
//@ts-ignore
13+
return fetch(url, options);
14+
};
15+
16+
export default callFetch;

src/lib/FetchRequest.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import FetchOptions from './FetchOptions';
2-
import { skip, isNode } from '../Utils';
2+
import { skip } from '../Utils';
33
import Fetch from '.';
44
import { QueryObject } from '../types';
5-
6-
if (typeof fetch == 'undefined') {
7-
var fetch = require('node-fetch');
8-
}
5+
import fetch from '../fetch';
96

107
export default class FetchRequest {
118
options: FetchOptions = new FetchOptions();

tsconfig.json

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"module": "CommonJS",
1010
},
1111
"exclude": [
12-
"node_modules",
1312
"exampleApp"
1413
]
1514
}

0 commit comments

Comments
 (0)