ignore.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { sep } from "node:path"
  2. export namespace FileIgnore {
  3. const FOLDERS = new Set([
  4. "node_modules",
  5. "bower_components",
  6. ".pnpm-store",
  7. "vendor",
  8. "dist",
  9. "build",
  10. "out",
  11. ".next",
  12. "target",
  13. "bin",
  14. "obj",
  15. ".git",
  16. ".svn",
  17. ".hg",
  18. ".vscode",
  19. ".idea",
  20. ".turbo",
  21. ".output",
  22. "desktop",
  23. ".sst",
  24. ])
  25. const FILES = [
  26. "**/*.swp",
  27. "**/*.swo",
  28. // OS
  29. "**/.DS_Store",
  30. "**/Thumbs.db",
  31. // Logs & temp
  32. "**/logs/**",
  33. "**/tmp/**",
  34. "**/temp/**",
  35. "**/*.log",
  36. // Coverage/test outputs
  37. "**/coverage/**",
  38. "**/.nyc_output/**",
  39. ]
  40. const FILE_GLOBS = FILES.map((p) => new Bun.Glob(p))
  41. export const PATTERNS = [...FILES, ...FOLDERS]
  42. export function match(
  43. filepath: string,
  44. opts?: {
  45. extra?: Bun.Glob[]
  46. whitelist?: Bun.Glob[]
  47. },
  48. ) {
  49. for (const glob of opts?.whitelist || []) {
  50. if (glob.match(filepath)) return false
  51. }
  52. const parts = filepath.split(sep)
  53. for (let i = 0; i < parts.length; i++) {
  54. if (FOLDERS.has(parts[i])) return true
  55. }
  56. const extra = opts?.extra || []
  57. for (const glob of [...FILE_GLOBS, ...extra]) {
  58. if (glob.match(filepath)) return true
  59. }
  60. return false
  61. }
  62. }