From eaff3c38e790ede417130762c2853d3110fa734d Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 5 Sep 2023 11:14:00 -0400 Subject: [PATCH 1/2] Update actions/checkout action to v4 (#544) Co-authored-by: Ryan Zimmerman --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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: From f99379ccc188cc25b05fbbda92ca659f4c098a1a Mon Sep 17 00:00:00 2001 From: Romain Menke <11521496+romainmenke@users.noreply.github.com> Date: Sat, 30 Sep 2023 19:02:44 +0200 Subject: [PATCH 2/2] check import cycles (#535) * check cycles * Update lib/parse-styles.js * add tests --- index.js | 2 +- lib/parse-styles.js | 10 ++++-- test/fixtures/cyclical-skip-duplicates.css | 4 +++ .../cyclical-skip-duplicates.expected.css | 23 ++++++++++++ test/fixtures/cyclical.css | 4 +++ test/fixtures/cyclical.expected.css | 31 ++++++++++++++++ test/fixtures/imports/cyclical-a.css | 5 +++ test/fixtures/imports/cyclical-all.css | 5 +++ test/fixtures/imports/cyclical-b.css | 5 +++ test/fixtures/imports/cyclical-screen.css | 5 +++ test/import.js | 35 +++++++++++++++---- 11 files changed, 119 insertions(+), 10 deletions(-) create mode 100644 test/fixtures/cyclical-skip-duplicates.css create mode 100644 test/fixtures/cyclical-skip-duplicates.expected.css create mode 100644 test/fixtures/cyclical.css create mode 100644 test/fixtures/cyclical.expected.css create mode 100644 test/fixtures/imports/cyclical-a.css create mode 100644 test/fixtures/imports/cyclical-all.css create mode 100644 test/fixtures/imports/cyclical-b.css create mode 100644 test/fixtures/imports/cyclical-screen.css diff --git a/index.js b/index.js index 12ebe824..59ed776d 100755 --- a/index.js +++ b/index.js @@ -63,7 +63,7 @@ function AtImport(options) { state, [], [], - "", + [], postcss ) diff --git a/lib/parse-styles.js b/lib/parse-styles.js index d3fbf3c2..6aaa245b 100644 --- a/lib/parse-styles.js +++ b/lib/parse-styles.js @@ -91,7 +91,7 @@ async function resolveImportId(result, stmt, options, state, postcss) { ) return - } else if (dataURL.isValid(stmt.from)) { + } else if (dataURL.isValid(stmt.from.slice(-1))) { // Data urls can't be used a base url to resolve imports. // When the parent statement has a data url // and the current statement doesn't have a data url we ignore the statement. @@ -148,7 +148,7 @@ async function loadImportContent( postcss ) { const atRule = stmt.node - const { media, layer } = stmt + const { media, layer, from } = stmt assignLayerNames(layer, atRule, state, options) @@ -168,6 +168,10 @@ async function loadImportContent( state.importedFiles[filename][media][layer] = true } + if (from.includes(filename)) { + return + } + const content = await options.load(filename, options) if (content.trim() === "" && options.warnOnEmpty) { @@ -215,7 +219,7 @@ async function loadImportContent( state, media, layer, - filename, + [...from, filename], postcss ) } 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..24c2d5e1 --- /dev/null +++ b/test/fixtures/cyclical-skip-duplicates.expected.css @@ -0,0 +1,23 @@ + + +.b { + color: red; +} + +.a { + color: blue; +} + +@media screen and all { + +.a { + color: aquamarine; +} +} + +@media screen { + +.a { + color: pink; +} +} diff --git a/test/fixtures/cyclical.css b/test/fixtures/cyclical.css new file mode 100644 index 00000000..4dc4d4a8 --- /dev/null +++ b/test/fixtures/cyclical.css @@ -0,0 +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 new file mode 100644 index 00000000..5779150f --- /dev/null +++ b/test/fixtures/cyclical.expected.css @@ -0,0 +1,31 @@ + + +.b { + color: red; +} + +.a { + color: blue; +} + +.a { + color: blue; +} + +.b { + color: red; +} + +@media screen and all { + +.a { + color: aquamarine; +} +} + +@media screen { + +.a { + color: pink; +} +} diff --git a/test/fixtures/imports/cyclical-a.css b/test/fixtures/imports/cyclical-a.css new file mode 100644 index 00000000..ec5adb43 --- /dev/null +++ b/test/fixtures/imports/cyclical-a.css @@ -0,0 +1,5 @@ +@import url(cyclical-b.css); + +.a { + color: blue; +} 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-b.css b/test/fixtures/imports/cyclical-b.css new file mode 100644 index 00000000..8452916c --- /dev/null +++ b/test/fixtures/imports/cyclical-b.css @@ -0,0 +1,5 @@ +@import url(cyclical-a.css); + +.b { + color: red; +} 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 f13d921f..e0d0b8ab 100644 --- a/test/import.js +++ b/test/import.js @@ -13,15 +13,38 @@ 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", + checkFixture, + "cyclical", + { + skipDuplicates: false, + } +) + +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 stylsheets with same content", checkFixture, "same") +test("should import stylesheets with same content", checkFixture, "same") test("should ignore & adjust external import", checkFixture, "ignore")