(filePath: string)
| 73 | * readSync(4KB). |
| 74 | */ |
| 75 | export function readFileSyncWithMetadata(filePath: string): { |
| 76 | content: string |
| 77 | encoding: BufferEncoding |
| 78 | lineEndings: LineEndingType |
| 79 | } { |
| 80 | const fs = getFsImplementation() |
| 81 | const { resolvedPath, isSymlink } = safeResolvePath(fs, filePath) |
| 82 | |
| 83 | if (isSymlink) { |
| 84 | logForDebugging(`Reading through symlink: ${filePath} -> ${resolvedPath}`) |
| 85 | } |
| 86 | |
| 87 | const encoding = detectEncodingForResolvedPath(resolvedPath) |
| 88 | const raw = fs.readFileSync(resolvedPath, { encoding }) |
| 89 | // Detect line endings from the raw head before CRLF normalization erases |
| 90 | // the distinction. 4096 code units is ≥ detectLineEndings's 4096-byte |
| 91 | // readSync sample (line endings are ASCII, so the unit mismatch is moot). |
| 92 | const lineEndings = detectLineEndingsForString(raw.slice(0, 4096)) |
| 93 | return { |
| 94 | content: raw.replaceAll('\r\n', '\n'), |
| 95 | encoding, |
| 96 | lineEndings, |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | export function readFileSync(filePath: string): string { |
| 101 | return readFileSyncWithMetadata(filePath).content |
no test coverage detected