Skip to content

Commit

Permalink
feat(imports): deprecate axios (#2542)
Browse files Browse the repository at this point in the history
* feat(imports): deprecate axios

* add back axios

* fix ie11

* remove added file
  • Loading branch information
straker authored Oct 7, 2020
1 parent d03d18a commit 82d43a0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
1 change: 1 addition & 0 deletions lib/core/imports/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @deprecated (axios)
import axios from 'axios';
import { CssSelectorParser } from 'css-selector-parser';
import doT from '@deque/dot';
Expand Down
28 changes: 17 additions & 11 deletions lib/core/utils/parse-crossorigin-stylesheet.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import axios from 'axios';
import parseStylesheet from './parse-stylesheet';
import constants from '../constants';

Expand All @@ -21,21 +20,28 @@ function parseCrossOriginStylesheet(
importedUrls,
isCrossOrigin
) {
const axiosOptions = {
method: 'get',
timeout: constants.preload.timeout,
url
};

/**
* Add `url` to `importedUrls`
*/
importedUrls.push(url);

/**
* Fetch `cross-origin stylesheet` via axios
*/
return axios(axiosOptions).then(({ data }) => {
return new Promise((resolve, reject) => {
const request = new XMLHttpRequest();
request.open('GET', url);

request.timeout = constants.preload.timeout;
request.addEventListener('error', reject);
request.addEventListener('timeout', reject);
request.addEventListener('loadend', event => {
if (event.loaded && request.responseText) {
return resolve(request.responseText);
}

reject(request.responseText);
});

request.send();
}).then(data => {
const result = options.convertDataToStylesheet({
data,
isCrossOrigin,
Expand Down

0 comments on commit 82d43a0

Please sign in to comment.