Skip to content

Commit

Permalink
Require Node.js 16 and remove AbortController ponyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Jul 28, 2023
1 parent 349bbe4 commit 1242b8d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
5 changes: 0 additions & 5 deletions index.js
@@ -1,5 +1,4 @@
import fetch, {Headers, Request, Response} from 'node-fetch';
import AbortController from 'abort-controller';

const TEN_MEGABYTES = 1000 * 1000 * 10;

Expand All @@ -19,10 +18,6 @@ if (!globalThis.Response) {
globalThis.Response = Response;
}

if (!globalThis.AbortController) {
globalThis.AbortController = AbortController;
}

if (!globalThis.ReadableStream) {
try {
globalThis.ReadableStream = await import('web-streams-polyfill/ponyfill/es2018');
Expand Down
15 changes: 7 additions & 8 deletions package.json
Expand Up @@ -16,7 +16,7 @@
"default": "./browser.js"
},
"engines": {
"node": ">=14.16"
"node": ">=16"
},
"scripts": {
"test": "xo && ava && tsd"
Expand Down Expand Up @@ -59,17 +59,16 @@
"node-fetch"
],
"dependencies": {
"abort-controller": "^3.0.0",
"node-fetch": "^3.2.10"
"node-fetch": "^3.3.2"
},
"devDependencies": {
"ava": "^4.3.3",
"ky": "^0.31.4",
"tsd": "^0.24.1",
"xo": "^0.52.4"
"ava": "^5.3.1",
"ky": "^0.33.3",
"tsd": "^0.28.1",
"xo": "^0.55.0"
},
"peerDependencies": {
"ky": ">=0.31.4",
"ky": ">=0.33.0",
"web-streams-polyfill": ">=3.2.1"
},
"peerDependenciesMeta": {
Expand Down
6 changes: 2 additions & 4 deletions readme.md
Expand Up @@ -2,19 +2,17 @@

> Use Ky in both Node.js and browsers
[Ky](https://github.com/sindresorhus/ky) is made for browsers, but this package makes it possible to use it in Node.js too, by polyfilling most of the required browser APIs using [`node-fetch`](https://github.com/bitinn/node-fetch) and [`abort-controller`](https://github.com/mysticatea/abort-controller).
[Ky](https://github.com/sindresorhus/ky) is made for browsers, but this package makes it possible to use it in Node.js too, by polyfilling most of the required browser APIs using [`node-fetch`](https://github.com/bitinn/node-fetch).

This package can be useful for:
- Isomorphic code
- Web apps (React, Vue.js, etc.) that use server-side rendering (SSR)
- Testing browser libraries using a Node.js test runner

**Note:** Before opening an issue, make sure it's an issue with Ky and not its polyfills. Generally, if something works in the browser, but not in Node.js, it's an issue with `node-fetch` or `abort-controller`.
**Note:** Before opening an issue, make sure it's an issue with Ky and not its polyfills. Generally, if something works in the browser, but not in Node.js, it's an issue with `node-fetch`.

Keep in mind that Ky targets [modern browsers](https://github.com/sindresorhus/ky#browser-support) when used in the browser. For older browsers, you will need to transpile and use a [`fetch` polyfill](https://github.com/github/fetch).

**If you only target Node.js, I would strongly recommend using [Got](https://github.com/sindresorhus/got) instead.**

## Install

```sh
Expand Down

0 comments on commit 1242b8d

Please sign in to comment.