|
| 1 | +import * as path from "path" |
| 2 | + |
| 3 | +/** |
| 4 | + * Checks if a file should be ignored for code indexing based on hardcoded rules. |
| 5 | + * This provides an additional layer of filtering beyond git and .rooignore rules. |
| 6 | + * |
| 7 | + * @param relativeFilePath - The relative path of the file to check |
| 8 | + * @returns true if the file should be ignored, false if it should be indexed |
| 9 | + */ |
| 10 | +export function shouldIgnoreFile(relativeFilePath: string): boolean { |
| 11 | + const fileName = path.basename(relativeFilePath) |
| 12 | + const ext = path.extname(relativeFilePath).toLowerCase() |
| 13 | + const pathSegments = relativeFilePath.split(path.sep) |
| 14 | + |
| 15 | + // Lock files |
| 16 | + if ( |
| 17 | + fileName === "package-lock.json" || |
| 18 | + fileName === "yarn.lock" || |
| 19 | + fileName === "pnpm-lock.yaml" || |
| 20 | + fileName === "bun.lockb" || |
| 21 | + fileName === "npm-shrinkwrap.json" || |
| 22 | + fileName === "Gemfile.lock" || |
| 23 | + fileName === "Cargo.lock" || |
| 24 | + fileName === "poetry.lock" || |
| 25 | + fileName === "composer.lock" || |
| 26 | + fileName === "Pipfile.lock" |
| 27 | + ) { |
| 28 | + return true |
| 29 | + } |
| 30 | + |
| 31 | + // Build artifacts and compiled output |
| 32 | + if ( |
| 33 | + ext === ".o" || |
| 34 | + ext === ".pyc" || |
| 35 | + ext === ".pyo" || |
| 36 | + ext === ".class" || |
| 37 | + ext === ".dll" || |
| 38 | + ext === ".exe" || |
| 39 | + ext === ".so" || |
| 40 | + ext === ".dylib" || |
| 41 | + ext === ".min.js" || |
| 42 | + ext === ".min.css" || |
| 43 | + ext === ".bundle.js" || |
| 44 | + ext === ".map" |
| 45 | + ) { |
| 46 | + return true |
| 47 | + } |
| 48 | + |
| 49 | + // Build and output directories |
| 50 | + if ( |
| 51 | + pathSegments.includes(".next") || |
| 52 | + pathSegments.includes(".nuxt") || |
| 53 | + pathSegments.includes(".svelte-kit") || |
| 54 | + pathSegments.includes(".angular") || |
| 55 | + pathSegments.includes("__pycache__") |
| 56 | + ) { |
| 57 | + return true |
| 58 | + } |
| 59 | + |
| 60 | + // Temporary files |
| 61 | + if ( |
| 62 | + ext === ".cache" || |
| 63 | + ext === ".tmp" || |
| 64 | + ext === ".swp" || |
| 65 | + ext === ".swo" || |
| 66 | + fileName === ".DS_Store" || |
| 67 | + fileName === "Thumbs.db" |
| 68 | + ) { |
| 69 | + return true |
| 70 | + } |
| 71 | + |
| 72 | + // Binary and media files |
| 73 | + if ( |
| 74 | + ext === ".png" || |
| 75 | + ext === ".jpg" || |
| 76 | + ext === ".jpeg" || |
| 77 | + ext === ".gif" || |
| 78 | + ext === ".ico" || |
| 79 | + ext === ".svg" || |
| 80 | + ext === ".pdf" || |
| 81 | + ext === ".zip" || |
| 82 | + ext === ".tar" || |
| 83 | + ext === ".gz" || |
| 84 | + ext === ".rar" || |
| 85 | + ext === ".7z" || |
| 86 | + ext === ".woff" || |
| 87 | + ext === ".woff2" || |
| 88 | + ext === ".ttf" || |
| 89 | + ext === ".eot" || |
| 90 | + ext === ".otf" || |
| 91 | + ext === ".mp4" || |
| 92 | + ext === ".mov" || |
| 93 | + ext === ".avi" || |
| 94 | + ext === ".webm" || |
| 95 | + ext === ".mp3" || |
| 96 | + ext === ".wav" |
| 97 | + ) { |
| 98 | + return true |
| 99 | + } |
| 100 | + |
| 101 | + // Database files |
| 102 | + if (ext === ".db" || ext === ".sqlite" || ext === ".sqlite3") { |
| 103 | + return true |
| 104 | + } |
| 105 | + |
| 106 | + // Dependency directories (usually gitignored but sometimes checked in) |
| 107 | + if (pathSegments.includes("node_modules") || pathSegments.includes(".venv")) { |
| 108 | + return true |
| 109 | + } |
| 110 | + |
| 111 | + // Package manager metadata |
| 112 | + if ( |
| 113 | + pathSegments.includes(".yarn") || |
| 114 | + pathSegments.includes(".npm") || |
| 115 | + pathSegments.includes(".pnp") || |
| 116 | + fileName.endsWith(".pnp.cjs") || |
| 117 | + fileName.endsWith(".pnp.js") |
| 118 | + ) { |
| 119 | + return true |
| 120 | + } |
| 121 | + |
| 122 | + // Framework-specific generated files |
| 123 | + if ( |
| 124 | + ext === ".g.dart" || |
| 125 | + ext === ".pb.go" || |
| 126 | + fileName.endsWith(".generated.ts") || |
| 127 | + fileName.endsWith(".generated.js") |
| 128 | + ) { |
| 129 | + return true |
| 130 | + } |
| 131 | + |
| 132 | + // VSCode extension specific |
| 133 | + if (ext === ".vsix") { |
| 134 | + return true |
| 135 | + } |
| 136 | + |
| 137 | + return false |
| 138 | +} |
0 commit comments