Skip to content

Commit

Permalink
Merge pull request #108 from willofindie/fix/issue-107
Browse files Browse the repository at this point in the history
fix: remote (@import) fetch redirects
  • Loading branch information
phoenisx authored Jul 2, 2023
2 parents 93c6879 + 73d50f0 commit 1d583c6
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 7 deletions.
6 changes: 6 additions & 0 deletions @types/follow-redirects.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare module "follow-redirects" {
const http: typeof import("http");
const https: typeof import("https");

export { http, https };
}
3 changes: 2 additions & 1 deletion examples/css-imports/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"cssvar.files": [
"*.css",
"https://unpkg.com/[email protected]/violet.min.css"
"https://unpkg.com/[email protected]/violet.min.css",
"https://unpkg.com/[email protected]"
]
}
1 change: 1 addition & 0 deletions examples/css-imports/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
/* @import 'pollen-css/pollen.css'; */

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

body {
color: var(--red-2);
Expand Down
Empty file.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@
"dependencies": {
"culori": "^2.0.3",
"fast-glob": "^3.2.12",
"follow-redirects": "^1.15.2",
"postcss": "^8.4.12",
"postcss-less": "^6.0.0"
},
Expand Down
14 changes: 8 additions & 6 deletions src/remote-paths.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createWriteStream, existsSync, mkdirSync, unlink } from "fs";
import { Readable } from "stream";
import { get, IncomingMessage } from "http";
import { get as sGet } from "https";
import { http, https } from "follow-redirects";
import { IncomingMessage } from "http";
import { URL } from "url";
import {
createUnzip,
Expand All @@ -22,8 +22,10 @@ const CSSGetError = class extends Error {
super(overrideMsg || response.statusMessage || "CSSGetError: ");

this.name = "CSSGetError";
this.message = overrideMsg || response.statusMessage || "";
this.code = response.statusCode || 200;
this.code = response.statusCode ?? 200;
this.message =
`Response Status Code: ${this.code}, Message: ` +
(overrideMsg ?? response.statusMessage ?? "");
}
};

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

if (_url.protocol === "http:") {
httpGet = get;
httpGet = http.get;
}

httpGet(
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2755,6 +2755,11 @@ flatted@^3.1.0:
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.6.tgz#022e9218c637f9f3fc9c35ab9c9193f05add60b2"
integrity sha512-0sQoMh9s0BYsm+12Huy/rkKxVu4R1+r96YX5cG44rHV0pQ6iC3Q+mkoMFaGWObMFYQxCVT+ssG1ksneA2MI9KQ==

follow-redirects@^1.15.2:
version "1.15.2"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==

fs.realpath@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
Expand Down

0 comments on commit 1d583c6

Please sign in to comment.