diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-04-20 03:09:25 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-04-24 16:14:29 +0200 |
commit | 82f2b76e25a4a67e01ec67e5ebe39d14ad771ea8 (patch) | |
tree | 965f6eb89b84d65a62b49008fd972c004832ccd1 /thirdparty/systemjs/lib/system-fetch.js | |
parent | e6e0cbc387c2a77b48e4065c229daa65bf1aa0fa (diff) |
Reorganize module loading.
We now use webpack instead of SystemJS, effectively bundling modules
into one file (plus commons chunks) for every entry point. This results
in a much smaller extension size (almost half). Furthermore we use
yarn/npm even for extension run-time dependencies. This relieves us
from manually vendoring and building dependencies. It's also easier to
understand for new developers familiar with node.
Diffstat (limited to 'thirdparty/systemjs/lib/system-fetch.js')
-rw-r--r-- | thirdparty/systemjs/lib/system-fetch.js | 125 |
1 files changed, 0 insertions, 125 deletions
diff --git a/thirdparty/systemjs/lib/system-fetch.js b/thirdparty/systemjs/lib/system-fetch.js deleted file mode 100644 index fb642caac..000000000 --- a/thirdparty/systemjs/lib/system-fetch.js +++ /dev/null @@ -1,125 +0,0 @@ - var fetchTextFromURL; - if (typeof XMLHttpRequest != 'undefined') { - fetchTextFromURL = function(url, authorization, fulfill, reject) { - var xhr = new XMLHttpRequest(); - var sameDomain = true; - var doTimeout = false; - if (!('withCredentials' in xhr)) { - // check if same domain - var domainCheck = /^(\w+:)?\/\/([^\/]+)/.exec(url); - if (domainCheck) { - sameDomain = domainCheck[2] === window.location.host; - if (domainCheck[1]) - sameDomain &= domainCheck[1] === window.location.protocol; - } - } - if (!sameDomain && typeof XDomainRequest != 'undefined') { - xhr = new XDomainRequest(); - xhr.onload = load; - xhr.onerror = error; - xhr.ontimeout = error; - xhr.onprogress = function() {}; - xhr.timeout = 0; - doTimeout = true; - } - function load() { - fulfill(xhr.responseText); - } - function error() { - reject(new Error('XHR error' + (xhr.status ? ' (' + xhr.status + (xhr.statusText ? ' ' + xhr.statusText : '') + ')' : '') + ' loading ' + url)); - } - - xhr.onreadystatechange = function () { - if (xhr.readyState === 4) { - // in Chrome on file:/// URLs, status is 0 - if (xhr.status == 0) { - if (xhr.responseText) { - load(); - } - else { - // when responseText is empty, wait for load or error event - // to inform if it is a 404 or empty file - xhr.addEventListener('error', error); - xhr.addEventListener('load', load); - } - } - else if (xhr.status === 200) { - load(); - } - else { - error(); - } - } - }; - xhr.open("GET", url, true); - - if (xhr.setRequestHeader) { - xhr.setRequestHeader('Accept', 'application/x-es-module, */*'); - // can set "authorization: true" to enable withCredentials only - if (authorization) { - if (typeof authorization == 'string') - xhr.setRequestHeader('Authorization', authorization); - xhr.withCredentials = true; - } - } - - if (doTimeout) { - setTimeout(function() { - xhr.send(); - }, 0); - } else { - xhr.send(null); - } - }; - } - else if (typeof require != 'undefined' && typeof process != 'undefined') { - var fs; - fetchTextFromURL = function(url, authorization, fulfill, reject) { - if (url.substr(0, 8) != 'file:///') - throw new Error('Unable to fetch "' + url + '". Only file URLs of the form file:/// allowed running in Node.'); - fs = fs || require('fs'); - if (isWindows) - url = url.replace(/\//g, '\\').substr(8); - else - url = url.substr(7); - return fs.readFile(url, function(err, data) { - if (err) { - return reject(err); - } - else { - // Strip Byte Order Mark out if it's the leading char - var dataString = data + ''; - if (dataString[0] === '\ufeff') - dataString = dataString.substr(1); - - fulfill(dataString); - } - }); - }; - } - else if (typeof self != 'undefined' && typeof self.fetch != 'undefined') { - fetchTextFromURL = function(url, authorization, fulfill, reject) { - var opts = { - headers: {'Accept': 'application/x-es-module, */*'} - }; - - if (authorization) { - if (typeof authorization == 'string') - opts.headers['Authorization'] = authorization; - opts.credentials = 'include'; - } - - fetch(url, opts) - .then(function (r) { - if (r.ok) { - return r.text(); - } else { - throw new Error('Fetch error: ' + r.status + ' ' + r.statusText); - } - }) - .then(fulfill, reject); - } - } - else { - throw new TypeError('No environment fetch API available.'); - } |