Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: failover from native fetch to node-fetch #481

Merged
merged 2 commits into from Jul 11, 2022

Conversation

baoshan
Copy link
Contributor

@baoshan baoshan commented Jul 10, 2022

fetch API has landed in Node.js 18 (and is available in modern browsers, Deno, Clodflare, etc). Failover from native fetch to node-fetch makes us confident that there will be no issues when node-fetch is removed (say in 2046).

A new pattern of testing is made possible: instead of creating new instances of Octokit in test cases (with different fetch mocks), I can simply stub globalThis.fetch in test cases using a same instance of Octokit (imported from non-test code).

In some rare cases, this PR may break existing code. But generally I think it is safe.

@ghost ghost added this to Inbox in JS Jul 10, 2022
@wolfy1339 wolfy1339 added the Type: Feature New feature or request label Jul 10, 2022
@ghost ghost moved this from Inbox to Features in JS Jul 10, 2022
@wolfy1339
Copy link
Member

Would this work as a fix for #456?

@baoshan
Copy link
Contributor Author

baoshan commented Jul 10, 2022

No.

To be absolutely friendly to bundlers that support importing npm packages, we need to remove the node-fetch dependency from @octokit/request; users need to pass a fetch if their runtime has no native fetch.

I think OP is using Netlify’s edge function, which is Deno Deploy rebranded. We can import https://esm.sh/@octokit/core or http://esm.sh/@octokit/request instead. node-fetch is replaced by node-fetch-native there.

@wolfy1339
Copy link
Member

Thanks for the clarifications

@wolfy1339 wolfy1339 enabled auto-merge (squash) July 11, 2022 14:02
@wolfy1339 wolfy1339 merged commit d000a0a into octokit:master Jul 11, 2022
JS automation moved this from Features to Done Jul 11, 2022
@github-actions
Copy link

🎉 This PR is included in version 6.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature New feature or request
Projects
No open projects
JS
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants