Skip to content

Commit

Permalink
fix: don't monkeypatch fs with promisified versions (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
malept authored Apr 29, 2019
1 parent 82d78f3 commit 319dd81
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/wrapped-fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@ const { promisify } = require('util')
const fs = process.versions.electron ? require('original-fs') : require('fs')
const mkdirp = require('mkdirp')

const methods = [
const promisifiedMethods = [
'lstat',
'readFile',
'stat',
'writeFile'
]

for (const method of methods) {
fs[method] = promisify(fs[method])
const promisified = {}

for (const method of Object.keys(fs)) {
if (promisifiedMethods.includes(method)) {
promisified[method] = promisify(fs[method])
} else {
promisified[method] = fs[method]
}
}
// To make it more like fs-extra
fs.mkdirp = promisify(mkdirp)
fs.mkdirpSync = mkdirp.sync
promisified.mkdirp = promisify(mkdirp)
promisified.mkdirpSync = mkdirp.sync

module.exports = fs
module.exports = promisified

0 comments on commit 319dd81

Please sign in to comment.