From 488e033e13fc809f237f236111d168780ee9a01f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20O=E2=80=99Shannessy?= Date: Fri, 25 Sep 2015 15:13:48 -0700 Subject: [PATCH] Switch to isomorphic-fetch --- package.json | 4 ++-- scripts/babel/default-options.js | 2 +- src/__forks__/fetch.js | 10 ++++++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 857234e4..bc0fd606 100644 --- a/package.json +++ b/package.json @@ -63,9 +63,9 @@ "dependencies": { "core-js": "^1.0.0", "loose-envify": "^1.0.0", + "isomorphic-fetch": "^2.1.1", "promise": "^7.0.3", - "ua-parser-js": "^0.7.9", - "whatwg-fetch": "^0.9.0" + "ua-parser-js": "^0.7.9" }, "devEngines": { "node": ">=3", diff --git a/scripts/babel/default-options.js b/scripts/babel/default-options.js index 2eb3065c..9a1e70e0 100644 --- a/scripts/babel/default-options.js +++ b/scripts/babel/default-options.js @@ -43,8 +43,8 @@ module.exports = { plugins: plugins, _moduleMap: { 'core-js/library/es6/map': 'core-js/library/es6/map', + 'isomorphic-fetch': 'isomorphic-fetch', 'promise': 'promise', 'ua-parser-js': 'ua-parser-js', - 'whatwg-fetch': 'whatwg-fetch', }, }; diff --git a/src/__forks__/fetch.js b/src/__forks__/fetch.js index 33f3cee4..743ce1d3 100644 --- a/src/__forks__/fetch.js +++ b/src/__forks__/fetch.js @@ -11,5 +11,11 @@ 'use strict'; -require('whatwg-fetch'); -module.exports = self.fetch.bind(self); +// This hopefully supports the React Native case, which is already bringing along +// its own fetch polyfill. That should exist on `global`. If that doesn't exist +// then we'll try to polyfill, which might not work correctly in all environments. +if (global.fetch) { + module.exports = global.fetch.bind(global); +} else { + module.exports = require('isomorphic-fetch'); +}