Last active
August 29, 2015 14:12
-
-
Save qubyte/21cade5e28c924c48bc1 to your computer and use it in GitHub Desktop.
Prevent the github/fetch shim actually shimming, and assign it instead to a variable.
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
// brfs is needed to use this anti-shim. | |
var fs = require('fs'); | |
var functionBody = [ | |
'var window = {};', | |
fs.readFileSync(__dirname + '/path/to/node_modules/fetch/fetch.js', 'utf8'), // Fix the path for your needs. | |
'return window.fetch;' | |
].join('\n'); | |
// Assigns a function fetch function to module.exports. Here I elect to use a native Promise implementation (or | |
// polyfilled). This is trivial to adapt into a library that can take a user defined Promise. | |
module.exports = new Function('Promise', functionBody)(Promise); | |
// Now require using this module. In the same directory: var fetch = require('./fetch'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment