Skip to content

Commit f6f69e0

Browse files
committed
Use whatwg-url over deprecated url apis, and swap out http-https for axios.
- Removes deprecated url apis - Fixes unlight#25 - And Axios is supported in both node.js and browser.
1 parent 9f2cb79 commit f6f69e0

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

index.js

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
const postcss = require('postcss');
2-
const hh = require('http-https');
2+
const axios = require('axios');
33
const isUrl = require('is-url');
44
const trim = require('lodash.trim');
5-
const resolveRelative = require('resolve-relative-url');
65
const assign = require('lodash.assign');
7-
const url = require('url');
86

97
const defaults = {
108
recursive: true,
@@ -26,7 +24,7 @@ function postcssImportUrl(options) {
2624
const params = space(atRule.params);
2725
let remoteFile = cleanupRemoteFile(params[0]);
2826
if (parentRemoteFile) {
29-
remoteFile = resolveRelative(remoteFile, parentRemoteFile);
27+
remoteFile = new URL(remoteFile, parentRemoteFile).href;
3028
}
3129
if (!isUrl(remoteFile)) {
3230
return;
@@ -102,7 +100,9 @@ function postcssImportUrl(options) {
102100
: Promise.resolve(newNode));
103101

104102
if (options.dataUrls) {
105-
atRule.params = `url(data:text/css;base64,${Buffer.from(importedTree.toString()).toString('base64')})`;
103+
atRule.params = `url(data:text/css;base64,${Buffer.from(
104+
importedTree.toString(),
105+
).toString('base64')})`;
106106
} else {
107107
atRule.replaceWith(importedTree);
108108
}
@@ -162,6 +162,18 @@ function createPromise(remoteFile, options) {
162162
request.end();
163163
}
164164
return new Promise(executor);
165+
function executor(resolve, reject) {
166+
axios(reqOptions)
167+
.then(response => {
168+
resolve({
169+
body: response.data,
170+
parent: remoteFile,
171+
});
172+
})
173+
.catch(error => {
174+
return reject(error);
175+
});
176+
}
165177
}
166178

167179
function urlParse(remoteFile) {

package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@
2121
"test:w": "gulp test:w"
2222
},
2323
"dependencies": {
24-
"http-https": "^1.0.0",
24+
"axios": "^1.4.0",
2525
"is-url": "^1.2.4",
2626
"lodash.assign": "^4.2.0",
27-
"lodash.trim": "^4.5.1",
28-
"resolve-relative-url": "^1.0.0"
27+
"lodash.trim": "^4.5.1"
2928
},
3029
"peerDependencies": {
3130
"postcss": "^8.0.0"

0 commit comments

Comments
 (0)