Skip to content

Commit 47384d5

Browse files
committed
merge #156
1 parent 5d6342b commit 47384d5

File tree

6 files changed

+56
-15
lines changed

6 files changed

+56
-15
lines changed

package.json

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,28 @@
22
"name": "unfetch",
33
"version": "4.2.0",
44
"description": "Bare minimum fetch polyfill in 500 bytes",
5-
"unpkg": "polyfill/index.js",
6-
"main": "dist/unfetch.js",
7-
"module": "dist/unfetch.module.js",
8-
"jsnext:main": "dist/unfetch.module.js",
9-
"umd:main": "dist/unfetch.umd.js",
5+
"unpkg": "./polyfill/index.js",
6+
"main": "./dist/unfetch.js",
7+
"module": "./dist/unfetch.mjs",
8+
"jsnext:main": "./dist/unfetch.mjs",
9+
"umd:main": "./dist/unfetch.umd.js",
1010
"scripts": {
1111
"test": "eslint && jest",
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",
12+
"build": "microbundle src/index.mjs -f cjs,esm,umd && microbundle polyfill/polyfill.mjs -o polyfill/index.js -f cjs --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
},
16+
"exports": {
17+
".": {
18+
"import": "./index.mjs",
19+
"default": "./index.js"
20+
},
21+
"./polyfill": {
22+
"default": "./polyfill/index.js"
23+
},
24+
"./package.json": "./package.json",
25+
"./*": "./*"
26+
},
1627
"workspaces": [
1728
"./packages/isomorphic-unfetch"
1829
],
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import fetch from 'unfetch';
2+
export default self.fetch || (self.fetch = fetch);
Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
function r(m){return m && m.default || m;}
2-
module.exports = global.fetch = global.fetch || (
3-
typeof process=='undefined' ? r(require('unfetch')) : (function(url, opts) {
4-
const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
5-
return r(fetch)(String(url).replace(/^\/\//g,'https://'), opts);
6-
})
7-
);
1+
function r(m) {
2+
return (m && m.default) || m;
3+
}
4+
module.exports = global.fetch =
5+
global.fetch ||
6+
(typeof process == "undefined"
7+
? r(require("unfetch"))
8+
: function (url, opts) {
9+
if (typeof url === "string" || url instanceof URL)
10+
url = String(url).replace(/^\/\//g, "https://");
11+
return import("node-fetch").then((m) => r(m)(url, opts));
12+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export default global.fetch =
2+
global.fetch ||
3+
(typeof process == "undefined"
4+
? function (url, opts) {
5+
return import('unfetch').then(m => (m.default || m)(url, opts));
6+
}
7+
: function (url, opts) {
8+
if (typeof url === "string" || url instanceof URL) {
9+
url = String(url).replace(/^\/\//g, "https://");
10+
}
11+
return import("node-fetch").then((m) => (m.default || m)(url, opts));
12+
});

packages/isomorphic-unfetch/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77
"index.d.ts",
88
"browser.js"
99
],
10+
"exports": {
11+
".": {
12+
"import": "./index.mjs",
13+
"default": "./index.js"
14+
},
15+
"./browser": {
16+
"import": "./browser.mjs",
17+
"default": "./browser.js"
18+
},
19+
"./package.json": "./package.json"
20+
},
1021
"license": "MIT",
1122
"repository": "developit/unfetch",
1223
"browser": "browser.js",

polyfill/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"name": "unfetch-polyfill",
3-
"main": "index.js",
4-
"module": "polyfill.module.js"
3+
"source": "polyfill.mjs",
4+
"main": "index.js"
55
}

0 commit comments

Comments
 (0)