-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
globals.ts
60 lines (55 loc) · 1.45 KB
/
globals.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
declare global {
namespace NodeJS {
interface ProcessEnv {
NODE_ENV: "development" | "production" | "test";
}
interface Global {
File: typeof File;
Headers: typeof Headers;
Request: typeof Request;
Response: typeof Response;
fetch: typeof fetch;
FormData: typeof FormData;
ReadableStream: typeof ReadableStream;
WritableStream: typeof WritableStream;
}
}
interface RequestInit {
duplex?: "half";
}
}
export function installGlobals({
nativeFetch,
}: { nativeFetch?: boolean } = {}) {
if (nativeFetch) {
let {
File: UndiciFile,
fetch: undiciFetch,
FormData: UndiciFormData,
Headers: UndiciHeaders,
Request: UndiciRequest,
Response: UndiciResponse,
} = require("undici");
global.File = UndiciFile as unknown as typeof File;
global.Headers = UndiciHeaders;
global.Request = UndiciRequest;
global.Response = UndiciResponse;
global.fetch = undiciFetch;
global.FormData = UndiciFormData;
} else {
let {
File: RemixFile,
fetch: RemixFetch,
FormData: RemixFormData,
Headers: RemixHeaders,
Request: RemixRequest,
Response: RemixResponse,
} = require("@remix-run/web-fetch");
global.File = RemixFile;
global.Headers = RemixHeaders;
global.Request = RemixRequest;
global.Response = RemixResponse;
global.fetch = RemixFetch;
global.FormData = RemixFormData;
}
}