maoberlehner / node-sass-magic-importer

Custom node-sass importer for selector specific imports, module importing, globbing support and importing files only once.
MIT License
292 stars 28 forks source link

Using the same pattern results in same content #183

Closed mvenghaus closed 5 years ago

mvenghaus commented 6 years ago

Hello,

when i import two files and these two files import files using the same pattern I get the same content twice.

Example: main.scss

@import "folder1/file";
@import "folder2/file";

folder1/_file.scss

@import "source/**/*.scss";

folder2/_file.scss

@import "source/**/*.scss";

It seems that the pattern is the key of an array and cannot be used twice.

Any suggestions?

Thx Marcus

maoberlehner commented 6 years ago

Hey @mvenghaus I'm not quite sure if I understand your problem correctly? If the same files are imported multiple times, they end up multiple times in the final CSS. That's the intended behavior.

mvenghaus commented 6 years ago

I've the following file structure. The "_module.scss" should always include all sub scss files.

main.scss

module1/_module.scss
module1/source/_sub1.scss
module1/source/_sub2.scss

module2/_module.scss
module2/source/_sub3.scss
module2/source/_sub4.scss

main.scss

@import "*/_module.scss";

Content of every "_module.scss"

@import "source/**/*.scss";

Problem is that _sub3 und _sub4 are never used .. instead I've the content of _sub1 and _sub2 twice.

maoberlehner commented 5 years ago

Have you already tried @import "**/_module.scss"; ?

Oh.. I misunderstood the exact problem. I'll try to reproduce on my own machine and reach back to you! Thanks for reporting this issue.

maoberlehner commented 5 years ago

Hey @mvenghaus!

I've investigated further and I'm pretty sure this is not a problem with this package but rather with node-sass itself. This issue seems to describe the same problem: https://github.com/sass/node-sass/issues/2556

See also my test case for this issue: https://github.com/maoberlehner/node-sass-magic-importer/pull/new/bugfix/same-dir-name-glob

saper commented 5 years ago

Importer entries in libsass are built using (name, contents, src map) triple. You might have a look at the sample C code and the API definition (look for for sass_make_import_entry).

The name (file parameter in node-sass) is still used and assigned even if no files are involved. If you play with importers a lot and you generate code on the fly I'd make sure to use the file parameter and give it unique name. Maybe we should document it better.

I know it's messy - that is why this is an experimental feature.

saper commented 5 years ago

https://github.com/sass/node-sass/issues/2556 has been solved - it is possible to teach importer how to deal with files that bear the same file name but are spread across the directory structure.