From be5539ece8fea10cb04ea92d497f38f78c649e0f Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Sat, 20 Aug 2022 13:52:29 +0000 Subject: [PATCH] fix: incorrect usage of `fs.mkdir` which does not return a promise Need to use `fs.promises.mkdir` instead. Also switched this to a little more readable part. --- base/services/writeFile.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/base/services/writeFile.js b/base/services/writeFile.js index 2fea8c2..4074077 100644 --- a/base/services/writeFile.js +++ b/base/services/writeFile.js @@ -6,12 +6,8 @@ const path = require('canonical-path'); * Write the given contents to a file, ensuring the path to the file exists */ module.exports = function writeFile() { - return (file, content) => - fs.mkdir(path.dirname(file), { recursive: true }) - .then(() => new Promise((resolve, reject) => { - return fs.writeFile(file, content, err => { - if (err) { reject(err); } - resolve(); - }); - })); + return async (file, content) => { + await fs.promises.mkdir(path.dirname(file), {recursive: true}); + await fs.promises.writeFile(file, content); + }; };