Skip to content

Instantly share code, notes, and snippets.

@qubyte
Last active August 29, 2015 14:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qubyte/21cade5e28c924c48bc1 to your computer and use it in GitHub Desktop.
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.
// 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