Skip to content

Commit

Permalink
fix: update documentation (#71)
Browse files Browse the repository at this point in the history
* docs: update README with information about ESM

* ci: add maintenance branches

* ci: add @semantic-release/github

* chore: rename main.yml -> release.yml

fix #70
  • Loading branch information
alexghr authored Dec 28, 2021
1 parent bebed32 commit 50a4fff
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/main.yml → .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- 'main'
- 'next'
- '4.x'

jobs:
test:
Expand Down Expand Up @@ -44,3 +45,4 @@ jobs:
- run: yarn release
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38 changes: 21 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,43 @@ fetch stuff over HTTP 😉
Why would you use this instead of got? Sometimes you might need a fetch
wrapper and this is it (e.g. [Apollo uses `fetch` to query remote schemas]).


## Install

`got` is a peer dependency so you will need to install it alongside `got-fetch`:
Support table:

```sh
$ npm install --save got got-fetch
```
|`got-fetch` version|works with `got` version|Notes |
|-------------------|------------------------|-------------------------------------|
|^5.0.0 |^12.0.0 |ESM package. You have to use `import`|
|^4.0.0 |^11.0.0 |CJS package. You can use `require` |

If you use Typescript then you will also need `@types/got` if you want your
project to build:
`got` is a peer dependency so you will need to install it alongside `got-fetch`:

```sh
$ npm install --save-dev @types/got
npm install --save got got-fetch
```

For CommonJS support, we maintain [v4 of this package](https://github.com/alexghr/got-fetch/tree/4.x).

## Usage

The module exports a global instance ready to fetch resources:
Use the default export:

```js
const { fetch } = require('got-fetch');
import fetch from 'got-fetch';

fetch('https://example.com').then(resp => {
console.log(resp.status); // should be 200
resp.text().then(body => console.log(body)); // should be some HTML code
});
// in ESM we can use top-level await
const resp = await fetch('https://example.com');

console.log(resp.status); // 200
console.log(await resp.text()); // a HTML document
```

The module also exports a function which allows you to use your own custom
`got` instance:

```js
const got = require('got');
const { createFetch } = require('got-fetch');
import got from 'got';
import { createFetch } from 'got-fetch';

const myGot = got.extend({
headers: {
Expand All @@ -61,6 +63,8 @@ around a Node-based HTTP client. Not all `fetch` features are supported:
-[RequestMode] `no-cors`, `same-origin`, `navigate`
-[RequestCache] `only-if-cached`
-[RequestRedirect] `error`, `manual`
- ❌ response body streaming. See https://github.com/alexghr/got-fetch/issues/25
- ❗ ESM vs CJS packages. See https://github.com/alexghr/got-fetch/issues/70
-[RequestHeaders] must be a plain object
-[RequestCache] if unset (or `default`) will use got's [caching algorithm]
(any other value will disable caching)
Expand All @@ -77,4 +81,4 @@ See [LICENSE] for information.
[RequestRedirect]: https://fetch.spec.whatwg.org/#concept-request-redirect-mode
[RequestHeaders]: https://fetch.spec.whatwg.org/#ref-for-concept-request-header-list
[caching algorithm]: https://github.com/sindresorhus/got/tree/f59a5638b93c450dc722848b58b09a44f730a66f#cache-adapters
[Apollo uses `fetch` to query remote schemas]: https://www.apollographql.com/docs/graphql-tools/remote-schemas/
[Apollo uses `fetch` to query remote schemas]: https://www.apollographql.com/docs/graphql-tools/remote-schemas/
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/commit-analyzer": "^9.0.1",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^8.0.2",
"@semantic-release/npm": "^8.0.2",
"@semantic-release/release-notes-generator": "^10.0.2",
"@types/jest": "^27.0.3",
Expand Down
2 changes: 2 additions & 0 deletions release.config.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { repository } = require("./package.json");
module.exports = {
branches: [
"+([0-9])?(.{+([0-9]),x}).x",
{ name: "main" },
{ name: "next", channel: "next", prerelease: "next" },
],
Expand All @@ -21,6 +22,7 @@ module.exports = {
"@semantic-release/changelog",
"@semantic-release/npm",
"@semantic-release/git",
"@semantic-release/github"
],

repositoryUrl: repository.url,
Expand Down
27 changes: 27 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,28 @@
p-retry "^4.0.0"
url-join "^4.0.0"

"@semantic-release/github@^8.0.2":
version "8.0.2"
resolved "https://registry.yarnpkg.com/@semantic-release/github/-/github-8.0.2.tgz#80114a41f6ec8ab6c0d38a436b48ff3f2223ab16"
integrity sha512-wIbfhOeuxlYzMTjtSAa2xgr54n7ZuPAS2gadyTWBpUt2PNAPgla7A6XxCXJnaKPgfVF0iFfSk3B+KlVKk6ByVg==
dependencies:
"@octokit/rest" "^18.0.0"
"@semantic-release/error" "^2.2.0"
aggregate-error "^3.0.0"
bottleneck "^2.18.1"
debug "^4.0.0"
dir-glob "^3.0.0"
fs-extra "^10.0.0"
globby "^11.0.0"
http-proxy-agent "^5.0.0"
https-proxy-agent "^5.0.0"
issue-parser "^6.0.0"
lodash "^4.17.4"
mime "^3.0.0"
p-filter "^2.0.0"
p-retry "^4.0.0"
url-join "^4.0.0"

"@semantic-release/npm@^8.0.0", "@semantic-release/npm@^8.0.2":
version "8.0.3"
resolved "https://registry.yarnpkg.com/@semantic-release/npm/-/npm-8.0.3.tgz#69378ce529bbd263aa8fc899b2d0f874114e0302"
Expand Down Expand Up @@ -4477,6 +4499,11 @@ mime@^2.4.3:
resolved "https://registry.npmjs.org/mime/-/mime-2.5.2.tgz"
integrity sha512-tqkh47FzKeCPD2PUiPB6pkbMzsCasjxAfC62/Wap5qrUWcb+sFasXUC5I3gYM5iBM8v/Qpn4UK0x+j0iHyFPDg==

mime@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/mime/-/mime-3.0.0.tgz#b374550dca3a0c18443b0c950a6a58f1931cf7a7"
integrity sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==

mimic-fn@^1.0.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022"
Expand Down

0 comments on commit 50a4fff

Please sign in to comment.