2021-09-27 12:49:36 +00:00
|
|
|
import path from 'pathe'
|
2020-07-02 13:02:35 +00:00
|
|
|
import pify from 'pify'
|
|
|
|
import { Volume, createFsFromVolume } from 'memfs'
|
|
|
|
|
2021-02-22 10:04:46 +00:00
|
|
|
import type { IFs } from 'memfs'
|
|
|
|
|
2020-07-02 13:02:35 +00:00
|
|
|
export function createMFS () {
|
|
|
|
// Create a new volume
|
|
|
|
const fs = createFsFromVolume(new Volume())
|
|
|
|
|
|
|
|
// Clone to extend
|
2021-02-22 10:04:46 +00:00
|
|
|
const _fs : Partial<IFs> & { join?(...paths: string[]): string } = { ...fs }
|
2020-07-02 13:02:35 +00:00
|
|
|
|
|
|
|
// fs.join method is (still) expected by webpack-dev-middleware
|
|
|
|
// There might be differences with https://github.com/webpack/memory-fs/blob/master/lib/join.js
|
|
|
|
_fs.join = path.join
|
|
|
|
|
|
|
|
// Used by vue-renderer
|
|
|
|
_fs.exists = p => Promise.resolve(_fs.existsSync(p))
|
|
|
|
_fs.readFile = pify(_fs.readFile)
|
|
|
|
|
|
|
|
return _fs
|
|
|
|
}
|