-
Notifications
You must be signed in to change notification settings - Fork 1
/
fs.ts
26 lines (25 loc) · 841 Bytes
/
fs.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import * as memfs from 'memfs'
/**
* isomorphic-git calls the async versions of file system APIs. But they _can_ all execute synchronously.
* So shim all the promisified functions to just call the sync equivalents.
*/
export const setupMemfs = () => {
const vol = new memfs.Volume()
const fs = memfs.createFsFromVolume(vol)
Object.assign(fs, {
promises: {
// shim the "promises" to be actually sync!
readFile: fs.readFileSync.bind(fs),
writeFile: fs.writeFileSync.bind(fs),
mkdir: fs.mkdirSync.bind(fs),
rmdir: fs.rmdirSync.bind(fs),
unlink: fs.unlinkSync.bind(fs),
stat: fs.statSync.bind(fs),
lstat: fs.lstatSync.bind(fs),
readdir: fs.readdirSync.bind(fs),
readlink: fs.readlinkSync.bind(fs),
symlink: fs.symlinkSync.bind(fs),
},
})
return {fs, vol}
}