Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into wip-rewrite--courte…
Browse files Browse the repository at this point in the history
…ous-antelope-d8443985a8
  • Loading branch information
romainmenke committed Sep 30, 2023
2 parents e3df2ba + f99379c commit f2943f8
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
matrix:
node-version: [14.x, 16.x, 18.x]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
Expand Down
7 changes: 6 additions & 1 deletion lib/parse-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async function resolveImportId(result, stmt, options, state, postcss) {
)

return
} else if (dataURL.isValid(stmt.from[stmt.from.length - 1])) {
} else if (dataURL.isValid(stmt.from.slice(-1))) {
// Data urls can't be used as a base url to resolve imports.
// Skip inlining and warn.
stmt.children = []
Expand All @@ -93,6 +93,7 @@ async function resolveImportId(result, stmt, options, state, postcss) {
node: stmt.node,
}
)

return
}

Expand Down Expand Up @@ -166,6 +167,10 @@ async function loadImportContent(
return
}

if (from.includes(filename)) {
return
}

const content = await options.load(filename, options)

if (content.trim() === "" && options.warnOnEmpty) {
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/cyclical-skip-duplicates.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@import "cyclical-a.css";
@import "cyclical-b.css";

@import "cyclical-screen.css" screen;
26 changes: 26 additions & 0 deletions test/fixtures/cyclical-skip-duplicates.expected.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@


.b {
color: red;
}

.a {
color: blue;
}

@media screen {

@media all {

.a {
color: aquamarine;
}
}
}

@media screen {

.a {
color: pink;
}
}
2 changes: 2 additions & 0 deletions test/fixtures/cyclical.css
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
@import "cyclical-a.css";
@import "cyclical-b.css";

@import "cyclical-screen.css" screen;
17 changes: 17 additions & 0 deletions test/fixtures/cyclical.expected.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,20 @@
.b {
color: red;
}

@media screen {

@media all {

.a {
color: aquamarine;
}
}
}

@media screen {

.a {
color: pink;
}
}
5 changes: 5 additions & 0 deletions test/fixtures/imports/cyclical-all.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import url(cyclical-screen.css) screen;

.a {
color: aquamarine;
}
5 changes: 5 additions & 0 deletions test/fixtures/imports/cyclical-screen.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import url(cyclical-all.css) all;

.a {
color: pink;
}
26 changes: 20 additions & 6 deletions test/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@ const atImport = require("..")
// internal tooling
const checkFixture = require("./helpers/check-fixture")

test("should import stylsheets", checkFixture, "simple")
test("should import stylesheets", checkFixture, "simple")

test("should not import a stylsheet twice", checkFixture, "no-duplicate")
test("should not import a stylesheet twice", checkFixture, "no-duplicate")

test("should be able to import a stylsheet twice", checkFixture, "duplicates", {
skipDuplicates: false,
})
test(
"should be able to import a stylesheet twice",
checkFixture,
"duplicates",
{
skipDuplicates: false,
}
)

test(
"should be able to import a stylesheet with cyclical dependencies",
Expand All @@ -30,7 +35,16 @@ test(
}
)

test("should import stylsheets with same content", checkFixture, "same")
test(
"should be able to import a stylesheet with cyclical dependencies and skip duplicates is true",
checkFixture,
"cyclical-skip-duplicates",
{
skipDuplicates: true,
}
)

test("should import stylesheets with same content", checkFixture, "same")

test("should ignore & adjust external import", checkFixture, "ignore")

Expand Down

0 comments on commit f2943f8

Please sign in to comment.