Fix glob pattern matching on Windows by normalizing path separators
Fix glob not working on Windows
Root Cause Analysis
The issue is in packages/glob/src/internal-pattern.ts in the match() and partialMatch() methods:
- Line 133: Pattern is converted to forward slashes (
/) for minimatch on Windows - Lines 144/156: Item paths are normalized to backslashes (
\) on Windows - Line 160: minimatch tries to match paths with backslashes against patterns with forward slashes, causing match failures
Implementation Plan
- [x] Analyze the exact issue and create minimal fix
- [x] Convert itemPath to forward slashes on Windows before passing to minimatch.match()
- [x] Ensure partialMatch() method has the same fix applied
- [x] Build and test the changes
- [x] Run existing test suite to ensure no regressions (all 74 tests passed)
- [x] Create a focused test case to validate the fix (5 new tests added, all passing)
- [x] Run security checks (CodeQL: 0 alerts)
- [x] Address code review feedback
- [x] Refactor duplicated code into helper method
- [x] Remove unused imports
- [x] Apply linting fixes
- [x] Final verification
Security Summary
CodeQL analysis completed with 0 alerts - no security vulnerabilities found.
Changes Made
-
packages/glob/src/internal-pattern.ts:
- Added private static helper method
convertToMinimatchPath()to eliminate code duplication - Convert itemPath to forward slashes on Windows before passing to minimatch.match()
- Convert itemPath to forward slashes on Windows in partialMatch() method
- Added private static helper method
- .gitignore: Added .nx/ directory to exclude build cache
- packages/glob/tests/windows-path-matching.test.ts: Added 5 comprehensive Windows-specific tests, removed unused import, applied eslint formatting fixes
Original prompt
This section details on the original issue you should resolve
<issue_title>glob doesn't work on windows</issue_title> <issue_description>Describe the bug When using the
@actions/globlibrary, it doesn't give any results when running on github's own windows runners.To Reproduce Steps to reproduce the behavior: I created a minimal typescript action that reproduces this issue on windows runners: https://github.com/Jimver/glob-test/actions/runs/15453189713/job/43499917075
Expected behavior Regardless of OS, I would expect glob to return the test file we just created.
Notes Strangely, the globber does actually work in unit tests I wrote, see https://github.com/Jimver/glob-test/blob/main/tests/glob.test.ts. Though this is probably why this wasn't caught in the existing unit tests (if they run on windows). So basically the issue only manifests when running the actual action. I tried reproducing locally as well on my windows desktop but it works fine there as well. When just using
readdirdirectly I see the file just fine on the windows runner (see the action log debug output), so it seems to be a combination ofgloband something about the windows runners which is going wrong. </issue_description>Comments on the Issue (you are @copilot in this section)
- Fixes actions/toolkit#2085
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.