2026-02-12 12:12:40 +01:00
|
|
|
import { lstatSync, realpathSync } from "fs"
|
2026-01-05 14:18:42 +09:00
|
|
|
import { promises as fs } from "fs"
|
2025-12-13 14:23:04 +09:00
|
|
|
|
2026-02-14 22:06:13 +09:00
|
|
|
function normalizeDarwinRealpath(filePath: string): string {
|
|
|
|
|
return filePath.startsWith("/private/var/") ? filePath.slice("/private".length) : filePath
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-13 14:23:04 +09:00
|
|
|
export function isMarkdownFile(entry: { name: string; isFile: () => boolean }): boolean {
|
|
|
|
|
return !entry.name.startsWith(".") && entry.name.endsWith(".md") && entry.isFile()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function isSymbolicLink(filePath: string): boolean {
|
|
|
|
|
try {
|
|
|
|
|
return lstatSync(filePath, { throwIfNoEntry: false })?.isSymbolicLink() ?? false
|
|
|
|
|
} catch {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function resolveSymlink(filePath: string): string {
|
|
|
|
|
try {
|
2026-02-14 22:06:13 +09:00
|
|
|
return normalizeDarwinRealpath(realpathSync(filePath))
|
2025-12-13 14:23:04 +09:00
|
|
|
} catch {
|
|
|
|
|
return filePath
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-01-05 14:18:42 +09:00
|
|
|
|
|
|
|
|
export async function resolveSymlinkAsync(filePath: string): Promise<string> {
|
|
|
|
|
try {
|
2026-02-14 22:06:13 +09:00
|
|
|
return normalizeDarwinRealpath(await fs.realpath(filePath))
|
2026-01-05 14:18:42 +09:00
|
|
|
} catch {
|
|
|
|
|
return filePath
|
|
|
|
|
}
|
|
|
|
|
}
|