diff --git a/.github/workflows/main.yml b/.github/workflows/release.yml similarity index 92% rename from .github/workflows/main.yml rename to .github/workflows/release.yml index ed44865..39615f0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/release.yml @@ -5,6 +5,7 @@ on: branches: - 'main' - 'next' + - '4.x' jobs: test: @@ -44,3 +45,4 @@ jobs: - run: yarn release env: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index 2c7e44a..a933488 100644 --- a/README.md +++ b/README.md @@ -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: { @@ -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) @@ -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/ \ No newline at end of file +[Apollo uses `fetch` to query remote schemas]: https://www.apollographql.com/docs/graphql-tools/remote-schemas/ diff --git a/package.json b/package.json index ccc6545..6691f08 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/release.config.cjs b/release.config.cjs index 116b483..a23627c 100644 --- a/release.config.cjs +++ b/release.config.cjs @@ -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" }, ], @@ -21,6 +22,7 @@ module.exports = { "@semantic-release/changelog", "@semantic-release/npm", "@semantic-release/git", + "@semantic-release/github" ], repositoryUrl: repository.url, diff --git a/yarn.lock b/yarn.lock index ab42d6c..89be91c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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"