(params: {
fullDirPath: string
projectRoot: string
fs: CodebuffFileSystem
})
| 190 | } |
| 191 | |
| 192 | export async function parseGitignore(params: { |
| 193 | fullDirPath: string |
| 194 | projectRoot: string |
| 195 | fs: CodebuffFileSystem |
| 196 | }): Promise<ignore.Ignore> { |
| 197 | const { fullDirPath, projectRoot, fs } = params |
| 198 | |
| 199 | const ig = ignore.default() |
| 200 | const relativeDirPath = path.relative(projectRoot, fullDirPath) |
| 201 | const ignoreFiles = [ |
| 202 | path.join(fullDirPath, '.gitignore'), |
| 203 | path.join(fullDirPath, '.codebuffignore'), |
| 204 | path.join(fullDirPath, '.manicodeignore'), // Legacy support |
| 205 | ] |
| 206 | |
| 207 | for (const ignoreFilePath of ignoreFiles) { |
| 208 | const ignoreFileExists = await fileExists({ filePath: ignoreFilePath, fs }) |
| 209 | if (!ignoreFileExists) continue |
| 210 | |
| 211 | let ignoreContent: string |
| 212 | try { |
| 213 | ignoreContent = await fs.readFile(ignoreFilePath, 'utf8') |
| 214 | } catch (error: unknown) { |
| 215 | // Ignore file may be inaccessible or deleted after existence check. |
| 216 | // Log with context for debugging, but continue without these ignore rules. |
| 217 | logFileTreeError('fs.readFile (ignore file)', ignoreFilePath, error) |
| 218 | continue |
| 219 | } |
| 220 | const lines = ignoreContent.split('\n') |
| 221 | for (let line of lines) { |
| 222 | line = line.trim() |
| 223 | if (line === '' || line.startsWith('#')) continue |
| 224 | |
| 225 | const finalPattern = rebaseGitignorePattern(line, relativeDirPath) |
| 226 | |
| 227 | ig.add(finalPattern) |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | return ig |
| 232 | } |
| 233 | |
| 234 | export function getAllFilePaths( |
| 235 | nodes: FileTreeNode[], |
no test coverage detected