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

@ -103,8 +103,7 @@ function isValidGitRepoUrl(gitRepoUrl: string) {
}
async function updatePkg(pkgPath: string, obj: {[key: string]: unknown}) {
const content = await fs.readFile(pkgPath, 'utf-8');
const pkg = JSON.parse(content);
const pkg = await fs.readJSON(pkgPath);
const newPkg = Object.assign(pkg, obj);
await fs.outputFile(pkgPath, `${JSON.stringify(newPkg, null, 2)}\n`);