Skip to content

Commit

Permalink
fix: incorrect usage of fs.mkdir which does not return a promise
Browse files Browse the repository at this point in the history
Need to use `fs.promises.mkdir` instead. Also switched this to
a little more readable part.
  • Loading branch information
devversion committed Aug 20, 2022
1 parent 4cabdcb commit be5539e
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions base/services/writeFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
};

0 comments on commit be5539e

Please sign in to comment.