diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 209586cc..ca3a969e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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: diff --git a/lib/parse-styles.js b/lib/parse-styles.js index e9ebd9fe..56aa0216 100644 --- a/lib/parse-styles.js +++ b/lib/parse-styles.js @@ -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 = [] @@ -93,6 +93,7 @@ async function resolveImportId(result, stmt, options, state, postcss) { node: stmt.node, } ) + return } @@ -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) { diff --git a/test/fixtures/cyclical-skip-duplicates.css b/test/fixtures/cyclical-skip-duplicates.css new file mode 100644 index 00000000..4dc4d4a8 --- /dev/null +++ b/test/fixtures/cyclical-skip-duplicates.css @@ -0,0 +1,4 @@ +@import "cyclical-a.css"; +@import "cyclical-b.css"; + +@import "cyclical-screen.css" screen; diff --git a/test/fixtures/cyclical-skip-duplicates.expected.css b/test/fixtures/cyclical-skip-duplicates.expected.css new file mode 100644 index 00000000..ab8eac83 --- /dev/null +++ b/test/fixtures/cyclical-skip-duplicates.expected.css @@ -0,0 +1,26 @@ + + +.b { + color: red; +} + +.a { + color: blue; +} + +@media screen { + + @media all { + +.a { + color: aquamarine; +} + } +} + +@media screen { + +.a { + color: pink; +} +} diff --git a/test/fixtures/cyclical.css b/test/fixtures/cyclical.css index 888fe4a3..4dc4d4a8 100644 --- a/test/fixtures/cyclical.css +++ b/test/fixtures/cyclical.css @@ -1,2 +1,4 @@ @import "cyclical-a.css"; @import "cyclical-b.css"; + +@import "cyclical-screen.css" screen; diff --git a/test/fixtures/cyclical.expected.css b/test/fixtures/cyclical.expected.css index dcc22c3f..819ad6be 100644 --- a/test/fixtures/cyclical.expected.css +++ b/test/fixtures/cyclical.expected.css @@ -15,3 +15,20 @@ .b { color: red; } + +@media screen { + + @media all { + +.a { + color: aquamarine; +} + } +} + +@media screen { + +.a { + color: pink; +} +} diff --git a/test/fixtures/imports/cyclical-all.css b/test/fixtures/imports/cyclical-all.css new file mode 100644 index 00000000..f1b5ab14 --- /dev/null +++ b/test/fixtures/imports/cyclical-all.css @@ -0,0 +1,5 @@ +@import url(cyclical-screen.css) screen; + +.a { + color: aquamarine; +} diff --git a/test/fixtures/imports/cyclical-screen.css b/test/fixtures/imports/cyclical-screen.css new file mode 100644 index 00000000..1e51af76 --- /dev/null +++ b/test/fixtures/imports/cyclical-screen.css @@ -0,0 +1,5 @@ +@import url(cyclical-all.css) all; + +.a { + color: pink; +} diff --git a/test/import.js b/test/import.js index 01fcbb49..e0d0b8ab 100644 --- a/test/import.js +++ b/test/import.js @@ -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", @@ -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")