refactor: normalize filesystem API usage

pull/5341/head
Divyansh Singh 6 days ago
parent 3f4530b0e2
commit b8ec0b563a

@ -248,7 +248,7 @@ export async function resolveUserConfig(
resolve(root, `config/index.${ext}`),
resolve(root, `config.${ext}`)
])
.find(fs.existsSync)
.find((p) => fs.existsSync(p))
let userConfig: RawConfigExports = {}
let configDeps: string[] = []

@ -121,7 +121,7 @@ export function createContentLoader<T = ContentData[]>(
if (cached && timestamp === cached.timestamp) return cached.data
const src = fs.readFileSync(file, 'utf-8')
const src = fs.readFileSync(file, 'utf8')
const renderExcerpt = options.excerpt
const { data: frontmatter, excerpt } = matter(

@ -178,7 +178,7 @@ export function scaffold({
const pkgPath = path.resolve('package.json')
const userPkg = fs.existsSync(pkgPath)
? JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
? JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
: {}
const useMjs = userPkg.type !== 'module'
@ -197,7 +197,7 @@ export function scaffold({
targetPath = path.resolve(resolvedSrcDir, file)
}
const content = fs.readFileSync(filePath, 'utf-8')
const content = fs.readFileSync(filePath, 'utf8')
const compiled = template(content)(data)
fs.mkdirSync(path.dirname(targetPath), { recursive: true })

@ -157,7 +157,7 @@ export const dynamicRoutesPlugin = async (
moduleGraph.add(id, [routeFile])
moduleGraph.add(routeFile, [matched.loaderPath])
let baseContent = fs.readFileSync(routeFile, 'utf-8')
let baseContent = fs.readFileSync(routeFile, 'utf8')
// inject raw content
// this is intended for integration with CMS

@ -54,7 +54,7 @@ export async function localSearchPlugin(
const { srcDir, cleanUrls = false } = siteConfig
const relativePath = slash(path.relative(srcDir, file))
const env: MarkdownEnv = { path: file, relativePath, cleanUrls }
const md_raw = await readFile(file, 'utf-8')
const md_raw = await readFile(file, 'utf8')
const md_src = processIncludes(md, srcDir, md_raw, file, [], cleanUrls)
if (options._render) {
return await options._render(md_src, env, md)

@ -36,7 +36,7 @@ export function processIncludes(
? path.join(srcDir, m1.slice(m1[1] === '/' ? 2 : 1))
: path.join(path.dirname(file), m1)
let content = fs.readFileSync(includePath, 'utf-8')
let content = fs.readFileSync(includePath, 'utf8')
if (region) {
const [regionName] = region

Loading…
Cancel
Save