MCPcopy Index your code
hub / github.com/codeaashu/claude-code / findMarkdownFilesNative

Function findMarkdownFilesNative

src/utils/markdownConfigLoader.ts:451–539  ·  view source on GitHub ↗

* Native implementation to find markdown files using Node.js fs APIs * * This implementation exists alongside ripgrep for the following reasons: * 1. Ripgrep has poor startup performance in native builds (noticeable on app startup) * 2. Provides a fallback when ripgrep is unavailable * 3. Can b

(
  dir: string,
  signal: AbortSignal,
)

Source from the content-addressed store, hash-verified

449 * @returns Array of file paths
450 */
451async function findMarkdownFilesNative(
452 dir: string,
453 signal: AbortSignal,
454): Promise<string[]> {
455 const files: string[] = []
456 const visitedDirs = new Set<string>()
457
458 async function walk(currentDir: string): Promise<void> {
459 if (signal.aborted) {
460 return
461 }
462
463 // Cycle detection: track visited directories by device+inode
464 // Uses bigint: true to handle filesystems with large inodes (e.g., ExFAT)
465 // that exceed JavaScript's Number precision (53 bits).
466 // See: https://github.com/anthropics/claude-code/issues/13893
467 try {
468 const stats = await stat(currentDir, { bigint: true })
469 if (stats.isDirectory()) {
470 const dirKey =
471 stats.dev !== undefined && stats.ino !== undefined
472 ? `${stats.dev}:${stats.ino}` // Unix/Linux: device + inode
473 : await realpath(currentDir) // Windows: canonical path
474
475 if (visitedDirs.has(dirKey)) {
476 logForDebugging(
477 `Skipping already visited directory (circular symlink): ${currentDir}`,
478 )
479 return
480 }
481 visitedDirs.add(dirKey)
482 }
483 } catch (error) {
484 const errorMessage =
485 error instanceof Error ? error.message : String(error)
486 logForDebugging(`Failed to stat directory ${currentDir}: ${errorMessage}`)
487 return
488 }
489
490 try {
491 const entries = await readdir(currentDir, { withFileTypes: true })
492
493 for (const entry of entries) {
494 if (signal.aborted) {
495 break
496 }
497
498 const fullPath = join(currentDir, entry.name)
499
500 try {
501 // Handle symlinks: isFile() and isDirectory() return false for symlinks
502 if (entry.isSymbolicLink()) {
503 try {
504 const stats = await stat(fullPath) // stat() follows symlinks
505 if (stats.isDirectory()) {
506 await walk(fullPath)
507 } else if (stats.isFile() && entry.name.endsWith('.md')) {
508 files.push(fullPath)

Callers 1

loadMarkdownFilesFunction · 0.85

Calls 1

walkFunction · 0.70

Tested by

no test coverage detected