-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
Copy pathglobals.ts
62 lines (50 loc) · 1.5 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
61
62
import {
ReadableStream as NodeReadableStream,
WritableStream as NodeWritableStream,
} from "@remix-run/web-stream";
import { AbortController as NodeAbortController } from "abort-controller";
import { atob, btoa } from "./base64";
import {
Blob as NodeBlob,
File as NodeFile,
FormData as NodeFormData,
Headers as NodeHeaders,
Request as NodeRequest,
Response as NodeResponse,
fetch as nodeFetch,
} from "./fetch";
declare global {
namespace NodeJS {
interface ProcessEnv {
NODE_ENV: "development" | "production" | "test";
}
interface Global {
atob: typeof atob;
btoa: typeof btoa;
Blob: typeof Blob;
File: typeof File;
Headers: typeof Headers;
Request: typeof Request;
Response: typeof Response;
fetch: typeof fetch;
FormData: typeof FormData;
ReadableStream: typeof ReadableStream;
WritableStream: typeof WritableStream;
AbortController: typeof AbortController;
}
}
}
export function installGlobals() {
global.atob = atob;
global.btoa = btoa;
global.Blob = NodeBlob;
global.File = NodeFile;
global.Headers = NodeHeaders as typeof Headers;
global.Request = NodeRequest as typeof Request;
global.Response = NodeResponse as unknown as typeof Response;
global.fetch = nodeFetch as typeof fetch;
global.FormData = NodeFormData;
global.ReadableStream = NodeReadableStream;
global.WritableStream = NodeWritableStream;
global.AbortController = global.AbortController || NodeAbortController;
}