Skip to content

Commit 0e99a3b

Browse files
author
Nikhil Thorat
authored
Remove the systemFetch export from platform_node (#1963)
BUG
1 parent 0b7287a commit 0e99a3b

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

tfjs-core/src/platforms/platform_node.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,19 @@ export const getNodeFetch = {
2424
importFetch: () => require('node-fetch')
2525
};
2626

27-
export let systemFetch: (url: string, init?: RequestInit) => Promise<Response>;
27+
type FetchFn = (url: string, init?: RequestInit) => Promise<Response>;
28+
let systemFetch: FetchFn;
29+
// These getters and setters are for testing so we don't export a mutable
30+
// variable.
31+
export function resetSystemFetch() {
32+
systemFetch = null;
33+
}
34+
export function setSystemFetch(fetchFn: FetchFn) {
35+
systemFetch = fetchFn;
36+
}
37+
export function getSystemFetch(): FetchFn {
38+
return systemFetch;
39+
}
2840

2941
export class PlatformNode implements Platform {
3042
private textEncoder: TextEncoder;

tfjs-core/src/platforms/platform_node_test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@ describeWithFlags('PlatformNode', NODE_ENVS, () => {
4242

4343
const platform = new PlatformNode();
4444

45-
const savedFetch = platform_node.systemFetch;
45+
const savedFetch = platform_node.getSystemFetch();
4646

4747
// Null out the system fetch so we force it to require node-fetch.
48-
// @ts-ignore
49-
platform_node.systemFetch = null;
48+
platform_node.resetSystemFetch();
5049

5150
const testFetch = {fetch: (url: string, init: RequestInit) => {}};
5251

@@ -63,8 +62,7 @@ describeWithFlags('PlatformNode', NODE_ENVS, () => {
6362
expect(platform_node.getNodeFetch.importFetch).toHaveBeenCalled();
6463
expect(testFetch.fetch).toHaveBeenCalledWith('test/url', {method: 'GET'});
6564

66-
// @ts-ignore
67-
platform_node.systemFetch = savedFetch;
65+
platform_node.setSystemFetch(savedFetch);
6866
ENV.global.fetch = globalFetch;
6967
});
7068

0 commit comments

Comments
 (0)