-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
56 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |