Mirror: A Node.js fetch shim using built-in Request, Response, and Headers (but without native fetch)
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: Protect against `node --no-experimental-fetch` (#11)

authored by

Phil Pluckthun and committed by
GitHub
2b29583b eaf68db8

+14 -4
+5
.changeset/ready-items-wear.md
··· 1 + --- 2 + 'fetch-nodeshim': patch 3 + --- 4 + 5 + Prevent outright error when `--no-experimental-fetch` is set, which causes `Request`, `Response`, `FormData`, and `Headers` to not be available globally.
+9 -4
src/webstd.ts
··· 81 81 init?: _RequestInit | Or<RequestInit, globalThis.RequestInit> 82 82 ): _Request; 83 83 } 84 - const _Request: RequestClass = Request; 85 84 86 85 interface _Response extends Or<Response, globalThis.Response> {} 87 86 interface ResponseClass 88 87 extends Or<typeof Response, typeof globalThis.Response> { 89 88 new (body?: BodyInit, init?: _ResponseInit): _Response; 90 89 } 91 - const _Response: ResponseClass = Response; 92 90 93 91 interface _Headers extends Or<Headers, globalThis.Headers> {} 94 92 interface HeadersClass extends Or<typeof Headers, typeof globalThis.Headers> { 95 93 new (init?: HeadersInit): _Headers; 96 94 } 97 - const _Headers: HeadersClass = Headers; 98 95 99 96 interface _FormData 100 97 extends Or< ··· 103 100 > {} 104 101 interface FormDataClass 105 102 extends Or<typeof FormData, typeof globalThis.FormData> {} 106 - const _FormData: FormDataClass = FormData; 103 + 104 + let _Request: RequestClass; 105 + let _Response: ResponseClass; 106 + let _Headers: HeadersClass; 107 + let _FormData: FormDataClass; 108 + if (typeof Request !== 'undefined') _Request = Request; 109 + if (typeof Response !== 'undefined') _Response = Response; 110 + if (typeof Headers !== 'undefined') _Headers = Headers; 111 + if (typeof FormData !== 'undefined') _FormData = FormData; 107 112 108 113 export { 109 114 type _RequestInit as RequestInit,