mizdra / happy-css-modules

Typed, definition jumpable CSS Modules. Moreover, easy!
MIT License
213 stars 5 forks source link

fix: watch mode not working on Windows #254

Closed Blithe-Chiang closed 1 month ago

Blithe-Chiang commented 1 month ago

I met an issue when i ran npx hcm 'src/**/*.module.{css,scss,less}' --watch on Windows 10. It will not generate the css file.

After some debugging, I found that the callback passed to watcher in not working correctly. The flow will always early returned in if (isExternalFile(filePath)), and I found that the root cause of the problem is that isMatchByGlob in src/util.ts always return false. This function call minimatch from minimatch.

The smallest reproduce code is as follows:

import { minimatch } from 'minimatch';
const path = 'D:\\awesome project\\src\\style\\index.module.less';
const pattern = 'D:\\awesome project\\src\\**\\*.module.less';
const matched = minimatch(path, pattern);
// matched: false

I found that minimatch has a third argument options on its repo's README. I tried to set options.windowsPathsNoEscape to true, and it works.

import { minimatch } from 'minimatch';
const path = 'D:\\awesome project\\src\\style\\index.module.less';
const pattern = 'D:\\awesome project\\src\\**\\*.module.less';
const matched = minimatch(path, pattern, { windowsPathsNoEscape: true });
// matched: true
mizdra commented 1 month ago

@Blithe-Chiang This is shipped on v3.0.1. Please try it.

https://github.com/mizdra/happy-css-modules/releases/tag/v3.0.1