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

Globbed files are not added to the import once filter #227

Open kevinramharak opened 3 years ago

kevinramharak commented 3 years ago

From what I can tell the following lines: https://github.com/maoberlehner/node-sass-magic-importer/blob/master/packages/node-sass-magic-importer/src/index.ts#L125-L128

Do not store the imported files. dart-sass (not sure about node-sass does not seem to run imports recusivly (took me a few hours). This allows for possible duplicates when using globbing.

Is this intendend? It seems easy enough to fix with something like:

        if (globFilePaths) {
            const contents = globFilePaths
                .reduce((result, resolvedUrl) => {
                    const id = getStoreId(resolvedUrl, selectorFilters, nodeFilters);
                    if (!store.has(id)) {
                        console.log('including:  ', resolvedUrl);
                        store.add(id);
                        result.push(`@import '${filterPrefix}${resolvedUrl}';`);
                    } else {
                        console.log('discarding: ', resolvedUrl);
                    }
                    return result; 
                }, []).join('\n');
            return { contents };
        }