Skip to content

Commit

Permalink
Allow urls that contain fragments, fixes #560 (#561)
Browse files Browse the repository at this point in the history
  • Loading branch information
romainmenke authored Mar 16, 2024
1 parent fa42e63 commit eb9899b
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 7 deletions.
5 changes: 0 additions & 5 deletions lib/parse-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,6 @@ function isProcessableURL(uri) {
try {
// needs a base to parse properly
const url = new URL(uri, "https://example.com")

if (url.hash) {
return false
}

if (url.search) {
return false
}
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/filter-ignore.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@
@import url('//css');
@import url(//css);
@import url('foo.css?query=string');
@import url('foo.css#hash');
content{}
1 change: 0 additions & 1 deletion test/fixtures/filter-ignore.expected.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
@import url('//css');
@import url(//css);
@import url('foo.css?query=string');
@import url('foo.css#hash');
@media (min-width: 25em){
ignore{}
}
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/imports/modules/subpath/a.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.foo {
color: green;
}
6 changes: 6 additions & 0 deletions test/fixtures/imports/modules/subpath/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"style": "style.css",
"imports": {
"#a.css": "./a.css"
}
}
1 change: 1 addition & 0 deletions test/fixtures/imports/modules/subpath/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import '#a.css';
1 change: 1 addition & 0 deletions test/fixtures/subpath.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "subpath";
3 changes: 3 additions & 0 deletions test/fixtures/subpath.expected.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.foo {
color: green;
}
23 changes: 23 additions & 0 deletions test/resolve.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"use strict"
// external tooling
const test = require("ava")
const fs = require("fs")
const path = require("path")

// internal tooling
const checkFixture = require("./helpers/check-fixture")
Expand Down Expand Up @@ -72,3 +74,24 @@ test(
{ path: null, addModulesDirectories: ["shared_modules"] },
{ from: "test/fixtures/imports/foo.css" },
)

test(
"should resolve modules with node subpath imports with a custom resolver",
checkFixture,
"subpath",
{
resolve: (id, basedir) => {
// see: https://nodejs.org/api/packages.html#subpath-imports
if (id.startsWith("#")) {
const pkgJSON = JSON.parse(
fs.readFileSync(path.join(basedir, "package.json")),
)

return path.join(basedir, pkgJSON.imports[id])
}

return id
},
path: "test/fixtures/imports/modules",
},
)

0 comments on commit eb9899b

Please sign in to comment.