diff --git a/README.md b/README.md index ce7e652b..9a4dea32 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/package.json b/package.json index 63176265..d705b9af 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ }, "dependencies": { "destr": "^1.1.1", - "node-fetch": "^3.2.4", + "node-fetch-native": "^0.1.3", "ufo": "^0.8.3", "undici": "^5.0.0" }, @@ -52,7 +52,6 @@ "@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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 13a74c14..d48f5fc2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,7 +4,6 @@ specifiers: '@nuxtjs/eslint-config-typescript': latest '@types/flat': latest '@types/node': latest - '@types/node-fetch': ^3.0.3 c8: ^7.11.2 destr: ^1.1.1 eslint: latest @@ -13,7 +12,7 @@ specifiers: h3: latest jiti: latest listhen: latest - node-fetch: ^3.2.4 + node-fetch-native: ^0.1.3 standard-version: latest typescript: latest ufo: ^0.8.3 @@ -23,15 +22,14 @@ specifiers: 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': 10.0.0_hcfsmds2fshutdssjqluwm76uu '@types/flat': 5.0.2 - '@types/node': 17.0.31 - '@types/node-fetch': 3.0.3 + '@types/node': 17.0.32 c8: 7.11.2 eslint: 8.15.0 fetch-blob: 3.1.5 @@ -485,15 +483,8 @@ packages: resolution: {integrity: sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==} dev: true - /@types/node-fetch/3.0.3: - resolution: {integrity: sha512-HhggYPH5N+AQe/OmN6fmhKmRRt2XuNJow+R3pQwJxOOF9GuwM7O2mheyGeIrs5MOIeNjDEdgdoyHBOrFeJBR3g==} - deprecated: This is a stub types definition. node-fetch provides its own type definitions, so you do not need this installed. - dependencies: - node-fetch: 3.2.4 - dev: true - - /@types/node/17.0.31: - resolution: {integrity: sha512-AR0x5HbXGqkEx9CadRH3EBYx/VkiUgZIhP4wvPn/+5KIsgpNoyFaRlVe0Zlx9gRtg8fA06a9tskE2MSN7TcG4Q==} + /@types/node/17.0.32: + resolution: {integrity: sha512-eAIcfAvhf/BkHcf4pkLJ7ECpBAhh9kcxRBpip9cTiO+hf+aJrsxYxBeS6OXvOd9WqNAJmavXVpZvY1rBjNsXmw==} dev: true /@types/normalize-package-data/2.4.1: @@ -503,7 +494,7 @@ packages: /@types/resolve/1.17.1: resolution: {integrity: sha512-yy7HuzQhj0dhGpD8RLXSZWEkLsV9ibvxvi6EiJ3bkqLAO1RGo0WbkWQiwpRlSFymTJRz0d3k5LM3kkx8ArDbLw==} dependencies: - '@types/node': 17.0.31 + '@types/node': 17.0.32 dev: true /@typescript-eslint/eslint-plugin/5.22.0_tal4xlmvnofklupd3hwjtzfb4q: @@ -1151,10 +1142,6 @@ packages: engines: {node: '>=8'} dev: true - /data-uri-to-buffer/4.0.0: - resolution: {integrity: sha512-Vr3mLBA8qWmcuschSLAOogKgQ/Jwxulv3RNE4FXnYWRGujzrRWQI4m12fQqRkwX06C0KanhLr4hK+GydchZsaA==} - engines: {node: '>= 12'} - /dateformat/3.0.3: resolution: {integrity: sha512-jyCETtSl3VMZMWeRo7iY1FL19ges1t55hMo5yaam4Jrsm5EPL89UQkoQRyiI+Yf4k8r2ZpdngkV8hr1lIdjb3Q==} dev: true @@ -2118,6 +2105,7 @@ packages: dependencies: node-domexception: 1.0.0 web-streams-polyfill: 3.2.1 + dev: true /figures/3.2.0: resolution: {integrity: sha512-yaduQFRKLXYOGgEn6AZau90j3ggSOyiqXU0F9JZfeXYhNa+Jk4X+s45A2zg5jns87GAFa34BBm2kXw4XpNcbdg==} @@ -2195,6 +2183,7 @@ packages: engines: {node: '>=12.20.0'} dependencies: fetch-blob: 3.1.5 + dev: true /fs-access/1.0.1: resolution: {integrity: sha1-1qh/JiJxzv6+wwxVNAf7mV2od3o=} @@ -3041,14 +3030,11 @@ packages: /node-domexception/1.0.0: resolution: {integrity: sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==} engines: {node: '>=10.5.0'} + dev: true - /node-fetch/3.2.4: - resolution: {integrity: sha512-WvYJRN7mMyOLurFR2YpysQGuwYrJN+qrrpHjJDuKMcSPdfFccRUla/kng2mz6HWSBxJcqPbvatS6Gb4RhOzCJw==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - dependencies: - data-uri-to-buffer: 4.0.0 - fetch-blob: 3.1.5 - formdata-polyfill: 4.0.10 + /node-fetch-native/0.1.3: + resolution: {integrity: sha512-Jf1IQZdovUIv9E+5avmN6Sf+bND+rnMlODnBQhdE2VRyuWP9WgqZb/KEgPekh19DAN1X2C4vbS1VCOaz2OH19g==} + dev: false /node-forge/1.3.1: resolution: {integrity: sha512-dPEtOeMvF9VMcYV/1Wb8CPoVAXtp6MKMlcbAt4ddqmGqUJ6fQZFXkNZNkNlfevtNkGtaSoXf/vNNNSvgrdXwtA==} @@ -4060,6 +4046,7 @@ packages: /web-streams-polyfill/3.2.1: resolution: {integrity: sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==} engines: {node: '>= 8'} + dev: true /which-boxed-primitive/1.0.2: resolution: {integrity: sha512-bwZdv0AKLpplFY2KZRX6TvyuN7ojjr7lwkg6ml0roIy9YeuSr7JS372qlNW18UQYzgYK9ziGcerWqZOmEn9VNg==} diff --git a/src/node.ts b/src/node.ts index f03d19c8..1c697133 100644 --- a/src/node.ts +++ b/src/node.ts @@ -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'