-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import { randomBytes, createHash } from 'node:crypto'; | ||
import { Readable } from 'node:stream'; | ||
import { performance } from 'node:perf_hooks'; | ||
import { ReadableStream } from 'node:stream/web'; | ||
import { Blob } from 'node:buffer'; | ||
import type { FixJSONCtlChars } from './Request.js'; | ||
import { SocketInfo } from './Response.js'; | ||
import symbols from './symbols.js'; | ||
|
@@ -205,3 +207,29 @@ export function convertHeader(headers: Headers): IncomingHttpHeaders { | |
} | ||
return res; | ||
} | ||
|
||
// support require from Node.js 16 | ||
export function patchForNode16() { | ||
if (typeof global.ReadableStream === 'undefined') { | ||
// @ts-ignore | ||
Check failure on line 214 in src/utils.ts GitHub Actions / Node.js / Test (ubuntu-latest, 18)
Check failure on line 214 in src/utils.ts GitHub Actions / Node.js / Test (ubuntu-latest, 20)
Check failure on line 214 in src/utils.ts GitHub Actions / Node.js / Test (ubuntu-latest, 18.19.0)
Check failure on line 214 in src/utils.ts GitHub Actions / Node.js / Test (ubuntu-latest, 23)
Check failure on line 214 in src/utils.ts GitHub Actions / Node.js / Test (ubuntu-latest, 22)
Check failure on line 214 in src/utils.ts GitHub Actions / Node.js / Test (macos-latest, 23)
Check failure on line 214 in src/utils.ts GitHub Actions / Node.js / Test (macos-latest, 20)
Check failure on line 214 in src/utils.ts GitHub Actions / Node.js / Test (macos-latest, 18.19.0)
Check failure on line 214 in src/utils.ts GitHub Actions / Node.js / Test (macos-latest, 18)
Check failure on line 214 in src/utils.ts GitHub Actions / Node.js / Test (macos-latest, 22)
Check failure on line 214 in src/utils.ts GitHub Actions / Node.js / Test (windows-latest, 23)
Check failure on line 214 in src/utils.ts GitHub Actions / Node.js / Test (windows-latest, 22)
Check failure on line 214 in src/utils.ts GitHub Actions / Node.js / Test (windows-latest, 18.19.0)
Check failure on line 214 in src/utils.ts GitHub Actions / Node.js / Test (windows-latest, 20)
Check failure on line 214 in src/utils.ts GitHub Actions / Node.js / Test (windows-latest, 18)
|
||
global.ReadableStream = ReadableStream; | ||
} | ||
if (typeof global.Blob === 'undefined') { | ||
// @ts-ignore | ||
Check failure on line 218 in src/utils.ts GitHub Actions / Node.js / Test (ubuntu-latest, 18)
Check failure on line 218 in src/utils.ts GitHub Actions / Node.js / Test (ubuntu-latest, 20)
Check failure on line 218 in src/utils.ts GitHub Actions / Node.js / Test (ubuntu-latest, 18.19.0)
Check failure on line 218 in src/utils.ts GitHub Actions / Node.js / Test (ubuntu-latest, 23)
Check failure on line 218 in src/utils.ts GitHub Actions / Node.js / Test (ubuntu-latest, 22)
Check failure on line 218 in src/utils.ts GitHub Actions / Node.js / Test (macos-latest, 23)
Check failure on line 218 in src/utils.ts GitHub Actions / Node.js / Test (macos-latest, 20)
Check failure on line 218 in src/utils.ts GitHub Actions / Node.js / Test (macos-latest, 18.19.0)
Check failure on line 218 in src/utils.ts GitHub Actions / Node.js / Test (macos-latest, 18)
Check failure on line 218 in src/utils.ts GitHub Actions / Node.js / Test (macos-latest, 22)
Check failure on line 218 in src/utils.ts GitHub Actions / Node.js / Test (windows-latest, 23)
Check failure on line 218 in src/utils.ts GitHub Actions / Node.js / Test (windows-latest, 22)
Check failure on line 218 in src/utils.ts GitHub Actions / Node.js / Test (windows-latest, 18.19.0)
Check failure on line 218 in src/utils.ts GitHub Actions / Node.js / Test (windows-latest, 20)
Check failure on line 218 in src/utils.ts GitHub Actions / Node.js / Test (windows-latest, 18)
|
||
global.Blob = Blob; | ||
} | ||
if (typeof global.DOMException === 'undefined') { | ||
// @ts-ignore | ||
Check failure on line 222 in src/utils.ts GitHub Actions / Node.js / Test (ubuntu-latest, 18)
Check failure on line 222 in src/utils.ts GitHub Actions / Node.js / Test (ubuntu-latest, 20)
Check failure on line 222 in src/utils.ts GitHub Actions / Node.js / Test (ubuntu-latest, 18.19.0)
Check failure on line 222 in src/utils.ts GitHub Actions / Node.js / Test (ubuntu-latest, 23)
Check failure on line 222 in src/utils.ts GitHub Actions / Node.js / Test (ubuntu-latest, 22)
Check failure on line 222 in src/utils.ts GitHub Actions / Node.js / Test (macos-latest, 23)
Check failure on line 222 in src/utils.ts GitHub Actions / Node.js / Test (macos-latest, 20)
Check failure on line 222 in src/utils.ts GitHub Actions / Node.js / Test (macos-latest, 18.19.0)
Check failure on line 222 in src/utils.ts GitHub Actions / Node.js / Test (macos-latest, 18)
Check failure on line 222 in src/utils.ts GitHub Actions / Node.js / Test (macos-latest, 22)
Check failure on line 222 in src/utils.ts GitHub Actions / Node.js / Test (windows-latest, 23)
Check failure on line 222 in src/utils.ts GitHub Actions / Node.js / Test (windows-latest, 22)
Check failure on line 222 in src/utils.ts GitHub Actions / Node.js / Test (windows-latest, 18.19.0)
Check failure on line 222 in src/utils.ts GitHub Actions / Node.js / Test (windows-latest, 20)
Check failure on line 222 in src/utils.ts GitHub Actions / Node.js / Test (windows-latest, 18)
|
||
global.DOMException = getDOMExceptionClass(); | ||
} | ||
} | ||
|
||
// https://github.com/jimmywarting/node-domexception/blob/main/index.js | ||
function getDOMExceptionClass() { | ||
try { | ||
// @ts-ignore | ||
Check failure on line 230 in src/utils.ts GitHub Actions / Node.js / Test (ubuntu-latest, 18)
Check failure on line 230 in src/utils.ts GitHub Actions / Node.js / Test (ubuntu-latest, 20)
Check failure on line 230 in src/utils.ts GitHub Actions / Node.js / Test (ubuntu-latest, 18.19.0)
Check failure on line 230 in src/utils.ts GitHub Actions / Node.js / Test (ubuntu-latest, 23)
Check failure on line 230 in src/utils.ts GitHub Actions / Node.js / Test (ubuntu-latest, 22)
Check failure on line 230 in src/utils.ts GitHub Actions / Node.js / Test (macos-latest, 23)
Check failure on line 230 in src/utils.ts GitHub Actions / Node.js / Test (macos-latest, 20)
Check failure on line 230 in src/utils.ts GitHub Actions / Node.js / Test (macos-latest, 18.19.0)
Check failure on line 230 in src/utils.ts GitHub Actions / Node.js / Test (macos-latest, 18)
Check failure on line 230 in src/utils.ts GitHub Actions / Node.js / Test (macos-latest, 22)
Check failure on line 230 in src/utils.ts GitHub Actions / Node.js / Test (windows-latest, 23)
Check failure on line 230 in src/utils.ts GitHub Actions / Node.js / Test (windows-latest, 22)
Check failure on line 230 in src/utils.ts GitHub Actions / Node.js / Test (windows-latest, 18.19.0)
Check failure on line 230 in src/utils.ts GitHub Actions / Node.js / Test (windows-latest, 20)
Check failure on line 230 in src/utils.ts GitHub Actions / Node.js / Test (windows-latest, 18)
|
||
atob(0); | ||
} catch (err: any) { | ||
return err.constructor; | ||
} | ||
} |