cmalven / vite-plugin-sass-glob-import

Use glob syntax for imports in your main Sass or SCSS file.
MIT License
18 stars 7 forks source link

[regression] Not resolving glob in Windows environment after 4.0.0 upgrade #17

Open psychobolt opened 1 month ago

psychobolt commented 1 month ago

Issue

There is no error being thrown from Vite, there is a style.css file output but has no contents for Windows. For MacOS, works normally

// style.scss
@use '**/*.module.scss';

Capture

Context:

Downgrading to 3.0.2 resolves my issue.

From latest glob README.md:

Note Glob patterns should always use / as a path separator, even on Windows systems, as \ is used to escape glob characters. If you wish to use \ as a path separator instead of using it as an escape character on Windows platforms, you may set windowsPathsNoEscape:true in the options. In this mode, special glob characters cannot be escaped, making it impossible to match a literal * ? and so on in filenames.

Readme suggests the use of windowsPathsNoEscape: true when backslash \ is present in path. However, it may limit special glob characters. A Windows path will resemble double slashes under node: D:\\project\\sub-path\\**\\*.scss. Futhermore, there are no unit tests for support of Windows paths.

psychobolt commented 1 month ago

If you're using yarn or patch-package , you can apply the following patch using the suggestion above:

diff --git a/dist/index.mjs b/dist/index.mjs
index 909ea96b2b4a5d7051690673d946536879e7613e..86706f04f370cbf71f5b628765c04daddca759a6 100644
--- a/dist/index.mjs
+++ b/dist/index.mjs
@@ -27,7 +27,8 @@ function sassGlobImports(options = {}) {
         for (let i2 = 0; i2 < searchBases.length; i2++) {
           basePath = searchBases[i2];
           files = globSync(path.join(basePath, globPattern), {
-            cwd: "./"
+            cwd: "./",
+            windowsPathsNoEscape: true
           }).sort((a, b) => a.localeCompare(b, "en"));
           const globPatternWithoutWildcard = globPattern.split("*")[0];
           if (globPatternWithoutWildcard.length) {
cmalven commented 1 month ago

@psychobolt Just wanted to say thank you for flagging this and I apologize for not responding. I've been very tied up with a big project. If you have the ability to test this on linux/windows I would definitely welcome a pull request. Unit tests for windows paths would be great, too!