refactor: prefer fs.readJSON over readFile.then(JSON.parse) (#7186)

* refactor: prefer fs.readJSON over readFile.then(JSON.parse)

* refactor: use promises
This commit is contained in:
Joshua Chen 2022-04-17 12:50:09 +08:00 committed by GitHub
parent 674a77f02d
commit 200009008b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 27 additions and 33 deletions

View file

@ -111,9 +111,7 @@ async function doRender(locals: Locals & {path: string}) {
const {generatedFilesDir} = locals;
const manifestPath = path.join(generatedFilesDir, 'client-manifest.json');
const manifest: Manifest = JSON.parse(
await fs.readFile(manifestPath, 'utf8'),
);
const manifest: Manifest = await fs.readJSON(manifestPath);
// Get all required assets for this particular page based on client
// manifest information.

View file

@ -58,7 +58,7 @@ async function readTranslationFileContent(
): Promise<TranslationFileContent | undefined> {
if (await fs.pathExists(filePath)) {
try {
const content = JSON.parse(await fs.readFile(filePath, 'utf8'));
const content = await fs.readJSON(filePath);
ensureTranslationFileContent(content);
return content;
} catch (err) {