Skip to content

Commit eb9899b

Browse files
authored
Allow urls that contain fragments, fixes #560 (#561)
1 parent fa42e63 commit eb9899b

9 files changed

+37
-7
lines changed

lib/parse-styles.js

-5
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,6 @@ function isProcessableURL(uri) {
227227
try {
228228
// needs a base to parse properly
229229
const url = new URL(uri, "https://example.com")
230-
231-
if (url.hash) {
232-
return false
233-
}
234-
235230
if (url.search) {
236231
return false
237232
}

test/fixtures/filter-ignore.css

-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,4 @@
1313
@import url('//css');
1414
@import url(//css);
1515
@import url('foo.css?query=string');
16-
@import url('foo.css#hash');
1716
content{}

test/fixtures/filter-ignore.expected.css

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
@import url('//css');
1515
@import url(//css);
1616
@import url('foo.css?query=string');
17-
@import url('foo.css#hash');
1817
@media (min-width: 25em){
1918
ignore{}
2019
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.foo {
2+
color: green;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"style": "style.css",
3+
"imports": {
4+
"#a.css": "./a.css"
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import '#a.css';

test/fixtures/subpath.css

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import "subpath";

test/fixtures/subpath.expected.css

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.foo {
2+
color: green;
3+
}

test/resolve.js

+23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"use strict"
22
// external tooling
33
const test = require("ava")
4+
const fs = require("fs")
5+
const path = require("path")
46

57
// internal tooling
68
const checkFixture = require("./helpers/check-fixture")
@@ -72,3 +74,24 @@ test(
7274
{ path: null, addModulesDirectories: ["shared_modules"] },
7375
{ from: "test/fixtures/imports/foo.css" },
7476
)
77+
78+
test(
79+
"should resolve modules with node subpath imports with a custom resolver",
80+
checkFixture,
81+
"subpath",
82+
{
83+
resolve: (id, basedir) => {
84+
// see: https://nodejs.org/api/packages.html#subpath-imports
85+
if (id.startsWith("#")) {
86+
const pkgJSON = JSON.parse(
87+
fs.readFileSync(path.join(basedir, "package.json")),
88+
)
89+
90+
return path.join(basedir, pkgJSON.imports[id])
91+
}
92+
93+
return id
94+
},
95+
path: "test/fixtures/imports/modules",
96+
},
97+
)

0 commit comments

Comments
 (0)