forked from stackblitz/bolt.new
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: added ignore patterns to remove or redact files from context
- Loading branch information
1 parent
821ccdd
commit d36aa17
Showing
3 changed files
with
65 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* A utility to match glob patterns in the browser | ||
* Supports basic glob features like * and ** | ||
*/ | ||
export function isMatch(path: string, pattern: string): boolean { | ||
// Convert glob pattern to regex | ||
const regex = pattern | ||
// Escape special regex characters except * and / | ||
.replace(/[.+?^${}()|[\]\\]/g, '\\$&') | ||
// Replace ** with special marker | ||
.replace(/\*\*/g, '{{GLOBSTAR}}') | ||
// Replace single * with non-slash matcher | ||
.replace(/\*/g, '[^/]*') | ||
// Replace globstar marker with proper pattern | ||
.replace(/{{GLOBSTAR}}/g, '.*') | ||
// Anchor pattern to full path match | ||
.replace(/^/, '^') | ||
.replace(/$/, '$'); | ||
|
||
return new RegExp(regex).test(path); | ||
} | ||
|
||
/** | ||
* Match multiple patterns against a path | ||
*/ | ||
export function matchPatterns(path: string, patterns: string[]): boolean { | ||
return patterns.some(pattern => isMatch(path, pattern)); | ||
} |