Skip to content

Commit

Permalink
chore: updated whatwg-fetch to 3.6.20 (#198)
Browse files Browse the repository at this point in the history
* chore: updated whatwg-fetch to 3.6.20

* chore: fixed wrapper that hijacks the global object
  • Loading branch information
lquixada authored Dec 15, 2024
1 parent a0fc47a commit 30bbb11
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"typescript": "4.4.4",
"webpack": "5.82.1",
"webpack-cli": "4.9.0",
"whatwg-fetch": "3.0.0",
"whatwg-fetch": "3.6.20",
"yargs": "16.2.0"
},
"files": [
Expand Down
32 changes: 19 additions & 13 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,35 @@ export default [
name: 'irrelevant',
strict: false,
banner: outdent(`
var global = typeof self !== 'undefined' ? self : this;
var __self__ = (function () {
// Save global object in a variable
var __global__ =
(typeof globalThis !== 'undefined' && globalThis) ||
(typeof self !== 'undefined' && self) ||
(typeof global !== 'undefined' && global);
// Create an object that extends from __global__ without the fetch function
var __globalThis__ = (function () {
function F() {
this.fetch = false;
this.DOMException = global.DOMException
this.DOMException = __global__.DOMException
}
F.prototype = global;
F.prototype = __global__; // Needed for feature detection on whatwg-fetch's code
return new F();
})();
(function(self) {
// Wraps whatwg-fetch with a function scope to hijack the global object
// "globalThis" that's going to be patched
(function(globalThis) {
`),
footer: outdent(`
})(__self__);
__self__.fetch.ponyfill = true;
})(__globalThis__);
// Remove "polyfill" property added by whatwg-fetch
delete __self__.fetch.polyfill;
// This is a ponyfill, so...
__globalThis__.fetch.ponyfill = true;
delete __globalThis__.fetch.polyfill;
// Choose between native implementation (global) or custom implementation (__self__)
// var ctx = global.fetch ? global : __self__;
var ctx = __self__; // this line disable service worker support temporarily
// Choose between native implementation (__global__) or custom implementation (__globalThis__)
var ctx = __global__.fetch ? __global__ : __globalThis__;
exports = ctx.fetch // To enable: import fetch from 'cross-fetch'
exports.default = ctx.fetch // For TypeScript consumers without esModuleInterop.
Expand Down

0 comments on commit 30bbb11

Please sign in to comment.