mirror of https://github.com/vuejs/vitepress
Adds readTextFile/readTextFileSync (CRLF/CR -> LF) next to the raw retrying readFile and switches the markdown-source readers to them (content loader, dynamic route templates, local search, includes). Raw reads stay in place where bytes must be preserved (serve, init scaffolding). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>unmerged-prs-triage
parent
b303dd341d
commit
6a4a977ce5
@ -0,0 +1,34 @@
|
|||||||
|
import { mkdtemp, rm, writeFile } from 'node:fs/promises'
|
||||||
|
import { tmpdir } from 'node:os'
|
||||||
|
import path from 'node:path'
|
||||||
|
import { readFile, readTextFile, readTextFileSync } from 'node/utils/fs'
|
||||||
|
|
||||||
|
describe('node/utils/fs', () => {
|
||||||
|
let root: string
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
root = await mkdtemp(path.join(tmpdir(), 'vitepress-fs-'))
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
await rm(root, { recursive: true, force: true })
|
||||||
|
})
|
||||||
|
|
||||||
|
test('readFile keeps line endings as is', async () => {
|
||||||
|
const file = path.join(root, 'crlf.txt')
|
||||||
|
await writeFile(file, 'a\r\nb\rc\nd')
|
||||||
|
expect(await readFile(file)).toBe('a\r\nb\rc\nd')
|
||||||
|
})
|
||||||
|
|
||||||
|
test('readTextFile normalizes CRLF and CR to LF', async () => {
|
||||||
|
const file = path.join(root, 'crlf.txt')
|
||||||
|
await writeFile(file, 'a\r\nb\rc\nd')
|
||||||
|
expect(await readTextFile(file)).toBe('a\nb\nc\nd')
|
||||||
|
})
|
||||||
|
|
||||||
|
test('readTextFileSync normalizes CRLF and CR to LF', async () => {
|
||||||
|
const file = path.join(root, 'crlf.txt')
|
||||||
|
await writeFile(file, 'a\r\nb\rc\nd')
|
||||||
|
expect(readTextFileSync(file)).toBe('a\nb\nc\nd')
|
||||||
|
})
|
||||||
|
})
|
||||||
Loading…
Reference in new issue