|
|
@@ -1,28 +1,26 @@
|
|
|
+import { sep } from "node:path"
|
|
|
+
|
|
|
export namespace FileIgnore {
|
|
|
- const DEFAULT_PATTERNS = [
|
|
|
- // Dependencies
|
|
|
- "**/node_modules/**",
|
|
|
- "**/bower_components/**",
|
|
|
- "**/.pnpm-store/**",
|
|
|
- "**/vendor/**",
|
|
|
-
|
|
|
- // Build outputs
|
|
|
- "**/dist/**",
|
|
|
- "**/build/**",
|
|
|
- "**/out/**",
|
|
|
- "**/.next/**",
|
|
|
- "**/target/**", // Rust
|
|
|
- "**/bin/**",
|
|
|
- "**/obj/**", // .NET
|
|
|
-
|
|
|
- // Version control
|
|
|
- "**/.git/**",
|
|
|
- "**/.svn/**",
|
|
|
- "**/.hg/**",
|
|
|
-
|
|
|
- // IDE/Editor
|
|
|
- "**/.vscode/**",
|
|
|
- "**/.idea/**",
|
|
|
+ const FOLDERS = new Set([
|
|
|
+ "node_modules",
|
|
|
+ "bower_components",
|
|
|
+ ".pnpm-store",
|
|
|
+ "vendor",
|
|
|
+ "dist",
|
|
|
+ "build",
|
|
|
+ "out",
|
|
|
+ ".next",
|
|
|
+ "target",
|
|
|
+ "bin",
|
|
|
+ "obj",
|
|
|
+ ".git",
|
|
|
+ ".svn",
|
|
|
+ ".hg",
|
|
|
+ ".vscode",
|
|
|
+ ".idea",
|
|
|
+ ])
|
|
|
+
|
|
|
+ const FILES = [
|
|
|
"**/*.swp",
|
|
|
"**/*.swo",
|
|
|
|
|
|
@@ -41,22 +39,29 @@ export namespace FileIgnore {
|
|
|
"**/.nyc_output/**",
|
|
|
]
|
|
|
|
|
|
- const GLOBS = DEFAULT_PATTERNS.map((p) => new Bun.Glob(p))
|
|
|
+ const FILE_GLOBS = FILES.map((p) => new Bun.Glob(p))
|
|
|
|
|
|
export function match(
|
|
|
filepath: string,
|
|
|
- opts: {
|
|
|
+ opts?: {
|
|
|
extra?: Bun.Glob[]
|
|
|
whitelist?: Bun.Glob[]
|
|
|
},
|
|
|
) {
|
|
|
- for (const glob of opts.whitelist || []) {
|
|
|
+ for (const glob of opts?.whitelist || []) {
|
|
|
if (glob.match(filepath)) return false
|
|
|
}
|
|
|
- const extra = opts.extra || []
|
|
|
- for (const glob of [...GLOBS, ...extra]) {
|
|
|
+
|
|
|
+ const parts = filepath.split(sep)
|
|
|
+ for (let i = 0; i < parts.length; i++) {
|
|
|
+ if (FOLDERS.has(parts[i])) return true
|
|
|
+ }
|
|
|
+
|
|
|
+ const extra = opts?.extra || []
|
|
|
+ for (const glob of [...FILE_GLOBS, ...extra]) {
|
|
|
if (glob.match(filepath)) return true
|
|
|
}
|
|
|
+
|
|
|
return false
|
|
|
}
|
|
|
}
|