1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Add ensureDir/Sync support to fake FS

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-12-02 16:15:46 -05:00
parent af48b7de5f
commit 8409d56fdf
2 changed files with 14 additions and 0 deletions

View File

@ -21,6 +21,8 @@ const fsInjectable = getInjectable({
rm,
access,
},
ensureDir,
ensureDirSync,
readFileSync,
readJson,
writeJson,
@ -48,6 +50,8 @@ const fsInjectable = getInjectable({
rm,
access,
copy: copy as (src: string, dest: string, options?: fse.CopyOptions) => Promise<void>,
ensureDir: ensureDir as (path: string, options?: number | fse.EnsureOptions ) => Promise<void>,
ensureDirSync,
};
},
causesSideEffects: true,

View File

@ -6,6 +6,7 @@ import type { DiContainer } from "@ogre-tools/injectable";
import fsInjectable from "../common/fs/fs.injectable";
import { createFsFromVolume, Volume } from "memfs";
import type {
ensureDirSync as ensureDirSyncImpl,
readJsonSync as readJsonSyncImpl,
writeJsonSync as writeJsonSyncImpl,
} from "fs-extra";
@ -32,6 +33,13 @@ export const getOverrideFsWithFakes = () => {
root.writeFileSync(file, JSON.stringify(object, options?.replacer, options?.spaces), options as any);
}) as typeof writeJsonSyncImpl;
const ensureDirSync = ((path, opts) => {
const mode = typeof opts === "number"
? opts
: opts?.mode;
root.mkdirpSync(path, mode);
}) as typeof ensureDirSyncImpl;
return (di: DiContainer) => {
di.override(fsInjectable, () => ({
@ -50,6 +58,8 @@ export const getOverrideFsWithFakes = () => {
rm: root.promises.rm,
access: root.promises.access,
copy: async (src, dest) => { throw new Error(`Tried to copy '${src}' to '${dest}'. Copying is not yet supported`); },
ensureDir: async (path, opts) => ensureDirSync(path, opts),
ensureDirSync,
}));
};
};