Skip to content

Commit

Permalink
feat: use node-fetch-native
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed May 11, 2022
1 parent 40379fd commit a881acb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 31 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const { $fetch } = require('ohmyfetch')
## ✔️ Works with Node.js

We use [conditional exports](https://nodejs.org/api/packages.html#packages_conditional_exports) to detect Node.js
and automatically use [node-fetch](https://github.com/node-fetch/node-fetch). If `globalThis.fetch` is available, will be used instead. To leverage Node.js 17.5.0 experimental native fetch API use [`--experimental-fetch` flag](https://nodejs.org/dist/latest-v17.x/docs/api/cli.html#--experimental-fetch).
and automatically use [unjs/node-fetch-native](https://github.com/unjs/node-fetch-native). If `globalThis.fetch` is available, will be used instead. To leverage Node.js 17.5.0 experimental native fetch API use [`--experimental-fetch` flag](https://nodejs.org/dist/latest-v17.x/docs/api/cli.html#--experimental-fetch).

### `undici` support

Expand All @@ -53,7 +53,7 @@ On Node.js versions older than `16.5`, node-fetch will be used as the fallback.

By setting `FETCH_KEEP_ALIVE` environment variable to `true`, A http/https agent will be registred that keeps sockets around even when there are no outstanding requests, so they can be used for future requests without having to reestablish a TCP connection.

**Note:** This option can potentially introduce memory leaks. Please check [node-fetch/node-fetch#1325](https://github.com/unjs/ohmyfetch/pull/22).
**Note:** This option can potentially introduce memory leaks. Please check [node-fetch/node-fetch#1325](https://github.com/node-fetch/node-fetch/pull/1325).

## ✔️ Parsing Response

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,14 @@
},
"dependencies": {
"destr": "^1.1.1",
"node-fetch": "^3.2.4",
"node-fetch-native": "^0.1.3",
"ufo": "^0.8.3",
"undici": "^5.0.0"
},
"devDependencies": {
"@nuxtjs/eslint-config-typescript": "latest",
"@types/flat": "latest",
"@types/node": "latest",
"@types/node-fetch": "^3.0.3",
"c8": "^7.11.2",
"eslint": "latest",
"fetch-blob": "^3.1.5",
Expand Down
39 changes: 13 additions & 26 deletions pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion src/node.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import http from 'http'
import https, { AgentOptions } from 'https'
import nodeFetch, { Headers as _Headers } from 'node-fetch'
import nodeFetch, { Headers as _Headers } from 'node-fetch-native'

import { createFetch } from './base'

Expand Down

0 comments on commit a881acb

Please sign in to comment.