File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { LRU } from 'ylru' ;
2+ import { patchForNode16 } from './utils.js' ;
3+
4+ patchForNode16 ( ) ;
5+
26import { HttpClient , HEADER_USER_AGENT } from './HttpClient.js' ;
37import { RequestOptions , RequestURL } from './Request.js' ;
48
Original file line number Diff line number Diff line change 11import { randomBytes , createHash } from 'node:crypto' ;
22import { Readable } from 'node:stream' ;
33import { performance } from 'node:perf_hooks' ;
4+ import { ReadableStream } from 'node:stream/web' ;
5+ import { Blob } from 'node:buffer' ;
46import type { FixJSONCtlChars } from './Request.js' ;
57import { SocketInfo } from './Response.js' ;
68import symbols from './symbols.js' ;
@@ -205,3 +207,29 @@ export function convertHeader(headers: Headers): IncomingHttpHeaders {
205207 }
206208 return res ;
207209}
210+
211+ // support require from Node.js 16
212+ export function patchForNode16 ( ) {
213+ if ( typeof global . ReadableStream === 'undefined' ) {
214+ // @ts -ignore
215+ global . ReadableStream = ReadableStream ;
216+ }
217+ if ( typeof global . Blob === 'undefined' ) {
218+ // @ts -ignore
219+ global . Blob = Blob ;
220+ }
221+ if ( typeof global . DOMException === 'undefined' ) {
222+ // @ts -ignore
223+ global . DOMException = getDOMExceptionClass ( ) ;
224+ }
225+ }
226+
227+ // https://github.com/jimmywarting/node-domexception/blob/main/index.js
228+ function getDOMExceptionClass ( ) {
229+ try {
230+ // @ts -ignore
231+ atob ( 0 ) ;
232+ } catch ( err : any ) {
233+ return err . constructor ;
234+ }
235+ }
You can’t perform that action at this time.
0 commit comments