import { path as pathModule } from '../path' import { AsyncFileSystem, FileSystem } from '../fs' import * as JSON5 from 'json5' export async function readJsonAsync(path: string, filename: string, fs: AsyncFileSystem) { const filePath = pathModule.resolve(path, filename) try { const jsonString = await fs.readFile(filePath, { encoding: 'utf8' }) return JSON5.parse(jsonString) } catch (e) { return {} } } export default function readJson(path: string, filename: string, fs: FileSystem) { const filePath = pathModule.resolve(path, filename) try { return JSON5.parse(fs.readFileSync(filePath, { encoding: 'utf-8' })) } catch (e) { throw new Error(`Failed to parse JSON file: ${filePath} (Reason: ${e instanceof Error ? e.message : e})`) } }