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:
parent
af48b7de5f
commit
8409d56fdf
@ -21,6 +21,8 @@ const fsInjectable = getInjectable({
|
|||||||
rm,
|
rm,
|
||||||
access,
|
access,
|
||||||
},
|
},
|
||||||
|
ensureDir,
|
||||||
|
ensureDirSync,
|
||||||
readFileSync,
|
readFileSync,
|
||||||
readJson,
|
readJson,
|
||||||
writeJson,
|
writeJson,
|
||||||
@ -48,6 +50,8 @@ const fsInjectable = getInjectable({
|
|||||||
rm,
|
rm,
|
||||||
access,
|
access,
|
||||||
copy: copy as (src: string, dest: string, options?: fse.CopyOptions) => Promise<void>,
|
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,
|
causesSideEffects: true,
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import type { DiContainer } from "@ogre-tools/injectable";
|
|||||||
import fsInjectable from "../common/fs/fs.injectable";
|
import fsInjectable from "../common/fs/fs.injectable";
|
||||||
import { createFsFromVolume, Volume } from "memfs";
|
import { createFsFromVolume, Volume } from "memfs";
|
||||||
import type {
|
import type {
|
||||||
|
ensureDirSync as ensureDirSyncImpl,
|
||||||
readJsonSync as readJsonSyncImpl,
|
readJsonSync as readJsonSyncImpl,
|
||||||
writeJsonSync as writeJsonSyncImpl,
|
writeJsonSync as writeJsonSyncImpl,
|
||||||
} from "fs-extra";
|
} from "fs-extra";
|
||||||
@ -32,6 +33,13 @@ export const getOverrideFsWithFakes = () => {
|
|||||||
|
|
||||||
root.writeFileSync(file, JSON.stringify(object, options?.replacer, options?.spaces), options as any);
|
root.writeFileSync(file, JSON.stringify(object, options?.replacer, options?.spaces), options as any);
|
||||||
}) as typeof writeJsonSyncImpl;
|
}) 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) => {
|
return (di: DiContainer) => {
|
||||||
di.override(fsInjectable, () => ({
|
di.override(fsInjectable, () => ({
|
||||||
@ -50,6 +58,8 @@ export const getOverrideFsWithFakes = () => {
|
|||||||
rm: root.promises.rm,
|
rm: root.promises.rm,
|
||||||
access: root.promises.access,
|
access: root.promises.access,
|
||||||
copy: async (src, dest) => { throw new Error(`Tried to copy '${src}' to '${dest}'. Copying is not yet supported`); },
|
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,
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user