forked from transitive-bullshit/agentic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove top-level await import for undici
- Loading branch information
1 parent
3efc85f
commit 23b9fcd
Showing
2 changed files
with
12 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,22 @@ | ||
/// <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 | ||
// NOTE: The top-level await is removed in a `postbuild` npm script for the | ||
// 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 } |