ignore.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. ".npm",
  9. "dist",
  10. "build",
  11. "out",
  12. ".next",
  13. "target",
  14. "bin",
  15. "obj",
  16. ".git",
  17. ".svn",
  18. ".hg",
  19. ".vscode",
  20. ".idea",
  21. ".turbo",
  22. ".output",
  23. "desktop",
  24. ".sst",
  25. ".cache",
  26. ".webkit-cache",
  27. "__pycache__",
  28. ".pytest_cache",
  29. "mypy_cache",
  30. ".history",
  31. ".gradle",
  32. ])
  33. const FILES = [
  34. "**/*.swp",
  35. "**/*.swo",
  36. "**/*.pyc",
  37. // OS
  38. "**/.DS_Store",
  39. "**/Thumbs.db",
  40. // Logs & temp
  41. "**/logs/**",
  42. "**/tmp/**",
  43. "**/temp/**",
  44. "**/*.log",
  45. // Coverage/test outputs
  46. "**/coverage/**",
  47. "**/.nyc_output/**",
  48. ]
  49. const FILE_GLOBS = FILES.map((p) => new Bun.Glob(p))
  50. export const PATTERNS = [...FILES, ...FOLDERS]
  51. export function match(
  52. filepath: string,
  53. opts?: {
  54. extra?: Bun.Glob[]
  55. whitelist?: Bun.Glob[]
  56. },
  57. ) {
  58. for (const glob of opts?.whitelist || []) {
  59. if (glob.match(filepath)) return false
  60. }
  61. const parts = filepath.split(sep)
  62. for (let i = 0; i < parts.length; i++) {
  63. if (FOLDERS.has(parts[i])) return true
  64. }
  65. const extra = opts?.extra || []
  66. for (const glob of [...FILE_GLOBS, ...extra]) {
  67. if (glob.match(filepath)) return true
  68. }
  69. return false
  70. }
  71. }