mirror of
https://github.com/actions/toolkit.git
synced 2026-08-20 00:00:14 +02:00
Refactor: Extract convertToMinimatchPath helper to eliminate code duplication
Co-authored-by: salmanmkc <[email protected]>
This commit is contained in:
co-authored by
salmanmkc
parent
a60e6db920
commit
9de8f6f5c3
@@ -158,9 +158,7 @@ export class Pattern {
|
|||||||
|
|
||||||
// Convert to forward slashes on Windows before matching with minimatch
|
// Convert to forward slashes on Windows before matching with minimatch
|
||||||
// since the pattern was converted to forward slashes in the constructor
|
// since the pattern was converted to forward slashes in the constructor
|
||||||
if (IS_WINDOWS) {
|
itemPath = Pattern.convertToMinimatchPath(itemPath)
|
||||||
itemPath = itemPath.replace(/\\/g, '/')
|
|
||||||
}
|
|
||||||
|
|
||||||
// Match
|
// Match
|
||||||
if (this.minimatch.match(itemPath)) {
|
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
|
// Convert to forward slashes on Windows to match the pattern format used by minimatch
|
||||||
if (IS_WINDOWS) {
|
itemPath = Pattern.convertToMinimatchPath(itemPath)
|
||||||
itemPath = itemPath.replace(/\\/g, '/')
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.minimatch.matchOne(
|
return this.minimatch.matchOne(
|
||||||
itemPath.split(/\/+/),
|
itemPath.split(/\/+/),
|
||||||
@@ -204,6 +200,18 @@ export class Pattern {
|
|||||||
.replace(/\*/g, '[*]') // escape '*'
|
.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
|
* Normalizes slashes and ensures absolute root
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user