refactor(grep): replace glob dependency with fs.readdirSync

- Add findFileRecursive function using native Node.js fs API
- Remove glob package from dependencies
- Add unit tests for findFileRecursive

🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
YeonGyu-Kim
2025-12-14 13:02:50 +09:00
parent 3d44186701
commit a2a6690c71
4 changed files with 126 additions and 29 deletions
+23 -13
View File
@@ -1,7 +1,21 @@
import { existsSync, mkdirSync, chmodSync, unlinkSync } from "node:fs"
import { existsSync, mkdirSync, chmodSync, unlinkSync, readdirSync } from "node:fs"
import { join } from "node:path"
import { spawn } from "bun"
export function findFileRecursive(dir: string, filename: string): string | null {
try {
const entries = readdirSync(dir, { withFileTypes: true, recursive: true })
for (const entry of entries) {
if (entry.isFile() && entry.name === filename) {
return join(entry.parentPath ?? dir, entry.name)
}
}
} catch {
return null
}
return null
}
const RG_VERSION = "14.1.1"
const PLATFORM_CONFIG: Record<string, { platform: string; extension: "tar.gz" | "zip" } | undefined> = {
@@ -70,14 +84,12 @@ async function extractZipWindows(archivePath: string, destDir: string): Promise<
throw new Error("Failed to extract zip with PowerShell")
}
const { globSync } = await import("glob")
const rgFiles = globSync("**/rg.exe", { cwd: destDir })
if (rgFiles.length > 0) {
const srcPath = join(destDir, rgFiles[0])
const foundPath = findFileRecursive(destDir, "rg.exe")
if (foundPath) {
const destPath = join(destDir, "rg.exe")
if (srcPath !== destPath) {
if (foundPath !== destPath) {
const { renameSync } = await import("node:fs")
renameSync(srcPath, destPath)
renameSync(foundPath, destPath)
}
}
}
@@ -92,14 +104,12 @@ async function extractZipUnix(archivePath: string, destDir: string): Promise<voi
throw new Error("Failed to extract zip")
}
const { globSync } = await import("glob")
const rgFiles = globSync("**/rg", { cwd: destDir })
if (rgFiles.length > 0) {
const srcPath = join(destDir, rgFiles[0])
const foundPath = findFileRecursive(destDir, "rg")
if (foundPath) {
const destPath = join(destDir, "rg")
if (srcPath !== destPath) {
if (foundPath !== destPath) {
const { renameSync } = await import("node:fs")
renameSync(srcPath, destPath)
renameSync(foundPath, destPath)
}
}
}