Skip to content

Commit

Permalink
merge #156
Browse files Browse the repository at this point in the history
  • Loading branch information
developit committed Dec 31, 2022
1 parent 5d6342b commit 47384d5
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 15 deletions.
23 changes: 17 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,28 @@
"name": "unfetch",
"version": "4.2.0",
"description": "Bare minimum fetch polyfill in 500 bytes",
"unpkg": "polyfill/index.js",
"main": "dist/unfetch.js",
"module": "dist/unfetch.module.js",
"jsnext:main": "dist/unfetch.module.js",
"umd:main": "dist/unfetch.umd.js",
"unpkg": "./polyfill/index.js",
"main": "./dist/unfetch.js",
"module": "./dist/unfetch.mjs",
"jsnext:main": "./dist/unfetch.mjs",
"umd:main": "./dist/unfetch.umd.js",
"scripts": {
"test": "eslint && jest",
"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",
"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",
"prepare": "npm run -s build",
"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"
},
"exports": {
".": {
"import": "./index.mjs",
"default": "./index.js"
},
"./polyfill": {
"default": "./polyfill/index.js"
},
"./package.json": "./package.json",
"./*": "./*"
},
"workspaces": [
"./packages/isomorphic-unfetch"
],
Expand Down
2 changes: 2 additions & 0 deletions packages/isomorphic-unfetch/browser.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import fetch from 'unfetch';
export default self.fetch || (self.fetch = fetch);
19 changes: 12 additions & 7 deletions packages/isomorphic-unfetch/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
function r(m){return m && m.default || m;}
module.exports = global.fetch = global.fetch || (
typeof process=='undefined' ? r(require('unfetch')) : (function(url, opts) {
const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
return r(fetch)(String(url).replace(/^\/\//g,'https://'), opts);
})
);
function r(m) {
return (m && m.default) || m;
}
module.exports = global.fetch =
global.fetch ||
(typeof process == "undefined"
? r(require("unfetch"))
: function (url, opts) {
if (typeof url === "string" || url instanceof URL)
url = String(url).replace(/^\/\//g, "https://");
return import("node-fetch").then((m) => r(m)(url, opts));
});
12 changes: 12 additions & 0 deletions packages/isomorphic-unfetch/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default global.fetch =
global.fetch ||
(typeof process == "undefined"
? function (url, opts) {
return import('unfetch').then(m => (m.default || m)(url, opts));
}
: function (url, opts) {
if (typeof url === "string" || url instanceof URL) {
url = String(url).replace(/^\/\//g, "https://");
}
return import("node-fetch").then((m) => (m.default || m)(url, opts));
});
11 changes: 11 additions & 0 deletions packages/isomorphic-unfetch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@
"index.d.ts",
"browser.js"
],
"exports": {
".": {
"import": "./index.mjs",
"default": "./index.js"
},
"./browser": {
"import": "./browser.mjs",
"default": "./browser.js"
},
"./package.json": "./package.json"
},
"license": "MIT",
"repository": "developit/unfetch",
"browser": "browser.js",
Expand Down
4 changes: 2 additions & 2 deletions polyfill/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "unfetch-polyfill",
"main": "index.js",
"module": "polyfill.module.js"
"source": "polyfill.mjs",
"main": "index.js"
}

0 comments on commit 47384d5

Please sign in to comment.