Skip to content

Commit 1d583c6

Browse files
authored
Merge pull request #108 from willofindie/fix/issue-107
fix: remote (@import) fetch redirects
2 parents 93c6879 + 73d50f0 commit 1d583c6

File tree

7 files changed

+23
-7
lines changed

7 files changed

+23
-7
lines changed

@types/follow-redirects.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
declare module "follow-redirects" {
2+
const http: typeof import("http");
3+
const https: typeof import("https");
4+
5+
export { http, https };
6+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"cssvar.files": [
33
"*.css",
4-
"https://unpkg.com/[email protected]/violet.min.css"
4+
"https://unpkg.com/[email protected]/violet.min.css",
5+
"https://unpkg.com/[email protected]"
56
]
67
}

examples/css-imports/index.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
/* @import 'pollen-css/pollen.css'; */
2222

2323
@import url(https://unpkg.com/[email protected]/pollen.css);
24+
@import "https://unpkg.com/pollen-css";
2425

2526
body {
2627
color: var(--red-2);

examples/with-plugins/src/testing.js

Whitespace-only changes.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@
462462
"dependencies": {
463463
"culori": "^2.0.3",
464464
"fast-glob": "^3.2.12",
465+
"follow-redirects": "^1.15.2",
465466
"postcss": "^8.4.12",
466467
"postcss-less": "^6.0.0"
467468
},

src/remote-paths.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createWriteStream, existsSync, mkdirSync, unlink } from "fs";
22
import { Readable } from "stream";
3-
import { get, IncomingMessage } from "http";
4-
import { get as sGet } from "https";
3+
import { http, https } from "follow-redirects";
4+
import { IncomingMessage } from "http";
55
import { URL } from "url";
66
import {
77
createUnzip,
@@ -22,8 +22,10 @@ const CSSGetError = class extends Error {
2222
super(overrideMsg || response.statusMessage || "CSSGetError: ");
2323

2424
this.name = "CSSGetError";
25-
this.message = overrideMsg || response.statusMessage || "";
26-
this.code = response.statusCode || 200;
25+
this.code = response.statusCode ?? 200;
26+
this.message =
27+
`Response Status Code: ${this.code}, Message: ` +
28+
(overrideMsg ?? response.statusMessage ?? "");
2729
}
2830
};
2931

@@ -38,10 +40,10 @@ const CSSGetError = class extends Error {
3840
export const fetchAndCacheAsset = (url: string) =>
3941
new Promise<void>((res, rej) => {
4042
const _url = new URL(url);
41-
let httpGet = sGet;
43+
let httpGet = https.get;
4244

4345
if (_url.protocol === "http:") {
44-
httpGet = get;
46+
httpGet = http.get;
4547
}
4648

4749
httpGet(

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2755,6 +2755,11 @@ flatted@^3.1.0:
27552755
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.6.tgz#022e9218c637f9f3fc9c35ab9c9193f05add60b2"
27562756
integrity sha512-0sQoMh9s0BYsm+12Huy/rkKxVu4R1+r96YX5cG44rHV0pQ6iC3Q+mkoMFaGWObMFYQxCVT+ssG1ksneA2MI9KQ==
27572757

2758+
follow-redirects@^1.15.2:
2759+
version "1.15.2"
2760+
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
2761+
integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==
2762+
27582763
fs.realpath@^1.0.0:
27592764
version "1.0.0"
27602765
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"

0 commit comments

Comments
 (0)