2021-10-02 16:01:17 +00:00
|
|
|
import { join } 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
|
2022-08-26 15:47:29 +00:00
|
|
|
const _fs: IFs & { join?(...paths: string[]): string } = { ...fs } as any
|
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
|
2021-10-02 16:01:17 +00:00
|
|
|
_fs.join = join
|
2020-07-02 13:02:35 +00:00
|
|
|
|
|
|
|
// Used by vue-renderer
|
|
|
|
_fs.exists = p => Promise.resolve(_fs.existsSync(p))
|
2023-04-14 12:53:21 +00:00
|
|
|
// @ts-expect-error need better types for `pify`
|
2020-07-02 13:02:35 +00:00
|
|
|
_fs.readFile = pify(_fs.readFile)
|
|
|
|
|
2022-02-25 19:11:01 +00:00
|
|
|
return _fs as IFs & { join?(...paths: string[]): string }
|
2020-07-02 13:02:35 +00:00
|
|
|
}
|