diff --git a/README.md b/README.md index 9c96cf2..5d12918 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,7 @@ postcss-import in your plugin chain will allow you to adjust assets `url()` (or even inline them) after inlining imported files. - In order to optimize output, **this plugin will only import a file once** on a given scope (root, media query...). -Tests are made from the path & the content of imported files (using a hash -table). +Duplicates are detected by the resolved file path. If this behavior is not what you want, look at `skipDuplicates` option - If you are looking for **Glob Imports**, you can use [postcss-import-ext-glob](https://github.com/dimitrinicolas/postcss-import-ext-glob) to extend postcss-import. - If you want to import remote sources, you can use [postcss-import-url](https://github.com/unlight/postcss-import-url) with its `dataUrls` plugin option to extend postcss-import. @@ -183,10 +182,8 @@ promised content. Type: `Boolean` Default: `true` -By default, similar files (based on the same content) are being skipped. -It's to optimize output and skip similar files like `normalize.css` for example. -If this behavior is not what you want, just set this option to `false` to -disable it. +By default, repeated imports of the same file are skipped. +Set this option to `false` to inline a file each time it is imported. #### `addModulesDirectories` diff --git a/index.js b/index.js index 1786988..c337e80 100755 --- a/index.js +++ b/index.js @@ -37,7 +37,6 @@ function AtImport(options) { async Once(styles, { result, atRule, postcss }) { const state = { importedFiles: {}, - hashFiles: {}, } if (styles.source?.input?.file) { diff --git a/lib/parse-styles.js b/lib/parse-styles.js index 766de9c..558c3ef 100644 --- a/lib/parse-styles.js +++ b/lib/parse-styles.js @@ -177,14 +177,6 @@ async function loadImportContent( return } - // skip previous imported files not containing @import rules - if ( - options.skipDuplicates && - state.hashFiles[content]?.[stmtDuplicateCheckKey] - ) { - return - } - const importedResult = await processContent( result, content, @@ -196,20 +188,6 @@ async function loadImportContent( const styles = importedResult.root result.messages = result.messages.concat(importedResult.messages) - if (options.skipDuplicates) { - const hasImport = styles.some(child => { - return child.type === "atrule" && child.name === "import" - }) - if (!hasImport) { - // save hash files to skip them next time - if (!state.hashFiles[content]) { - state.hashFiles[content] = {} - } - - state.hashFiles[content][stmtDuplicateCheckKey] = true - } - } - // recursion: import @import from imported file return parseStyles( result, diff --git a/test/fixtures/imports/same-file-dedup/a/shared.css b/test/fixtures/imports/same-file-dedup/a/shared.css new file mode 100644 index 0000000..6abac48 --- /dev/null +++ b/test/fixtures/imports/same-file-dedup/a/shared.css @@ -0,0 +1 @@ +shared {} diff --git a/test/fixtures/imports/same-file-dedup/b/shared.css b/test/fixtures/imports/same-file-dedup/b/shared.css new file mode 100644 index 0000000..6abac48 --- /dev/null +++ b/test/fixtures/imports/same-file-dedup/b/shared.css @@ -0,0 +1 @@ +shared {} diff --git a/test/fixtures/no-duplicate.expected.css b/test/fixtures/no-duplicate.expected.css index 82382a1..b9170a6 100644 --- a/test/fixtures/no-duplicate.expected.css +++ b/test/fixtures/no-duplicate.expected.css @@ -1,4 +1,8 @@ foo{} +foo{} +@media screen{ +foo{} +} @media screen{ foo{} } diff --git a/test/fixtures/same-file-dedup.css b/test/fixtures/same-file-dedup.css new file mode 100644 index 0000000..ef02919 --- /dev/null +++ b/test/fixtures/same-file-dedup.css @@ -0,0 +1,3 @@ +@import "same-file-dedup/a/shared.css"; +@import "same-file-dedup/b/shared.css"; +@import "same-file-dedup/a/shared.css"; diff --git a/test/fixtures/same-file-dedup.expected.css b/test/fixtures/same-file-dedup.expected.css new file mode 100644 index 0000000..572363e --- /dev/null +++ b/test/fixtures/same-file-dedup.expected.css @@ -0,0 +1,2 @@ +shared {} +shared {} diff --git a/test/import.js b/test/import.js index e2a2bd1..87a01c5 100644 --- a/test/import.js +++ b/test/import.js @@ -46,6 +46,12 @@ test( test("should import stylesheets with same content", checkFixture, "same") +test( + "should not skip different files with the same content", + checkFixture, + "same-file-dedup", +) + test("should ignore & adjust external import", checkFixture, "ignore") test("should not fail with only one absolute import", t => {