Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: watch mode not working on Windows #254

Merged
merged 1 commit into from
May 26, 2024

Conversation

Blithe-Chiang
Copy link
Contributor

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 mizdra added the Type: Fix Fix bug. label May 26, 2024
@mizdra mizdra mentioned this pull request May 26, 2024
Copy link
Owner

@mizdra mizdra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks!

@mizdra mizdra merged commit 3ed4fdd into mizdra:main May 26, 2024
6 checks passed
@mizdra
Copy link
Owner

mizdra commented May 26, 2024

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Fix Fix bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants