(params: {
filePath: string
projectRoot: string
fs: CodebuffFileSystem
})
| 287 | } |
| 288 | |
| 289 | export async function isFileIgnored(params: { |
| 290 | filePath: string |
| 291 | projectRoot: string |
| 292 | fs: CodebuffFileSystem |
| 293 | }): Promise<boolean> { |
| 294 | const { filePath, projectRoot, fs } = params |
| 295 | |
| 296 | const defaultIgnore = ignore.default() |
| 297 | for (const pattern of DEFAULT_IGNORED_PATHS) { |
| 298 | defaultIgnore.add(pattern) |
| 299 | } |
| 300 | |
| 301 | const relativeFilePath = path.relative( |
| 302 | projectRoot, |
| 303 | path.join(projectRoot, filePath), |
| 304 | ) |
| 305 | const dirPath = path.dirname(path.join(projectRoot, filePath)) |
| 306 | |
| 307 | // Get ignore patterns from the directory containing the file and all parent directories |
| 308 | const mergedIgnore = ignore.default().add(defaultIgnore) |
| 309 | let currentDir = dirPath |
| 310 | while (currentDir.startsWith(projectRoot)) { |
| 311 | mergedIgnore.add( |
| 312 | await parseGitignore({ fullDirPath: currentDir, projectRoot, fs }), |
| 313 | ) |
| 314 | currentDir = path.dirname(currentDir) |
| 315 | } |
| 316 | |
| 317 | return mergedIgnore.ignores(relativeFilePath) |
| 318 | } |
no test coverage detected