kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
fix: remove top-level await import for undici
rodzic
3efc85fa38
commit
23b9fcd595
|
@ -27,7 +27,7 @@
|
|||
"dev": "tsup --watch",
|
||||
"clean": "del build",
|
||||
"prebuild": "run-s clean",
|
||||
"postbuild": "[ -n CI ] && sed -i '' 's/ *\\?\\? *(await import(\"undici\")).fetch//' build/browser/index.js || echo 'skipping postbuild on CI'",
|
||||
"postbuild": "[ -n CI ] && sed -i '' 's/await import(\"undici\")/null/' build/browser/index.js || echo 'skipping postbuild on CI'",
|
||||
"predev": "run-s clean",
|
||||
"pretest": "run-s build",
|
||||
"docs": "typedoc",
|
||||
|
|
12
src/fetch.ts
12
src/fetch.ts
|
@ -1,5 +1,7 @@
|
|||
/// <reference lib="dom" />
|
||||
|
||||
let _undici: any
|
||||
|
||||
// Use `undici` for node.js 16 and 17
|
||||
// Use `fetch` for node.js >= 18
|
||||
// Use `fetch` for all other environments, including browsers
|
||||
|
@ -7,6 +9,14 @@
|
|||
// browser build
|
||||
const fetch =
|
||||
globalThis.fetch ??
|
||||
((await import('undici')).fetch as unknown as typeof globalThis.fetch)
|
||||
async function undiciFetchWrapper(
|
||||
...args: Parameters<typeof globalThis.fetch>
|
||||
): Promise<Response> {
|
||||
if (!_undici) {
|
||||
_undici = await import('undici')
|
||||
}
|
||||
|
||||
return _undici.fetch(...args)
|
||||
}
|
||||
|
||||
export { fetch }
|
||||
|
|
Ładowanie…
Reference in New Issue