Skip to content

Commit 1583aad

Browse files
authored
Merge branch 'master' into topic/export-request-init-type
2 parents cfd6bff + aff2b9d commit 1583aad

File tree

11 files changed

+70
-12
lines changed

11 files changed

+70
-12
lines changed

.github/workflows/main.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Compressed Size
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v2-beta
12+
with:
13+
fetch-depth: 1
14+
- uses: preactjs/compressed-size-action@v1
15+
with:
16+
repo-token: "${{ secrets.GITHUB_TOKEN }}"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ Unfetch will account for the following properties in `options`:
139139
target resource (The most common ones being `GET`, `POST`, `PUT`, `PATCH`, `HEAD`, `OPTIONS` or `DELETE`).
140140
* `headers`: An `Object` containing additional information to be sent with the request, e.g. `{ 'Content-Type': 'application/json' }` to indicate a JSON-typed request body.
141141
* `credentials`: ⚠ Accepts a `"include"` string, which will allow both CORS and same origin requests to work with cookies. As pointed in the ['Caveats' section](#caveats), Unfetch won't send or receive cookies otherwise. The `"same-origin"` value is not supported. ⚠
142-
* `body`: The content to be transmited in request's body. Common content types include `FormData`, `JSON`, `Blob`, `ArrayBuffer` or plain text.
142+
* `body`: The content to be transmitted in request's body. Common content types include `FormData`, `JSON`, `Blob`, `ArrayBuffer` or plain text.
143143

144144
### `response` Methods and Attributes
145145
These methods are used to handle the response accordingly in your Promise chain. Instead of implementing full spec-compliant [Response Class](https://fetch.spec.whatwg.org/#response-class) functionality, Unfetch provides the following methods and attributes:

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
"description": "Bare minimum fetch polyfill in 500 bytes",
55
"unpkg": "polyfill/index.js",
66
"main": "dist/unfetch.js",
7-
"module": "dist/unfetch.mjs",
8-
"jsnext:main": "dist/unfetch.mjs",
7+
"module": "dist/unfetch.module.js",
8+
"jsnext:main": "dist/unfetch.module.js",
99
"umd:main": "dist/unfetch.umd.js",
1010
"scripts": {
1111
"test": "eslint src test && jest",
12-
"build": "microbundle src/index.mjs && microbundle -f cjs polyfill/polyfill.mjs -o polyfill/index.js --no-sourcemap && cp dist/unfetch.mjs dist/unfetch.es.js",
12+
"build": "microbundle src/index.mjs && microbundle -f cjs polyfill/polyfill.mjs -o polyfill/index.js --no-sourcemap && cp dist/unfetch.module.js dist/unfetch.es.js",
1313
"prepare": "npm run -s build",
1414
"release": "cross-var npm run build -s && cross-var git commit -am $npm_package_version && cross-var git tag $npm_package_version && git push && git push --tags && npm publish"
1515
},
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = window.fetch || (window.fetch = require('unfetch').default || require('unfetch'));
1+
module.exports = self.fetch || (self.fetch = require('unfetch').default || require('unfetch'));
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
function r(m){return m && m.default || m;}
12
module.exports = global.fetch = global.fetch || (
2-
typeof process=='undefined' ? (require('unfetch').default || require('unfetch')) : (function(url, opts) {
3-
return require('node-fetch')(url.replace(/^\/\//g,'https://'), opts);
3+
typeof process=='undefined' ? r(require('unfetch')) : (function(url, opts) {
4+
return r(require('node-fetch'))(String(url).replace(/^\/\//g,'https://'), opts);
45
})
56
);

packages/isomorphic-unfetch/package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/isomorphic-unfetch/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
"index.d.ts",
88
"browser.js"
99
],
10+
"license": "MIT",
1011
"repository": "developit/unfetch",
1112
"browser": "browser.js",
1213
"main": "index.js",
1314
"types": "index.d.ts",
1415
"dependencies": {
15-
"node-fetch": "^2.2.0",
16+
"node-fetch": "^2.6.1",
1617
"unfetch": "^4.0.0"
1718
}
1819
}

polyfill/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"name": "unfetch-polyfill",
33
"main": "index.js",
4-
"module": "polyfill.mjs"
4+
"module": "polyfill.module.js"
55
}

polyfill/polyfill.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
import unfetch from '../src/index.mjs';
1+
import unfetch from '..';
22
if (!self.fetch) self.fetch = unfetch;

src/index.d.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,33 @@ declare namespace unfetch {
1414
export type IsomorphicRequestInit = RequestInit | NodeRequestInit;
1515
}
1616

17-
declare const unfetch: typeof fetch;
17+
type UnfetchResponse = {
18+
ok: boolean,
19+
statusText: string,
20+
status: number,
21+
url: string,
22+
text: () => Promise<string>,
23+
json: () => Promise<any>,
24+
blob: () => Promise<Blob>,
25+
clone: () => UnfetchResponse,
26+
headers: {
27+
keys: () => string[],
28+
entries: () => Array<[string, string]>,
29+
get: (key: string) => string | undefined,
30+
has: (key: string) => boolean,
31+
}
32+
}
33+
34+
type Unfetch = (
35+
url: string,
36+
options?: {
37+
method?: string,
38+
headers?: Record<string, string>,
39+
credentials?: 'include' | 'omit',
40+
body?: Parameters<XMLHttpRequest["send"]>[0]
41+
}
42+
) => Promise<UnfetchResponse>
43+
44+
declare const unfetch: Unfetch;
1845

1946
export default unfetch;

0 commit comments

Comments
 (0)