fix: use sync fs methods in writeFileTree (#2341)

closes #2275

Iterating over async functions would put too many write calls in I/O
queue in the same time, leading to weird bugs.
This commit is contained in:
Haoqun Jiang
2018-09-03 22:34:53 +08:00
committed by GitHub
parent 5efbd1b632
commit ba15fa26b2

View File

@@ -19,9 +19,9 @@ module.exports = async function writeFileTree (dir, files, previousFiles) {
if (previousFiles) {
await deleteRemovedFiles(dir, files, previousFiles)
}
return Promise.all(Object.keys(files).map(async (name) => {
Object.keys(files).forEach((name) => {
const filePath = path.join(dir, name)
await fs.ensureDir(path.dirname(filePath))
await fs.writeFile(filePath, files[name])
}))
fs.ensureDirSync(path.dirname(filePath))
fs.writeFileSync(filePath, files[name])
})
}