Skip to content

Commit

Permalink
fix: do not include node-fetch in runtime bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
ctjlewis committed Jun 23, 2023
1 parent d8fdf04 commit 5970b66
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@
"ava": "^5.2.0",
"dotenv": "^16.0.3",
"eslint": "^8.41.0",
"node-fetch": "^3.3.1",
"openai": "^3.3.0",
"typedoc": "^0.24.7",
"typescript": "^5.0.4"
},
"dependencies": {
"eventsource-parser": "^1.0.0",
"node-fetch": "^3.3.1",
"yield-stream": "^3.0.0"
},
"keywords": [
Expand Down
17 changes: 8 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions src/lib/backoff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ export interface BackoffOptions {
export const fetchWithBackoff = async (
input: RequestInfo & NodeFetchRequestInfo,
init?: RequestInit & NodeFetchRequestInit,
fetch?: Fetch,
fetch: Fetch = globalThis.fetch,
{ delay, maxRetries }: BackoffOptions = {
delay: 500,
maxRetries: 7
}
) => {
if (!fetch) {
const { default: nodeFetch } = await import("node-fetch");
fetch = nodeFetch;
throw new Error("No fetch implementation found.");
}

for (let i = 0; i <= maxRetries; i++) {
Expand Down

0 comments on commit 5970b66

Please sign in to comment.