diff --git a/packages/glob/src/internal-pattern.ts b/packages/glob/src/internal-pattern.ts index b73a181b..cd92efab 100644 --- a/packages/glob/src/internal-pattern.ts +++ b/packages/glob/src/internal-pattern.ts @@ -158,9 +158,7 @@ export class Pattern { // Convert to forward slashes on Windows before matching with minimatch // since the pattern was converted to forward slashes in the constructor - if (IS_WINDOWS) { - itemPath = itemPath.replace(/\\/g, '/') - } + itemPath = Pattern.convertToMinimatchPath(itemPath) // Match if (this.minimatch.match(itemPath)) { @@ -183,9 +181,7 @@ export class Pattern { } // Convert to forward slashes on Windows to match the pattern format used by minimatch - if (IS_WINDOWS) { - itemPath = itemPath.replace(/\\/g, '/') - } + itemPath = Pattern.convertToMinimatchPath(itemPath) return this.minimatch.matchOne( itemPath.split(/\/+/), @@ -204,6 +200,18 @@ export class Pattern { .replace(/\*/g, '[*]') // escape '*' } + /** + * Converts path to forward slashes on Windows for compatibility with minimatch. + * On Windows, minimatch patterns use forward slashes, so paths must be converted + * to match the same format. + */ + private static convertToMinimatchPath(itemPath: string): string { + if (IS_WINDOWS) { + return itemPath.replace(/\\/g, '/') + } + return itemPath + } + /** * Normalizes slashes and ensures absolute root */